Skip to content

Commit 5cd6d3d

Browse files
authored
Agda files
0 parents  commit 5cd6d3d

10 files changed

+7322
-0
lines changed

Continuity.agda

+820
Large diffs are not rendered by default.

ExtraProperties.agda

+302
Large diffs are not rendered by default.

Inverse.agda

+300
Large diffs are not rendered by default.

MetricBase.agda

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
-- Metric spaces definitions and results.
2+
-- Work on this file was discontinued when I realized I would need square roots to define the
3+
-- Cauchy-Schwarz inequality, which would, in turn, require calculus to define.
4+
5+
{-# OPTIONS --without-K --safe #-}
6+
7+
module MetricBase where
8+
9+
open import Algebra
10+
open import Data.Bool.Base using (Bool; if_then_else_)
11+
open import Function.Base using (_∘_)
12+
open import Data.Integer.Base as ℤ
13+
using (ℤ; +_; +0; +[1+_]; -[1+_])
14+
import Data.Integer.Properties as ℤP
15+
open import Data.Integer.DivMod as ℤD
16+
open import Data.Nat as ℕ using (ℕ; zero; suc)
17+
open import Data.Nat.Properties as ℕP using (≤-step)
18+
import Data.Nat.DivMod as ℕD
19+
open import Level using (0ℓ)
20+
open import Data.Product
21+
open import Relation.Nullary
22+
open import Relation.Nullary.Negation using (contraposition)
23+
open import Relation.Nullary.Decidable
24+
open import Relation.Unary using (Pred)
25+
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; refl; cong; sym; subst; trans; ≢-sym)
26+
open import Relation.Binary
27+
open import Data.Rational.Unnormalised as ℚ using (ℚᵘ; mkℚᵘ; _≢0; _/_; 0ℚᵘ; 1ℚᵘ; ↥_; ↧_; ↧ₙ_)
28+
import Data.Rational.Unnormalised.Properties as ℚP
29+
open import Algebra.Bundles
30+
open import Algebra.Structures
31+
open import Data.Empty
32+
open import Data.Sum
33+
open import Data.Maybe.Base
34+
open import Data.List
35+
open import Function.Structures {_} {_} {_} {_} {ℕ} _≡_ {ℕ} _≡_
36+
37+
{-
38+
The solvers are used and renamed often enough to warrant them being opened up here
39+
for the sake of consistency and cleanliness.
40+
-}
41+
open import NonReflectiveZ as ℤ-Solver using ()
42+
renaming
43+
( solve to ℤsolve
44+
; _⊕_ to _:+_
45+
; _⊗_ to _:*_
46+
; _⊖_ to _:-_
47+
; ⊝_ to :-_
48+
; _⊜_ to _:=_
49+
; Κ to ℤΚ
50+
)
51+
open import NonReflectiveQ as ℚ-Solver using ()
52+
renaming
53+
( solve to ℚsolve
54+
; _⊕_ to _+:_
55+
; _⊗_ to _*:_
56+
; _⊖_ to _-:_
57+
; ⊝_ to -:_
58+
; _⊜_ to _=:_
59+
; Κ to ℚΚ
60+
)
61+
62+
open import ExtraProperties
63+
open import Real
64+
open import RealProperties
65+
open import Inverse
66+
open ℝ-Solver
67+
68+
{-
69+
(M,ρ) is a metric space if:
70+
(i) x = y ⇒ ρ x y = 0
71+
(ii) ρ x y ≤ ρ x z + ρ z y
72+
(iii) ρ x y = ρ y x
73+
(iv) ρ x y ≥ 0
74+
75+
-}
76+
record PseudoMetricSpace (M : Set) (ρ : M M ℝ) (_≈_ : Rel M 0ℓ) : Set where
77+
constructor mkPseudo
78+
field
79+
≈-isEquivalence : IsEquivalence _≈_
80+
positivity : {x y : M} ρ x y ≥ 0ℝ
81+
nondegen-if : {x y : M} x ≈ y ρ x y ≃ 0ℝ
82+
symmetry : {x y : M} ρ x y ≃ ρ y x
83+
triangle-inequality : {x y z : M} ρ x y ≤ ρ x z + ρ z y
84+
85+
open PseudoMetricSpace public
86+
87+
record MetricSpace (M : Set) (ρ : M M ℝ) (_≈_ : Rel M 0ℓ) : Set where
88+
constructor mkMetric
89+
field
90+
pseudo : PseudoMetricSpace M ρ _≈_
91+
nondegen-onlyif : {x y : M} ρ x y ≃ 0ℝ x ≈ y
92+
93+
open MetricSpace public
94+
95+
productFunction : {M₁ M₂ : Set} (ρ₁ : M₁ M₁ ℝ) (ρ₂ : M₂ M₂ ℝ)
96+
M₁ × M₂ M₁ × M₂
97+
productFunction ρ₁ ρ₂ x y = ρ₁ (proj₁ x) (proj₁ y) + ρ₂ (proj₂ x) (proj₂ y)
98+
99+
productEquality : {M₁ M₂ : Set} (_≈₁_ : Rel M₁ 0ℓ) (_≈₂ : Rel M₂ 0ℓ)
100+
Rel (M₁ × M₂) 0ℓ
101+
productEquality _≈₁_ _≈₂_ x y = (proj₁ x ≈₁ proj₁ y) × (proj₂ x ≈₂ proj₂ y)
102+
103+
productPseudoMetric : {M₁ M₂ : Set} {ρ₁ : M₁ M₁ ℝ} {ρ₂ : M₂ M₂ ℝ}
104+
{_≈₁_ : Rel M₁ 0ℓ} {_≈₂_ : Rel M₂ 0ℓ}
105+
PseudoMetricSpace M₁ ρ₁ _≈₁_
106+
PseudoMetricSpace M₂ ρ₂ _≈₂_
107+
PseudoMetricSpace (M₁ × M₂) (productFunction ρ₁ ρ₂) (productEquality _≈₁_ _≈₂_)
108+
productPseudoMetric {M₁} {M₂} {ρ₁} {ρ₂} {_≈₁_} {_≈₂_} spaceM₁ spaceM₂ = mkPseudo {!!} {!!} {!!} {!!} {!!}
109+
where
110+
ρ : (x y : M₁ × M₂)
111+
ρ = productFunction ρ₁ ρ₂
112+
113+
_≈_ : Rel (M₁ × M₂) 0ℓ
114+
_≈_ = productEquality _≈₁_ _≈₂_
115+
116+
≈-isEq : IsEquivalence _≈_
117+
≈-isEq = {!!}

NonReflective.agda

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{-
2+
This module is almost exactly the same as the Tactic.RingSolver.NonReflective in
3+
the Agda Standard Library as of commit 84dcc85. The key difference is that this
4+
version allows the user to use a coefficient ring other than the carrier ring
5+
(given via homomorphism), while that version does not.
6+
Without this change, the solver does not function well with real numbers since
7+
we are forced to use the reals as the coefficient ring and the carrier ring.
8+
Using the rationals for coefficients fixes our problems. The main change comes from
9+
the ring solver's original documentation at
10+
https://oisdk.github.io/agda-ring-solver/Polynomial.Solver.html,
11+
where Raw.Carrier is used instead of Carrier.
12+
-}
13+
14+
{-# OPTIONS --without-K --safe #-}
15+
16+
open import Tactic.RingSolver.Core.AlmostCommutativeRing
17+
open import Tactic.RingSolver.Core.Polynomial.Parameters
18+
19+
module NonReflective
20+
{ℓ₁ ℓ₂ ℓ₃ ℓ₄}
21+
(homo : Homomorphism ℓ₁ ℓ₂ ℓ₃ ℓ₄)
22+
(let open Homomorphism homo)
23+
where
24+
25+
open import Algebra.Morphism
26+
open import Function
27+
open import Data.Bool.Base using (Bool; true; false; T; if_then_else_)
28+
open import Data.Maybe.Base
29+
open import Data.Empty using (⊥-elim)
30+
open import Data.Nat.Base using (ℕ)
31+
open import Data.Product
32+
open import Data.Vec hiding (_⊛_)
33+
open import Data.Vec.N-ary
34+
35+
open import Tactic.RingSolver.Core.Expression
36+
open import Algebra.Properties.Semiring.Exp.TCOptimised semiring
37+
38+
myMorphism : _
39+
myMorphism = _-Raw-AlmostCommutative⟶_.⟦_⟧ morphism
40+
41+
open Eval (AlmostCommutativeRing.rawRing to) myMorphism
42+
open import Tactic.RingSolver.Core.Polynomial.Base from
43+
44+
norm : {n} -> Expr Raw.Carrier n -> Poly n
45+
norm (Κ x) = κ x
46+
norm (Ι x) = ι x
47+
norm (x ⊕ y) = norm x ⊞ norm y
48+
norm (x ⊗ y) = norm x ⊠ norm y
49+
norm (x ⊛ i) = norm x ⊡ i
50+
norm (⊝ x) = ⊟ norm x
51+
52+
⟦_⇓⟧ : {n} Expr Raw.Carrier n Vec Carrier n Carrier
53+
⟦ expr ⇓⟧ = ⟦ norm expr ⟧ₚ where
54+
55+
open import Tactic.RingSolver.Core.Polynomial.Semantics homo
56+
renaming (⟦_⟧ to ⟦_⟧ₚ)
57+
58+
correct : {n} -> (e : Expr Raw.Carrier n) ->: Vec Carrier n) -> ⟦ e ⇓⟧ ρ ≈ ⟦ e ⟧ ρ
59+
correct {n} = go
60+
where
61+
open import Tactic.RingSolver.Core.Polynomial.Homomorphism homo
62+
63+
go : (expr : Expr Raw.Carrier n) ρ ⟦ expr ⇓⟧ ρ ≈ ⟦ expr ⟧ ρ
64+
go (Κ x) ρ = κ-hom x ρ
65+
go (Ι x) ρ = ι-hom x ρ
66+
go (x ⊕ y) ρ = ⊞-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ +-cong ⟩ go y ρ)
67+
go (x ⊗ y) ρ = ⊠-hom (norm x) (norm y) ρ ⟨ trans ⟩ (go x ρ ⟨ *-cong ⟩ go y ρ)
68+
go (x ⊛ i) ρ = ⊡-hom (norm x) i ρ ⟨ trans ⟩ ^-congˡ i (go x ρ)
69+
go (⊝ x) ρ = ⊟-hom (norm x) ρ ⟨ trans ⟩ -‿cong (go x ρ)
70+
71+
open import Relation.Binary.Reflection setoid Ι ⟦_⟧ ⟦_⇓⟧ correct public
72+
{-
73+
We are using the ⊖ notation instead of ⊝ (notice the former has a longer line) because
74+
of a parsing error when using the latter.
75+
-}
76+
infixl 6 _⊖_
77+
_⊖_ : {n : ℕ} ->
78+
Expr Raw.Carrier n ->
79+
Expr Raw.Carrier n ->
80+
Expr Raw.Carrier n
81+
x ⊖ y = x ⊕ (⊝ y)

NonReflectiveQ.agda

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- The nonreflective ring solver instantiated for the rational numbers.
2+
3+
{-# OPTIONS --without-K --safe #-}
4+
5+
open import Agda.Builtin.Bool
6+
open import Data.Maybe.Base using (Maybe; just; nothing)
7+
open import Relation.Nullary
8+
open import Data.Rational.Unnormalised.Base using (ℚᵘ; 0ℚᵘ; _≃_)
9+
open import Data.Rational.Unnormalised.Properties using (+-*-commutativeRing; _≃?_)
10+
11+
isZero? : (p : ℚᵘ) -> Maybe (0ℚᵘ ≃ p)
12+
isZero? p with 0ℚᵘ ≃? p
13+
... | .true because ofʸ p₁ = just p₁
14+
... | .false because ofⁿ ¬p = nothing
15+
16+
open import Tactic.RingSolver.Core.AlmostCommutativeRing using (fromCommutativeRing)
17+
open import Tactic.RingSolver.NonReflective (fromCommutativeRing +-*-commutativeRing isZero?) public

0 commit comments

Comments
 (0)