{-# OPTIONS --cubical --allow-unsolved-metas #-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Empty hiding (elim ; rec)
open import Cubical.Data.Unit renaming (Unit to ⊤)
open import Cubical.Data.Nat as ℕ using (ℕ)
open import Cubical.Data.Nat.Order as ℕ using ()
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Data.Int.MoreInts.BiInvInt renaming (BiInvℤ to ℤ) hiding (_+_ ; +-assoc ; +-comm ; +-zero ; +-suc ; +-pred ; neg ; _-_) public
open import Misc
one : ℤ
one = suc zero
-one : ℤ
-one = pred zero
elim : ∀ {ℓ} (A : ℤ → Type ℓ)
(z : A zero)
(s : (n : ℤ) → A n → A (suc n))
(p : (n : ℤ) → A n → A (predl n))
(p' : (n : ℤ) → A n → A (predr n))
(ps : (n : ℤ) → (x : A n) → PathP (λ i → A (predl-suc n i)) (p (suc n) (s n x)) x)
(sp' : (n : ℤ) → (x : A n) → PathP (λ i → A (suc-predr n i)) (s (predr n) (p' n x)) x)
(n : ℤ) → A n
elim A z s p p' ps sp' zero = z
elim A z s p p' ps sp' (suc n) = s n (elim A z s p p' ps sp' n)
elim A z s p p' ps sp' (predl n) = p n (elim A z s p p' ps sp' n)
elim A z s p p' ps sp' (predr n) = p' n (elim A z s p p' ps sp' n)
elim A z s p p' ps sp' (predl-suc n i) = ps n (elim A z s p p' ps sp' n) i
elim A z s p p' ps sp' (suc-predr n i) = sp' n (elim A z s p p' ps sp' n) i
elim' : ∀ {ℓ} (A : ℤ → Type ℓ)
(z : A zero)
(s : (n : ℤ) → A n → A (suc n))
(p : (n : ℤ) → A n → A (predl n))
(ps : (n : ℤ) → (x : A n) → PathP (λ i → A (predl-suc n i)) (p (suc n) (s n x)) x)
(sp' : (n : ℤ) → (x : A n) → PathP (λ i → A (suc-predr n i)) (s (predr n) (subst A (predl≡predr n) (p n x))) x)
(n : ℤ) → A n
elim' A z s p ps sp' n = elim A z s p (λ n An → subst A (predl≡predr n) (p n An)) ps sp' n
rec : ∀ {ℓ} {A : Type ℓ}
(z : A)
(s : ℤ → A → A)
(p : ℤ → A → A)
(p' : ℤ → A → A)
(ps : (n : ℤ) → (x : A) → (p (suc n) (s n x)) ≡ x)
(sp' : (n : ℤ) → (x : A) → (s (predr n) (p' n x)) ≡ x) →
ℤ → A
rec {A = A} z s p p' ps sp' n = elim (λ _ → A) z s p p' ps sp' n
postulate discrete : Discrete ℤ
ℤ-isSet : isSet ℤ
ℤ-isSet = Discrete→isSet discrete
postulate
1≢0 : ¬ (suc zero ≡ zero)
_+_ : ℤ → ℤ → ℤ
zero + n = n
suc m + n = suc (m + n)
predl m + n = predl (m + n)
predr m + n = predr (m + n)
predl-suc m i + n = predl-suc (m + n) i
suc-predr m i + n = suc-predr (m + n) i
postulate
+-assoc : (m n o : ℤ) → m + (n + o) ≡ (m + n) + o
+-comm : (m n : ℤ) → m + n ≡ n + m
zero-+ : (n : ℤ) → zero + n ≡ n
+-zero : (n : ℤ) → n + zero ≡ n
+-suc : (m n : ℤ) → m + suc n ≡ suc (m + n)
+-pred : (m n : ℤ) → m + pred n ≡ pred (m + n)
+-predr : (m n : ℤ) → m + predr n ≡ predr (m + n)
+1-suc : (n : ℤ) → n + one ≡ suc n
-1+suc : (n : ℤ) → -one + suc n ≡ n
suc+-1 : (n : ℤ) → suc n + -one ≡ n
cong-+-r : (m : ℤ) {n n' : ℤ} → n ≡ n' → m + n ≡ m + n'
cong-+-r m p = cong (λ n → m + n) p
neg : ℤ → ℤ
neg zero = zero
neg (suc n) = predl (neg n)
neg (predl n) = suc (neg n)
neg (predr n) = suc (neg n)
neg (predl-suc n i) = suc-predl (neg n) i
neg (suc-predr n i) = predl-suc (neg n) i
postulate
neg-neg : (n : ℤ) → neg (neg n) ≡ n
neg+≡0 : (n : ℤ) → (neg n) + n ≡ zero
+neg≡0 : (n : ℤ) → n + (neg n) ≡ zero
neg-+ : (m n : ℤ) → neg (m + n) ≡ neg m + neg n
_-_ : ℤ → ℤ → ℤ
m - n = m + neg n
postulate
n-n≡0 : (n : ℤ) → n - n ≡ zero
-1-pred : (n : ℤ) → n - one ≡ pred n
fromℕ : ℕ → ℤ
fromℕ ℕ.zero = zero
fromℕ (ℕ.suc n) = suc (fromℕ n)
postulate
fromℕ-+ : (m n : ℕ) → fromℕ (m ℕ.+ n) ≡ fromℕ m + fromℕ n
open import Cubical.Data.Int as Int using (pos ; negsuc ; predSuc ; sucPred) renaming (ℤ to ℤ' ; sucℤ to sucℤ' ; predℤ to predℤ')
toInt : ℤ → ℤ'
toInt zero = Int.pos ℕ.zero
toInt (suc n) = Int.sucℤ (toInt n)
toInt (predl n) = Int.predℤ (toInt n)
toInt (predr n) = Int.predℤ (toInt n)
toInt (predl-suc n i) = predSuc (toInt n) i
toInt (suc-predr n i) = sucPred (toInt n) i
fromInt : ℤ' → ℤ
fromInt (pos n) = fromℕ n
fromInt (negsuc n) = neg (fromℕ (ℕ.suc n))
open import Cubical.Core.Everything
open import Cubical.Foundations.Isomorphism
postulate
ℤ≃Int : ℤ' ≃ ℤ
data is-even : ℤ → Type₀
data is-odd : ℤ → Type₀
data is-even where
even-zero : is-even zero
even-suc : {n : ℤ} → is-odd n → is-even (suc n)
even-predl : {n : ℤ} → is-odd n → is-even (predl n)
even-predr : {n : ℤ} → is-odd n → is-even (predr n)
data is-odd where
odd-suc : {n : ℤ} → is-even n → is-odd (suc n)
odd-predl : {n : ℤ} → is-even n → is-odd (predl n)
odd-predr : {n : ℤ} → is-even n → is-odd (predr n)
postulate is-even-isProp : {n : ℤ} → isProp (is-even n)
postulate is-odd-isProp : {n : ℤ} → isProp (is-odd n)
postulate even-or-odd : (n : ℤ) → ¬ (is-even n × is-odd n)
postulate
even-suc-inv : (n : ℤ) → is-even (suc n) → is-odd n
open import Cubical.Data.Sum
dec-parity : (n : ℤ) → Type₀
dec-parity n = is-even n ⊎ is-odd n
parity : (n : ℤ) → dec-parity n
parity zero = inl even-zero
parity (suc n) with parity n
... | inl e = inr (odd-suc e)
... | inr o = inl (even-suc o)
parity (predl n) with parity n
... | inl e = inr (odd-predl e)
... | inr o = inl (even-predl o)
parity (predr n) with parity n
... | inl e = inr (odd-predr e)
... | inr o = inl (even-predr o)
parity (predl-suc n i) = lem n i
where
postulate lem : (n : ℤ) → PathP (λ i → dec-parity (predl-suc n i)) (parity (predl (suc n))) (parity n)
parity (suc-predr n i) = lem n i
where
postulate lem : (n : ℤ) → PathP (λ i → dec-parity (suc-predr n i)) (parity (suc (predr n))) (parity n)
open import Nat as ℕ using (suc ; even-zero ; even-suc ; odd-suc)
is-evenℕ : {n : ℕ} → ℕ.is-even n → is-even (fromℕ n)
is-oddℕ : {n : ℕ} → ℕ.is-odd n → is-odd (fromℕ n)
is-evenℕ even-zero = even-zero
is-evenℕ (even-suc p) = even-suc (is-oddℕ p)
is-oddℕ (odd-suc p) = odd-suc (is-evenℕ p)
postulate
zero-abs : {n : ℤ} → abs n ≡ 0 → n ≡ zero
_≤_ : ℤ → ℤ → Type₀
m ≤ n = Σ ℕ λ k → fromℕ k + m ≡ n
_<_ : ℤ → ℤ → Type₀
m < n = suc m ≤ n
_>_ : ℤ → ℤ → Type₀
m > n = n < m
0<1 : zero < one
0<1 = 0 , refl
≤-refl : {n : ℤ} → n ≤ n
≤-refl {n} = 0 , refl
≤-≡ : {m n : ℤ} → m ≡ n → m ≤ n
≤-≡ {m} {n} p = subst (λ n → m ≤ n) p ≤-refl
≤-path : {m n : ℤ} → m ≡ n → m ≤ n
≤-path {m} {n} p = subst (λ n → m ≤ n) p ≤-refl
≤-trans : {m n o : ℤ} → m ≤ n → n ≤ o → m ≤ o
≤-trans {m} {n} {o} m≤n n≤o = fst m≤n ℕ.+ fst n≤o ,
(fromℕ (fst m≤n ℕ.+ fst n≤o) + m ≡⟨ cong (λ n → n + m) (fromℕ-+ (fst m≤n) (fst n≤o)) ⟩
(fromℕ (fst m≤n) + fromℕ (fst n≤o)) + m ≡⟨ cong (λ n → n + m) (+-comm (fromℕ (fst m≤n)) _) ⟩
(fromℕ (fst n≤o) + fromℕ (fst m≤n)) + m ≡⟨ sym (+-assoc (fromℕ (fst n≤o)) _ _) ⟩
(fromℕ (fst n≤o) + (fromℕ (fst m≤n) + m)) ≡⟨ cong (λ n → fromℕ (fst n≤o) + n) (snd m≤n) ⟩
fromℕ (fst n≤o) + n ≡⟨ snd n≤o ⟩
o ∎)
≤-suc : {m n : ℤ} → m ≤ n → m ≤ suc n
≤-suc (k , p) = suc k , cong suc p
<→≤ : {m n : ℤ} → m < n → m ≤ n
<→≤ m<n = ≤-trans (≤-suc ≤-refl) m<n
postulate
≤-neg : {m n : ℤ} → neg n ≤ neg m → m ≤ n
pos-fromℕ : {n : ℤ} → zero ≤ n → Σ ℕ (λ n' → n ≡ fromℕ n')
data Trichotomy (m n : ℤ) : Type₀ where
lt : m < n → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : n < m → Trichotomy m n
postulate
_≟_ : (m n : ℤ) → Trichotomy m n
ℤ≃ℕ : ℤ ≃ ℕ
ℤ≃ℕ = isoToEquiv i
where
f : ℤ → ℕ
f n with toInt n
... | pos k = 2 ℕ.· k
... | negsuc k = suc (2 ℕ.· k)
g : ℕ → ℤ
g n = aux (ℕ.parity n)
where
aux : {n : ℕ} → ℕ.is-even n ⊎ ℕ.is-odd n → ℤ
aux (inl even-zero) = ℤ.zero
aux (inl (even-suc (odd-suc p))) = suc (aux (inl p))
aux (inr (odd-suc even-zero)) = neg one
aux (inr (odd-suc (even-suc p))) = pred (aux (inr p))
i : Iso ℤ ℕ
Iso.fun i = f
Iso.inv i = g
Iso.rightInv i n = {!!}
Iso.leftInv i n = {!!}
_≺_ : ℤ → ℤ → Type₀
m ≺ n = equivFun ℤ≃ℕ m ℕ.< equivFun ℤ≃ℕ n
open import Cubical.Foundations.Univalence
postulate
≺≡< : transport (cong (λ N → N → N → Type₀) (ua ℤ≃ℕ)) _≺_ ≡ ℕ._<_
open import Cubical.Induction.WellFounded
postulate
≺-wellfounded : WellFounded _≺_