Skip to content

Commit c876509

Browse files
committed
Add relation between integer definitions
1 parent 0627e8a commit c876509

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- To be merged into Data.Integer.Properties before merging!
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --safe --cubical-compatible #-}
8+
9+
module Data.Integer.IntConstruction.IntProperties where
10+
11+
open import Data.Integer.Base
12+
open import Data.Integer.IntConstruction as INT using (_≃_)
13+
open import Data.Integer.IntConstruction.Tmp
14+
open import Data.Integer.Properties
15+
import Data.Nat.Base as ℕ
16+
open import Data.Product.Base
17+
open import Function.Base
18+
open import Relation.Binary.PropositionalEquality
19+
20+
fromINT-cong : {i j} i ≃ j fromINT i ≡ fromINT j
21+
fromINT-cong {a INT.⊖ b} {c INT.⊖ d} a+d≡c+b = begin
22+
a ⊖ b ≡⟨ m-n≡m⊖n a b ⟨
23+
+ a - + b ≡⟨ cong (_- + b) (+-identityʳ (+ a)) ⟨
24+
(+ a + 0ℤ) - + b ≡⟨ cong (λ z (+ a + z) - + b) (+-inverseʳ (+ d)) ⟨
25+
(+ a + (+ d - + d)) - + b ≡⟨ cong (_- + b) (+-assoc (+ a) (+ d) (- + d)) ⟨
26+
(+ (a ℕ.+ d) - + d) - + b ≡⟨ cong (λ z (+ z - + d) - + b) a+d≡c+b ⟩
27+
(+ (c ℕ.+ b) - + d) - + b ≡⟨ cong (_- + b) (+-assoc (+ c) (+ b) (- + d)) ⟩
28+
(+ c + (+ b - + d)) - + b ≡⟨ cong (λ z (+ c + z) - + b) (+-comm (+ b) (- + d)) ⟩
29+
(+ c + (- + d + + b)) - + b ≡⟨ cong (_- + b) (+-assoc (+ c) (- + d) (+ b)) ⟨
30+
((+ c - + d) + + b) - + b ≡⟨ +-assoc (+ c - + d) (+ b) (- + b) ⟩
31+
(+ c - + d) + (+ b - + b) ≡⟨ cong₂ _+_ (m-n≡m⊖n c d) (+-inverseʳ (+ b)) ⟩
32+
c ⊖ d + 0ℤ ≡⟨ +-identityʳ (c ⊖ d) ⟩
33+
c ⊖ d ∎
34+
where open ≡-Reasoning
35+
36+
fromINT-injective : {i j} fromINT i ≡ fromINT j i ≃ j
37+
fromINT-injective {a INT.⊖ b} {c INT.⊖ d} a⊖b≡c⊖d = +-injective $ begin
38+
+ a + + d ≡⟨ cong (_+ + d) (+-identityʳ (+ a)) ⟨
39+
(+ a + 0ℤ) + + d ≡⟨ cong (λ z (+ a + z) + + d) (+-inverseˡ (+ b)) ⟨
40+
(+ a + (- + b + + b)) + + d ≡⟨ cong (_+ + d) (+-assoc (+ a) (- + b) (+ b)) ⟨
41+
((+ a - + b) + + b) + + d ≡⟨ cong (λ z (z + + b) + + d) (m-n≡m⊖n a b) ⟩
42+
(a ⊖ b + + b) + + d ≡⟨ cong (λ z (z + + b) + + d) a⊖b≡c⊖d ⟩
43+
(c ⊖ d + + b) + + d ≡⟨ cong (λ z (z + + b) + + d) (m-n≡m⊖n c d) ⟨
44+
((+ c - + d) + + b) + + d ≡⟨ cong (_+ + d) (+-assoc (+ c) (- + d) (+ b)) ⟩
45+
(+ c + (- + d + + b)) + + d ≡⟨ cong (λ z (+ c + z) + + d) (+-comm (- + d) (+ b)) ⟩
46+
(+ c + (+ b - + d)) + + d ≡⟨ cong (_+ + d) (+-assoc (+ c) (+ b) (- + d)) ⟨
47+
((+ c + + b) - + d) + + d ≡⟨ +-assoc (+ c + + b) (- + d) (+ d) ⟩
48+
(+ c + + b) + (- + d + + d) ≡⟨ cong (_+_ (+ c + + b)) (+-inverseˡ (+ d)) ⟩
49+
(+ c + + b) + 0ℤ ≡⟨ +-identityʳ (+ c + + b) ⟩
50+
+ c + + b ∎
51+
where open ≡-Reasoning
52+
53+
fromINT-surjective : j ∃[ i ] {z} z ≃ i fromINT z ≡ j
54+
fromINT-surjective j .proj₁ = toINT j
55+
fromINT-surjective (+ n) .proj₂ {a INT.⊖ b} a+0≡n+b = begin
56+
a ⊖ b ≡⟨ m-n≡m⊖n a b ⟨
57+
+ a - + b ≡⟨ cong (_- + b) (+-identityʳ (+ a)) ⟨
58+
(+ a + 0ℤ) - + b ≡⟨ cong (λ z + z - + b) a+0≡n+b ⟩
59+
(+ n + + b) - + b ≡⟨ +-assoc (+ n) (+ b) (- + b) ⟩
60+
+ n + (+ b - + b) ≡⟨ cong (_+_ (+ n)) (+-inverseʳ (+ b)) ⟩
61+
+ n + 0ℤ ≡⟨ +-identityʳ (+ n) ⟩
62+
+ n ∎
63+
where open ≡-Reasoning
64+
fromINT-surjective (-[1+ n ]) .proj₂ {a INT.⊖ b} a+sn≡b = begin
65+
a ⊖ b ≡⟨ m-n≡m⊖n a b ⟨
66+
+ a - + b ≡⟨ cong (λ z + a - + z) a+sn≡b ⟨
67+
+ a - (+ a + + ℕ.suc n) ≡⟨ cong (_+_ (+ a)) (neg-distrib-+ (+ a) (+ ℕ.suc n)) ⟩
68+
+ a + (- + a - + ℕ.suc n) ≡⟨ +-assoc (+ a) (- + a) (- + ℕ.suc n) ⟨
69+
(+ a - + a) - + ℕ.suc n ≡⟨ cong (_- + ℕ.suc n) (+-inverseʳ (+ a)) ⟩
70+
0ℤ - + ℕ.suc n ≡⟨ +-identityˡ (- + ℕ.suc n) ⟩
71+
-[1+ n ] ∎
72+
where open ≡-Reasoning
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- To be merged into Data.Integer.Base before merging!
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --safe --cubical-compatible #-}
8+
9+
module Data.Integer.IntConstruction.Tmp where
10+
11+
open import Data.Integer.Base
12+
import Data.Integer.IntConstruction as INT
13+
import Data.Nat.Base as ℕ
14+
15+
fromINT : INT.ℤ
16+
fromINT (m INT.⊖ n) = m ⊖ n
17+
18+
toINT : INT.ℤ
19+
toINT (+ n) = n INT.⊖ 0
20+
toINT (-[1+ n ]) = 0 INT.⊖ ℕ.suc n
21+
22+
-- here we have a choice:
23+
-- * either we can show the definitions in Data.Int.Base match those on INT under the above isomorphism;
24+
-- * or we could _redefine_ those operations _as_ the operations on INT under the above isormophism.

0 commit comments

Comments
 (0)