File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,10 @@ Deprecated names
139139New modules
140140-----------
141141
142+ * Added tactic ring solvers for rational numbers (issue #1879 ):
143+ ` Data.Rational.Tactic.RingSolver ` ,
144+ ` Data.Rational.Unnormalised.Tactic.RingSolver ` .
145+
142146* ` Algebra.Construct.Sub.Group ` for the definition of subgroups.
143147
144148* ` Algebra.Module.Construct.Sub.Bimodule ` for the definition of subbimodules.
Original file line number Diff line number Diff line change 1+ ------------------------------------------------------------------------
2+ -- The Agda standard library
3+ --
4+ -- Some examples showing where the rational numbers and some related
5+ -- operations and properties are defined, and how they can be used
6+ ------------------------------------------------------------------------
7+
8+ {-# OPTIONS --cubical-compatible #-}
9+
10+ module README.Data.Rational where
11+
12+ open import Data.Integer using (+_)
13+ open import Data.Rational
14+ open import Data.Rational.Properties
15+ open import Relation.Binary.PropositionalEquality using (_≡_; refl)
16+
17+ 1/4 : ℚ
18+ 1/4 = + 1 / 4
19+
20+ 3/4 : ℚ
21+ 3/4 = + 3 / 4
22+
23+ expr : ℚ
24+ expr = (1/4 + ½) * 1ℚ - 0ℚ
25+
26+ eqEx : expr ≡ 3/4
27+ eqEx = refl
28+
29+ open import Data.Rational.Tactic.RingSolver
30+
31+ lemma : ∀ (x y : ℚ) → x + y + 1/4 + ½ ≡ 3/4 + y + x
32+ lemma = solve-∀
Original file line number Diff line number Diff line change 1+ module README.Data.Rational.Unnormalised where
2+
3+ open import Data.Integer using (+_)
4+ open import Data.Rational.Unnormalised
5+ open import Data.Rational.Unnormalised.Properties
6+ open import Relation.Binary.PropositionalEquality using (refl)
7+
8+ 1/4 : ℚᵘ
9+ 1/4 = + 1 / 4
10+
11+ 3/4 : ℚᵘ
12+ 3/4 = + 3 / 4
13+
14+ 6/8 : ℚᵘ
15+ 6/8 = + 6 / 8
16+
17+ expr : ℚᵘ
18+ expr = (1/4 + ½) * 1ℚᵘ - 0ℚᵘ
19+
20+ eqEx : expr ≃ 3/4
21+ eqEx = *≡* refl
22+
23+ open import Data.Rational.Unnormalised.Tactic.RingSolver
24+
25+ lemma₁ : ∀ (x y : ℚᵘ) → x + y + 1/4 + ½ ≃ 6/8 + y + x
26+ lemma₁ = solve-∀
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import Algebra.Lattice.Morphism.LatticeMonomorphism as LatticeMonomorphisms
2727import Algebra.Properties.CommutativeSemigroup as CommSemigroupProperties
2828import Algebra.Properties.Group as GroupProperties
2929open import Data.Bool.Base using (T; true; false)
30+ open import Data.Maybe.Base using (Maybe; just; nothing)
3031open import Data.Integer.Base as ℤ using (ℤ; +_; -[1+_]; +[1+_]; +0; 0ℤ; 1ℤ; _◃_)
3132open import Data.Integer.Coprimality using (coprime-divisor)
3233import Data.Integer.Properties as ℤ
@@ -190,6 +191,11 @@ drop-*≡* (*≡* eq) = eq
190191p≡0⇒↥p≡0 : ∀ p → p ≡ 0ℚ → ↥ p ≡ 0ℤ
191192p≡0⇒↥p≡0 p refl = refl
192193
194+ 0≡?-weak : (p : ℚ) → Maybe (0ℚ ≡ p)
195+ 0≡?-weak p with ↥ p ℤ.≟ 0ℤ
196+ ... | yes ↥p≡0 = just (sym (↥p≡0⇒p≡0 p ↥p≡0))
197+ ... | no _ = nothing
198+
193199↥p≡↥q≡0⇒p≡q : ∀ p q → ↥ p ≡ 0ℤ → ↥ q ≡ 0ℤ → p ≡ q
194200↥p≡↥q≡0⇒p≡q p q ↥p≡0 ↥q≡0 = trans (↥p≡0⇒p≡0 p ↥p≡0) (sym (↥p≡0⇒p≡0 q ↥q≡0))
195201
Original file line number Diff line number Diff line change 1+ ------------------------------------------------------------------------
2+ -- The Agda standard library
3+ --
4+ -- Automatic solvers for equations over rationals
5+ ------------------------------------------------------------------------
6+
7+ -- See README.Tactic.RingSolver for examples of how to use this solver
8+
9+ {-# OPTIONS --cubical-compatible --safe #-}
10+
11+ module Data.Rational.Tactic.RingSolver where
12+
13+ open import Agda.Builtin.Reflection using (Term; TC)
14+ open import Data.Rational.Properties using (+-*-commutativeRing; 0≡?-weak)
15+ open import Level using (0ℓ)
16+ open import Data.Unit.Base using (⊤)
17+
18+ import Tactic.RingSolver as Solver using (solve-macro; solve-∀-macro)
19+ import Tactic.RingSolver.Core.AlmostCommutativeRing as ACR
20+
21+ ------------------------------------------------------------------------
22+ -- A module for automatically solving propositional equalities
23+ -- containing _+_ and _*_
24+
25+ ring : ACR.AlmostCommutativeRing 0ℓ 0ℓ
26+ ring = ACR.fromCommutativeRing
27+ +-*-commutativeRing
28+ 0≡?-weak
29+
30+ macro
31+ solve-∀ : Term → TC ⊤
32+ solve-∀ = Solver.solve-∀-macro (quote ring)
33+
34+ macro
35+ solve : Term → Term → TC ⊤
36+ solve n = Solver.solve-macro n (quote ring)
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ open import Algebra.Construct.NaturalChoice.Base
2828import Algebra.Construct.NaturalChoice.MinMaxOp as MinMaxOp
2929import Algebra.Lattice.Construct.NaturalChoice.MinMaxOp as LatticeMinMaxOp
3030open import Data.Bool.Base using (T; true; false)
31+ open import Data.Maybe.Base using (Maybe; just; nothing)
3132open import Data.Nat.Base as ℕ using (suc; pred)
3233import Data.Nat.Properties as ℕ
3334 using (≤-refl; +-comm; +-identityʳ; +-assoc
@@ -185,6 +186,10 @@ p≃0⇒↥p≡0 p (*≡* eq) = begin
185186↥p≡↥q≡0⇒p≃q : ∀ p q → ↥ p ≡ 0ℤ → ↥ q ≡ 0ℤ → p ≃ q
186187↥p≡↥q≡0⇒p≃q p q ↥p≡0 ↥q≡0 = ≃-trans (↥p≡0⇒p≃0 p ↥p≡0) (≃-sym (↥p≡0⇒p≃0 _ ↥q≡0))
187188
189+ 0≃?-weak : (p : ℚᵘ) → Maybe (0ℚᵘ ≃ p)
190+ 0≃?-weak p with ↥ p ℤ.≟ 0ℤ
191+ ... | yes ↥p≡0 = just (≃-sym (↥p≡0⇒p≃0 p ↥p≡0))
192+ ... | no _ = nothing
188193
189194------------------------------------------------------------------------
190195-- Properties of -_
Original file line number Diff line number Diff line change 1+ ------------------------------------------------------------------------
2+ -- The Agda standard library
3+ --
4+ -- Automatic solvers for equations over unnormalised rationals
5+ ------------------------------------------------------------------------
6+
7+ -- See README.Tactic.RingSolver for examples of how to use this solver
8+
9+ {-# OPTIONS --cubical-compatible --safe #-}
10+
11+ module Data.Rational.Unnormalised.Tactic.RingSolver where
12+
13+ open import Agda.Builtin.Reflection using (Term; TC)
14+ open import Data.Rational.Unnormalised.Properties using (+-*-commutativeRing; 0≃?-weak)
15+ open import Level using (0ℓ)
16+ open import Data.Unit.Base using (⊤)
17+
18+ import Tactic.RingSolver as Solver using (solve-∀-macro; solve-macro)
19+ import Tactic.RingSolver.Core.AlmostCommutativeRing as ACR
20+
21+ ------------------------------------------------------------------------
22+ -- A module for automatically solving propositional equivalences
23+ -- containing _+_ and _*_
24+
25+ ring : ACR.AlmostCommutativeRing 0ℓ 0ℓ
26+ ring = ACR.fromCommutativeRing
27+ +-*-commutativeRing
28+ 0≃?-weak
29+
30+ macro
31+ solve-∀ : Term → TC ⊤
32+ solve-∀ = Solver.solve-∀-macro (quote ring)
33+
34+ macro
35+ solve : Term → Term → TC ⊤
36+ solve n = Solver.solve-macro n (quote ring)
You can’t perform that action at this time.
0 commit comments