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

RP2 #847

Merged
merged 139 commits into from
Sep 12, 2022
Merged

RP2 #847

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
3f62a82
Fix Direct-sum :
thomas-lamiaux Apr 6, 2022
620bfc5
Merge branch 'agda:master' into master
thomas-lamiaux Apr 6, 2022
1f12e1f
add the definition of the cohomology ring
thomas-lamiaux Apr 6, 2022
3bee7f0
some progress for the graded property
thomas-lamiaux Apr 7, 2022
a075003
module name changes
thomas-lamiaux Apr 7, 2022
0ee0210
Add gradedComm proof :
thomas-lamiaux Apr 7, 2022
015710b
uniformisation of the notation
thomas-lamiaux Apr 7, 2022
ecad958
Computation of H*(Unit) cong Z
thomas-lamiaux Apr 8, 2022
d4adcc7
Proof in a more general setting :
thomas-lamiaux Apr 9, 2022
37342d4
Simplification
thomas-lamiaux Apr 9, 2022
22f07e7
Renaming
thomas-lamiaux Apr 9, 2022
4e45548
correct trailing-whitespaces and one path
thomas-lamiaux Apr 9, 2022
67d21cf
Fix dependencies :
thomas-lamiaux Apr 9, 2022
d38d370
Fix dependecies
thomas-lamiaux Apr 9, 2022
53d1962
fix dependecies
thomas-lamiaux Apr 9, 2022
c3ea1cb
fix dependencies
thomas-lamiaux Apr 9, 2022
cb88096
Fix dependency brunerie
thomas-lamiaux Apr 9, 2022
b21dc11
Add a recursor for the special case A / < a, ..., c >
thomas-lamiaux Apr 9, 2022
39ccad1
moved files
thomas-lamiaux Apr 9, 2022
7721b8b
Add a special recursor for polynomes :
thomas-lamiaux Apr 9, 2022
3b1e38c
delete trailing-white-spaces
thomas-lamiaux Apr 9, 2022
b4b3685
Begining to build a general framework ot the example of unit
thomas-lamiaux Apr 10, 2022
1167e9c
H*-Unit->Z[x] is a ring morphism
thomas-lamiaux Apr 10, 2022
4df89fa
Add functions H* Unit <-> Z[X]/X
thomas-lamiaux Apr 10, 2022
6c385a4
Builds all the framework except e-sect
thomas-lamiaux Apr 10, 2022
5696cae
Fix : commented a part
thomas-lamiaux Apr 10, 2022
c24276c
Compute H* Unit in a generalisable way
thomas-lamiaux Apr 10, 2022
86af319
A simplification
thomas-lamiaux Apr 12, 2022
a1861b2
Add the functions for S1 in both sens and stat proving some properties
thomas-lamiaux Apr 12, 2022
f3d2c17
Add the following :
thomas-lamiaux Apr 13, 2022
1938cb6
Add a proof of e-sect
thomas-lamiaux Apr 13, 2022
5b5d11f
Proof of the ring morphism for the case H0 H0
thomas-lamiaux Apr 14, 2022
a17e98f
stuck on filing squares in the ring morphism part
thomas-lamiaux Apr 14, 2022
e4815fc
First complete computation of H*(S¹) equiv Z[X]/X²
thomas-lamiaux Apr 15, 2022
c3419d7
clean up
thomas-lamiaux Apr 15, 2022
49ed72d
Add direct prod for rings
thomas-lamiaux Apr 18, 2022
d7c30ea
Add Direct Prod for CommRing
thomas-lamiaux Apr 18, 2022
d6d6104
Merge branch 'agda:master' into master
thomas-lamiaux Apr 20, 2022
6dcf4b0
Partially add Coproduct
thomas-lamiaux Apr 20, 2022
11c9cce
Coproduct : add proof of sect
thomas-lamiaux Apr 20, 2022
7d4284f
Add morphism on the cup product
thomas-lamiaux Apr 20, 2022
efc74ed
Coproduct : Add H*(X coprod Y) equiv H*(X) x H*(Y)
thomas-lamiaux Apr 20, 2022
2ad2efb
Coproduct : clean up
thomas-lamiaux Apr 20, 2022
05ae65d
small clean up Unit
thomas-lamiaux Apr 20, 2022
514a50f
S0 : refine doesn't type check in time
thomas-lamiaux Apr 20, 2022
d763231
Same issue
thomas-lamiaux Apr 21, 2022
dc1dd58
Clean up but still fails computing :
thomas-lamiaux Apr 21, 2022
fc7902c
Uniformisation of the files
thomas-lamiaux Apr 22, 2022
8e41dad
Clean up :
thomas-lamiaux Apr 22, 2022
fb60c60
clean up on S0, still issue
thomas-lamiaux Apr 22, 2022
67ce7d3
Fix for S0 !
thomas-lamiaux Apr 22, 2022
78d5668
Add notation for the polynomial ring
thomas-lamiaux Apr 22, 2022
4e4c217
Fix : forgot to add a file
thomas-lamiaux Apr 22, 2022
2e0cea6
Sn : Partition + transport + functions in both sens
thomas-lamiaux Apr 23, 2022
9ee3cd1
S1 : Big issue what to do in the case 0 < k < Sn and 0 < l < Sn ?
thomas-lamiaux Apr 23, 2022
6e2aa4b
Sn : Fix the wronfull traduction + Add / Miss :
thomas-lamiaux Apr 24, 2022
72941a6
Sn : Add secction and retraction, Missing computation rule
thomas-lamiaux Apr 25, 2022
0e1dadd
Sn : change the partition
thomas-lamiaux Apr 25, 2022
774f49a
Sn : change the partition
thomas-lamiaux Apr 25, 2022
e4a40da
Sn : computed !
thomas-lamiaux Apr 25, 2022
afed64c
CP2 : All but cup product morpism on H2 -> H2 -> H4
thomas-lamiaux Apr 26, 2022
516c5ae
CP2 : All except but cup product morphism H2 -> H2 -> H4
thomas-lamiaux Apr 26, 2022
1cf0b2b
Renaming + add some encode-decode proof
thomas-lamiaux Apr 27, 2022
28c243d
Remove CP2 from pull request + Continue adding lemma
thomas-lamiaux Apr 28, 2022
4a95228
add a file
thomas-lamiaux Apr 28, 2022
42b6e63
Adding lemma for vec to prove the equivalence
thomas-lamiaux Apr 29, 2022
b306cc7
Add PA->A-cancel
thomas-lamiaux Apr 30, 2022
559a91a
Add lemma -> entirely prove PA->A-cancel
thomas-lamiaux Apr 30, 2022
4e3b821
Fit an offet issue between 1k0 on Vec and FinVec
thomas-lamiaux May 2, 2022
eaaceda
Complete the proof of A[X1,...,Xn]/<X1,...,Xn> equiv A
thomas-lamiaux May 3, 2022
574ce6d
Merge branch 'agda:master' into master
thomas-lamiaux May 3, 2022
7b14401
Merge branch 'master' into cup-product
thomas-lamiaux May 3, 2022
99c9d7a
Fix some merging issues
thomas-lamiaux May 3, 2022
8a0291a
Add an explicit equivalence for the previous commit
thomas-lamiaux May 3, 2022
5678778
Add A[X]/X equiv A
thomas-lamiaux May 4, 2022
3283566
Add a H*(Unit) = Z + fix a bug
thomas-lamiaux May 4, 2022
64efe74
Merge branch 'agda:master' into master
thomas-lamiaux May 5, 2022
a1a5e86
Merge branch 'master' into cup-product
thomas-lamiaux May 5, 2022
f53b681
Enfonce new convention for importing module
thomas-lamiaux May 5, 2022
1eb2d11
Enforce module import convention
thomas-lamiaux May 5, 2022
b52322f
Enforcing using bot.rec rather then rec-bot
thomas-lamiaux May 5, 2022
41fe5b1
clean up importing module + enforcing rec, elim import
thomas-lamiaux May 5, 2022
0802720
clean up
thomas-lamiaux May 5, 2022
e182ade
enforce notation pred...
thomas-lamiaux May 5, 2022
f8cd307
Enforece pres... notation
thomas-lamiaux May 5, 2022
9cbb571
Enforce pres... notation
thomas-lamiaux May 5, 2022
0b29d54
Enforcing Algebra convention
thomas-lamiaux May 5, 2022
06fe36e
Fix pull request
thomas-lamiaux May 6, 2022
fc4d006
fix trailing white spaces
thomas-lamiaux May 6, 2022
a4fa9af
Merge branch 'agda:master' into master
thomas-lamiaux May 7, 2022
e833b03
Merge branch 'master' into cup-product
thomas-lamiaux May 7, 2022
e711dde
Merge branch 'agda:master' into master
thomas-lamiaux May 7, 2022
48480fc
Merge branch 'master' into cup-product
thomas-lamiaux May 7, 2022
30e5f5e
Add theframework around CP2
thomas-lamiaux May 7, 2022
fdf9af8
Merge branch 'agda:master' into master
thomas-lamiaux May 9, 2022
39c4855
Merge branch 'agda:master' into master
thomas-lamiaux May 13, 2022
1c66581
Merge branch 'master' into cup-product
thomas-lamiaux May 13, 2022
99f978c
update CP2
thomas-lamiaux May 13, 2022
79538ca
Merge branch 'agda:master' into master
thomas-lamiaux May 29, 2022
737cef0
Merge branch 'master' into cup-product
thomas-lamiaux May 29, 2022
db9a22b
A sketch of proof for CP2
thomas-lamiaux May 30, 2022
271992c
Try introducing notation
thomas-lamiaux May 31, 2022
aff3c90
Why isn't working ?
thomas-lamiaux May 31, 2022
4b7bc8d
Improve package of the proof
thomas-lamiaux May 31, 2022
5a11c79
Add a lemma file
thomas-lamiaux Jun 1, 2022
71204a1
Weird issue
thomas-lamiaux Jun 1, 2022
4bb13ca
Merge branch 'agda:master' into master
thomas-lamiaux Jun 3, 2022
53d8b56
Merge branch 'agda:master' into master
thomas-lamiaux Jun 8, 2022
b02cd00
Merge branch 'agda:master' into master
thomas-lamiaux Jun 13, 2022
58c0b83
Merge branch 'agda:master' into master
thomas-lamiaux Jun 16, 2022
9c0b869
Merge branch 'master' into cup-product
thomas-lamiaux Jun 17, 2022
11a976f
Adding CP2 + cleaning Unit
thomas-lamiaux Jun 19, 2022
d7fbba6
cleaning S1
thomas-lamiaux Jun 19, 2022
250ad2b
Fix a dependency
thomas-lamiaux Jun 19, 2022
e7b9a9e
Begin doing Sn
thomas-lamiaux Jun 19, 2022
c2112bc
Clean Sn
thomas-lamiaux Jun 19, 2022
13514c9
Delete useless diff
thomas-lamiaux Jun 19, 2022
5f2ff89
Delete CP2
thomas-lamiaux Jun 19, 2022
660f800
Fix issue
thomas-lamiaux Jun 19, 2022
fd05e11
RP2 work in progress
thomas-lamiaux Jun 20, 2022
98f7956
Add a converse function
thomas-lamiaux Jun 25, 2022
5c5aba6
some progress
thomas-lamiaux Jun 25, 2022
7e32b23
Almost done with section
thomas-lamiaux Jun 25, 2022
ff64514
Add section
thomas-lamiaux Jun 25, 2022
904e88e
add retraction
thomas-lamiaux Jun 26, 2022
357800c
Clean up
thomas-lamiaux Jun 26, 2022
8d4ffb8
Merge branch 'agda:master' into master
thomas-lamiaux Jul 22, 2022
8b8c11c
Merge branch 'master' into RP2
thomas-lamiaux Jul 22, 2022
06c69c5
WIP : add proof for IsEven
thomas-lamiaux Jul 22, 2022
6b37ce3
Finish proving lemma on IsEven
thomas-lamiaux Jul 22, 2022
2d3189e
Computation of RP2 !
thomas-lamiaux Jul 22, 2022
19ef23d
Seperate file
thomas-lamiaux Jul 22, 2022
8c047fe
Delete duplicate lemma
thomas-lamiaux Jul 22, 2022
dd12df1
Modifying an import
thomas-lamiaux Aug 7, 2022
a8c066a
Merge branch 'agda:master' into master
thomas-lamiaux Aug 16, 2022
1385232
Merge branch 'agda:master' into master
thomas-lamiaux Aug 17, 2022
8106284
Merge branch 'master' into RP2
thomas-lamiaux Aug 17, 2022
a3729ba
Fix conflict
thomas-lamiaux Aug 17, 2022
4a52f82
Fixed RP2 with the new notations
thomas-lamiaux Aug 17, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly-Quot
ℤ'[X]/X : CommRing ℓ-zero
ℤ'[X]/X = A[X1,···,Xn]/<X1,···,Xn> ℤCommRing 1

-- there is a unification problem that keep pop in up everytime I modify something
-- there is a unification problem that keep poping up everytime I modify something
-- equivℤ[X] : ℤ'[X]/X ≡ ℤ[X]/X
-- equivℤ[X] = cong₂ _/_ refl (cong (λ X → genIdeal (A[X1,···,Xn] ℤCommRing {!!}) X) {!!})
4 changes: 4 additions & 0 deletions Cubical/Data/Bool/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ dichotomyBool : (x : Bool) → (x ≡ true) ⊎ (x ≡ false)
dichotomyBool true = inl refl
dichotomyBool false = inr refl

dichotomyBoolSym : (x : Bool) → (x ≡ false) ⊎ (x ≡ true)
dichotomyBoolSym false = inl refl
dichotomyBoolSym true = inr refl

-- TODO: this should be uncommented and implemented using instance arguments
-- _==_ : {dA : Discrete A} → A → A → Bool
-- _==_ {dA = dA} x y = Dec→Bool (dA x y)
137 changes: 137 additions & 0 deletions Cubical/Data/Int/IsEven.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{-# OPTIONS --safe #-}
module Cubical.Data.Int.IsEven where

open import Cubical.Foundations.Prelude

open import Cubical.Relation.Nullary

open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat
using (ℕ ; zero ; suc ; +-zero ; +-suc ; injSuc ; +-comm ;snotz ; znots ; ·-distribˡ)
renaming
(_+_ to _+ℕ_ ;
_·_ to _·ℕ_ ;
isEven to isEvenℕ ;
isOdd to isOddℕ)
import Cubical.Data.Nat.IsEven as ℕeven

open import Cubical.Data.Int
open import Cubical.Data.Sum

open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Instances.Bool

open GroupStr (snd BoolGroup) using ()
renaming ( _·_ to _+Bool_ )

-----------------------------------------------------------------------------
-- Lemma over ℤ

2negsuc : (k : ℕ) → 2 · negsuc k ≡ negsuc (1 +ℕ 2 ·ℕ k)
2negsuc k = sym
(negsuc (1 +ℕ 2 ·ℕ k) ≡⟨ refl ⟩
neg (suc (1 +ℕ 2 ·ℕ k)) ≡⟨ cong neg refl ⟩
neg (2 +ℕ 2 ·ℕ k) ≡⟨ cong neg (·-distribˡ 2 1 k) ⟩
neg (2 ·ℕ (suc k)) ≡⟨ refl ⟩
- pos (2 ·ℕ (suc k)) ≡⟨ cong -_ (pos·pos 2 (suc k)) ⟩
- (2 · pos (suc k)) ≡⟨ -DistR· 2 (pos (suc k)) ⟩
2 · neg (suc k) ≡⟨ refl ⟩
2 · negsuc k ∎)

1+2kNegsuc : (k : ℕ) → 1 + 2 · negsuc k ≡ negsuc (2 ·ℕ k)
1+2kNegsuc k = cong (λ X → 1 + X)
( 2negsuc k
∙ cong negsuc (+-comm 1 (2 ·ℕ k))
∙ negsuc+ (2 ·ℕ k) 1
∙ +Comm (negsuc (2 ·ℕ k)) (- 1))
∙ +Assoc 1 (- 1) (negsuc (2 ·ℕ k))
∙ sym (pos0+ (negsuc (2 ·ℕ k)))

1+2kPos : (k : ℕ) → pos (1 +ℕ 2 ·ℕ k) ≡ 1 + 2 · (pos k)
1+2kPos k = pos+ 1 (2 ·ℕ k) ∙ cong (λ X → 1 + X) (pos·pos 2 k)

-- isEven → 2k / isOdd → 1 + 2k
isEvenTrue : (a : ℤ) → (isEven a ≡ true) → Σ[ m ∈ ℤ ] a ≡ (2 · m)
isEvenTrue (pos n) p = (pos k) , (cong pos pp ∙ pos·pos 2 k )
where
k = fst (ℕeven.isEvenTrue n p)
pp = snd (ℕeven.isEvenTrue n p)
isEvenTrue (negsuc n) p = (negsuc k) , cong negsuc pp ∙ sym (2negsuc k)
where
k = fst (ℕeven.isOddTrue n p)
pp = snd (ℕeven.isOddTrue n p)

isEvenFalse : (a : ℤ) → (isEven a ≡ false) → Σ[ m ∈ ℤ ] a ≡ 1 + (2 · m)
isEvenFalse (pos n) p = (pos k) , (cong pos pp ∙ 1+2kPos k)
where
k = fst (ℕeven.isEvenFalse n p)
pp = snd (ℕeven.isEvenFalse n p)
isEvenFalse (negsuc n) p = (negsuc k) , (cong negsuc pp ∙ sym (1+2kNegsuc k))
where
k = fst (ℕeven.isOddFalse n p)
pp = snd (ℕeven.isOddFalse n p)


-- 2k → isEven / 1 + 2k → isOdd
trueIsEven : (a : ℤ) → Σ[ m ∈ ℤ ] a ≡ (2 · m) → (isEven a ≡ true)
trueIsEven (pos n) (pos m , p) = ℕeven.trueIsEven n (m , injPos (p ∙ sym (pos·pos 2 m)))
trueIsEven (pos n) (negsuc m , p) = ⊥.rec (posNotnegsuc n (1 +ℕ 2 ·ℕ m) (p ∙ 2negsuc m))
trueIsEven (negsuc n) (pos m , p) = ⊥.rec (negsucNotpos n (2 ·ℕ m) (p ∙ sym (pos·pos 2 m)))
trueIsEven (negsuc n) (negsuc m , p) = ℕeven.¬IsEvenFalse n (ℕeven.falseIsEven n
(m , (injNegsuc (p ∙ 2negsuc m))))

falseIsEven : (a : ℤ) → Σ[ m ∈ ℤ ] a ≡ 1 + (2 · m) → isEven a ≡ false
falseIsEven (pos n) (pos m , p) = ℕeven.falseIsEven n
(m , (injPos (p ∙ sym (1+2kPos m))))
falseIsEven (pos n) (negsuc m , p) = ⊥.rec (posNotnegsuc n (2 ·ℕ m) (p ∙ 1+2kNegsuc m))
falseIsEven (negsuc n) (pos m , p) = ⊥.rec (negsucNotpos n (1 +ℕ 2 ·ℕ m) (p ∙ sym (1+2kPos m)))
falseIsEven (negsuc n) (negsuc m , p) = ℕeven.¬IsEvenTrue n (ℕeven.trueIsEven n (m , (injNegsuc (p ∙ 1+2kNegsuc m ))))


-- Value of isEven (x + y) depending on IsEven x, IsEven y
isOddIsOdd→IsEven : (x y : ℤ) → isEven x ≡ false → isEven y ≡ false → isEven (x + y) ≡ true
isOddIsOdd→IsEven x y px py = trueIsEven (x + y) ((1 + k + l) , cong₂ _+_ qk ql ∙ sym helper)
where
k = fst (isEvenFalse x px)
qk = snd (isEvenFalse x px)
l = fst (isEvenFalse y py)
ql = snd (isEvenFalse y py)
helper : 2 · ((1 + k) + l) ≡ (1 + 2 · k) + (1 + 2 · l)
helper = 2 · ((1 + k) + l) ≡⟨ ·DistR+ 2 (1 + k) l ⟩
2 · (1 + k) + 2 · l ≡⟨ cong (λ X → X + 2 · l)
(·DistR+ 2 1 k ∙ sym (+Assoc 1 1 (2 · k)) ∙ +Comm 1 (1 + 2 · k)) ⟩
((1 + 2 · k) + 1) + 2 · l ≡⟨ sym (+Assoc (1 + 2 · k) 1 (2 · l)) ⟩
(1 + 2 · k) + (1 + 2 · l) ∎

isOddIsEven→IsOdd : (x y : ℤ) → isEven x ≡ false → isEven y ≡ true → isEven (x + y) ≡ false
isOddIsEven→IsOdd x y px py = falseIsEven (x + y) ((k + l) , ( cong₂ _+_ qk ql ∙ helper))
where
k = fst (isEvenFalse x px)
qk = snd (isEvenFalse x px)
l = fst (isEvenTrue y py)
ql = snd (isEvenTrue y py)
helper : _
helper = (1 + 2 · k) + 2 · l ≡⟨ sym (+Assoc 1 (2 · k) (2 · l)) ⟩
1 + (2 · k + 2 · l) ≡⟨ cong (λ X → 1 + X) (sym (·DistR+ 2 k l)) ⟩
1 + 2 · (k + l) ∎

isEvenIsOdd→IsOdd : (x y : ℤ) → isEven x ≡ true → isEven y ≡ false → isEven (x + y) ≡ false
isEvenIsOdd→IsOdd x y px py = cong isEven (+Comm x y) ∙ isOddIsEven→IsOdd y x py px

isEvenIsEven→IsEven : (x y : ℤ) → isEven x ≡ true → isEven y ≡ true → isEven (x + y) ≡ true
isEvenIsEven→IsEven x y px py = trueIsEven (x + y) ((k + l) , cong₂ _+_ qk ql ∙ sym (·DistR+ 2 k l))
where
k = fst (isEvenTrue x px)
qk = snd (isEvenTrue x px)
l = fst (isEvenTrue y py)
ql = snd (isEvenTrue y py)


-- Proof that isEven is morphism
isEven-pres+ : (x y : ℤ) → isEven (x + y) ≡ isEven x +Bool isEven y
isEven-pres+ x y with (dichotomyBoolSym (isEven x)) | dichotomyBoolSym (isEven y)
... | inl xf | inl yf = isOddIsOdd→IsEven x y xf yf ∙ sym (cong₂ _+Bool_ xf yf)
... | inl xf | inr yt = isOddIsEven→IsOdd x y xf yt ∙ sym (cong₂ _+Bool_ xf yt)
... | inr xt | inl yf = isEvenIsOdd→IsOdd x y xt yf ∙ sym (cong₂ _+Bool_ xt yf)
... | inr xt | inr yt = isEvenIsEven→IsEven x y xt yt ∙ sym (cong₂ _+Bool_ xt yt)
22 changes: 10 additions & 12 deletions Cubical/Data/Int/Properties.agda
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ module Cubical.Data.Int.Properties where
open import Cubical.Core.Everything

open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Function

open import Cubical.Data.Empty as Empty
open import Cubical.Relation.Nullary

open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat
hiding (+-assoc ; +-comm)
renaming (_·_ to _·ℕ_; _+_ to _+ℕ_ ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Bool
renaming (_·_ to _·ℕ_; _+_ to _+ℕ_ ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm ; isEven to isEvenℕ ; isOdd to isOddℕ)
open import Cubical.Data.Sum
open import Cubical.Data.Int.Base

open import Cubical.Relation.Nullary
open import Cubical.Data.Int.Base

sucPred : ∀ i → sucℤ (predℤ i) ≡ i
sucPred (pos zero) = refl
Expand Down Expand Up @@ -524,20 +522,20 @@ abs· (negsuc m) (negsuc n) = cong abs (negsuc·negsuc m n) ∙ absPos·Pos (suc
-- ℤ is integral domain

isIntegralℤPosPos : (c m : ℕ) → pos c · pos m ≡ 0 → ¬ c ≡ 0 → m ≡ 0
isIntegralℤPosPos 0 m _ q = Empty.rec (q refl)
isIntegralℤPosPos 0 m _ q = .rec (q refl)
isIntegralℤPosPos (suc c) m p _ =
sym (0≡n·sm→0≡n {n = m} {m = c} (sym (injPos (pos·pos (suc c) m ∙ p)) ∙ ·ℕ-comm (suc c) m))

isIntegralℤ : (c m : ℤ) → c · m ≡ 0 → ¬ c ≡ 0 → m ≡ 0
isIntegralℤ (pos c) (pos m) p h i = pos (isIntegralℤPosPos c m p (λ r → h (cong pos r)) i)
isIntegralℤ (pos c) (negsuc m) p h =
Empty.rec (snotz (isIntegralℤPosPos c (suc m)
.rec (snotz (isIntegralℤPosPos c (suc m)
(sym (-Involutive _) ∙ cong (-_) (sym (pos·negsuc c m) ∙ p)) (λ r → h (cong pos r))))
isIntegralℤ (negsuc c) (pos m) p _ i =
pos (isIntegralℤPosPos (suc c) m
(sym (-Involutive _) ∙ cong (-_) (sym (negsuc·pos c m) ∙ p)) snotz i)
isIntegralℤ (negsuc c) (negsuc m) p _ =
Empty.rec (snotz (isIntegralℤPosPos (suc c) (suc m) (sym (negsuc·negsuc c m) ∙ p) snotz))
.rec (snotz (isIntegralℤPosPos (suc c) (suc m) (sym (negsuc·negsuc c m) ∙ p) snotz))

private
·lCancel-helper : (c m n : ℤ) → c · m ≡ c · n → c · (m - n) ≡ 0
Expand Down
60 changes: 60 additions & 0 deletions Cubical/Data/Nat/IsEven.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{-# OPTIONS --safe #-}
module Cubical.Data.Nat.IsEven where

open import Cubical.Foundations.Prelude

open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat

-- negation result
¬IsEvenFalse : (n : ℕ) → (isEven n ≡ false) → isOdd n ≡ true
¬IsEvenFalse zero p = ⊥.rec (true≢false p)
¬IsEvenFalse (suc zero) p = refl
¬IsEvenFalse (suc (suc n)) p = ¬IsEvenFalse n p

¬IsEvenTrue : (n : ℕ) → (isEven n ≡ true) → isOdd n ≡ false
¬IsEvenTrue zero p = refl
¬IsEvenTrue (suc zero) p = ⊥.rec (false≢true p)
¬IsEvenTrue (suc (suc n)) p = ¬IsEvenTrue n p

¬IsOddFalse : (n : ℕ) → (isOdd n ≡ false) → isEven n ≡ true
¬IsOddFalse zero p = refl
¬IsOddFalse (suc zero) p = ⊥.rec (true≢false p)
¬IsOddFalse (suc (suc n)) p = ¬IsOddFalse n p

¬IsOddTrue : (n : ℕ) → (isOdd n ≡ true) → isEven n ≡ false
¬IsOddTrue zero p = ⊥.rec (false≢true p)
¬IsOddTrue (suc zero) p = refl
¬IsOddTrue (suc (suc n)) p = ¬IsOddTrue n p


-- isEven → 2k / isOdd → 1 + 2k
isEvenTrue : (n : ℕ) → (isEven n ≡ true) → Σ[ m ∈ ℕ ] n ≡ (2 · m)
isOddTrue : (n : ℕ) → (isOdd n ≡ true) → Σ[ m ∈ ℕ ] n ≡ 1 + (2 · m)
isEvenTrue zero p = 0 , refl
isEvenTrue (suc n) p = (suc k) , cong suc pp ∙ cong suc (sym (+-suc _ _))
where
k = fst (isOddTrue n p)
pp = snd (isOddTrue n p)
isOddTrue zero p = ⊥.rec (false≢true p)
isOddTrue (suc n) p = (fst (isEvenTrue n p)) , (cong suc (snd (isEvenTrue n p)))

isEvenFalse : (n : ℕ) → (isEven n ≡ false) → Σ[ m ∈ ℕ ] n ≡ 1 + (2 · m)
isEvenFalse n p = isOddTrue n (¬IsEvenFalse n p)

isOddFalse : (n : ℕ) → (isOdd n ≡ false) → Σ[ m ∈ ℕ ] n ≡ (2 · m)
isOddFalse n p = isEvenTrue n (¬IsOddFalse n p)


-- 2k -> isEven
trueIsEven : (n : ℕ) → Σ[ m ∈ ℕ ] n ≡ (2 · m) → (isEven n ≡ true)
trueIsEven zero (m , p) = refl
trueIsEven (suc zero) (zero , p) = ⊥.rec (snotz p)
trueIsEven (suc zero) (suc m , p) = ⊥.rec (znots (injSuc (p ∙ cong suc (+-suc _ _))))
trueIsEven (suc (suc n)) (zero , p) = ⊥.rec (snotz p)
trueIsEven (suc (suc n)) (suc m , p) = trueIsEven n (m , (injSuc (injSuc (p ∙ cong suc (+-suc _ _)))))

falseIsEven : (n : ℕ) → Σ[ m ∈ ℕ ] n ≡ (1 + 2 · m) → (isEven n ≡ false)
falseIsEven zero (m , p) = ⊥.rec (znots p)
falseIsEven (suc n) (m , p) = ¬IsEvenTrue n (trueIsEven n (m , (injSuc p)))
Loading