Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up RingSolver and extract NatSolver #621

Merged
merged 27 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d0403dd
Use the same syntax for nat solver and ring solver
felixwellen Nov 15, 2021
1140039
Separate code of ring- and nat-solver
felixwellen Nov 15, 2021
086774b
Remove obsolete
felixwellen Nov 15, 2021
a4e8384
Remove obsolete
felixwellen Nov 15, 2021
3aa4588
Rename
felixwellen Nov 15, 2021
012d205
Rename
felixwellen Nov 15, 2021
3ee0df3
Rename + remove unused imports
felixwellen Nov 15, 2021
82e3b7a
Remove obsolete
felixwellen Nov 15, 2021
e3bbb13
Rename + remove obsolete
felixwellen Nov 15, 2021
4dafdbb
clean up, remove obsolete
felixwellen Nov 16, 2021
8aac276
adjust reflection interface for the nat-solver
felixwellen Nov 16, 2021
26ed7e3
explained more thoroughly, how the solver can be used
felixwellen Nov 16, 2021
6f3fd0f
Merge branch 'master' into clean-up-nat-solver
felixwellen Nov 16, 2021
3f5ce7b
oops
felixwellen Nov 16, 2021
2074103
remove obsolete
felixwellen Nov 16, 2021
7c62cfc
typo
felixwellen Dec 16, 2021
b7a71d0
rename to EvalHom
felixwellen Dec 16, 2021
eab3227
shorten line
felixwellen Dec 16, 2021
5205924
Simplify according to Evan's suggestion
felixwellen Dec 16, 2021
8ea47b0
Merge branch 'master' into clean-up-nat-solver
felixwellen Dec 16, 2021
804e811
Make n implicit for eval
felixwellen Dec 16, 2021
c5455d6
More implicit n's
felixwellen Dec 16, 2021
d72f8ad
More implicit n's
felixwellen Dec 16, 2021
d964daa
Reindent
felixwellen Dec 16, 2021
e3823bd
More implicit n's
felixwellen Dec 16, 2021
7b3f4be
More implicit n's
felixwellen Dec 16, 2021
c955599
Simplify
felixwellen Dec 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Ideal using (isIdeal)
open import Cubical.Algebra.RingSolver.ReflectionSolving

private
variable
Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/CommRing/BinomialThm.agda
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open import Cubical.Data.Empty as ⊥
open import Cubical.Algebra.Monoid.BigOp
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection

private
variable
Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/CommRing/FGIdeal.agda
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.Ring.QuotientRing
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Matrix

private
Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/CommRing/Ideal.agda
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Ideal renaming (IdealsIn to IdealsInRing)
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection

private
variable
Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/CommRing/Localisation/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open import Cubical.Relation.Binary

open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection

open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection

open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary

open import Cubical.Algebra.Ring
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base

Expand Down
2 changes: 1 addition & 1 deletion Cubical/Algebra/CommRing/RadicalIdeal.agda
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.BinomialThm
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.RingSolver.Reflection

private
variable
Expand Down
196 changes: 196 additions & 0 deletions Cubical/Algebra/NatSolver/EvalHom.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.EvalHom where

open import Cubical.Foundations.Prelude

open import Cubical.Data.Nat
open import Cubical.Data.FinData
open import Cubical.Data.Vec

open import Cubical.Algebra.NatSolver.HornerForms

private
variable
ℓ : Level

module HomomorphismProperties where
open IteratedHornerOperations

evalHom+0 : {n : ℕ} (P : IteratedHornerForms n) (xs : Vec ℕ n)
→ eval (0ₕ +ₕ P) xs ≡ eval P xs
evalHom+0 (const x) [] = refl
evalHom+0 _ (x ∷ xs) = refl

eval0H : {n : ℕ} (xs : Vec ℕ n)
→ eval 0ₕ xs ≡ 0
eval0H [] = refl
eval0H (x ∷ xs) = refl

eval1ₕ : {n : ℕ} (xs : Vec ℕ n)
→ eval 1ₕ xs ≡ 1
eval1ₕ [] = refl
eval1ₕ (x ∷ xs) =
eval 1ₕ (x ∷ xs) ≡⟨ refl ⟩
eval (0H ·X+ 1ₕ) (x ∷ xs) ≡⟨ refl ⟩
eval 0H (x ∷ xs) · x + eval 1ₕ xs ≡⟨ cong (λ u → u · x + eval 1ₕ xs)
(eval0H (x ∷ xs)) ⟩
0 · x + eval 1ₕ xs ≡⟨ cong (λ u → 0 · x + u)
(eval1ₕ xs) ⟩
1 ∎


+ShufflePairs : (a b c d : ℕ)
→ (a + b) + (c + d) ≡ (a + c) + (b + d)
+ShufflePairs a b c d =
(a + b) + (c + d) ≡⟨ +-assoc (a + b) c d ⟩
((a + b) + c) + d ≡⟨ cong (λ u → u + d) (sym (+-assoc a b c)) ⟩
(a + (b + c)) + d ≡⟨ cong (λ u → (a + u) + d) (+-comm b c) ⟩
(a + (c + b)) + d ≡⟨ cong (λ u → u + d) (+-assoc a c b) ⟩
((a + c) + b) + d ≡⟨ sym (+-assoc (a + c) b d) ⟩
(a + c) + (b + d) ∎

+Homeval :
{n : ℕ} (P Q : IteratedHornerForms n) (xs : Vec ℕ n)
→ eval (P +ₕ Q) xs ≡ (eval P xs) + (eval Q xs)
+Homeval (const x) (const y) [] = refl
+Homeval 0H Q xs =
eval (0H +ₕ Q) xs ≡⟨ refl ⟩
0 + eval Q xs ≡⟨ cong (λ u → u + eval Q xs) (sym (eval0H xs)) ⟩
eval 0H xs + eval Q xs ∎
+Homeval (P ·X+ Q) 0H xs =
eval ((P ·X+ Q) +ₕ 0H) xs ≡⟨ refl ⟩
eval (P ·X+ Q) xs ≡⟨ sym (+-zero _) ⟩
eval (P ·X+ Q) xs + 0 ≡⟨ cong (λ u → eval (P ·X+ Q) xs + u)
(sym (eval0H xs)) ⟩
eval (P ·X+ Q) xs + eval 0H xs ∎
+Homeval (P ·X+ Q) (S ·X+ T) (x ∷ xs) =
eval ((P ·X+ Q) +ₕ (S ·X+ T)) (x ∷ xs)
≡⟨ refl ⟩
eval ((P +ₕ S) ·X+ (Q +ₕ T)) (x ∷ xs)
≡⟨ refl ⟩
(eval (P +ₕ S) (x ∷ xs)) · x + eval (Q +ₕ T) xs
≡⟨ cong (λ u → (eval (P +ₕ S) (x ∷ xs)) · x + u) (+Homeval Q T xs) ⟩
(eval (P +ₕ S) (x ∷ xs)) · x + (eval Q xs + eval T xs)
≡⟨ cong (λ u → u · x + (eval Q xs + eval T xs)) (+Homeval P S (x ∷ xs)) ⟩
(eval P (x ∷ xs) + eval S (x ∷ xs)) · x
+ (eval Q xs + eval T xs)
≡⟨ cong (λ u → u + (eval Q xs + eval T xs))
(sym (·-distribʳ (eval P (x ∷ xs)) (eval S (x ∷ xs)) x)) ⟩
(eval P (x ∷ xs)) · x + (eval S (x ∷ xs)) · x
+ (eval Q xs + eval T xs)
≡⟨ +ShufflePairs ((eval P (x ∷ xs)) · x) ((eval S (x ∷ xs)) · x) (eval Q xs) (eval T xs) ⟩
((eval P (x ∷ xs)) · x + eval Q xs)
+ ((eval S (x ∷ xs)) · x + eval T xs)

⋆Homeval : {n : ℕ}
(r : IteratedHornerForms n)
(P : IteratedHornerForms (ℕ.suc n)) (x : ℕ) (xs : Vec ℕ n)
→ eval (r ⋆ P) (x ∷ xs) ≡ eval r xs · eval P (x ∷ xs)


⋆0LeftAnnihilates :
{n : ℕ} (P : IteratedHornerForms (ℕ.suc n)) (xs : Vec ℕ (ℕ.suc n))
→ eval (0ₕ ⋆ P) xs ≡ 0

·Homeval : {n : ℕ} (P Q : IteratedHornerForms n) (xs : Vec ℕ n)
→ eval (P ·ₕ Q) xs ≡ (eval P xs) · (eval Q xs)

⋆0LeftAnnihilates 0H xs = eval0H xs
⋆0LeftAnnihilates (P ·X+ Q) (x ∷ xs) =
eval (0ₕ ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩
eval ((0ₕ ⋆ P) ·X+ (0ₕ ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩
(eval (0ₕ ⋆ P) (x ∷ xs)) · x + eval (0ₕ ·ₕ Q) xs
≡⟨ cong (λ u → (u · x) + eval (0ₕ ·ₕ Q) _) (⋆0LeftAnnihilates P (x ∷ xs)) ⟩
0 · x + eval (0ₕ ·ₕ Q) xs
≡⟨ ·Homeval 0ₕ Q _ ⟩
eval 0ₕ xs · eval Q xs
≡⟨ cong (λ u → u · eval Q xs) (eval0H xs) ⟩
0 · eval Q xs ∎

⋆Homeval r 0H x xs =
eval (r ⋆ 0H) (x ∷ xs) ≡⟨ refl ⟩
0 ≡⟨ 0≡m·0 (eval r xs) ⟩
eval r xs · 0 ≡⟨ refl ⟩
eval r xs · eval 0H (x ∷ xs) ∎
⋆Homeval r (P ·X+ Q) x xs =
eval (r ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩
eval ((r ⋆ P) ·X+ (r ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩
(eval (r ⋆ P) (x ∷ xs)) · x + eval (r ·ₕ Q) xs
≡⟨ cong (λ u → u · x + eval (r ·ₕ Q) xs) (⋆Homeval r P x xs) ⟩
(eval r xs · eval P (x ∷ xs)) · x + eval (r ·ₕ Q) xs
≡⟨ cong (λ u → (eval r xs · eval P (x ∷ xs)) · x + u) (·Homeval r Q xs) ⟩
(eval r xs · eval P (x ∷ xs)) · x + eval r xs · eval Q xs
≡⟨ cong (λ u → u + eval r xs · eval Q xs) (sym (·-assoc (eval r xs) (eval P (x ∷ xs)) x)) ⟩
eval r xs · (eval P (x ∷ xs) · x) + eval r xs · eval Q xs
≡⟨ ·-distribˡ (eval r xs) ((eval P (x ∷ xs) · x)) (eval Q xs) ⟩
eval r xs · ((eval P (x ∷ xs) · x) + eval Q xs)
≡⟨ refl ⟩
eval r xs · eval (P ·X+ Q) (x ∷ xs) ∎

combineCases :
{n : ℕ} (Q : IteratedHornerForms n) (P S : IteratedHornerForms (ℕ.suc n))
(xs : Vec ℕ (ℕ.suc n))
→ eval ((P ·X+ Q) ·ₕ S) xs ≡ eval (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) xs
combineCases Q P S (x ∷ xs) with (P ·ₕ S)
... | 0H =
eval (Q ⋆ S) (x ∷ xs) ≡⟨ refl ⟩
0 + eval (Q ⋆ S) (x ∷ xs) ≡⟨ cong (λ u → u + eval (Q ⋆ S) (x ∷ xs)) lemma ⟩
eval (0H ·X+ 0ₕ) (x ∷ xs)
+ eval (Q ⋆ S) (x ∷ xs) ≡⟨ sym (+Homeval
(0H ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs)) ⟩
eval ((0H ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs) ∎
where lemma : 0 ≡ eval (0H ·X+ 0ₕ) (x ∷ xs)
lemma = 0
≡⟨ refl ⟩
0 + 0
≡⟨ cong (λ u → u + 0) refl ⟩
0 · x + 0
≡⟨ cong (λ u → 0 · x + u) (sym (eval0H xs)) ⟩
0 · x + eval 0ₕ xs
≡⟨ cong (λ u → u · x + eval 0ₕ xs) (sym (eval0H (x ∷ xs))) ⟩
eval 0H (x ∷ xs) · x + eval 0ₕ xs
≡⟨ refl ⟩
eval (0H ·X+ 0ₕ) (x ∷ xs) ∎
... | (_ ·X+ _) = refl

·Homeval (const x) (const y) [] = refl
·Homeval 0H Q xs =
eval (0H ·ₕ Q) xs ≡⟨ eval0H xs ⟩
0 ≡⟨ refl ⟩
0 · eval Q xs ≡⟨ cong (λ u → u · eval Q xs) (sym (eval0H xs)) ⟩
eval 0H xs · eval Q xs ∎
·Homeval (P ·X+ Q) S (x ∷ xs) =
eval ((P ·X+ Q) ·ₕ S) (x ∷ xs)
≡⟨ combineCases Q P S (x ∷ xs) ⟩
eval (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs)
≡⟨ +Homeval ((P ·ₕ S) ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs) ⟩
eval ((P ·ₕ S) ·X+ 0ₕ) (x ∷ xs) + eval (Q ⋆ S) (x ∷ xs)
≡⟨ refl ⟩
(eval (P ·ₕ S) (x ∷ xs) · x + eval 0ₕ xs)
+ eval (Q ⋆ S) (x ∷ xs)
≡⟨ cong (λ u → u + eval (Q ⋆ S) (x ∷ xs))
((eval (P ·ₕ S) (x ∷ xs) · x + eval 0ₕ xs)
≡⟨ cong (λ u → eval (P ·ₕ S) (x ∷ xs) · x + u) (eval0H xs) ⟩
(eval (P ·ₕ S) (x ∷ xs) · x + 0)
≡⟨ +-zero _ ⟩
(eval (P ·ₕ S) (x ∷ xs) · x)
≡⟨ cong (λ u → u · x) (·Homeval P S (x ∷ xs)) ⟩
((eval P (x ∷ xs) · eval S (x ∷ xs)) · x)
≡⟨ sym (·-assoc (eval P (x ∷ xs)) (eval S (x ∷ xs)) x) ⟩
(eval P (x ∷ xs) · (eval S (x ∷ xs) · x))
≡⟨ cong (λ u → eval P (x ∷ xs) · u) (·-comm _ x) ⟩
(eval P (x ∷ xs) · (x · eval S (x ∷ xs)))
≡⟨ ·-assoc (eval P (x ∷ xs)) x (eval S (x ∷ xs)) ⟩
(eval P (x ∷ xs) · x) · eval S (x ∷ xs)
∎) ⟩
(eval P (x ∷ xs) · x) · eval S (x ∷ xs)
+ eval (Q ⋆ S) (x ∷ xs)
≡⟨ cong (λ u → (eval P (x ∷ xs) · x) · eval S (x ∷ xs) + u)
(⋆Homeval Q S x xs) ⟩
(eval P (x ∷ xs) · x) · eval S (x ∷ xs)
+ eval Q xs · eval S (x ∷ xs)
≡⟨ ·-distribʳ (eval P (x ∷ xs) · x) (eval Q xs) (eval S (x ∷ xs)) ⟩
((eval P (x ∷ xs) · x) + eval Q xs) · eval S (x ∷ xs)
≡⟨ refl ⟩
eval (P ·X+ Q) (x ∷ xs) · eval S (x ∷ xs) ∎
Loading