Source code on Github{-# OPTIONS --safe --without-K #-}
module Tactic.Solver.Ring.Tests.EdgeCases where
open import Algebra using (CommutativeRing; CommutativeSemiring)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Tactic.Solver.Ring using (solve-≈)
module GoalTypeAlias where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
Goal : ℕ → ℕ → Set
Goal a b = a + b ≡ b + a
test : ∀ a b → Goal a b
test a b = solve-≈ +-*-commutativeSemiring
module GoalSideAlias where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
myExpr : ℕ → ℕ → ℕ
myExpr a b = a + b
test : ∀ a b → myExpr a b ≡ b + a
test a b = solve-≈ +-*-commutativeSemiring
module FoldrExposed where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
open import Data.List using (foldr; _∷_; [])
test : ∀ a b → foldr _+_ 0 (a ∷ b ∷ []) ≡ b + a
test a b = solve-≈ +-*-commutativeSemiring
module HiddenPis where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
hidden : ∀ {a b} → a + b ≡ b + a
hidden = solve-≈ +-*-commutativeSemiring
mixed : ∀ {a} b → a + b ≡ b + a
mixed = solve-≈ +-*-commutativeSemiring
module ProjectionLiterals where
open import Data.Nat using (ℕ)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
open CommutativeSemiring +-*-commutativeSemiring using (_≈_; _*_; _+_; 1#; 0#)
one-mul : ∀ a → 1# * a ≈ a
one-mul a = solve-≈ +-*-commutativeSemiring
zero-add : ∀ a → 0# + a ≈ a
zero-add a = solve-≈ +-*-commutativeSemiring
module ProjectionLiteralsℚ where
import Data.Rational.Properties as ℚP
open CommutativeRing ℚP.+-*-commutativeRing using (_≈_; _*_; 1#)
one-mul : ∀ q → 1# * q ≈ q
one-mul q = solve-≈ ℚP.+-*-commutativeRing
module ℚSubNeg where
open import Data.Rational using (ℚ; 0ℚ; _+_; _*_; _-_; -_)
import Data.Rational.Properties as ℚP
sub-comm : ∀ p q → p - q ≡ - q + p
sub-comm p q = solve-≈ ℚP.+-*-commutativeRing
neg-zero : - 0ℚ ≡ 0ℚ
neg-zero = solve-≈ ℚP.+-*-commutativeRing
neg-distrib : ∀ p q → - (p + q) ≡ - p - q
neg-distrib p q = solve-≈ ℚP.+-*-commutativeRing
module NegLiteral where
open import Data.Integer using (ℤ; +_; _+_; _*_; -_)
open import Data.Integer.Properties using (+-*-commutativeRing)
neg-lit : ∀ a → - (+ 1) * a ≡ - a
neg-lit a = solve-≈ +-*-commutativeRing
module ℤLiteralAliases where
open import Data.Integer using (ℤ; 0ℤ; 1ℤ; +_; _+_; _*_)
open import Data.Integer.Properties using (+-*-commutativeSemiring)
one-mul : ∀ a → 1ℤ * a ≡ a
one-mul a = solve-≈ +-*-commutativeSemiring
zero-add : ∀ a → 0ℤ + a ≡ a
zero-add a = solve-≈ +-*-commutativeSemiring
two : 1ℤ + 1ℤ ≡ + 2
two = solve-≈ +-*-commutativeSemiring
module ℕZero where
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
zero-mul : ∀ a → a * 0 ≡ 0
zero-mul a = solve-≈ +-*-commutativeSemiring
module InlineAccessor where
open import Data.Rational using (ℚ; 1ℚ; _+_; _*_)
import Data.Rational.Properties as ℚP
one-mul : ∀ q → q * 1ℚ ≡ q
one-mul q = solve-≈ (CommutativeRing.commutativeSemiring ℚP.+-*-commutativeRing)
module WhereBundle where
open import Data.Integer as ℤ using (ℤ)
import Data.Integer.Properties as ℤP
test : ∀ (a b : ℤ) → a ℤ.+ b ≡ b ℤ.+ a
test a b = solve-≈ myR
where
myR : CommutativeSemiring _ _
myR = record
{ Carrier = ℤ ; _≈_ = _≡_
; _+_ = ℤ._+_ ; _*_ = ℤ._*_
; 0# = ℤ.+ 0 ; 1# = ℤ.+ 1
; isCommutativeSemiring = ℤP.+-*-isCommutativeSemiring
}
module BigLiteral where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
test : ∀ a → 100 + a ≡ a + 100
test a = solve-≈ +-*-commutativeSemiring
module ViaSetoid where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
open import Relation.Binary using (Setoid)
open CommutativeSemiring +-*-commutativeSemiring using (setoid)
test : ∀ a b → Setoid._≈_ setoid (a + b) (b + a)
test a b = solve-≈ +-*-commutativeSemiring
module UnderTrans where
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Nat.Properties using (+-*-commutativeSemiring; *-comm)
open import Relation.Binary.PropositionalEquality using (trans; sym)
test : ∀ a b → (a + b) * a ≡ a * a + b * a
test a b = trans (*-comm (a + b) a) (solve-≈ +-*-commutativeSemiring)
module NegativeLiterals where
open import Data.Integer using (ℤ; -1ℤ; 1ℤ; -[1+_]; +_; _+_; _*_; -_)
open import Data.Integer.Properties using (+-*-commutativeRing)
neg-one-mul : ∀ a → -1ℤ * a ≡ - a
neg-one-mul a = solve-≈ +-*-commutativeRing
neg-lit-add : -[1+ 1 ] + (+ 2) ≡ + 0
neg-lit-add = solve-≈ +-*-commutativeRing
neg-times-neg : -1ℤ * -1ℤ ≡ 1ℤ
neg-times-neg = solve-≈ +-*-commutativeRing
module AtomSpelling where
open import Data.Rational using (ℚ; ½; _+_; _*_)
import Data.Rational.Properties as ℚP
q₁ q₂ : ℚ
q₁ = ½
q₂ = ½
spelled : ∀ q → q₁ + q ≡ q + q₂
spelled q = solve-≈ ℚP.+-*-commutativeRing
module WrappedSuc where
open import Data.Nat using (suc)
open import Data.Integer using (ℤ; +_; _+_; _*_; -_)
open import Data.Integer.Properties using (+-*-commutativeSemiring; +-*-commutativeRing)
wrapped-suc : ∀ n → + suc n ≡ + n + + 1
wrapped-suc n = solve-≈ +-*-commutativeSemiring
wrapped-suc-cr : ∀ n → + suc (suc n) ≡ + n + + 2
wrapped-suc-cr n = solve-≈ +-*-commutativeRing
mixed : ∀ n → (- (+ suc n)) * (+ 1) ≡ (- (+ 1)) + (- (+ n))
mixed n = solve-≈ +-*-commutativeRing
module NestedUpdates where
open import Data.Integer as ℤ using (ℤ)
import Data.Integer.Properties as ℤP
twice : CommutativeSemiring _ _
twice = record (record ℤP.+-*-commutativeSemiring { 0# = ℤ.+ 0 }) { 1# = ℤ.+ 1 }
open CommutativeSemiring twice
comm+ : ∀ a b → (a + b) ≈ (b + a)
comm+ a b = solve-≈ twice
one-mul : ∀ a → (a * (ℤ.+ 1)) ≈ a
one-mul a = solve-≈ twice
module ExoticBinders where
open import Data.Nat using (ℕ; _+_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
open import Level using (Level)
record Tag : Set where
constructor mkTag
inst : ⦃ _ : Tag ⦄ → ∀ a b → a + b ≡ b + a
inst = solve-≈ +-*-commutativeSemiring
lvl : ∀ {ℓ} (A : Set ℓ) (a b : ℕ) → a + b ≡ b + a
lvl = solve-≈ +-*-commutativeSemiring
module AliasedOperator where
open import Data.Integer as ℤ using (ℤ)
open import Data.Integer.Properties using (+-*-commutativeSemiring)
myPlus : ℤ → ℤ → ℤ
myPlus = ℤ._+_
test : ∀ a b → myPlus a b ≡ b ℤ.+ a
test a b = solve-≈ +-*-commutativeSemiring
module NegsucVariable where
open import Data.Nat using (ℕ)
open import Data.Integer using (ℤ; -[1+_]; _+_)
open import Data.Integer.Properties using (+-*-commutativeRing)
ok : ∀ n a → -[1+ n ] + a ≡ a + -[1+ n ]
ok n a = solve-≈ +-*-commutativeRing
module PerfCanaries where
module ComputedLiteral where
open import Data.Nat using (ℕ; _+_; _^_)
open import Data.Nat.Properties using (+-*-commutativeSemiring)
big : ∀ a → a + 2 ^ 16 ≡ 2 ^ 16 + a
big a = solve-≈ +-*-commutativeSemiring
module ConcreteℚAtoms where
open import Data.Rational using (ℚ; _+_; _/_)
open import Data.Integer using (+_)
import Data.Rational.Properties as ℚP
q₁ q₂ q₃ q₄ q₅ q₆ q₇ q₈ : ℚ
q₁ = + 1 / 2 ; q₂ = + 2 / 3 ; q₃ = + 3 / 4 ; q₄ = + 4 / 5
q₅ = + 5 / 6 ; q₆ = + 6 / 7 ; q₇ = + 7 / 8 ; q₈ = + 8 / 9
shuffle : (q₁ + (q₂ + (q₃ + (q₄ + (q₅ + (q₆ + (q₇ + q₈)))))))
≡ (q₈ + (q₇ + (q₆ + (q₅ + (q₄ + (q₃ + (q₂ + q₁)))))))
shuffle = solve-≈ ℚP.+-*-commutativeRing