{-# OPTIONS --safe #-}
module Cubical.Tactics.CommRingSolver.Examples where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Data.Int.Base hiding (ℤ; _+_ ; _·_ ; _-_)
open import Cubical.Data.List
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int
open import Cubical.Algebra.CommAlgebra
open import Cubical.Tactics.CommRingSolver.Reflection
private
variable
ℓ ℓ' : Level
module TestErrors (R : CommRing ℓ) where
open CommRingStr (snd R)
module TestWithℤ where
open CommRingStr (ℤCommRing .snd)
_ : (a b : fst ℤCommRing) → a + b ≡ b + a
_ = solve ℤCommRing
module Test (R : CommRing ℓ) where
open CommRingStr (snd R)
_ : 0r ≡ 0r
_ = solve R
_ : 1r · (1r + 0r)
≡ (1r · 0r) + 1r
_ = solve R
_ : 1r · 0r + (1r - 1r)
≡ 0r - 0r
_ = solve R
_ : ∀ x → x ≡ x
_ = solve R
_ : ∀ x y → x ≡ x
_ = solve R
_ : ∀ x y → x + y ≡ y + x
_ = solve R
_ : ∀ x y → y ≡ (y - x) + x
_ = solve R
_ : ∀ x y → x ≡ (x - y) + y
_ = solve R
_ : ∀ x y → (x + y) · (x - y) ≡ x · x - y · y
_ = solve R
_ : (x y z : (fst R)) → (x + y) · (x + y) · (x + y) · (x + y)
≡ x · x · x · x + (fromℤ R 4) · x · x · x · y + (fromℤ R 6) · x · x · y · y
+ (fromℤ R 4) · x · y · y · y + y · y · y · y
_ = solve R
_ : (x : (fst R)) → x · 0r ≡ 0r
_ = solve R
_ : (x y z : (fst R)) → x · (y - z) ≡ x · y - x · z
_ = solve R
module _ (R : CommRing ℓ) (A : CommAlgebra R ℓ') where
open CommAlgebraStr {{...}}
private
instance
_ = (snd A)
_ : (x y : ⟨ A ⟩) → x + y ≡ y + x
_ = solve (CommAlgebra→CommRing A)
module TestInPlaceSolving (R : CommRing ℓ) where
open CommRingStr (snd R)
testWithOneVariabl : (x : fst R) → x + 0r ≡ 0r + x
testWithOneVariabl x = solveInPlace R (x ∷ [])
testWithTwoVariables : (x y : fst R) → x + y ≡ y + x
testWithTwoVariables x y =
x + y ≡⟨ solveInPlace R (x ∷ y ∷ []) ⟩
y + x ∎
testEquationalReasoning : (x : fst R) → x + 0r ≡ 0r + x
testEquationalReasoning x =
x + 0r ≡⟨ solveInPlace R (x ∷ []) ⟩
0r + x ∎
testEquationalReasoning' : (p : (y : fst R) → 0r + y ≡ 1r) (x : fst R) → x + 0r ≡ 1r
testEquationalReasoning' p x =
x + 0r ≡⟨ solveInPlace R (x ∷ []) ⟩
0r + x ≡⟨ p x ⟩
1r ∎