Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Orders.Total.Definition
open import Orders.Partial.Definition
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Setoids.Orders.Total.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {c : _} {_<_ : A → A → Set c} {P : SetoidPartialOrder S _<_} (T : SetoidTotalOrder P) where
open SetoidTotalOrder T
open SetoidPartialOrder P
open Setoid S
open Equivalence eq
maxInequalitiesR : {a b c : A} → (a < b) → (a < c) → (a < max b c)
maxInequalitiesR {a} {b} {c} a<b a<c with totality b c
... | inl (inl x) = a<c
... | inl (inr x) = a<b
... | inr x = a<c
minInequalitiesR : {a b c : A} → (a < b) → (a < c) → (a < min b c)
minInequalitiesR {a} {b} {c} a<b a<c with totality b c
... | inl (inl x) = a<b
... | inl (inr x) = a<c
... | inr x = a<b
maxInequalitiesL : {a b c : A} → (a < c) → (b < c) → (max a b < c)
maxInequalitiesL {a} {b} {c} a<b a<c with totality a b
... | inl (inl x) = a<c
... | inl (inr x) = a<b
... | inr x = a<c
minInequalitiesL : {a b c : A} → (a < c) → (b < c) → (min a b < c)
minInequalitiesL {a} {b} {c} a<b a<c with totality a b
... | inl (inl x) = a<b
... | inl (inr x) = a<c
... | inr x = a<b
minLessL : (a b : A) → min a b <= a
minLessL a b with totality a b
... | inl (inl x) = inr reflexive
... | inl (inr x) = inl x
... | inr x = inr reflexive
minLessR : (a b : A) → min a b <= b
minLessR a b with totality a b
... | inl (inl x) = inl x
... | inl (inr x) = inr reflexive
... | inr x = inr x
maxGreaterL : (a b : A) → a <= max a b
maxGreaterL a b with totality a b
... | inl (inl x) = inl x
... | inl (inr x) = inr reflexive
... | inr x = inr x
maxGreaterR : (a b : A) → b <= max a b
maxGreaterR a b with totality a b
... | inl (inl x) = inr reflexive
... | inl (inr x) = inl x
... | inr x = inr reflexive
| {
"alphanum_fraction": 0.5949926362,
"avg_line_length": 29.9558823529,
"ext": "agda",
"hexsha": "3290a14407d76955c104ffdbf3b244331194f72b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Setoids/Orders/Total/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Setoids/Orders/Total/Lemmas.agda",
"max_line_length": 171,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Setoids/Orders/Total/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 827,
"size": 2037
} |
-- {-# OPTIONS -v tc.lhs.shadow:30 #-}
module PatternShadowsConstructor3 where
data Bool : Set where
true false : Bool
module A where
data B : Set where
x : B
data C : Set where
c : B → C
open A using (C; c)
T : Bool → Set
T true = C → C
T false = Bool
f : (b : Bool) → T b
f true (c x) = x
f false = true
| {
"alphanum_fraction": 0.5884146341,
"avg_line_length": 13.12,
"ext": "agda",
"hexsha": "a9f5b4fac66572af1199039a4a690029aa704638",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/PatternShadowsConstructor3.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/PatternShadowsConstructor3.agda",
"max_line_length": 39,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/PatternShadowsConstructor3.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 114,
"size": 328
} |
{-# OPTIONS --without-K #-}
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.Commutes {i} (d : Span^2 {i}) where
open Span^2 d
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.FromTo
open import homotopy.3x3.ToFrom
abstract
theorem : Pushout^2 d ≃ Pushout^2 (transpose d)
theorem = equiv to from (to-from d) (from-to d) | {
"alphanum_fraction": 0.7459349593,
"avg_line_length": 22.3636363636,
"ext": "agda",
"hexsha": "43aefb94d1eb82c794faf4184c1afafa793acf60",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "homotopy/3x3/Commutes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "homotopy/3x3/Commutes.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/3x3/Commutes.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 174,
"size": 492
} |
module Data.ListSized.Proofs where
import Lvl
open import Data.ListSized
open import Data.ListSized.Functions
open import Functional
open import Function.Equals
open import Numeral.Finite
open import Numeral.Natural
open import Numeral.Natural.Function
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Operator
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Type
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable T A A₁ A₂ B B₁ B₂ C C₁ C₂ Result : Type{ℓ}
private variable a b n n₁ n₂ : ℕ
private variable f : B → C
private variable g : A → B
private variable l l₁ l₂ : List(T)(n)
private variable x : T
map-id : (map{A = A}{n = n} id ⊜ id)
_⊜_.proof map-id {∅} = reflexivity(_≡_)
_⊜_.proof map-id {x ⊰ l} = congruence₂ᵣ(_⊰_)(_) (_⊜_.proof map-id {l})
map-[∘] : (map{n = n} (f ∘ g) ⊜ (map f) ∘ (map g))
_⊜_.proof map-[∘] {∅} = reflexivity(_≡_)
_⊜_.proof map-[∘] {x ⊰ l} = congruence₂ᵣ(_⊰_)(_) (_⊜_.proof map-[∘] {l})
map-[++] : map f(l₁ ++ l₂) ≡ map f(l₁) ++ map f(l₂)
map-[++] {l₁ = ∅} = reflexivity(_≡_)
map-[++] {l₁ = x₁ ⊰ l₁} = congruence₂ᵣ(_⊰_)(_) (map-[++] {l₁ = l₁})
map-repeat : map f(repeat x n) ≡ repeat (f(x)) n
map-repeat {n = 𝟎} = reflexivity(_≡_)
map-repeat {n = 𝐒 n} = congruence₂ᵣ(_⊰_)(_) (map-repeat {n = n})
[+][++]-repeat : repeat x (n₁ + n₂) ≡ repeat x n₁ ++ repeat x n₂
[+][++]-repeat {n₁ = 𝟎} = reflexivity(_≡_)
[+][++]-repeat {n₁ = 𝐒 n₁} = congruence₂ᵣ(_⊰_)(_) ([+][++]-repeat {n₁ = n₁})
| {
"alphanum_fraction": 0.6462116468,
"avg_line_length": 33.9787234043,
"ext": "agda",
"hexsha": "df9cfe14188744d93f880e9fb974eb5bedb92e7f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/ListSized/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/ListSized/Proofs.agda",
"max_line_length": 76,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/ListSized/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 627,
"size": 1597
} |
module functions where
open import level
open import eq
open import product
{- Note that the Agda standard library has an interesting generalization
of the following basic composition operator, with more dependent typing. -}
_∘_ : ∀{ℓ ℓ' ℓ''}{A : Set ℓ}{B : Set ℓ'}{C : Set ℓ''} →
(B → C) → (A → B) → (A → C)
f ∘ g = λ x → f (g x)
∘-assoc : ∀{ℓ ℓ' ℓ'' ℓ'''}{A : Set ℓ}{B : Set ℓ'}{C : Set ℓ''}{D : Set ℓ'''}
(f : C → D)(g : B → C)(h : A → B) → (f ∘ g) ∘ h ≡ f ∘ (g ∘ h)
∘-assoc f g h = refl
id : ∀{ℓ}{A : Set ℓ} → A → A
id x = x
∘-id : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}(f : A → B) → f ∘ id ≡ f
∘-id f = refl
id-∘ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}(f : A → B) → id ∘ f ≡ f
id-∘ f = refl
extensionality : {ℓ₁ ℓ₂ : Level} → Set (lsuc ℓ₁ ⊔ lsuc ℓ₂)
extensionality {ℓ₁}{ℓ₂} = ∀{A : Set ℓ₁}{B : Set ℓ₂}{f g : A → B} → (∀{a : A} → f a ≡ g a) → f ≡ g
record Iso {ℓ₁ ℓ₂ : Level} (A : Set ℓ₁) (B : Set ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
constructor isIso
field
l-inv : A → B
r-inv : B → A
l-cancel : r-inv ∘ l-inv ≡ id
r-cancel : l-inv ∘ r-inv ≡ id
curry : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃} → ((A × B) → C) → (A → B → C)
curry f x y = f (x , y)
uncurry : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃} → (A → B → C) → ((A × B) → C)
uncurry f (x , y) = f x y
compose-cong : ∀{ℓ}{A : Set ℓ}{B : Set ℓ}{C : Set ℓ}{f f' : A → B}{g g' : B → C} → f ≡ f' → g ≡ g' → g ∘ f ≡ g' ∘ f'
compose-cong refl refl = refl
| {
"alphanum_fraction": 0.4816354816,
"avg_line_length": 31.3695652174,
"ext": "agda",
"hexsha": "91606426cce89b57481ac826173ccfe0be8b172e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "functions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "functions.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "functions.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 722,
"size": 1443
} |
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module 06-universes where
import 05-identity-types
open 05-identity-types public
-- Section 6.3 Pointed types
-- Definition 6.3.1
UU-pt : (i : Level) → UU (lsuc i)
UU-pt i = Σ (UU i) (λ X → X)
type-UU-pt : {i : Level} → UU-pt i → UU i
type-UU-pt = pr1
pt-UU-pt : {i : Level} (A : UU-pt i) → type-UU-pt A
pt-UU-pt = pr2
-- Definition 6.3.2
_→*_ : {i j : Level} → UU-pt i → UU-pt j → UU-pt (i ⊔ j)
A →* B =
pair
( Σ (type-UU-pt A → type-UU-pt B) (λ f → Id (f (pt-UU-pt A)) (pt-UU-pt B)))
( pair
( const (type-UU-pt A) (type-UU-pt B) (pt-UU-pt B))
( refl))
-- Definition 6.3.3
Ω : {i : Level} → UU-pt i → UU-pt i
Ω A = pair (Id (pt-UU-pt A) (pt-UU-pt A)) refl
-- Definition 6.3.4
iterated-loop-space : {i : Level} → ℕ → UU-pt i → UU-pt i
iterated-loop-space zero-ℕ A = A
iterated-loop-space (succ-ℕ n) A = Ω (iterated-loop-space n A)
-- Section 6.4 Families and relations on the natural numbers
-- Definition 6.4.1
Fin : ℕ → UU lzero
Fin zero-ℕ = empty
Fin (succ-ℕ n) = coprod (Fin n) unit
-- Definition 6.4.2
-- Observational equality on the natural numbers
Eq-ℕ : ℕ → (ℕ → UU lzero)
Eq-ℕ zero-ℕ zero-ℕ = 𝟙
Eq-ℕ zero-ℕ (succ-ℕ n) = 𝟘
Eq-ℕ (succ-ℕ m) zero-ℕ = 𝟘
Eq-ℕ (succ-ℕ m) (succ-ℕ n) = Eq-ℕ m n
-- Lemma 6.4.3
refl-Eq-ℕ : (n : ℕ) → Eq-ℕ n n
refl-Eq-ℕ zero-ℕ = star
refl-Eq-ℕ (succ-ℕ n) = refl-Eq-ℕ n
succ-relation-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) → ℕ → ℕ → UU i
succ-relation-ℕ R m n = R (succ-ℕ m) (succ-ℕ n)
succ-reflexivity-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(n : ℕ) → succ-relation-ℕ R n n
succ-reflexivity-ℕ R ρ n = ρ (succ-ℕ n)
{- In the book we suggest that first the order of the variables should be
swapped, in order to make the inductive hypothesis stronger. Agda's pattern
matching mechanism allows us to bypass this step and give a more direct
construction. -}
least-reflexive-Eq-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(m n : ℕ) → Eq-ℕ m n → R m n
least-reflexive-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
least-reflexive-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
least-reflexive-Eq-ℕ (succ-relation-ℕ R) (succ-reflexivity-ℕ R ρ) m n e
-- Exercises
-- Exercise 6.1
{- In this exercise we were asked to show that the observational equality on ℕ
is an equivalence relation. -}
symmetric-Eq-ℕ : (m n : ℕ) → Eq-ℕ m n → Eq-ℕ n m
symmetric-Eq-ℕ zero-ℕ zero-ℕ star = star
symmetric-Eq-ℕ (succ-ℕ m) (succ-ℕ n) t = symmetric-Eq-ℕ m n t
transitive-Eq-ℕ : (l m n : ℕ) → Eq-ℕ l m → Eq-ℕ m n → Eq-ℕ l n
transitive-Eq-ℕ zero-ℕ zero-ℕ zero-ℕ p q = star
transitive-Eq-ℕ (succ-ℕ l) (succ-ℕ m) (succ-ℕ n) p q =
transitive-Eq-ℕ l m n p q
-- Exercise 6.2
{- In this exercise we were asked to show that any function on the natural
numbers preserves observational equality. The quick solution uses the fact
that observational equality is the least reflexive relation. -}
preserve_Eq-ℕ : (f : ℕ → ℕ) (n m : ℕ) → (Eq-ℕ n m) → (Eq-ℕ (f n) (f m))
preserve_Eq-ℕ f =
least-reflexive-Eq-ℕ
( λ x y → Eq-ℕ (f x) (f y))
( λ x → refl-Eq-ℕ (f x))
-- Exercise 6.3
{- In this exercise we were asked to construct the relations ≤ and < on the
natural numbers, and show basic properties about them. -}
-- Exercise 6.3(a)
-- The definition of ≤
leq-ℕ : ℕ → ℕ → UU lzero
leq-ℕ zero-ℕ m = unit
leq-ℕ (succ-ℕ n) zero-ℕ = empty
leq-ℕ (succ-ℕ n) (succ-ℕ m) = leq-ℕ n m
_≤_ = leq-ℕ
leq-zero-ℕ :
(n : ℕ) → leq-ℕ zero-ℕ n
leq-zero-ℕ n = star
-- The definition of <
le-ℕ : ℕ → ℕ → UU lzero
le-ℕ m zero-ℕ = empty
le-ℕ zero-ℕ (succ-ℕ m) = unit
le-ℕ (succ-ℕ n) (succ-ℕ m) = le-ℕ n m
_<_ = le-ℕ
reflexive-leq-ℕ : (n : ℕ) → n ≤ n
reflexive-leq-ℕ zero-ℕ = star
reflexive-leq-ℕ (succ-ℕ n) = reflexive-leq-ℕ n
anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n < n)
anti-reflexive-le-ℕ zero-ℕ = ind-empty
anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n
transitive-leq-ℕ :
(n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l)
transitive-leq-ℕ zero-ℕ m l p q = star
transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-leq-ℕ n m l p q
transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l)
transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star
transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-le-ℕ n m l p q
succ-leq-ℕ : (n : ℕ) → leq-ℕ n (succ-ℕ n)
succ-leq-ℕ zero-ℕ = star
succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n
succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n)
succ-le-ℕ zero-ℕ = star
succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
anti-symmetric-leq-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ n m → Id m n
anti-symmetric-leq-ℕ zero-ℕ zero-ℕ p q = refl
anti-symmetric-leq-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-leq-ℕ m n p q)
anti-symmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → Id m n
anti-symmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-le-ℕ m n p q)
-- Exercise 6.5
{- In this exercise we were asked to construct observational equality on the
booleans. This construction is analogous to, but simpler than, the
construction of observational equality on the natural numbers. -}
Eq-𝟚 : bool → bool → UU lzero
Eq-𝟚 true true = unit
Eq-𝟚 true false = empty
Eq-𝟚 false true = empty
Eq-𝟚 false false = unit
reflexive-Eq-𝟚 : (x : bool) → Eq-𝟚 x x
reflexive-Eq-𝟚 true = star
reflexive-Eq-𝟚 false = star
least-reflexive-Eq-𝟚 : {i : Level}
(R : bool → bool → UU i) (ρ : (x : bool) → R x x)
(x y : bool) → Eq-𝟚 x y → R x y
least-reflexive-Eq-𝟚 R ρ true true p = ρ true
least-reflexive-Eq-𝟚 R ρ true false p = ind-empty p
least-reflexive-Eq-𝟚 R ρ false true p = ind-empty p
least-reflexive-Eq-𝟚 R ρ false false p = ρ false
-- Exercise 6.6
{- In this exercise we were asked to define the relations ≤ and < on the
integers. As a criterion of correctness, we were then also asked to show
that the type of all integers l satisfying k ≤ l satisfy the induction
principle of the natural numbers. -}
diff-ℤ : ℤ → ℤ → ℤ
diff-ℤ k l = add-ℤ (neg-ℤ k) l
is-non-negative-ℤ : ℤ → UU lzero
is-non-negative-ℤ (inl x) = empty
is-non-negative-ℤ (inr k) = unit
leq-ℤ : ℤ → ℤ → UU lzero
leq-ℤ k l = is-non-negative-ℤ (diff-ℤ k l)
reflexive-leq-ℤ : (k : ℤ) → leq-ℤ k k
reflexive-leq-ℤ k =
tr is-non-negative-ℤ (inv (left-inverse-law-add-ℤ k)) star
is-non-negative-succ-ℤ :
(k : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ (succ-ℤ k)
is-non-negative-succ-ℤ (inr (inl star)) p = star
is-non-negative-succ-ℤ (inr (inr x)) p = star
is-non-negative-add-ℤ :
(k l : ℤ) →
is-non-negative-ℤ k → is-non-negative-ℤ l → is-non-negative-ℤ (add-ℤ k l)
is-non-negative-add-ℤ (inr (inl star)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inl star)) (inr (inr n)) p q = star
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inl star)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inl star)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inl star)) star star)
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inr m)) star star = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inr m)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inr m)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inr m)) star star)
triangle-diff-ℤ :
(k l m : ℤ) → Id (add-ℤ (diff-ℤ k l) (diff-ℤ l m)) (diff-ℤ k m)
triangle-diff-ℤ k l m =
( associative-add-ℤ (neg-ℤ k) l (diff-ℤ l m)) ∙
( ap
( add-ℤ (neg-ℤ k))
( ( inv (associative-add-ℤ l (neg-ℤ l) m)) ∙
( ( ap (λ x → add-ℤ x m) (right-inverse-law-add-ℤ l)) ∙
( left-unit-law-add-ℤ m))))
transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ k l → leq-ℤ l m → leq-ℤ k m
transitive-leq-ℤ k l m p q =
tr is-non-negative-ℤ
( triangle-diff-ℤ k l m)
( is-non-negative-add-ℤ
( add-ℤ (neg-ℤ k) l)
( add-ℤ (neg-ℤ l) m)
( p)
( q))
succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k)
succ-leq-ℤ k =
tr is-non-negative-ℤ
( inv
( ( right-successor-law-add-ℤ (neg-ℤ k) k) ∙
( ap succ-ℤ (left-inverse-law-add-ℤ k))))
( star)
leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l)
leq-ℤ-succ-leq-ℤ k l p = transitive-leq-ℤ k l (succ-ℤ l) p (succ-leq-ℤ l)
is-positive-ℤ : ℤ → UU lzero
is-positive-ℤ k = is-non-negative-ℤ (pred-ℤ k)
le-ℤ : ℤ → ℤ → UU lzero
le-ℤ (inl zero-ℕ) (inl x) = empty
le-ℤ (inl zero-ℕ) (inr y) = unit
le-ℤ (inl (succ-ℕ x)) (inl zero-ℕ) = unit
le-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ y)) = le-ℤ (inl x) (inl y)
le-ℤ (inl (succ-ℕ x)) (inr y) = unit
le-ℤ (inr x) (inl y) = empty
le-ℤ (inr (inl star)) (inr (inl star)) = empty
le-ℤ (inr (inl star)) (inr (inr x)) = unit
le-ℤ (inr (inr x)) (inr (inl star)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr (succ-ℕ y))) = unit
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ y))) =
le-ℤ (inr (inr x)) (inr (inr y))
-- Extra material
-- We show that ℕ is an ordered semi-ring
leq-eq-ℕ : {m m' n n' : ℕ} → Id m m' → Id n n' → leq-ℕ m n → leq-ℕ m' n'
leq-eq-ℕ refl refl = id
left-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
left-law-leq-add-ℕ zero-ℕ m n = id
left-law-leq-add-ℕ (succ-ℕ k) m n H = left-law-leq-add-ℕ k m n H
right-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ k m) (add-ℕ k n)
right-law-leq-add-ℕ k m n H =
leq-eq-ℕ
( commutative-add-ℕ m k)
( commutative-add-ℕ n k)
( left-law-leq-add-ℕ k m n H)
preserves-leq-add-ℕ :
{m m' n n' : ℕ} → leq-ℕ m m' → leq-ℕ n n' → leq-ℕ (add-ℕ m n) (add-ℕ m' n')
preserves-leq-add-ℕ {m} {m'} {n} {n'} H K =
transitive-leq-ℕ
( add-ℕ m n)
( add-ℕ m' n)
( add-ℕ m' n')
( left-law-leq-add-ℕ n m m' H)
( right-law-leq-add-ℕ m' n n' K)
right-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ k m) (mul-ℕ k n)
right-law-leq-mul-ℕ zero-ℕ m n H = star
right-law-leq-mul-ℕ (succ-ℕ k) m n H = {!!}
{-
preserves-leq-add-ℕ
{ m = mul-ℕ k m}
{ m' = mul-ℕ k n}
( right-law-leq-mul-ℕ k m n H) H
left-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
left-law-leq-mul-ℕ k m n H =
leq-eq-ℕ
( commutative-mul-ℕ k m)
( commutative-mul-ℕ k n)
( right-law-leq-mul-ℕ k m n H)
-- We show that ℤ is an ordered ring
{-
leq-add-ℤ : (m k l : ℤ) → leq-ℤ k l → leq-ℤ (add-ℤ m k) (add-ℤ m l)
leq-add-ℤ (inl zero-ℕ) k l H = {!!}
leq-add-ℤ (inl (succ-ℕ x)) k l H = {!!}
leq-add-ℤ (inr m) k l H = {!!}
-}
-- Section 5.5 Identity systems
succ-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) →
(m n : ℕ) → Eq-ℕ m n → UU i
succ-fam-Eq-ℕ R m n e = R (succ-ℕ m) (succ-ℕ n) e
succ-refl-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
(ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
(n : ℕ) → (succ-fam-Eq-ℕ R n n (refl-Eq-ℕ n))
succ-refl-fam-Eq-ℕ R ρ n = ρ (succ-ℕ n)
path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( m n : ℕ) (e : Eq-ℕ m n) → R m n e
path-ind-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
path-ind-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
path-ind-Eq-ℕ (succ-fam-Eq-ℕ R) (succ-refl-fam-Eq-ℕ R ρ) m n e
comp-path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( n : ℕ) → Id (path-ind-Eq-ℕ R ρ n n (refl-Eq-ℕ n)) (ρ n)
comp-path-ind-Eq-ℕ R ρ zero-ℕ = refl
comp-path-ind-Eq-ℕ R ρ (succ-ℕ n) =
comp-path-ind-Eq-ℕ (succ-fam-Eq-ℕ R) (succ-refl-fam-Eq-ℕ R ρ) n
-}
{-
-- Graphs
Gph : (i : Level) → UU (lsuc i)
Gph i = Σ (UU i) (λ X → (X → X → (UU i)))
-- Reflexive graphs
rGph : (i : Level) → UU (lsuc i)
rGph i = Σ (UU i) (λ X → Σ (X → X → (UU i)) (λ R → (x : X) → R x x))
-}
-- Exercise 3.7
{- With the construction of the divisibility relation we open the door to basic
number theory. -}
divides : (d n : ℕ) → UU lzero
divides d n = Σ ℕ (λ m → Eq-ℕ (mul-ℕ d m) n)
| {
"alphanum_fraction": 0.5843433505,
"avg_line_length": 30.0399002494,
"ext": "agda",
"hexsha": "21745cd3dd0658a48c528e6cfec7f08eedbaef17",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "hemangandhi/HoTT-Intro",
"max_forks_repo_path": "Agda/06-universes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "hemangandhi/HoTT-Intro",
"max_issues_repo_path": "Agda/06-universes.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "hemangandhi/HoTT-Intro",
"max_stars_repo_path": "Agda/06-universes.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5684,
"size": 12046
} |
module PatternSynonymMutualBlock where
data D : Set where
c : D
mutual
pattern p = c
| {
"alphanum_fraction": 0.7252747253,
"avg_line_length": 11.375,
"ext": "agda",
"hexsha": "c8b5fe6d4884e3ed94c385a5192c5ea837876318",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/PatternSynonymMutualBlock.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/PatternSynonymMutualBlock.agda",
"max_line_length": 38,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/PatternSynonymMutualBlock.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 29,
"size": 91
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.CartesianClosed.Properties where
open import Level
open import Data.Product using (Σ; _,_; Σ-syntax; proj₁; proj₂)
open import Categories.Category
open import Categories.Category.CartesianClosed
module _ {o ℓ e} {𝒞 : Category o ℓ e} (𝓥 : CartesianClosed 𝒞) where
open Category 𝒞
open CartesianClosed 𝓥
open HomReasoning
PointSurjective : ∀ {A X Y : Obj} → (X ⇒ Y ^ A) → Set (ℓ ⊔ e)
PointSurjective {A = A} {X = X} {Y = Y} ϕ =
∀ (f : A ⇒ Y) → Σ[ x ∈ ⊤ ⇒ X ] (∀ (a : ⊤ ⇒ A) → eval′ ∘ first ϕ ∘ ⟨ x , a ⟩ ≈ f ∘ a)
lawvere-fixed-point : ∀ {A B : Obj} → (ϕ : A ⇒ B ^ A) → PointSurjective ϕ → (f : B ⇒ B) → Σ[ s ∈ ⊤ ⇒ B ] f ∘ s ≈ s
lawvere-fixed-point {A = A} {B = B} ϕ surjective f = g ∘ x , g-fixed-point
where
g : A ⇒ B
g = f ∘ eval′ ∘ ⟨ ϕ , id ⟩
x : ⊤ ⇒ A
x = proj₁ (surjective g)
g-surjective : eval′ ∘ first ϕ ∘ ⟨ x , x ⟩ ≈ g ∘ x
g-surjective = proj₂ (surjective g) x
lemma : ∀ {A B C D} → (f : B ⇒ C) → (g : B ⇒ D) → (h : A ⇒ B) → (f ⁂ g) ∘ ⟨ h , h ⟩ ≈ ⟨ f , g ⟩ ∘ h
lemma f g h = begin
(f ⁂ g) ∘ ⟨ h , h ⟩ ≈⟨ ⁂∘⟨⟩ ⟩
⟨ f ∘ h , g ∘ h ⟩ ≈˘⟨ ⟨⟩∘ ⟩
⟨ f , g ⟩ ∘ h ∎
g-fixed-point : f ∘ (g ∘ x) ≈ g ∘ x
g-fixed-point = begin
f ∘ g ∘ x ≈⟨ refl⟩∘⟨ sym g-surjective ⟩
f ∘ eval′ ∘ first ϕ ∘ ⟨ x , x ⟩ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ lemma ϕ id x ⟩
f ∘ eval′ ∘ ⟨ ϕ , id ⟩ ∘ x ≈˘⟨ ∘-resp-≈ˡ sym-assoc ○ assoc ○ assoc ⟩
(f ∘ eval′ ∘ ⟨ ϕ , id ⟩) ∘ x ≈⟨ refl ⟩
g ∘ x ∎
| {
"alphanum_fraction": 0.4504283966,
"avg_line_length": 35.5217391304,
"ext": "agda",
"hexsha": "fcc9b882fcc1ff386bbafdecf54e40afd202ec5b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/CartesianClosed/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Category/CartesianClosed/Properties.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/CartesianClosed/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 712,
"size": 1634
} |
------------------------------------------------------------------------------
-- The gcd program is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the gcd program using
-- the Euclid's algorithm.
module FOTC.Program.GCD.Partial.CorrectnessProofI where
open import FOTC.Base
open import FOTC.Data.Nat.Divisibility.NotBy0.PropertiesI
using ( 0∤x ; x∣S→x≤S )
open import FOTC.Data.Nat.Type
open import FOTC.Program.GCD.Partial.CommonDivisorI using ( gcdCD )
open import FOTC.Program.GCD.Partial.Definitions
open import FOTC.Program.GCD.Partial.DivisibleI using ( gcdDivisible )
open import FOTC.Program.GCD.Partial.GCD using ( gcd )
import FOTC.Program.GCD.Partial.GreatestAnyCommonDivisor
open module GreatestAnyCommonDivisorI =
FOTC.Program.GCD.Partial.GreatestAnyCommonDivisor x∣S→x≤S 0∤x
using ( gcdGACD )
open import FOTC.Program.GCD.Partial.TotalityI using ( gcd-N )
------------------------------------------------------------------------------
-- The gcd is correct.
gcdCorrect : ∀ {m n} → N m → N n → x≢0≢y m n → gcdSpec m n (gcd m n)
gcdCorrect Nm Nn m≢0≢n = gcdCD Nm Nn m≢0≢n
, gcdGACD (gcd-N Nm Nn m≢0≢n)
(gcdCD Nm Nn m≢0≢n)
(gcdDivisible Nm Nn m≢0≢n)
| {
"alphanum_fraction": 0.5561391989,
"avg_line_length": 40.0789473684,
"ext": "agda",
"hexsha": "6e81d8ae38a9a060c5c673031626e8af013db8c0",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/GCD/Partial/CorrectnessProofI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/GCD/Partial/CorrectnessProofI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/GCD/Partial/CorrectnessProofI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 404,
"size": 1523
} |
-- Andreas, 2013-05-02 This ain't a bug, it is a feature.
-- {-# OPTIONS -v scope.name:10 #-}
module Issue836 where
open import Common.Equality
module M where
record R : Set₁ where
field
X : Set
open M using (R)
X : R → Set
X = R.X
-- The open directive did not mention the /module/ R, so (I think
-- that) the code above should be rejected.
-- NO, it is a feature that projections can also be accessed via
-- the record /type/.
-- The following directive is (and should be) rejected:
-- open R
-- Bug.agda:19,6-7
-- No such module R
-- when scope checking the declaration
-- open R
module N where
data D : Set₁ where
c : Set → D
open N using (D) renaming (module D to MD)
twoWaysToQualify : D.c ≡ MD.c
twoWaysToQualify = refl
| {
"alphanum_fraction": 0.6653543307,
"avg_line_length": 17.7209302326,
"ext": "agda",
"hexsha": "00bf8d9a60f6af172308c78029046050b4b677b9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue836.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue836.agda",
"max_line_length": 65,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue836.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 229,
"size": 762
} |
module AnyBoolean where
open import Data.Bool
open import Data.Nat
open import Data.List hiding (any)
open import Relation.Binary.PropositionalEquality
even : ℕ → Bool
even zero = true
even (suc zero) = false
even (suc (suc n)) = even n
test-6-even : even 6 ≡ true
test-6-even = refl
odd : ℕ → Bool
odd zero = false
odd (suc zero) = true
odd (suc (suc n)) = odd n
test-5-odd : odd 5 ≡ true
test-5-odd = refl
any : {A : Set} → (A → Bool) → List A → Bool
any _ [] = false
any p (x ∷ xs) with p x
... | true = true
... | false = any p xs
test-any-even-true :
any even (3 ∷ 6 ∷ 9 ∷ []) ≡ true
test-any-even-true = refl
test-any-even-false :
any even (3 ∷ 7 ∷ 9 ∷ []) ≡ false
test-any-even-false = refl
test-any-odd-true :
any odd (4 ∷ 7 ∷ 10 ∷ []) ≡ true
test-any-odd-true = refl
test-any-odd-false :
any odd (4 ∷ 8 ∷ 10 ∷ []) ≡ false
test-any-odd-false = refl
| {
"alphanum_fraction": 0.6195899772,
"avg_line_length": 19.9545454545,
"ext": "agda",
"hexsha": "d08ca99a2258f57dc222ad2fa643095efa5a90e8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T12:03:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T12:03:09.000Z",
"max_forks_repo_head_hexsha": "60f71d369015b83b9ef5fabc75a70f367d20ac97",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/bahug-april2010",
"max_forks_repo_path": "AnyBoolean.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "60f71d369015b83b9ef5fabc75a70f367d20ac97",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/bahug-april2010",
"max_issues_repo_path": "AnyBoolean.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "60f71d369015b83b9ef5fabc75a70f367d20ac97",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/bahug-april2010",
"max_stars_repo_path": "AnyBoolean.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 334,
"size": 878
} |
------------------------------------------------------------------------------
-- Definition of the gcd of two natural numbers using the Euclid's algorithm
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.GCD.Partial.GCD where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Loop
------------------------------------------------------------------------------
-- In GHC ≤ 7.0.4 the gcd is a partial function, i.e. gcd 0 0 = undefined.
-- Let T = D → D → D be a type. Instead of defining gcdh : T → T, we
-- use the LTC-PCF λ-abstraction and application to avoid use a
-- polymorphic fixed-point operator.
gcdh : D → D
gcdh g = lam (λ m → lam (λ n →
if (iszero₁ n)
then (if (iszero₁ m) then error else m)
else (if (iszero₁ m)
then n
else (if (gt m n)
then g · (m ∸ n) · n
else g · m · (n ∸ m)))))
gcd : D → D → D
gcd m n = fix gcdh · m · n
| {
"alphanum_fraction": 0.4431372549,
"avg_line_length": 35.4166666667,
"ext": "agda",
"hexsha": "a74d1347874ccd802e6976f489226a4c1d8ffbc9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GCD.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GCD.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GCD.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 299,
"size": 1275
} |
{-# OPTIONS --without-K #-}
module Interval where
open import Pitch
open import Data.Bool using (Bool; true; false; _∨_; _∧_; not; if_then_else_)
open import Data.Integer using (+_; _-_; sign; ∣_∣)
open import Data.Fin using (toℕ)
open import Data.Nat using (ℕ; _≡ᵇ_)
open import Data.Nat.DivMod using (_mod_)
open import Data.Product using (_×_; _,_; Σ; proj₁; proj₂)
open import Data.Sign using (Sign)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_)
PitchPair : Set
PitchPair = Pitch × Pitch
data Interval : Set where
interval : ℕ → Interval
infix 4 _==_
_==_ : Interval → Interval → Bool
(interval a) == (interval b) = a ≡ᵇ b
intervalWithinOctave : Interval → Interval
intervalWithinOctave (interval i) = interval (toℕ (i mod chromaticScaleSize))
SignedInterval : Set
SignedInterval = Sign × Interval
-- Names for intervals
per1 = interval 0
min2 = interval 1
maj2 = interval 2
min3 = interval 3
maj3 = interval 4
per4 = interval 5
aug4 = interval 6
per5 = interval 7
min6 = interval 8
maj6 = interval 9
min7 = interval 10
maj7 = interval 11
per8 = interval 12
min9 = interval 13
maj9 = interval 14
min10 = interval 15
maj10 = interval 16
isConsonant : Interval → Bool
isConsonant iv =
(i == per1) ∨
(i == min3) ∨
(i == maj3) ∨
(i == per5) ∨
(i == min6) ∨
(i == maj6) ∨
(i == per8)
where i = intervalWithinOctave iv
isDissonant : Interval → Bool
isDissonant = not ∘ isConsonant
isPerfect : Interval → Bool
isPerfect iv =
(i == per1) ∨
(i == per4) ∨
(i == per5) ∨
(i == per8)
where i = intervalWithinOctave iv
isUnison : Interval → Bool
isUnison i = i == per1
isThird : Interval → Bool
isThird i = (i == min3) ∨ (i == maj3)
-- Half or whole step; ignores key for now.
isStep : Interval → Bool
isStep i =
(i == min2) ∨
(i == maj2)
PitchInterval : Set
PitchInterval = Pitch × Interval
pitchIntervalToPitchPair : PitchInterval → PitchPair
pitchIntervalToPitchPair (p , interval n) = (p , transposePitch (+ n) p)
secondPitch : PitchInterval → Pitch
secondPitch = proj₂ ∘ pitchIntervalToPitchPair
pitchPairToSignedInterval : PitchPair → SignedInterval
pitchPairToSignedInterval (pitch p , pitch q) =
let d = (+ q) - (+ p)
in sign d , interval ∣ d ∣
-- Assumes p ≤ q
pitchPairToPitchInterval : PitchPair → PitchInterval
pitchPairToPitchInterval pq = proj₁ pq , proj₂ (pitchPairToSignedInterval pq)
stepUp : Pitch → Pitch → Bool
stepUp p q with pitchPairToSignedInterval (p , q)
... | Sign.- , _ = false
... | Sign.+ , i = isStep i
stepDown : Pitch → Pitch → Bool
stepDown p q with pitchPairToSignedInterval (p , q)
... | Sign.- , i = isStep i
... | Sign.+ , _ = false
-- Check if q is a passing tone between p and r
-- The interval between end points need to be a 3rd
isPassingTone : Pitch → Pitch → Pitch → Bool
isPassingTone p q r =
(stepUp p q ∧ stepUp q r) ∨ (stepDown p q ∧ stepDown q r) ∨
(isThird (proj₂ (pitchPairToSignedInterval (p , r))))
moveUp : Pitch → Pitch → Bool
moveUp p q with pitchPairToSignedInterval (p , q)
... | Sign.- , _ = false
... | Sign.+ , i = true
moveDown : Pitch → Pitch → Bool
moveDown p q with pitchPairToSignedInterval (p , q)
... | Sign.- , i = true
... | Sign.+ , _ = false
-- Check if q is left by step in the opposite direction from its approach
isOppositeStep : Pitch → Pitch → Pitch → Bool
isOppositeStep p q r = (moveUp p q ∧ stepDown q r) ∨ (moveDown p q ∧ stepUp q r)
| {
"alphanum_fraction": 0.6703926627,
"avg_line_length": 25.4671532847,
"ext": "agda",
"hexsha": "36299027d4baa3c9fc0f5075bb9f1b91d6f49900",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "doc/icfp20/code/Interval.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "doc/icfp20/code/Interval.agda",
"max_line_length": 83,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "doc/icfp20/code/Interval.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 1143,
"size": 3489
} |
------------------------------------------------------------------------------
-- All the LTC-PCF modules
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Everything where
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
open import LTC-PCF.Data.Bool
open import LTC-PCF.Data.Bool.Properties
open import LTC-PCF.Data.Bool.Type
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Divisibility.By0
open import LTC-PCF.Data.Nat.Divisibility.By0.Properties
open import LTC-PCF.Data.Nat.Divisibility.NotBy0
open import LTC-PCF.Data.Nat.Divisibility.NotBy0.Properties
open import LTC-PCF.Data.Nat.Induction.NonAcc.Lexicographic
open import LTC-PCF.Data.Nat.Induction.NonAcc.WF
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Inequalities.ConversionRules
open import LTC-PCF.Data.Nat.Inequalities.EliminationProperties
open import LTC-PCF.Data.Nat.Inequalities.Properties
open import LTC-PCF.Data.Nat.Properties
open import LTC-PCF.Data.Nat.Rec
open import LTC-PCF.Data.Nat.Rec.ConversionRules
open import LTC-PCF.Data.Nat.Type
open import LTC-PCF.Data.Nat.UnaryNumbers
open import LTC-PCF.Data.Nat.UnaryNumbers.Totality
open import LTC-PCF.Loop
open import LTC-PCF.Program.Division.ConversionRules
open import LTC-PCF.Program.Division.CorrectnessProof
open import LTC-PCF.Program.Division.Division
open import LTC-PCF.Program.Division.Result
open import LTC-PCF.Program.Division.Specification
open import LTC-PCF.Program.Division.Totality
open import LTC-PCF.Program.GCD.Partial.CommonDivisor
open import LTC-PCF.Program.GCD.Partial.ConversionRules
open import LTC-PCF.Program.GCD.Partial.CorrectnessProof
open import LTC-PCF.Program.GCD.Partial.Definitions
open import LTC-PCF.Program.GCD.Partial.Divisible
open import LTC-PCF.Program.GCD.Partial.GCD
open import LTC-PCF.Program.GCD.Partial.GreatestAnyCommonDivisor
open import LTC-PCF.Program.GCD.Partial.GreatestAnyCommonDivisor
open import LTC-PCF.Program.GCD.Partial.Totality
open import LTC-PCF.Program.GCD.Total.CommonDivisor
open import LTC-PCF.Program.GCD.Total.CorrectnessProof
open import LTC-PCF.Program.GCD.Total.ConversionRules
open import LTC-PCF.Program.GCD.Total.Definitions
open import LTC-PCF.Program.GCD.Total.Divisible
open import LTC-PCF.Program.GCD.Total.GCD
open import LTC-PCF.Program.GCD.Total.Totality
| {
"alphanum_fraction": 0.7594488189,
"avg_line_length": 40.3174603175,
"ext": "agda",
"hexsha": "ef1a528ca68699952c98a4210168ca1e2ba263cd",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Everything.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 664,
"size": 2540
} |
module Tactic.Nat where
open import Prelude
open import Tactic.Nat.Generic (quote _≤_) (quote id) (quote id) public
{-
All tactics know about addition, multiplication and subtraction
of natural numbers, and can prove equalities and inequalities (_<_).
The available tactics are:
* auto
Prove an equation or inequality.
* by eq
Prove the goal using the given assumption. For equalities it simplifies
the goal and the assumption and checks if they match any of the following
forms (up to symmetry):
a ≡ b → a ≡ b
a + b ≡ 0 → a ≡ 0
For inequalities, to prove a < b -> c < d, it simplifies the assumption and
goal and then tries to prove c′ ≤ a′ and b′ ≤ d′.
When proving that an inequality follows from an equality a ≡ b, the equality
is weakened to a ≤ b before applying the above procedure.
Proving an equality from an inequality works if the inequality simplifies to
a ≤ 0 (or a < 0 in which case it's trivial). It then reduces that to a ≡ 0
and tries to prove the goal from that.
* refute eq
Proves an arbitrary proposition given a false equation. Works for equations
that simplify to 0 ≡ suc n (or symmetric) or n < 0, for some n.
* simplify-goal ?
Simplify the current goal and let you keep working on the new goal.
In most cases 'by prf' works better than
'simplify-goal prf' since it will also simplify prf. The advantage
of simplify-goal is that it allows holes in prf.
* simplify eq λ x → ?
Simplify the given equation (and the current goal) and bind the simplified
equation to x in the new goal.
* induction
Prove a goal ∀ n → P n using induction. Applies 'auto' in the base case
and 'by IH' in the step case.
-}
| {
"alphanum_fraction": 0.6919566458,
"avg_line_length": 30.224137931,
"ext": "agda",
"hexsha": "749535db8027af7b2904a7344cd65c67e01ce85e",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat.agda",
"max_line_length": 80,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 458,
"size": 1753
} |
module cantor where
data Empty : Set where
data One : Set where
one : One
data coprod (A : Set1) (B : Set1) : Set1 where
inl : ∀ (a : A) -> coprod A B
inr : ∀ (b : B) -> coprod A B
postulate exmid : ∀ (A : Set1) -> coprod A (A -> Empty)
data Eq1 {A : Set1} (x : A) : A -> Set1 where
refleq1 : Eq1 x x
cast : ∀ { A B } -> Eq1 A B -> A -> B
cast refleq1 a = a
Eq1cong : ∀ {f g : Set -> Set} a -> Eq1 f g -> Eq1 (f a) (g a)
Eq1cong a refleq1 = refleq1
Eq1sym : ∀ {A : Set1} { x y : A } -> Eq1 x y -> Eq1 y x
Eq1sym refleq1 = refleq1
Eq1trans : ∀ {A : Set1} { x y z : A } -> Eq1 x y -> Eq1 y z -> Eq1 x z
Eq1trans refleq1 refleq1 = refleq1
data I : (Set -> Set) -> Set where
Iinj : ∀ { x y : Set -> Set } -> Eq1 (I x) (I y) -> Eq1 x y
Iinj refleq1 = refleq1
data invimageI (a : Set) : Set1 where
invelmtI : forall x -> (Eq1 (I x) a) -> invimageI a
J : Set -> (Set -> Set)
J a with exmid (invimageI a)
J a | inl (invelmtI x y) = x
J a | inr b = λ x → Empty
data invimageJ (x : Set -> Set) : Set1 where
invelmtJ : forall a -> (Eq1 (J a) x) -> invimageJ x
IJIeqI : ∀ x -> Eq1 (I (J (I x))) (I x)
IJIeqI x with exmid (invimageI (I x))
IJIeqI x | inl (invelmtI x' y) = y
IJIeqI x | inr b with b (invelmtI x refleq1)
IJIeqI x | inr b | ()
J_srj : ∀ (x : Set -> Set) -> invimageJ x
J_srj x = invelmtJ (I x) (Iinj (IJIeqI x))
cantor : Set -> Set
cantor a with exmid (Eq1 (J a a) Empty)
cantor a | inl a' = One
cantor a | inr b = Empty
OneNeqEmpty : Eq1 One Empty -> Empty
OneNeqEmpty p = cast p one
cantorone : ∀ a -> Eq1 (J a a) Empty -> Eq1 (cantor a) One
cantorone a p with exmid (Eq1 (J a a) Empty)
cantorone a p | inl a' = refleq1
cantorone a p | inr b with b p
cantorone a p | inr b | ()
cantorempty : ∀ a -> (Eq1 (J a a) Empty -> Empty) -> Eq1 (cantor a) Empty
cantorempty a p with exmid (Eq1 (J a a) Empty)
cantorempty a p | inl a' with p a'
cantorempty a p | inl a' | ()
cantorempty a p | inr b = refleq1
cantorcase : ∀ a -> Eq1 cantor (J a) -> Empty
cantorcase a pf with exmid (Eq1 (J a a) Empty)
cantorcase a pf | inl a' = OneNeqEmpty (Eq1trans (Eq1trans (Eq1sym (cantorone a a')) (Eq1cong a pf)) a')
cantorcase a pf | inr b = b (Eq1trans (Eq1sym (Eq1cong a pf)) (cantorempty a b))
absurd : Empty
absurd with (J_srj cantor)
absurd | invelmtJ a y = cantorcase a (Eq1sym y)
| {
"alphanum_fraction": 0.571369637,
"avg_line_length": 29.5609756098,
"ext": "agda",
"hexsha": "601a973a0a5b99e75e318bdf143fbe58ea21eaa1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1bcdcc1bc160aa70dafcff5030077021c61d9c38",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/AN201710",
"max_forks_repo_path": "Learn/cantor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1bcdcc1bc160aa70dafcff5030077021c61d9c38",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/AN201710",
"max_issues_repo_path": "Learn/cantor.agda",
"max_line_length": 106,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "1bcdcc1bc160aa70dafcff5030077021c61d9c38",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/NomicCoin201710",
"max_stars_repo_path": "Learn/cantor.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-24T08:57:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-22T03:25:59.000Z",
"num_tokens": 1040,
"size": 2424
} |
------------------------------------------------------------------------
-- Precedence-correct expressions
------------------------------------------------------------------------
module Mixfix.Expr where
open import Data.Vec using (Vec)
open import Data.List using (List; []; _∷_)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Unary.Any using (here; there)
open import Data.Product using (∃; _,_)
open import Mixfix.Fixity
open import Mixfix.Operator
------------------------------------------------------------------------
-- An abstract definition of precedence graphs
-- The interface of precedence graphs.
record PrecedenceGraphInterface : Set₁ where
field
-- Precedence graphs.
PrecedenceGraph : Set
-- Precedence levels.
Precedence : PrecedenceGraph → Set
-- The operators of the given precedence.
ops : (g : PrecedenceGraph) →
Precedence g → (fix : Fixity) → List (∃ (Operator fix))
-- The immediate successors of the precedence level.
↑ : (g : PrecedenceGraph) → Precedence g → List (Precedence g)
-- All precedence levels in the graph.
anyPrecedence : (g : PrecedenceGraph) → List (Precedence g)
-- When a precedence graph is given the following module may be
-- convenient to avoid having to write "g" all the time.
module PrecedenceGraph
(i : PrecedenceGraphInterface)
(g : PrecedenceGraphInterface.PrecedenceGraph i)
where
PrecedenceGraph : Set
PrecedenceGraph = PrecedenceGraphInterface.PrecedenceGraph i
Precedence : Set
Precedence = PrecedenceGraphInterface.Precedence i g
ops : Precedence → (fix : Fixity) → List (∃ (Operator fix))
ops = PrecedenceGraphInterface.ops i g
↑ : Precedence → List Precedence
↑ = PrecedenceGraphInterface.↑ i g
anyPrecedence : List Precedence
anyPrecedence = PrecedenceGraphInterface.anyPrecedence i g
------------------------------------------------------------------------
-- Precedence-correct operator applications
-- Parameterised on a precedence graph.
module PrecedenceCorrect
(i : PrecedenceGraphInterface)
(g : PrecedenceGraphInterface.PrecedenceGraph i)
where
open PrecedenceGraph i g public
mutual
infixl 4 _⟨_⟩ˡ_
infixr 4 _⟨_⟩ʳ_
infix 4 _⟨_⟩_ _⟨_⟫ ⟪_⟩_ _∙_
-- Expr ps contains expressions where the outermost operator has
-- one of the precedences in ps.
data Expr (ps : List Precedence) : Set where
_∙_ : ∀ {p assoc} (p∈ps : p ∈ ps) (e : ExprIn p assoc) → Expr ps
-- ExprIn p assoc contains expressions where the outermost
-- operator has precedence p (is /in/ precedence level p) and the
-- associativity assoc.
data ExprIn (p : Precedence) : Associativity → Set where
⟪_⟫ : (op : Inner (ops p closed )) → ExprIn p non
_⟨_⟫ : (l : Outer p left) (op : Inner (ops p postfx )) → ExprIn p left
⟪_⟩_ : (op : Inner (ops p prefx )) (r : Outer p right) → ExprIn p right
_⟨_⟩_ : (l : Expr (↑ p) ) (op : Inner (ops p (infx non ))) (r : Expr (↑ p) ) → ExprIn p non
_⟨_⟩ˡ_ : (l : Outer p left) (op : Inner (ops p (infx left ))) (r : Expr (↑ p) ) → ExprIn p left
_⟨_⟩ʳ_ : (l : Expr (↑ p) ) (op : Inner (ops p (infx right))) (r : Outer p right) → ExprIn p right
-- Outer p fix contains expressions where the head operator either
-- ⑴ has precedence p and associativity assoc or
-- ⑵ binds strictly tighter than p.
data Outer (p : Precedence) (assoc : Associativity) : Set where
similar : (e : ExprIn p assoc) → Outer p assoc
tighter : (e : Expr (↑ p)) → Outer p assoc
-- Inner ops contains the internal parts (operator plus
-- internal arguments) of operator applications. The operators
-- have to be members of ops.
data Inner {fix} (ops : List (∃ (Operator fix))) : Set where
_∙_ : ∀ {arity op}
(op∈ops : (arity , op) ∈ ops)
(args : Vec (Expr anyPrecedence) arity) →
Inner ops
-- "Weakening".
weakenE : ∀ {p ps} → Expr ps → Expr (p ∷ ps)
weakenE (p∈ps ∙ e) = there p∈ps ∙ e
weakenI : ∀ {fix ops} {op : ∃ (Operator fix)} →
Inner ops → Inner (op ∷ ops)
weakenI (op∈ops ∙ args) = there op∈ops ∙ args
| {
"alphanum_fraction": 0.5883971566,
"avg_line_length": 35.1693548387,
"ext": "agda",
"hexsha": "59b551fa69f581476c2f012f5d2041a3201469ed",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "Mixfix/Expr.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "Mixfix/Expr.agda",
"max_line_length": 104,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "Mixfix/Expr.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 1231,
"size": 4361
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Semigroup.Subsemigroup where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Algebra
open import Cubical.Algebra.Semigroup.Morphism
open import Cubical.Algebra.Magma.Submagma
open import Cubical.Relation.Unary
open import Cubical.Relation.Unary.Subtype
record IsSubsemigroup {c ℓ} (S : Semigroup c) (Member : Pred ⟨ S ⟩ ℓ) : Type (ℓ-max c ℓ) where
constructor issubsemigroup
private module S = Semigroup S
field
closed : S._•_ Preserves₂ Member
isSubmagma : IsSubmagma S.magma Member
isSubmagma = record { closed = closed }
open IsSubmagma isSubmagma hiding (closed) public
assoc : Associative _•_
assoc _ _ _ = ΣPathTransport→PathΣ _ _ (S.assoc _ _ _ , isProp[ Member ] _ _ _)
isSemigroup : IsSemigroup Carrier _•_
isSemigroup = record
{ isMagma = isMagma
; assoc = assoc
}
semigroup : Semigroup _
semigroup = record { isSemigroup = isSemigroup }
open Semigroup semigroup using (_^_) public
record Subsemigroup {c} (S : Semigroup c) ℓ : Type (ℓ-max c (ℓ-suc ℓ)) where
constructor mksubsemigroup
private module S = Semigroup S
field
Member : Pred ⟨ S ⟩ ℓ
isSubsemigroup : IsSubsemigroup S Member
open IsSubsemigroup isSubsemigroup public
submagma : Submagma S.magma ℓ
submagma = record { isSubmagma = isSubmagma }
instance
SubsemigroupCarrier : ∀ {c ℓ} {S : Semigroup c} → HasCarrier (Subsemigroup S ℓ) _
SubsemigroupCarrier = record { ⟨_⟩ = Subsemigroup.Carrier }
module _ {ℓ} (S : Semigroup ℓ) where
open Semigroup S
∅-isSubsemigroup : IsSubsemigroup S ∅
∅-isSubsemigroup = record { closed = λ () }
∅-subsemigroup : Subsemigroup S _
∅-subsemigroup = record { isSubsemigroup = ∅-isSubsemigroup }
U-isSubsemigroup : IsSubsemigroup S U
U-isSubsemigroup = record {} -- trivial
U-subsemigroup : Subsemigroup S _
U-subsemigroup = record { isSubsemigroup = U-isSubsemigroup }
| {
"alphanum_fraction": 0.7237728585,
"avg_line_length": 25.3414634146,
"ext": "agda",
"hexsha": "a3ef64c1033a38963f001c62c3937fedd0181904",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Semigroup/Subsemigroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Semigroup/Subsemigroup.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Semigroup/Subsemigroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 657,
"size": 2078
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.CohomologyRings.Unit where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_)
open import Cubical.Data.Int
open import Cubical.Data.Vec
open import Cubical.Data.FinData
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int renaming (ℤGroup to ℤG)
open import Cubical.Algebra.DirectSum.Base
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR)
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.Polynomials.Multivariate.Base renaming (base to baseP)
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.A[X]X-A
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ
open import Cubical.HITs.Truncation
open import Cubical.HITs.SetQuotients as SQ renaming (_/_ to _/sq_)
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.CohomologyRing
open import Cubical.ZCohomology.Groups.Unit
open Iso
module Equiv-Unit-Properties where
open CommRingStr (snd ℤCR) using ()
renaming
( 0r to 0ℤ
; 1r to 1ℤ
; _+_ to _+ℤ_
; -_ to -ℤ_
; _·_ to _·ℤ_
; +Assoc to +ℤAssoc
; +Identity to +ℤIdentity
; +Lid to +ℤLid
; +Rid to +ℤRid
; +Inv to +ℤInv
; +Linv to +ℤLinv
; +Rinv to +ℤRinv
; +Comm to +ℤComm
; ·Assoc to ·ℤAssoc
; ·Identity to ·ℤIdentity
; ·Lid to ·ℤLid
; ·Rid to ·ℤRid
; ·Rdist+ to ·ℤRdist+
; ·Ldist+ to ·ℤLdist+
; is-set to isSetℤ )
open RingStr (snd (H*R Unit)) using ()
renaming
( 0r to 0H*
; 1r to 1H*
; _+_ to _+H*_
; -_ to -H*_
; _·_ to _cup_
; +Assoc to +H*Assoc
; +Identity to +H*Identity
; +Lid to +H*Lid
; +Rid to +H*Rid
; +Inv to +H*Inv
; +Linv to +H*Linv
; +Rinv to +H*Rinv
; +Comm to +H*Comm
; ·Assoc to ·H*Assoc
; ·Identity to ·H*Identity
; ·Lid to ·H*Lid
; ·Rid to ·H*Rid
; ·Rdist+ to ·H*Rdist+
; ·Ldist+ to ·H*Ldist+
; is-set to isSetH* )
open CommRingStr (snd ℤ[X]) using ()
renaming
( 0r to 0Pℤ
; 1r to 1Pℤ
; _+_ to _+Pℤ_
; -_ to -Pℤ_
; _·_ to _·Pℤ_
; +Assoc to +PℤAssoc
; +Identity to +PℤIdentity
; +Lid to +PℤLid
; +Rid to +PℤRid
; +Inv to +PℤInv
; +Linv to +PℤLinv
; +Rinv to +PℤRinv
; +Comm to +PℤComm
; ·Assoc to ·PℤAssoc
; ·Identity to ·PℤIdentity
; ·Lid to ·PℤLid
; ·Rid to ·PℤRid
; ·Rdist+ to ·PℤRdist+
; ·Ldist+ to ·PℤLdist+
; is-set to isSetPℤ )
open CommRingStr (snd ℤ[X]/X) using ()
renaming
( 0r to 0PℤI
; 1r to 1PℤI
; _+_ to _+PℤI_
; -_ to -PℤI_
; _·_ to _·PℤI_
; +Assoc to +PℤIAssoc
; +Identity to +PℤIIdentity
; +Lid to +PℤILid
; +Rid to +PℤIRid
; +Inv to +PℤIInv
; +Linv to +PℤILinv
; +Rinv to +PℤIRinv
; +Comm to +PℤIComm
; ·Assoc to ·PℤIAssoc
; ·Identity to ·PℤIIdentity
; ·Lid to ·PℤILid
; ·Rid to ·PℤIRid
; ·Rdist+ to ·PℤIRdist+
; ·Ldist+ to ·PℤILdist+
; is-set to isSetPℤI )
-----------------------------------------------------------------------------
-- Direct Sens on ℤ[x]
ℤ[x]→H*-Unit : ℤ[x] → H* Unit
ℤ[x]→H*-Unit = Poly-Rec-Set.f _ _ _ isSetH*
0H*
base-trad
_+H*_
+H*Assoc
+H*Rid
+H*Comm
base-neutral-eq
base-add-eq
where
base-trad : _
base-trad (zero ∷ []) a = base zero (inv (fst H⁰-Unit≅ℤ) a)
base-trad (suc n ∷ []) a = 0H*
base-neutral-eq : _
base-neutral-eq (zero ∷ []) = base-neutral _
base-neutral-eq (suc n ∷ []) = refl
base-add-eq : _
base-add-eq (zero ∷ []) a b = base-add _ _ _
base-add-eq (suc n ∷ []) a b = +H*Rid _
ℤ[x]→H*-Unit-pres1Pℤ : ℤ[x]→H*-Unit (1Pℤ) ≡ 1H*
ℤ[x]→H*-Unit-pres1Pℤ = refl
ℤ[x]→H*-Unit-pres+ : (x y : ℤ[x]) → ℤ[x]→H*-Unit (x +Pℤ y) ≡ ℤ[x]→H*-Unit x +H* ℤ[x]→H*-Unit y
ℤ[x]→H*-Unit-pres+ x y = refl
-- Proving the morphism on the cup product
T0 : (z : ℤ) → coHom 0 Unit
T0 = λ z → inv (fst H⁰-Unit≅ℤ) z
T0g : IsGroupHom (ℤG .snd) (fst (invGroupIso H⁰-Unit≅ℤ) .fun) (coHomGr 0 Unit .snd)
T0g = snd (invGroupIso H⁰-Unit≅ℤ)
-- idea : control of the unfolding + simplification of T0 on the left
pres·-base-case-00 : (a : ℤ) → (b : ℤ) →
T0 (a ·ℤ b) ≡ (T0 a) ⌣ (T0 b)
pres·-base-case-00 (pos zero) b = (IsGroupHom.pres1 T0g)
pres·-base-case-00 (pos (suc n)) b = ((IsGroupHom.pres· T0g b (pos n ·ℤ b)))
∙ (cong (λ X → (T0 b) +ₕ X) (pres·-base-case-00 (pos n) b))
pres·-base-case-00 (negsuc zero) b = IsGroupHom.presinv T0g b
pres·-base-case-00 (negsuc (suc n)) b = cong T0 (+ℤComm (-ℤ b) (negsuc n ·ℤ b)) -- ·ℤ and ·₀ are defined asymetrically !
∙ IsGroupHom.pres· T0g (negsuc n ·ℤ b) (-ℤ b)
∙ cong₂ _+ₕ_ (pres·-base-case-00 (negsuc n) b)
(IsGroupHom.presinv T0g b)
pres·-base-case-int : (n : ℕ) → (a : ℤ) → (m : ℕ) → (b : ℤ) →
ℤ[x]→H*-Unit (baseP (n ∷ []) a ·Pℤ baseP (m ∷ []) b)
≡ ℤ[x]→H*-Unit (baseP (n ∷ []) a) cup ℤ[x]→H*-Unit (baseP (m ∷ []) b)
pres·-base-case-int zero a zero b = cong (base 0) (pres·-base-case-00 a b)
pres·-base-case-int zero a (suc m) b = refl
pres·-base-case-int (suc n) a m b = refl
pres·-base-case-vec : (v : Vec ℕ 1) → (a : ℤ) → (v' : Vec ℕ 1) → (b : ℤ) →
ℤ[x]→H*-Unit (baseP v a ·Pℤ baseP v' b)
≡ ℤ[x]→H*-Unit (baseP v a) cup ℤ[x]→H*-Unit (baseP v' b)
pres·-base-case-vec (n ∷ []) a (m ∷ []) b = pres·-base-case-int n a m b
ℤ[x]→H*-Unit-pres· : (x y : ℤ[x]) → ℤ[x]→H*-Unit (x ·Pℤ y) ≡ ℤ[x]→H*-Unit x cup ℤ[x]→H*-Unit y
ℤ[x]→H*-Unit-pres· = Poly-Ind-Prop.f _ _ _
(λ x p q i y j → isSetH* _ _ (p y) (q y) i j)
(λ y → refl)
base-case
λ {U V} ind-U ind-V y → cong₂ _+H*_ (ind-U y) (ind-V y)
where
base-case : _
base-case (n ∷ []) a = Poly-Ind-Prop.f _ _ _ (λ _ → isSetH* _ _)
(sym (RingTheory.0RightAnnihilates (H*R Unit) _))
(λ v' b → pres·-base-case-vec (n ∷ []) a v' b)
λ {U V} ind-U ind-V → (cong₂ _+H*_ ind-U ind-V) ∙ sym (·H*Rdist+ _ _ _)
-- raising to the product
ℤ[x]→H*-Unit-cancelX : (k : Fin 1) → ℤ[x]→H*-Unit (<X> k) ≡ 0H*
ℤ[x]→H*-Unit-cancelX zero = refl
ℤ[X]→H*-Unit : RingHom (CommRing→Ring ℤ[X]) (H*R Unit)
fst ℤ[X]→H*-Unit = ℤ[x]→H*-Unit
snd ℤ[X]→H*-Unit = makeIsRingHom ℤ[x]→H*-Unit-pres1Pℤ ℤ[x]→H*-Unit-pres+ ℤ[x]→H*-Unit-pres·
ℤ[X]/X→H*R-Unit : RingHom (CommRing→Ring ℤ[X]/X) (H*R Unit)
ℤ[X]/X→H*R-Unit = Quotient-FGideal-CommRing-Ring.f ℤ[X] (H*R Unit) ℤ[X]→H*-Unit <X> ℤ[x]→H*-Unit-cancelX
ℤ[x]/x→H*-Unit : ℤ[x]/x → H* Unit
ℤ[x]/x→H*-Unit = fst ℤ[X]/X→H*R-Unit
-----------------------------------------------------------------------------
-- Converse Sens on ℤ[X]
H*-Unit→ℤ[x] : H* Unit → ℤ[x]
H*-Unit→ℤ[x] = DS-Rec-Set.f _ _ _ _ isSetPℤ
0Pℤ
base-trad
_+Pℤ_
+PℤAssoc
+PℤRid
+PℤComm
base-neutral-eq
base-add-eq
where
base-trad : (n : ℕ) → coHom n Unit → ℤ[x]
base-trad zero a = baseP (0 ∷ []) (fun (fst H⁰-Unit≅ℤ) a)
base-trad (suc n) a = 0Pℤ
base-neutral-eq : _
base-neutral-eq zero = base-0P _
base-neutral-eq (suc n) = refl
base-add-eq : _
base-add-eq zero a b = base-poly+ _ _ _
∙ cong (baseP (0 ∷ [])) (sym (IsGroupHom.pres· (snd H⁰-Unit≅ℤ) a b))
base-add-eq (suc n) a b = +PℤRid _
H*-Unit→ℤ[x]-pres+ : (x y : H* Unit) → H*-Unit→ℤ[x] ( x +H* y) ≡ H*-Unit→ℤ[x] x +Pℤ H*-Unit→ℤ[x] y
H*-Unit→ℤ[x]-pres+ x y = refl
H*-Unit→ℤ[x]/x : H* Unit → ℤ[x]/x
H*-Unit→ℤ[x]/x = [_] ∘ H*-Unit→ℤ[x]
H*-Unit→ℤ[x]/x-pres+ : (x y : H* Unit) → H*-Unit→ℤ[x]/x (x +H* y) ≡ (H*-Unit→ℤ[x]/x x) +PℤI (H*-Unit→ℤ[x]/x y)
H*-Unit→ℤ[x]/x-pres+ x y = cong [_] (H*-Unit→ℤ[x]-pres+ x y)
-----------------------------------------------------------------------------
-- Section
e-sect : (x : H* Unit) → ℤ[x]/x→H*-Unit (H*-Unit→ℤ[x]/x x) ≡ x
e-sect = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH* _ _)
refl
base-case
λ {U V} ind-U ind-V → cong ℤ[x]/x→H*-Unit (H*-Unit→ℤ[x]/x-pres+ U V)
∙ IsRingHom.pres+ (snd ℤ[X]/X→H*R-Unit) (H*-Unit→ℤ[x]/x U) (H*-Unit→ℤ[x]/x V)
∙ cong₂ _+H*_ ind-U ind-V
where
base-case : _
base-case zero a = cong (base 0) (leftInv (fst H⁰-Unit≅ℤ) a)
base-case (suc n) a = (sym (base-neutral (suc n)))
∙ (cong (base (suc n)) ((isContr→isProp (isContrHⁿ-Unit n) _ a)))
-----------------------------------------------------------------------------
-- Retraction
e-retr : (x : ℤ[x]/x) → H*-Unit→ℤ[x]/x (ℤ[x]/x→H*-Unit x) ≡ x
e-retr = SQ.elimProp (λ _ → isSetPℤI _ _)
(Poly-Ind-Prop.f _ _ _ (λ _ → isSetPℤI _ _)
refl
base-case
λ {U V} ind-U ind-V → cong₂ _+PℤI_ ind-U ind-V)
where
base-case : _
base-case (zero ∷ []) a = refl
base-case (suc n ∷ []) a = eq/ 0Pℤ (baseP (suc n ∷ []) a) ∣ ((λ x → baseP (n ∷ []) (-ℤ a)) , foo) ∣₁
where
foo : (0P poly+ baseP (suc n ∷ []) (- a)) ≡ (baseP (n +n 1 ∷ []) (- a · pos 1) poly+ 0P)
foo = (0P poly+ baseP (suc n ∷ []) (- a)) ≡⟨ +PℤLid _ ⟩
baseP (suc n ∷ []) (- a) ≡⟨ cong₂ baseP (cong (λ X → X ∷ []) (sym ((+-suc n 0)
∙ (cong suc (+-zero n))))) (sym (·ℤRid _)) ⟩
baseP (n +n suc 0 ∷ []) (- a ·ℤ 1ℤ) ≡⟨ refl ⟩
baseP (n +n 1 ∷ []) (- a · pos 1) ≡⟨ sym (+PℤRid _) ⟩
(baseP (n +n 1 ∷ []) (- a · pos 1) poly+ 0P) ∎
-----------------------------------------------------------------------------
-- Computation of the Cohomology Ring
module _ where
open Equiv-Unit-Properties
open RingEquivs
Unit-CohomologyRingP : RingEquiv (CommRing→Ring ℤ[X]/X) (H*R Unit)
fst Unit-CohomologyRingP = isoToEquiv is
where
is : Iso ℤ[x]/x (H* Unit)
fun is = ℤ[x]/x→H*-Unit
inv is = H*-Unit→ℤ[x]/x
rightInv is = e-sect
leftInv is = e-retr
snd Unit-CohomologyRingP = snd ℤ[X]/X→H*R-Unit
CohomologyRing-UnitP : RingEquiv (H*R Unit) (CommRing→Ring ℤ[X]/X)
CohomologyRing-UnitP = invEquivRing Unit-CohomologyRingP
Unit-CohomologyRingℤ : RingEquiv (CommRing→Ring ℤCR) (H*R Unit)
Unit-CohomologyRingℤ = compRingEquiv (invEquivRing Equiv-ℤ[X]/X-ℤ) Unit-CohomologyRingP
CohomologyRing-Unitℤ : RingEquiv (H*R Unit) (CommRing→Ring ℤCR)
CohomologyRing-Unitℤ = compRingEquiv CohomologyRing-UnitP Equiv-ℤ[X]/X-ℤ
| {
"alphanum_fraction": 0.495,
"avg_line_length": 36.5781710914,
"ext": "agda",
"hexsha": "37ed3aef5ef5a64c4e9fb76492018730a67b6477",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xekoukou/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/CohomologyRings/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xekoukou/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/CohomologyRings/Unit.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xekoukou/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/CohomologyRings/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4705,
"size": 12400
} |
-- Andreas, 2016-12-30, issue #1886
-- Make sure we do not duplicate types of parameters.
-- {-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.data:40 -v scope.data.def:40 -v tc.decl:10 -v tc:20 #-}
data D {A : Set} (x y : {!!}) : Set where
-- Expected: only one type and one sort meta.
| {
"alphanum_fraction": 0.6212624585,
"avg_line_length": 27.3636363636,
"ext": "agda",
"hexsha": "3686b2a4b1abddd74cf92ae5d6fab6c4dc45c43d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue1886-dont-duplicate-ip.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue1886-dont-duplicate-ip.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1886-dont-duplicate-ip.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 97,
"size": 301
} |
-- 2014-08-25 reported by Wolfram Kahl, test case shrunk by Ulf, fixed by Andreas and Ulf
-- {-# OPTIONS --show-implicit -v tc.cover.splittree:10 -v tc.with:40 -v tc.cc:12 #-}
postulate K : Set
data SUList : K → Set where
cons : ∀ {k} (es : SUList k) → SUList k
data Tri : Set where
tri< tri> : Tri
postulate
k : K
compareK : Tri
dummy : Set
es : SUList k
diff : SUList k → SUList k → Tri → Set
diff (cons _) _ tri< = K
diff es₁ (cons es₂) tri> = diff es₁ es₂ compareK
test = diff (cons es) (cons es) tri>
-- normalizing test
-- gives WRONG diff (cons k es) es compareK
-- should be diff (cons {k} es) es compareK
-- Problem was in the clause compiler
-- Trigger the bug:
from : (es : SUList k) (c : Tri) → diff (cons es) (cons es) c → Set
from es tri< d = K
from es tri> d with dummy
... | _ = K
-- WAS:
-- Expected a hidden argument, but found a visible argument
-- when checking that the type
-- Set → (es₁ : SUList k) (d : diff (cons k es₁) es₁ compareK) → Set
-- of the generated with function is well-formed
| {
"alphanum_fraction": 0.6439539347,
"avg_line_length": 27.4210526316,
"ext": "agda",
"hexsha": "fdae369b33e33d5842936777f1421c1298d02c5b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1186.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1186.agda",
"max_line_length": 89,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1186.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 352,
"size": 1042
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of pointwise equality for containers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Relation.Binary.Pointwise.Properties where
open import Axiom.Extensionality.Propositional
open import Data.Container.Core
open import Data.Container.Relation.Binary.Pointwise
open import Data.Product using (_,_; Σ-syntax; -,_)
open import Level using (_⊔_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
using (_≡_; subst; cong)
module _ {s p x r} {X : Set x} (C : Container s p) (R : Rel X r) where
refl : Reflexive R → Reflexive (Pointwise C R)
refl R-refl = P.refl , λ p → R-refl
sym : Symmetric R → Symmetric (Pointwise C R)
sym R-sym (P.refl , f) = P.refl , λ p → R-sym (f p)
trans : Transitive R → Transitive (Pointwise C R)
trans R-trans (P.refl , f) (P.refl , g) = P.refl , λ p → R-trans (f p) (g p)
private
-- Note that, if propositional equality were extensional, then
-- Eq _≡_ and _≡_ would coincide.
Eq⇒≡ : ∀ {s p x} {C : Container s p} {X : Set x} {xs ys : ⟦ C ⟧ X} →
Extensionality p x → Pointwise C _≡_ xs ys → xs ≡ ys
Eq⇒≡ ext (P.refl , f≈f′) = cong -,_ (ext f≈f′)
| {
"alphanum_fraction": 0.5918215613,
"avg_line_length": 34.4871794872,
"ext": "agda",
"hexsha": "773d23ea03ebd8a2aa5083486522533b5f7e4974",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Pointwise/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Pointwise/Properties.agda",
"max_line_length": 78,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Container/Relation/Binary/Pointwise/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 397,
"size": 1345
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Groups.Definition
open import Groups.Homomorphisms.Definition
open import Groups.SymmetricGroups.Definition
open import Groups.Actions.Definition
open import Sets.EquivalenceRelations
module Groups.ActionIsSymmetry {a b c d : _} {A : Set a} {B : Set b} {S : Setoid {a} {c} A} {T : Setoid {b} {d} B} {_+_ : A → A → A} {G : Group S _+_} (gAction : GroupAction G T) where
open Group G
open GroupAction gAction
actionPermutation : (g : A) → SymmetryGroupElements T
actionPermutation g = sym {f = λ x → action g x} (record { inj = record { injective = inj ; wellDefined = actionWellDefined2 } ; surj = record { surjective = surj ; wellDefined = actionWellDefined2 } })
where
open Setoid T
open Equivalence eq
inj : {x y : B} → (Setoid._∼_ T (action g x) (action g y)) → Setoid._∼_ T x y
inj {x} {y} gx=gy = transitive (symmetric identityAction) (transitive (transitive (symmetric (actionWellDefined1 (invLeft {g}))) (transitive (transitive associativeAction (transitive (actionWellDefined2 gx=gy) (symmetric associativeAction))) (actionWellDefined1 (invLeft {g})))) identityAction)
surj : {x : B} → Sg B (λ a → action g a ∼ x)
surj {x} = action (inverse g) x , transitive (symmetric associativeAction) (transitive (actionWellDefined1 invRight) identityAction)
actionPermutationMapIsHom : GroupHom G (symmetricGroup T) actionPermutation
GroupHom.groupHom actionPermutationMapIsHom = associativeAction
GroupHom.wellDefined actionPermutationMapIsHom x=y = actionWellDefined1 x=y
| {
"alphanum_fraction": 0.7353485503,
"avg_line_length": 55.8965517241,
"ext": "agda",
"hexsha": "fe44bac8933b6251979a2a14431476d900b4a19b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/ActionIsSymmetry.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/ActionIsSymmetry.agda",
"max_line_length": 298,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/ActionIsSymmetry.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 480,
"size": 1621
} |
module tests.Arith where
open import Prelude.IO
open import Prelude.Nat
open import Prelude.Unit
test : Nat
test = 4
foobar : Nat -> Nat
foobar Z = Z
foobar (S n) = S (S n)
main : IO Unit
main =
-- n <- readNat ,
printNat 0 ,,
printNat (0 + 1) ,,
printNat (1 * 2) ,,
printNat (S (S (S (S Z))) - S Z) ,,
printNat test ,,
printNat (foobar 4) ,,
-- printNat n ,,
return unit
| {
"alphanum_fraction": 0.5974683544,
"avg_line_length": 15.8,
"ext": "agda",
"hexsha": "9c14dd7ca679747b51a57e1cf8f1c0f79c1211cc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "test/epic/tests/Arith.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "test/epic/tests/Arith.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/epic/tests/Arith.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 143,
"size": 395
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists
------------------------------------------------------------------------
module Data.List where
open import Data.Nat
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂)
open import Data.Bool
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Product as Prod using (_×_; _,_)
open import Function
open import Algebra
import Relation.Binary.PropositionalEquality as PropEq
import Algebra.FunctionProperties as FunProp
infixr 5 _∷_ _++_
------------------------------------------------------------------------
-- Types
data List {a} (A : Set a) : Set a where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
{-# IMPORT Data.FFI #-}
{-# COMPILED_DATA List Data.FFI.AgdaList [] (:) #-}
------------------------------------------------------------------------
-- Some operations
-- * Basic functions
[_] : ∀ {a} {A : Set a} → A → List A
[ x ] = x ∷ []
_++_ : ∀ {a} {A : Set a} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
-- Snoc.
infixl 5 _∷ʳ_
_∷ʳ_ : ∀ {a} {A : Set a} → List A → A → List A
xs ∷ʳ x = xs ++ [ x ]
null : ∀ {a} {A : Set a} → List A → Bool
null [] = true
null (x ∷ xs) = false
-- * List transformations
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
replicate : ∀ {a} {A : Set a} → (n : ℕ) → A → List A
replicate zero x = []
replicate (suc n) x = x ∷ replicate n x
zipWith : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
→ (A → B → C) → List A → List B → List C
zipWith f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys
zipWith f _ _ = []
zip : ∀ {a b} {A : Set a} {B : Set b} → List A → List B → List (A × B)
zip = zipWith (_,_)
intersperse : ∀ {a} {A : Set a} → A → List A → List A
intersperse x [] = []
intersperse x (y ∷ []) = [ y ]
intersperse x (y ∷ z ∷ zs) = y ∷ x ∷ intersperse x (z ∷ zs)
-- * Reducing lists (folds)
foldr : ∀ {a b} {A : Set a} {B : Set b} → (A → B → B) → B → List A → B
foldr c n [] = n
foldr c n (x ∷ xs) = c x (foldr c n xs)
foldl : ∀ {a b} {A : Set a} {B : Set b} → (A → B → A) → A → List B → A
foldl c n [] = n
foldl c n (x ∷ xs) = foldl c (c n x) xs
-- ** Special folds
concat : ∀ {a} {A : Set a} → List (List A) → List A
concat = foldr _++_ []
concatMap : ∀ {a b} {A : Set a} {B : Set b} →
(A → List B) → List A → List B
concatMap f = concat ∘ map f
and : List Bool → Bool
and = foldr _∧_ true
or : List Bool → Bool
or = foldr _∨_ false
any : ∀ {a} {A : Set a} → (A → Bool) → List A → Bool
any p = or ∘ map p
all : ∀ {a} {A : Set a} → (A → Bool) → List A → Bool
all p = and ∘ map p
sum : List ℕ → ℕ
sum = foldr _+_ 0
product : List ℕ → ℕ
product = foldr _*_ 1
length : ∀ {a} {A : Set a} → List A → ℕ
length = foldr (λ _ → suc) 0
reverse : ∀ {a} {A : Set a} → List A → List A
reverse = foldl (λ rev x → x ∷ rev) []
-- * Building lists
-- ** Scans
scanr : ∀ {a b} {A : Set a} {B : Set b} →
(A → B → B) → B → List A → List B
scanr f e [] = e ∷ []
scanr f e (x ∷ xs) with scanr f e xs
... | [] = [] -- dead branch
... | y ∷ ys = f x y ∷ y ∷ ys
scanl : ∀ {a b} {A : Set a} {B : Set b} →
(A → B → A) → A → List B → List A
scanl f e [] = e ∷ []
scanl f e (x ∷ xs) = e ∷ scanl f (f e x) xs
-- ** Unfolding
-- Unfold. Uses a measure (a natural number) to ensure termination.
unfold : ∀ {a b} {A : Set a} (B : ℕ → Set b)
(f : ∀ {n} → B (suc n) → Maybe (A × B n)) →
∀ {n} → B n → List A
unfold B f {n = zero} s = []
unfold B f {n = suc n} s with f s
... | nothing = []
... | just (x , s') = x ∷ unfold B f s'
-- downFrom 3 = 2 ∷ 1 ∷ 0 ∷ [].
downFrom : ℕ → List ℕ
downFrom n = unfold Singleton f (wrap n)
where
data Singleton : ℕ → Set where
wrap : (n : ℕ) → Singleton n
f : ∀ {n} → Singleton (suc n) → Maybe (ℕ × Singleton n)
f {n} (wrap .(suc n)) = just (n , wrap n)
-- ** Conversions
fromMaybe : ∀ {a} {A : Set a} → Maybe A → List A
fromMaybe (just x) = [ x ]
fromMaybe nothing = []
-- * Sublists
-- ** Extracting sublists
take : ∀ {a} {A : Set a} → ℕ → List A → List A
take zero xs = []
take (suc n) [] = []
take (suc n) (x ∷ xs) = x ∷ take n xs
drop : ∀ {a} {A : Set a} → ℕ → List A → List A
drop zero xs = xs
drop (suc n) [] = []
drop (suc n) (x ∷ xs) = drop n xs
splitAt : ∀ {a} {A : Set a} → ℕ → List A → (List A × List A)
splitAt zero xs = ([] , xs)
splitAt (suc n) [] = ([] , [])
splitAt (suc n) (x ∷ xs) with splitAt n xs
... | (ys , zs) = (x ∷ ys , zs)
takeWhile : ∀ {a} {A : Set a} → (A → Bool) → List A → List A
takeWhile p [] = []
takeWhile p (x ∷ xs) with p x
... | true = x ∷ takeWhile p xs
... | false = []
dropWhile : ∀ {a} {A : Set a} → (A → Bool) → List A → List A
dropWhile p [] = []
dropWhile p (x ∷ xs) with p x
... | true = dropWhile p xs
... | false = x ∷ xs
span : ∀ {a} {A : Set a} → (A → Bool) → List A → (List A × List A)
span p [] = ([] , [])
span p (x ∷ xs) with p x
... | true = Prod.map (_∷_ x) id (span p xs)
... | false = ([] , x ∷ xs)
break : ∀ {a} {A : Set a} → (A → Bool) → List A → (List A × List A)
break p = span (not ∘ p)
inits : ∀ {a} {A : Set a} → List A → List (List A)
inits [] = [] ∷ []
inits (x ∷ xs) = [] ∷ map (_∷_ x) (inits xs)
tails : ∀ {a} {A : Set a} → List A → List (List A)
tails [] = [] ∷ []
tails (x ∷ xs) = (x ∷ xs) ∷ tails xs
infixl 5 _∷ʳ'_
data InitLast {a} {A : Set a} : List A → Set a where
[] : InitLast []
_∷ʳ'_ : (xs : List A) (x : A) → InitLast (xs ∷ʳ x)
initLast : ∀ {a} {A : Set a} (xs : List A) → InitLast xs
initLast [] = []
initLast (x ∷ xs) with initLast xs
initLast (x ∷ .[]) | [] = [] ∷ʳ' x
initLast (x ∷ .(ys ∷ʳ y)) | ys ∷ʳ' y = (x ∷ ys) ∷ʳ' y
-- * Searching lists
-- ** Searching with a predicate
-- A generalised variant of filter.
gfilter : ∀ {a b} {A : Set a} {B : Set b} →
(A → Maybe B) → List A → List B
gfilter p [] = []
gfilter p (x ∷ xs) with p x
... | just y = y ∷ gfilter p xs
... | nothing = gfilter p xs
filter : ∀ {a} {A : Set a} → (A → Bool) → List A → List A
filter p = gfilter (λ x → if p x then just x else nothing)
partition : ∀ {a} {A : Set a} → (A → Bool) → List A → (List A × List A)
partition p [] = ([] , [])
partition p (x ∷ xs) with p x | partition p xs
... | true | (ys , zs) = (x ∷ ys , zs)
... | false | (ys , zs) = (ys , x ∷ zs)
------------------------------------------------------------------------
-- List monoid
monoid : ∀ {ℓ} → Set ℓ → Monoid _ _
monoid A = record
{ Carrier = List A
; _≈_ = _≡_
; _∙_ = _++_
; ε = []
; isMonoid = record
{ isSemigroup = record
{ isEquivalence = PropEq.isEquivalence
; assoc = assoc
; ∙-cong = cong₂ _++_
}
; identity = ((λ _ → refl) , identity)
}
}
where
open PropEq
open FunProp _≡_
identity : RightIdentity [] _++_
identity [] = refl
identity (x ∷ xs) = cong (_∷_ x) (identity xs)
assoc : Associative _++_
assoc [] ys zs = refl
assoc (x ∷ xs) ys zs = cong (_∷_ x) (assoc xs ys zs)
------------------------------------------------------------------------
-- List monad
open import Category.Monad
monad : ∀ {ℓ} → RawMonad (List {ℓ})
monad = record
{ return = λ x → x ∷ []
; _>>=_ = λ xs f → concat (map f xs)
}
monadZero : ∀ {ℓ} → RawMonadZero (List {ℓ})
monadZero = record
{ monad = monad
; ∅ = []
}
monadPlus : ∀ {ℓ} → RawMonadPlus (List {ℓ})
monadPlus = record
{ monadZero = monadZero
; _∣_ = _++_
}
------------------------------------------------------------------------
-- Monadic functions
private
module Monadic {m} {M : Set m → Set m} (Mon : RawMonad M) where
open RawMonad Mon
sequence : ∀ {A} → List (M A) → M (List A)
sequence [] = return []
sequence (x ∷ xs) = _∷_ <$> x ⊛ sequence xs
mapM : ∀ {a} {A : Set a} {B} → (A → M B) → List A → M (List B)
mapM f = sequence ∘ map f
open Monadic public
| {
"alphanum_fraction": 0.4647016012,
"avg_line_length": 25.6822429907,
"ext": "agda",
"hexsha": "cf4e080c2c1d7f38332eeb79d660ce0c4afca9d6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/List.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/List.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 3033,
"size": 8244
} |
open import Everything
module Test.Transassociativity where
test-transassociativity-≡ : ∀
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯}
⦃ _ : Transitivity.class _∼_ ⦄
⦃ _ : Transassociativity!.class _∼_ Proposequality ⦄
→ ∀ {w x y z} (f : w ∼ x) (g : x ∼ y) (h : y ∼ z) → (h ∙ g) ∙ f ≡ h ∙ g ∙ f
test-transassociativity-≡ f g h rewrite transassociativity![ Proposequality ] f g h = ∅ -- transassociativity
| {
"alphanum_fraction": 0.6082725061,
"avg_line_length": 31.6153846154,
"ext": "agda",
"hexsha": "65944f9c3adb51a92e8349207f006d9dda16c437",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test/Transassociativity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test/Transassociativity.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test/Transassociativity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 184,
"size": 411
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Unit
open import Agda.Builtin.Equality
data Unit : Set where unit : Unit
A : Unit → Set
A unit = ⊤
postulate
a b : (u : Unit) → A u
mutual
_X : Unit
_X = {!unit!}
test : a _X ≡ b _X
test = refl
| {
"alphanum_fraction": 0.6204379562,
"avg_line_length": 13.7,
"ext": "agda",
"hexsha": "b710bf47138999397cb37a479f7d17a4f289e6a7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3776.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3776.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3776.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 98,
"size": 274
} |
module Issue289 where
data D : Set where
d : D
record ⊤ : Set where
foo : (x y : D) → ⊤
foo d y = {!y!}
-- WAS:
-- Right hand side must be a single hole when making a case
-- distinction.
-- when checking that the expression ? has type ⊤
-- NOW: (Andreas, 2013-03-22)
-- Since goal is solved, further case distinction is not supported;
-- try `Solve constraints' instead
-- when checking that the expression ? has type ⊤
| {
"alphanum_fraction": 0.6728971963,
"avg_line_length": 21.4,
"ext": "agda",
"hexsha": "ce1761c7979fc902848caa589d9c194042b0c779",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/interaction/Issue289.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/interaction/Issue289.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/interaction/Issue289.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 124,
"size": 428
} |
{-# OPTIONS --without-K --exact-split --safe #-}
module 04-inductive-types where
import 03-natural-numbers
open 03-natural-numbers public
--------------------------------------------------------------------------------
-- Section 4.2 The unit type
-- Definition 4.2.1
data unit : UU lzero where
star : unit
𝟙 = unit
ind-unit : {i : Level} {P : unit → UU i} → P star → ((x : unit) → P x)
ind-unit p star = p
--------------------------------------------------------------------------------
-- Section 4.3 The empty type
-- Definition 4.3.1
data empty : UU lzero where
𝟘 = empty
ind-empty : {i : Level} {P : empty → UU i} → ((x : empty) → P x)
ind-empty ()
ex-falso : {i : Level} {A : UU i} → empty → A
ex-falso = ind-empty
-- Definition 4.3.2
¬ : {i : Level} → UU i → UU i
¬ A = A → empty
-- Proposition 4.3.3
functor-neg : {l1 l2 : Level} {P : UU l1} {Q : UU l2} →
(P → Q) → (¬ Q → ¬ P)
functor-neg f nq p = nq (f p)
--------------------------------------------------------------------------------
-- Section 4.4 The booleans
-- Definition 4.4.1
data bool : UU lzero where
true false : bool
-- Example 4.4.2
neg-𝟚 : bool → bool
neg-𝟚 true = false
neg-𝟚 false = true
conjunction-𝟚 : bool → (bool → bool)
conjunction-𝟚 true true = true
conjunction-𝟚 true false = false
conjunction-𝟚 false true = false
conjunction-𝟚 false false = false
disjunction-𝟚 : bool → (bool → bool)
disjunction-𝟚 true true = true
disjunction-𝟚 true false = true
disjunction-𝟚 false true = true
disjunction-𝟚 false false = false
--------------------------------------------------------------------------------
-- Section 4.5 Coproducts
-- Definition 4.5.1
data coprod {i j : Level} (A : UU i) (B : UU j) : UU (i ⊔ j) where
inl : A → coprod A B
inr : B → coprod A B
ind-coprod : {i j k : Level} {A : UU i} {B : UU j} (C : coprod A B → UU k) →
((x : A) → C (inl x)) → ((y : B) → C (inr y)) →
(t : coprod A B) → C t
ind-coprod C f g (inl x) = f x
ind-coprod C f g (inr x) = g x
-- Remark 4.5.2
functor-coprod :
{l1 l2 l1' l2' : Level} {A : UU l1} {B : UU l2} {A' : UU l1'} {B' : UU l2'} →
(A → A') → (B → B') → coprod A B → coprod A' B'
functor-coprod f g (inl x) = inl (f x)
functor-coprod f g (inr y) = inr (g y)
-- Proposition 4.5.3
coprod-elim-left :
{i j : Level} (A : UU i) (B : UU j) →
¬ B → coprod A B → A
coprod-elim-left A B nb (inl a) = a
coprod-elim-left A B nb (inr b) = ex-falso (nb b)
coprod-elim-right :
{i j : Level} (A : UU i) (B : UU j) →
¬ A → coprod A B → B
coprod-elim-right A B na (inl a) = ex-falso (na a)
coprod-elim-right A B na (inr b) = b
--------------------------------------------------------------------------------
-- Section 4.6 Dependent pair types
-- Definition 4.6.1
data Σ {i j : Level} (A : UU i) (B : A → UU j) : UU (i ⊔ j) where
pair : (x : A) → (B x → Σ A B)
ind-Σ : {i j k : Level} {A : UU i} {B : A → UU j} {C : Σ A B → UU k} →
((x : A) (y : B x) → C (pair x y)) → ((t : Σ A B) → C t)
ind-Σ f (pair x y) = f x y
-- Remark 4.6.2
ev-pair :
{l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {C : Σ A B → UU l3} →
((t : Σ A B) → C t) → (x : A) (y : B x) → C (pair x y)
ev-pair f x y = f (pair x y)
-- Definition 4.6.3
pr1 : {i j : Level} {A : UU i} {B : A → UU j} → Σ A B → A
pr1 (pair a b) = a
pr2 : {i j : Level} {A : UU i} {B : A → UU j} → (t : Σ A B) → B (pr1 t)
pr2 (pair a b) = b
-- Definition 4.6.4
prod : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j)
prod A B = Σ A (λ a → B)
pair' :
{i j : Level} {A : UU i} {B : UU j} → A → B → prod A B
pair' = pair
_×_ : {i j : Level} (A : UU i) (B : UU j) → UU (i ⊔ j)
A × B = prod A B
--------------------------------------------------------------------------------
-- Section 4.7 The type of integers
-- Definition 4.7.1
-- The type of integers
ℤ : UU lzero
ℤ = coprod ℕ (coprod unit ℕ)
-- Inclusion of the negative integers
in-neg : ℕ → ℤ
in-neg n = inl n
-- Negative one
neg-one-ℤ : ℤ
neg-one-ℤ = in-neg zero-ℕ
-- Zero
zero-ℤ : ℤ
zero-ℤ = inr (inl star)
-- One
one-ℤ : ℤ
one-ℤ = inr (inr zero-ℕ)
-- Inclusion of the positive integers
in-pos : ℕ → ℤ
in-pos n = inr (inr n)
-- Inclusion of the natural numbers
int-ℕ : ℕ → ℤ
int-ℕ zero-ℕ = zero-ℤ
int-ℕ (succ-ℕ n) = in-pos n
-- Proposition 4.7.2
ind-ℤ :
{i : Level} (P : ℤ → UU i) →
P neg-one-ℤ → ((n : ℕ) → P (inl n) → P (inl (succ-ℕ n))) →
P zero-ℤ →
P one-ℤ → ((n : ℕ) → P (inr (inr (n))) → P (inr (inr (succ-ℕ n)))) →
(k : ℤ) → P k
ind-ℤ P p-1 p-S p0 p1 pS (inl zero-ℕ) = p-1
ind-ℤ P p-1 p-S p0 p1 pS (inl (succ-ℕ x)) =
p-S x (ind-ℤ P p-1 p-S p0 p1 pS (inl x))
ind-ℤ P p-1 p-S p0 p1 pS (inr (inl star)) = p0
ind-ℤ P p-1 p-S p0 p1 pS (inr (inr zero-ℕ)) = p1
ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (succ-ℕ x))) =
pS x (ind-ℤ P p-1 p-S p0 p1 pS (inr (inr (x))))
-- Definition 4.7.3
succ-ℤ : ℤ → ℤ
succ-ℤ (inl zero-ℕ) = zero-ℤ
succ-ℤ (inl (succ-ℕ x)) = inl x
succ-ℤ (inr (inl star)) = one-ℤ
succ-ℤ (inr (inr x)) = inr (inr (succ-ℕ x))
--------------------------------------------------------------------------------
-- Exercises
-- Exercise 4.1 (a)
pred-ℤ : ℤ → ℤ
pred-ℤ (inl x) = inl (succ-ℕ x)
pred-ℤ (inr (inl star)) = inl zero-ℕ
pred-ℤ (inr (inr zero-ℕ)) = inr (inl star)
pred-ℤ (inr (inr (succ-ℕ x))) = inr (inr x)
-- Exercise 4.1 (b)
-- Addition on ℤ
add-ℤ : ℤ → ℤ → ℤ
add-ℤ (inl zero-ℕ) l = pred-ℤ l
add-ℤ (inl (succ-ℕ x)) l = pred-ℤ (add-ℤ (inl x) l)
add-ℤ (inr (inl star)) l = l
add-ℤ (inr (inr zero-ℕ)) l = succ-ℤ l
add-ℤ (inr (inr (succ-ℕ x))) l = succ-ℤ (add-ℤ (inr (inr x)) l)
add-ℤ' : ℤ → ℤ → ℤ
add-ℤ' x y = add-ℤ y x
-- The negative of an integer
neg-ℤ : ℤ → ℤ
neg-ℤ (inl x) = inr (inr x)
neg-ℤ (inr (inl star)) = inr (inl star)
neg-ℤ (inr (inr x)) = inl x
-- Exercise 4.1 (c)
-- Multiplication on ℤ
mul-ℤ : ℤ → ℤ → ℤ
mul-ℤ (inl zero-ℕ) l = neg-ℤ l
mul-ℤ (inl (succ-ℕ x)) l = add-ℤ (neg-ℤ l) (mul-ℤ (inl x) l)
mul-ℤ (inr (inl star)) l = zero-ℤ
mul-ℤ (inr (inr zero-ℕ)) l = l
mul-ℤ (inr (inr (succ-ℕ x))) l = add-ℤ l (mul-ℤ (inr (inr x)) l)
mul-ℤ' : ℤ → ℤ → ℤ
mul-ℤ' x y = mul-ℤ y x
-- Exercise 4.2
¬¬ : {l : Level} → UU l → UU l
¬¬ P = ¬ (¬ P)
¬¬¬ : {l : Level} → UU l → UU l
¬¬¬ P = ¬ (¬ (¬ P))
-- Exercise 4.2 (a)
no-fixed-points-neg :
{l1 : Level} (A : UU l1) → ¬ ((A → ¬ A) × (¬ A → A))
no-fixed-points-neg A (pair f g) =
( λ (h : ¬ A) → h (g h)) (λ (a : A) → f a a)
-- Exercise 4.2 (b)
intro-dn : {l : Level} {P : UU l} → P → ¬¬ P
intro-dn p f = f p
-- Exercise 4.2 (c)
functor-dn : {l1 l2 : Level} {P : UU l1} {Q : UU l2} →
(P → Q) → (¬¬ P → ¬¬ Q)
functor-dn f = functor-neg (functor-neg f)
-- Exercise 4.2 (d)
{- In this exercise we were asked to show that (A + ¬A) implies (¬¬A → A). In
other words, we get double negation elimination for the types that are
decidable. -}
double-negation-elim-is-decidable :
{i : Level} (P : UU i) → coprod P (¬ P) → (¬¬ P → P)
double-negation-elim-is-decidable P (inl x) p = x
double-negation-elim-is-decidable P (inr x) p = ind-empty (p x)
-- Exercise 4.2 (e)
dn-is-decidable : {l : Level} {P : UU l} → ¬¬ (coprod P (¬ P))
dn-is-decidable {P = P} f =
functor-neg (inr {A = P} {B = ¬ P}) f
( functor-neg (inl {A = P} {B = ¬ P}) f)
-- Exercise 4.2 (f)
dn-dn-elim : {l : Level} {P : UU l} → ¬¬ (¬¬ P → P)
dn-dn-elim {P = P} f =
( λ (np : ¬ P) → f (λ (nnp : ¬¬ P) → ind-empty {P = λ x → P} (nnp np)))
( λ (p : P) → f (λ (nnp : ¬¬ P) → p))
-- Exercise 4.2 (g)
tautology-4-2-f :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
¬¬ (((P → Q) → P) → P)
tautology-4-2-f {P = P} {Q} f =
( λ (np : ¬ P) → f (λ h → h (λ p → ex-falso (np p))))
( λ (p : P) → f (λ h → p))
-- Exercise 4.2 (h)
dn-linearity-implication :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
¬¬ (coprod (P → Q) (Q → P))
dn-linearity-implication {P = P} {Q = Q} f =
( λ (np : ¬ P) →
functor-neg (inl {A = P → Q} {B = Q → P}) f (λ p → ind-empty (np p)))
( λ (p : P) →
functor-neg (inr {A = P → Q} {B = Q → P}) f (λ q → p))
-- Exercise 4.2 (i)
dn-elim-neg : {l : Level} (P : UU l) → ¬¬¬ P → ¬ P
dn-elim-neg P f p = f (λ g → g p)
-- Exercise 4.2 (j)
dn-extend :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
(P → ¬¬ Q) → (¬¬ P → ¬¬ Q)
dn-extend {P = P} {Q = Q} f = dn-elim-neg (¬ Q) ∘ (functor-dn f)
-- Exercise 4.2 (k)
dn-elim-exp :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
¬¬ (P → ¬¬ Q) → (P → ¬¬ Q)
dn-elim-exp {P = P} {Q = Q} f p =
dn-elim-neg (¬ Q) (functor-dn (λ (g : P → ¬¬ Q) → g p) f)
-- Exercise 4.2 (l)
dn-elim-prod :
{l1 l2 : Level} {P : UU l1} {Q : UU l2} →
¬¬ ((¬¬ P) × (¬¬ Q)) → (¬¬ P) × (¬¬ Q)
dn-elim-prod {P = P} {Q = Q} f =
pair
( dn-elim-neg (¬ P) (functor-dn pr1 f))
( dn-elim-neg (¬ Q) (functor-dn pr2 f))
-- Exercise 4.3
-- Exercise 4.3 (a)
data list {l : Level} (A : UU l) : UU l where
nil : list A
cons : A → list A → list A
in-list : {l : Level} {A : UU l} → A → list A
in-list a = cons a nil
-- Exercise 4.3 (b)
fold-list :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (b : B) (μ : A → (B → B)) →
list A → B
fold-list b μ nil = b
fold-list b μ (cons a l) = μ a (fold-list b μ l)
-- Exercise 4.3 (c)
length-list :
{l : Level} {A : UU l} → list A → ℕ
length-list = fold-list zero-ℕ (λ a → succ-ℕ)
-- Exercise 4.3 (d)
sum-list-ℕ :
list ℕ → ℕ
sum-list-ℕ = fold-list zero-ℕ add-ℕ
-- Exercise 4.3 (e)
concat-list :
{l : Level} {A : UU l} → list A → (list A → list A)
concat-list {l} {A} = fold-list id (λ a f → (cons a) ∘ f)
-- Exercise 4.3 (f)
flatten-list :
{l : Level} {A : UU l} → list (list A) → list A
flatten-list = fold-list nil concat-list
-- Exercise 4.3 (g)
reverse-list :
{l : Level} {A : UU l} → list A → list A
reverse-list nil = nil
reverse-list (cons a l) = concat-list (reverse-list l) (in-list a)
| {
"alphanum_fraction": 0.4923805601,
"avg_line_length": 23.2901678657,
"ext": "agda",
"hexsha": "2ace4ccdc98984838a2527d8411354264aa06989",
"lang": "Agda",
"max_forks_count": 30,
"max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z",
"max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_forks_repo_path": "Agda/04-inductive-types.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_issues_repo_path": "Agda/04-inductive-types.agda",
"max_line_length": 80,
"max_stars_count": 333,
"max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_stars_repo_path": "Agda/04-inductive-types.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z",
"num_tokens": 4381,
"size": 9712
} |
-- Andreas, 2016-12-30, issues #555 and #1886, reported by nad
-- Hidden parameters can be omitted in the repetition
-- of the parameter list.
record R {a} (A : Set a) : Set a
record R A where
field f : A
data D {a} (A : Set a) : Set a
data D A where
c : A → D A
| {
"alphanum_fraction": 0.6323529412,
"avg_line_length": 18.1333333333,
"ext": "agda",
"hexsha": "83b8ae494b0ad27d527971fd65a56eb9764a6dbd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Succeed/Issue1886-omit-hidden.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Succeed/Issue1886-omit-hidden.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Succeed/Issue1886-omit-hidden.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 93,
"size": 272
} |
module BuiltinSucWarning where
data Nat : Set where
zero : Nat
suc : (n : Nat) → Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
foo : Nat
foo = 13
| {
"alphanum_fraction": 0.6073298429,
"avg_line_length": 13.6428571429,
"ext": "agda",
"hexsha": "5450c0a63f2135394f81e86ded5aff1383d65ee6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/BuiltinSucWarning.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/BuiltinSucWarning.agda",
"max_line_length": 30,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/BuiltinSucWarning.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 191
} |
------------------------------------------------------------------------------
-- Non-intuitionistic logic theorems
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOL.NonIntuitionistic.TheoremsATP where
open import FOL.Base hiding ( pem )
------------------------------------------------------------------------------
-- The principle of the excluded middle.
postulate pem : ∀ {A} → A ∨ ¬ A
{-# ATP prove pem #-}
-- The principle of indirect proof (proof by contradiction).
postulate ¬-elim : ∀ {A} → (¬ A → ⊥) → A
{-# ATP prove ¬-elim #-}
-- Double negation elimination.
postulate ¬¬-elim : ∀ {A} → ¬ ¬ A → A
{-# ATP prove ¬¬-elim #-}
-- The reductio ab absurdum rule. (Some authors uses this name for the
-- principle of indirect proof).
postulate raa : ∀ {A} → (¬ A → A) → A
{-# ATP prove raa #-}
-- ∃ in terms of ∀ and ¬.
postulate ¬∃¬→∀ : {A : D → Set} → ¬ (∃[ x ] ¬ A x) → ∀ {x} → A x
{-# ATP prove ¬∃¬→∀ #-}
| {
"alphanum_fraction": 0.4479717813,
"avg_line_length": 32.4,
"ext": "agda",
"hexsha": "f5b897be8dfab087eba42b6dcebcbab05e62c0d9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOL/NonIntuitionistic/TheoremsATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOL/NonIntuitionistic/TheoremsATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOL/NonIntuitionistic/TheoremsATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 278,
"size": 1134
} |
------------------------------------------------------------------------
-- Subtyping defined in terms of finite approximations
------------------------------------------------------------------------
module RecursiveTypes.Subtyping.Semantic.Inductive where
open import Data.Nat
open import Data.Fin
open import Codata.Musical.Notation
open import RecursiveTypes.Syntax
open import RecursiveTypes.Semantics
-- Finite trees.
infixr 10 _⟶_
data FinTree (n : ℕ) : Set where
⊥ : FinTree n
⊤ : FinTree n
var : (x : Fin n) → FinTree n
_⟶_ : (σ τ : FinTree n) → FinTree n
-- Functions which prune a possibly infinite tree.
infix 8 _↑_ _↓_
mutual
_↑_ : ∀ {n} → Tree n → ℕ → FinTree n
τ ↑ zero = ⊤
⊥ ↑ suc k = ⊥
⊤ ↑ suc k = ⊤
var x ↑ suc k = var x
σ ⟶ τ ↑ suc k = (♭ σ ↓ k) ⟶ (♭ τ ↑ k)
_↓_ : ∀ {n} → Tree n → ℕ → FinTree n
τ ↓ zero = ⊥
⊥ ↓ suc k = ⊥
⊤ ↓ suc k = ⊤
var x ↓ suc k = var x
σ ⟶ τ ↓ suc k = (♭ σ ↑ k) ⟶ (♭ τ ↓ k)
-- Subtyping for finite trees.
infix 4 _≤Fin_ _≤↓_ _≤↑_ _≤Ind_
data _≤Fin_ {n} : FinTree n → FinTree n → Set where
⊥ : ∀ {τ} → ⊥ ≤Fin τ
⊤ : ∀ {σ} → σ ≤Fin ⊤
refl : ∀ {τ} → τ ≤Fin τ
_⟶_ : ∀ {σ₁ σ₂ τ₁ τ₂}
(τ₁≤σ₁ : τ₁ ≤Fin σ₁) (σ₂≤τ₂ : σ₂ ≤Fin τ₂) →
σ₁ ⟶ σ₂ ≤Fin τ₁ ⟶ τ₂
-- Subtyping for possibly infinite trees, defined in terms of
-- subtyping for finite trees.
_≤↓_ : ∀ {n} → Tree n → Tree n → Set
σ ≤↓ τ = ∀ k → σ ↓ k ≤Fin τ ↓ k
_≤↑_ : ∀ {n} → Tree n → Tree n → Set
σ ≤↑ τ = ∀ k → σ ↑ k ≤Fin τ ↑ k
-- Subtyping for recursive types, defined in terms of subtyping for
-- possibly infinite trees.
_≤Ind_ : ∀ {n} → Ty n → Ty n → Set
σ ≤Ind τ = ⟦ σ ⟧ ≤↓ ⟦ τ ⟧
| {
"alphanum_fraction": 0.4979228487,
"avg_line_length": 24.0714285714,
"ext": "agda",
"hexsha": "6dd6c72528acadfa9c9e56998f41b434b833d698",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "RecursiveTypes/Subtyping/Semantic/Inductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "RecursiveTypes/Subtyping/Semantic/Inductive.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "RecursiveTypes/Subtyping/Semantic/Inductive.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 647,
"size": 1685
} |
module Computability.Data.Nat.Iteration where
open import Computability.Prelude
iterate : {A : Set} → (A → A) → ℕ → A → A
iterate f zero a = a
iterate f (suc n) a = f (iterate f n a)
split-iterate : {A : Set}(f : A → A)(a : A)
→ (n m : ℕ)
→ iterate f (n + m) a ≡ iterate f n (iterate f m a)
split-iterate f a zero m = refl
split-iterate f a (suc n) m rewrite split-iterate f a n m = refl
| {
"alphanum_fraction": 0.5880952381,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "3a4784c65b216bdf89ce7c22deebc388e0d31bc9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jesyspa/computability-in-agda",
"max_forks_repo_path": "Computability/Data/Nat/Iteration.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jesyspa/computability-in-agda",
"max_issues_repo_path": "Computability/Data/Nat/Iteration.agda",
"max_line_length": 65,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jesyspa/computability-in-agda",
"max_stars_repo_path": "Computability/Data/Nat/Iteration.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-30T11:15:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-19T15:51:22.000Z",
"num_tokens": 140,
"size": 420
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Coprimality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Coprimality where
open import Data.Empty
open import Data.Fin using (toℕ; fromℕ≤)
open import Data.Fin.Properties using (toℕ-fromℕ≤)
open import Data.Nat
open import Data.Nat.Divisibility
open import Data.Nat.GCD
open import Data.Nat.GCD.Lemmas
open import Data.Nat.Primality
open import Data.Nat.Properties
open import Data.Product as Prod
open import Function
open import Level using (0ℓ)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; refl; cong; subst; module ≡-Reasoning)
open import Relation.Nullary
open import Relation.Binary
------------------------------------------------------------------------
-- Coprime m n is inhabited iff m and n are coprime (relatively
-- prime), i.e. if their only common divisor is 1.
Coprime : Rel ℕ 0ℓ
Coprime m n = ∀ {i} → i ∣ m × i ∣ n → i ≡ 1
------------------------------------------------------------------------
-- Relationship between GCD and coprimality
coprime-gcd : ∀ {m n} → Coprime m n → GCD m n 1
coprime-gcd {m} {n} c = GCD.is (1∣ m , 1∣ n) greatest
where
greatest : ∀ {d} → d ∣ m × d ∣ n → d ∣ 1
greatest cd with c cd
... | refl = 1∣ 1
gcd-coprime : ∀ {m n} → GCD m n 1 → Coprime m n
gcd-coprime g cd with GCD.greatest g cd
... | divides q eq = i*j≡1⇒j≡1 q _ (P.sym eq)
------------------------------------------------------------------------
-- Coprime is decidable.
private
0≢1 : 0 ≢ 1
0≢1 ()
2+≢1 : ∀ {n} → suc (suc n) ≢ 1
2+≢1 ()
coprime? : Decidable Coprime
coprime? i j with gcd i j
... | (0 , g) = no (0≢1 ∘ GCD.unique g ∘ coprime-gcd)
... | (1 , g) = yes (gcd-coprime g)
... | (suc (suc d) , g) = no (2+≢1 ∘ GCD.unique g ∘ coprime-gcd)
-- The coprimality relation is symmetric.
sym : Symmetric Coprime
sym c = c ∘ swap
-- Everything is coprime to 1.
1-coprimeTo : ∀ m → Coprime 1 m
1-coprimeTo m = ∣1⇒≡1 ∘ proj₁
-- Nothing except for 1 is coprime to 0.
0-coprimeTo-m⇒m≡1 : ∀ {m} → Coprime 0 m → m ≡ 1
0-coprimeTo-m⇒m≡1 {m} c = c (m ∣0 , ∣-refl)
-- If m and n are coprime, then n + m and n are also coprime.
coprime-+ : ∀ {m n} → Coprime m n → Coprime (n + m) n
coprime-+ c (d₁ , d₂) = c (∣m+n∣m⇒∣n d₁ d₂ , d₂)
-- If the "gcd" in Bézout's identity is non-zero, then the "other"
-- divisors are coprime.
Bézout-coprime : ∀ {i j d} →
Bézout.Identity (suc d) (i * suc d) (j * suc d) →
Coprime i j
Bézout-coprime (Bézout.+- x y eq) (divides q₁ refl , divides q₂ refl) =
lem₁₀ y q₂ x q₁ eq
Bézout-coprime (Bézout.-+ x y eq) (divides q₁ refl , divides q₂ refl) =
lem₁₀ x q₁ y q₂ eq
-- Coprime numbers satisfy Bézout's identity.
coprime-Bézout : ∀ {i j} → Coprime i j → Bézout.Identity 1 i j
coprime-Bézout = Bézout.identity ∘ coprime-gcd
-- If i divides jk and is coprime to j, then it divides k.
coprime-divisor : ∀ {k i j} → Coprime i j → i ∣ j * k → i ∣ k
coprime-divisor {k} c (divides q eq′) with coprime-Bézout c
... | Bézout.+- x y eq = divides (x * k ∸ y * q) (lem₈ x y eq eq′)
... | Bézout.-+ x y eq = divides (y * q ∸ x * k) (lem₉ x y eq eq′)
-- If d is a common divisor of mk and nk, and m and n are coprime,
-- then d divides k.
coprime-factors : ∀ {d m n k} →
Coprime m n → d ∣ m * k × d ∣ n * k → d ∣ k
coprime-factors c (divides q₁ eq₁ , divides q₂ eq₂) with coprime-Bézout c
... | Bézout.+- x y eq = divides (x * q₁ ∸ y * q₂) (lem₁₁ x y eq eq₁ eq₂)
... | Bézout.-+ x y eq = divides (y * q₂ ∸ x * q₁) (lem₁₁ y x eq eq₂ eq₁)
-- A variant of GCD.
data GCD′ : ℕ → ℕ → ℕ → Set where
gcd-* : ∀ {d} q₁ q₂ (c : Coprime q₁ q₂) →
GCD′ (q₁ * d) (q₂ * d) d
-- The two definitions are equivalent.
gcd-gcd′ : ∀ {d m n} → GCD m n d → GCD′ m n d
gcd-gcd′ g with GCD.commonDivisor g
gcd-gcd′ {zero} g | (divides q₁ refl , divides q₂ refl)
with q₁ * 0 | *-comm 0 q₁ | q₂ * 0 | *-comm 0 q₂
... | .0 | refl | .0 | refl = gcd-* 1 1 (1-coprimeTo 1)
gcd-gcd′ {suc d} g | (divides q₁ refl , divides q₂ refl) =
gcd-* q₁ q₂ (Bézout-coprime (Bézout.identity g))
gcd′-gcd : ∀ {m n d} → GCD′ m n d → GCD m n d
gcd′-gcd (gcd-* q₁ q₂ c) = GCD.is (n∣m*n q₁ , n∣m*n q₂) (coprime-factors c)
-- Calculates (the alternative representation of) the gcd of the
-- arguments.
gcd′ : ∀ m n → ∃ λ d → GCD′ m n d
gcd′ m n = Prod.map id gcd-gcd′ (gcd m n)
-- Primality implies coprimality.
prime⇒coprime : ∀ m → Prime m →
∀ n → 0 < n → n < m → Coprime m n
prime⇒coprime 0 () _ _ _ _
prime⇒coprime 1 () _ _ _ _
prime⇒coprime (suc (suc m)) _ 0 () _ _
prime⇒coprime (suc (suc m)) _ _ _ _ {1} _ = refl
prime⇒coprime (suc (suc m)) p _ _ _ {0} (divides q 2+m≡q*0 , _) =
⊥-elim $ i+1+j≢i 0 (begin
2 + m ≡⟨ 2+m≡q*0 ⟩
q * 0 ≡⟨ *-zeroʳ q ⟩
0 ∎)
where open ≡-Reasoning
prime⇒coprime (suc (suc m)) p (suc n) _ 1+n<2+m {suc (suc i)}
(2+i∣2+m , 2+i∣1+n) =
⊥-elim (p _ 2+i′∣2+m)
where
i<m : i < m
i<m = +-cancelˡ-< 2 (begin-strict
2 + i ≤⟨ ∣⇒≤ 2+i∣1+n ⟩
1 + n <⟨ 1+n<2+m ⟩
2 + m ∎)
where open ≤-Reasoning
2+i′∣2+m : 2 + toℕ (fromℕ≤ i<m) ∣ 2 + m
2+i′∣2+m = subst (_∣ 2 + m)
(P.sym (cong (2 +_) (toℕ-fromℕ≤ i<m)))
2+i∣2+m
| {
"alphanum_fraction": 0.5378508124,
"avg_line_length": 31.6725146199,
"ext": "agda",
"hexsha": "603f3b91cb5f4f877986cd982e01d4cf187b5f36",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Coprimality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Coprimality.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/Coprimality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2224,
"size": 5416
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- a zero object is both terminal and initial.
module Categories.Object.Zero {o ℓ e} (C : Category o ℓ e) where
open import Level using (_⊔_)
open import Categories.Object.Terminal C
open import Categories.Object.Initial C
open import Categories.Morphism C
open Category C
open HomReasoning
record Zero : Set (o ⊔ ℓ ⊔ e) where
field
zero : Obj
! : ∀ {A} → zero ⇒ A
¡ : ∀ {A} → A ⇒ zero
zero⇒ : ∀ {A B : Obj} → A ⇒ B
zero⇒ {A} = ! ∘ ¡
field
!-unique : ∀ {A} (f : zero ⇒ A) → ! ≈ f
¡-unique : ∀ {A} (f : A ⇒ zero) → ¡ ≈ f
¡-unique₂ : ∀ {A} (f g : A ⇒ zero) → f ≈ g
¡-unique₂ f g = ⟺ (¡-unique f) ○ ¡-unique g
!-unique₂ : ∀ {A} (f g : zero ⇒ A) → f ≈ g
!-unique₂ f g = ⟺ (!-unique f) ○ !-unique g
initial : Initial
initial = record
{ ⊥ = zero
; ⊥-is-initial = record
{ ! = !
; !-unique = !-unique
}
}
terminal : Terminal
terminal = record
{ ⊤ = zero
; ⊤-is-terminal = record
{ ! = ¡
; !-unique = ¡-unique
}
}
module initial = Initial initial
module terminal = Terminal terminal
!-Mono : ∀ {A} → Mono (! {A})
!-Mono = from-⊤-is-Mono {t = terminal} !
¡-Epi : ∀ {A} → Epi (¡ {A})
¡-Epi = to-⊥-is-Epi {i = initial} ¡
| {
"alphanum_fraction": 0.5244274809,
"avg_line_length": 20.46875,
"ext": "agda",
"hexsha": "1a926f3d4dfe5857f1a8684fa23fc2303ffe5441",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FintanH/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Zero.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "FintanH/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Zero.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FintanH/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Zero.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 476,
"size": 1310
} |
-- Andreas, 2014-01-21, Issue 1209 reported by Andrea
{-# OPTIONS --cubical-compatible #-}
{-# OPTIONS --copatterns #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
record R (i : Size) : Set where
coinductive
field
force : (j : Size< i) → R j
postulate
f : ∀ {i} → R i → R i
t : (i : Size) → R i
R.force (t i) j = f (t j)
-- should termination check
| {
"alphanum_fraction": 0.5973333333,
"avg_line_length": 17.8571428571,
"ext": "agda",
"hexsha": "74f6e406da8fd20b21f32bcd034d41ecd68ac40e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue1409.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue1409.agda",
"max_line_length": 53,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue1409.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 125,
"size": 375
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some algebraic structures (not packed up with sets, operations,
-- etc.)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
-- The structures are parameterised by an equivalence relation
module Algebra.Structures {a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Algebra.FunctionProperties _≈_
import Algebra.FunctionProperties.Consequences as Consequences
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
------------------------------------------------------------------------
-- Semigroups
record IsMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∙-cong : Congruent₂ ∙
open IsEquivalence isEquivalence public
setoid : Setoid a ℓ
setoid = record { isEquivalence = isEquivalence }
∙-congˡ : LeftCongruent ∙
∙-congˡ y≈z = ∙-cong refl y≈z
∙-congʳ : RightCongruent ∙
∙-congʳ y≈z = ∙-cong y≈z refl
record IsSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isMagma : IsMagma ∙
assoc : Associative ∙
open IsMagma isMagma public
record IsBand (∙ : Op₂ A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
idem : Idempotent ∙
open IsSemigroup isSemigroup public
record IsSemilattice (∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isBand : IsBand ∧
comm : Commutative ∧
open IsBand isBand public
renaming (∙-cong to ∧-cong; ∙-congˡ to ∧-congˡ; ∙-congʳ to ∧-congʳ)
------------------------------------------------------------------------
-- Monoids
record IsMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identity : Identity ε ∙
open IsSemigroup isSemigroup public
identityˡ : LeftIdentity ε ∙
identityˡ = proj₁ identity
identityʳ : RightIdentity ε ∙
identityʳ = proj₂ identity
record IsCommutativeMonoid (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityˡ : LeftIdentity ε ∙
comm : Commutative ∙
open IsSemigroup isSemigroup public
identityʳ : RightIdentity ε ∙
identityʳ = Consequences.comm+idˡ⇒idʳ setoid comm identityˡ
identity : Identity ε ∙
identity = (identityˡ , identityʳ)
isMonoid : IsMonoid ∙ ε
isMonoid = record
{ isSemigroup = isSemigroup
; identity = identity
}
record IsIdempotentCommutativeMonoid (∙ : Op₂ A)
(ε : A) : Set (a ⊔ ℓ) where
field
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
idem : Idempotent ∙
open IsCommutativeMonoid isCommutativeMonoid public
------------------------------------------------------------------------
-- Groups
record IsGroup (_∙_ : Op₂ A) (ε : A) (_⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isMonoid : IsMonoid _∙_ ε
inverse : Inverse ε _⁻¹ _∙_
⁻¹-cong : Congruent₁ _⁻¹
open IsMonoid isMonoid public
infixl 7 _-_
_-_ : Op₂ A
x - y = x ∙ (y ⁻¹)
inverseˡ : LeftInverse ε _⁻¹ _∙_
inverseˡ = proj₁ inverse
inverseʳ : RightInverse ε _⁻¹ _∙_
inverseʳ = proj₂ inverse
uniqueˡ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → x ≈ (y ⁻¹)
uniqueˡ-⁻¹ = Consequences.assoc+id+invʳ⇒invˡ-unique
setoid ∙-cong assoc identity inverseʳ
uniqueʳ-⁻¹ : ∀ x y → (x ∙ y) ≈ ε → y ≈ (x ⁻¹)
uniqueʳ-⁻¹ = Consequences.assoc+id+invˡ⇒invʳ-unique
setoid ∙-cong assoc identity inverseˡ
record IsAbelianGroup (∙ : Op₂ A)
(ε : A) (⁻¹ : Op₁ A) : Set (a ⊔ ℓ) where
field
isGroup : IsGroup ∙ ε ⁻¹
comm : Commutative ∙
open IsGroup isGroup public
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isSemigroup = isSemigroup
; identityˡ = identityˡ
; comm = comm
}
------------------------------------------------------------------------
-- Semirings
record IsNearSemiring (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isMonoid : IsMonoid + 0#
*-isSemigroup : IsSemigroup *
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
open IsMonoid +-isMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
)
open IsSemigroup *-isSemigroup public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; isMagma to *-isMagma
)
record IsSemiringWithoutOne (+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isSemigroup : IsSemigroup *
distrib : * DistributesOver +
zero : Zero 0# *
open IsCommutativeMonoid +-isCommutativeMonoid public
using ()
renaming
( isMonoid to +-isMonoid
; comm to +-comm
)
zeroˡ : LeftZero 0# *
zeroˡ = proj₁ zero
zeroʳ : RightZero 0# *
zeroʳ = proj₂ zero
isNearSemiring : IsNearSemiring + * 0#
isNearSemiring = record
{ +-isMonoid = +-isMonoid
; *-isSemigroup = *-isSemigroup
; distribʳ = proj₂ distrib
; zeroˡ = zeroˡ
}
open IsNearSemiring isNearSemiring public
hiding (+-isMonoid; zeroˡ)
record IsSemiringWithoutAnnihilatingZero (+ * : Op₂ A)
(0# 1# : A) : Set (a ⊔ ℓ) where
field
-- Note that these structures do have an additive unit, but this
-- unit does not necessarily annihilate multiplication.
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
distribˡ : * DistributesOverˡ +
distribˡ = proj₁ distrib
distribʳ : * DistributesOverʳ +
distribʳ = proj₂ distrib
open IsCommutativeMonoid +-isCommutativeMonoid public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
record IsSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutAnnihilatingZero :
IsSemiringWithoutAnnihilatingZero + * 0# 1#
zero : Zero 0# *
open IsSemiringWithoutAnnihilatingZero
isSemiringWithoutAnnihilatingZero public
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
isSemiringWithoutOne = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isSemigroup = *-isSemigroup
; distrib = distrib
; zero = zero
}
open IsSemiringWithoutOne isSemiringWithoutOne public
using
( isNearSemiring
; zeroˡ
; zeroʳ
)
record IsCommutativeSemiringWithoutOne
(+ * : Op₂ A) (0# : A) : Set (a ⊔ ℓ) where
field
isSemiringWithoutOne : IsSemiringWithoutOne + * 0#
*-comm : Commutative *
open IsSemiringWithoutOne isSemiringWithoutOne public
record IsCommutativeSemiring (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
private
module +-CM = IsCommutativeMonoid +-isCommutativeMonoid
open module *-CM = IsCommutativeMonoid *-isCommutativeMonoid public
using () renaming (comm to *-comm)
distribˡ : * DistributesOverˡ +
distribˡ = Consequences.comm+distrʳ⇒distrˡ
+-CM.setoid +-CM.∙-cong *-comm distribʳ
distrib : * DistributesOver +
distrib = (distribˡ , distribʳ)
zeroʳ : RightZero 0# *
zeroʳ = Consequences.comm+zeˡ⇒zeʳ +-CM.setoid *-comm zeroˡ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isSemiring : IsSemiring + * 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-CM.isMonoid
; distrib = distrib
}
; zero = zero
}
open IsSemiring isSemiring public
hiding
( distrib; distribʳ; distribˡ
; zero; zeroˡ; zeroʳ
; +-isCommutativeMonoid
)
isCommutativeSemiringWithoutOne :
IsCommutativeSemiringWithoutOne + * 0#
isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = isSemiringWithoutOne
; *-comm = *-CM.comm
}
------------------------------------------------------------------------
-- Rings
record IsRing (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
open IsAbelianGroup +-isAbelianGroup public
renaming
( assoc to +-assoc
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identity to +-identity
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; inverse to -‿inverse
; inverseˡ to -‿inverseˡ
; inverseʳ to -‿inverseʳ
; ⁻¹-cong to -‿cong
; comm to +-comm
; isMagma to +-isMagma
; isSemigroup to +-isSemigroup
; isMonoid to +-isMonoid
; isCommutativeMonoid to +-isCommutativeMonoid
; isGroup to +-isGroup
)
open IsMonoid *-isMonoid public
using ()
renaming
( assoc to *-assoc
; ∙-cong to *-cong
; ∙-congˡ to *-congˡ
; ∙-congʳ to *-congʳ
; identity to *-identity
; identityˡ to *-identityˡ
; identityʳ to *-identityʳ
; isMagma to *-isMagma
; isSemigroup to *-isSemigroup
)
zeroˡ : LeftZero 0# *
zeroˡ = Consequences.assoc+distribʳ+idʳ+invʳ⇒zeˡ setoid
+-cong *-cong +-assoc (proj₂ distrib) +-identityʳ -‿inverseʳ
zeroʳ : RightZero 0# *
zeroʳ = Consequences.assoc+distribˡ+idʳ+invʳ⇒zeʳ setoid
+-cong *-cong +-assoc (proj₁ distrib) +-identityʳ -‿inverseʳ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isSemiringWithoutAnnihilatingZero
: IsSemiringWithoutAnnihilatingZero + * 0# 1#
isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-isMonoid
; distrib = distrib
}
isSemiring : IsSemiring + * 0# 1#
isSemiring = record
{ isSemiringWithoutAnnihilatingZero =
isSemiringWithoutAnnihilatingZero
; zero = zero
}
open IsSemiring isSemiring public
using (distribˡ; distribʳ; isNearSemiring; isSemiringWithoutOne)
record IsCommutativeRing
(+ * : Op₂ A) (- : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isRing : IsRing + * - 0# 1#
*-comm : Commutative *
open IsRing isRing public
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
*-isCommutativeMonoid = record
{ isSemigroup = *-isSemigroup
; identityˡ = *-identityˡ
; comm = *-comm
}
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isCommutativeMonoid = *-isCommutativeMonoid
; distribʳ = distribʳ
; zeroˡ = zeroˡ
}
open IsCommutativeSemiring isCommutativeSemiring public
using ( isCommutativeSemiringWithoutOne )
------------------------------------------------------------------------
-- Lattices
-- Note that this record is not defined in terms of IsSemilattice
-- because the idempotence laws of ∨ and ∧ can be derived from the
-- absorption laws, which makes the corresponding "idem" fields
-- redundant. The derived idempotence laws are stated and proved in
-- Algebra.Properties.Lattice along with the fact that every lattice
-- consists of two semilattices.
record IsLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isEquivalence : IsEquivalence _≈_
∨-comm : Commutative ∨
∨-assoc : Associative ∨
∨-cong : Congruent₂ ∨
∧-comm : Commutative ∧
∧-assoc : Associative ∧
∧-cong : Congruent₂ ∧
absorptive : Absorptive ∨ ∧
open IsEquivalence isEquivalence public
∨-absorbs-∧ : ∨ Absorbs ∧
∨-absorbs-∧ = proj₁ absorptive
∧-absorbs-∨ : ∧ Absorbs ∨
∧-absorbs-∨ = proj₂ absorptive
∧-congˡ : LeftCongruent ∧
∧-congˡ y≈z = ∧-cong refl y≈z
∧-congʳ : RightCongruent ∧
∧-congʳ y≈z = ∧-cong y≈z refl
∨-congˡ : LeftCongruent ∨
∨-congˡ y≈z = ∨-cong refl y≈z
∨-congʳ : RightCongruent ∨
∨-congʳ y≈z = ∨-cong y≈z refl
record IsDistributiveLattice (∨ ∧ : Op₂ A) : Set (a ⊔ ℓ) where
field
isLattice : IsLattice ∨ ∧
∨-∧-distribʳ : ∨ DistributesOverʳ ∧
open IsLattice isLattice public
record IsBooleanAlgebra
(∨ ∧ : Op₂ A) (¬ : Op₁ A) (⊤ ⊥ : A) : Set (a ⊔ ℓ) where
field
isDistributiveLattice : IsDistributiveLattice ∨ ∧
∨-complementʳ : RightInverse ⊤ ¬ ∨
∧-complementʳ : RightInverse ⊥ ¬ ∧
¬-cong : Congruent₁ ¬
open IsDistributiveLattice isDistributiveLattice public
| {
"alphanum_fraction": 0.579599141,
"avg_line_length": 28.2222222222,
"ext": "agda",
"hexsha": "38c3919c242189b4a5dce1ca6bde8eabbfffb444",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Structures.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Structures.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4802,
"size": 13970
} |
-- Andreas, 2014-09-02
module _ where
module Data where
data D : Set where
A : D
module _ (A : Set) where
open Data using (D; A)
x : D
x = A
| {
"alphanum_fraction": 0.5786163522,
"avg_line_length": 9.9375,
"ext": "agda",
"hexsha": "1f0dec81a09222f3ce3c20d80008263360790eba",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue1266b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue1266b.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1266b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 59,
"size": 159
} |
-- Andreas, 2011-04-07
module IrrelevantFamilyIndex where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
-- irrelevant index
data Fin : .Nat -> Set where
zero : .(n : Nat) -> Fin (suc n)
suc : .(n : Nat) -> Fin n -> Fin (suc n)
t : Fin zero
t = zero zero
-- the following is ok, since Fin _ is really just Nat
toNat : Fin zero -> Nat
toNat (zero _) = zero
toNat (suc _ i) = suc (toNat i)
data Pos : Nat -> Set where
pos : (n : Nat) -> Pos (suc n)
f : (n : Nat) -> Fin n -> Pos n
f .(suc n) (zero n) = pos n
f .(suc n) (suc n i) = pos n
-- cannot infer value of dot pattern
{-
f : (n : Nat) -> Fin n -> Pos n
f .(suc _) (zero _) = pos _
f .(suc _) (suc _ _) = pos _
f' : (n : Nat) -> Fin n -> Pos n
f' _ (zero _) = pos _
f' _ (suc _ _) = pos _
-}
| {
"alphanum_fraction": 0.5496774194,
"avg_line_length": 18.9024390244,
"ext": "agda",
"hexsha": "4ed3df28736257727b9e37c92ef3bba3df79094a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/IrrelevantFamilyIndex.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/IrrelevantFamilyIndex.agda",
"max_line_length": 54,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/IrrelevantFamilyIndex.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 301,
"size": 775
} |
{- Copyright © 2015 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an ‘AS IS’ BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. -}
module B.Prelude.Product where
import Data.Product
open Data.Product
using (_×_; proj₁; proj₂; _,_; _,′_; curry; uncurry; uncurry′)
public
module Product where
| {
"alphanum_fraction": 0.7706919946,
"avg_line_length": 32.0434782609,
"ext": "agda",
"hexsha": "3aad69dc37102e0b18c73be27c35ff40b5822277",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "bbarenblat/B",
"max_forks_repo_path": "Prelude/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "bbarenblat/B",
"max_issues_repo_path": "Prelude/Product.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "bbarenblat/B",
"max_stars_repo_path": "Prelude/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-30T15:59:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-30T15:59:38.000Z",
"num_tokens": 178,
"size": 737
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- N-ary products
------------------------------------------------------------------------
-- Vectors (as in Data.Vec) also represent n-ary products, so what is
-- the point of this module? The n-ary products below are intended to
-- be used with a fixed n, in which case the nil constructor can be
-- avoided: pairs are represented as pairs (x , y), not as triples
-- (x , y , unit).
{-# OPTIONS --without-K --safe #-}
module Data.Product.N-ary where
open import Data.Nat as Nat hiding (_^_)
open import Data.Fin hiding (lift)
open import Data.Product as P using (_×_ ; _,_ ; ∃₂ ; uncurry)
open import Data.Sum using (_⊎_)
open import Data.Unit
open import Data.Empty
open import Function
open import Level using (Lift; lift)
open import Relation.Binary.PropositionalEquality using (_≡_)
-- Types and patterns
------------------------------------------------------------------------
pattern 2+_ n = suc (suc n)
infix 8 _^_
_^_ : ∀ {ℓ} → Set ℓ → ℕ → Set ℓ
A ^ 0 = Lift _ ⊤
A ^ 1 = A
A ^ 2+ n = A × A ^ suc n
pattern [] = lift tt
module _ {a} {A : Set a} where
infix 3 _∈[_]_
_∈[_]_ : A → ∀ n → A ^ n → Set a
a ∈[ 0 ] as = Lift _ ⊥
a ∈[ 1 ] a′ = a ≡ a′
a ∈[ 2+ n ] a′ , as = a ≡ a′ ⊎ a ∈[ suc n ] as
-- Basic operations
------------------------------------------------------------------------
module _ {a} {A : Set a} where
cons : ∀ n → A → A ^ n → A ^ suc n
cons 0 a _ = a
cons (suc n) a as = a , as
uncons : ∀ n → A ^ suc n → A × A ^ n
uncons 0 a = a , lift tt
uncons (suc n) (a , as) = a , as
head : ∀ n → A ^ suc n → A
head n as = P.proj₁ (uncons n as)
tail : ∀ n → A ^ suc n → A ^ n
tail n as = P.proj₂ (uncons n as)
lookup : ∀ {n} (k : Fin n) → A ^ n → A
lookup {suc n} zero = head n
lookup {suc n} (suc k) = lookup k ∘′ tail n
replicate : ∀ n → A → A ^ n
replicate 0 a = []
replicate 1 a = a
replicate (2+ n) a = a , replicate (suc n) a
tabulate : ∀ n → (Fin n → A) → A ^ n
tabulate 0 f = []
tabulate 1 f = f zero
tabulate (2+ n) f = f zero , tabulate (suc n) (f ∘′ suc)
append : ∀ m n → A ^ m → A ^ n → A ^ (m Nat.+ n)
append 0 n xs ys = ys
append 1 n x ys = cons n x ys
append (2+ m) n (x , xs) ys = x , append (suc m) n xs ys
splitAt : ∀ m n → A ^ (m Nat.+ n) → A ^ m × A ^ n
splitAt 0 n xs = [] , xs
splitAt (suc m) n xs =
let (ys , zs) = splitAt m n (tail (m Nat.+ n) xs) in
cons m (head (m Nat.+ n) xs) ys , zs
-- Manipulating N-ary products
------------------------------------------------------------------------
module _ {a b} {A : Set a} {B : Set b} where
map : (A → B) → ∀ n → A ^ n → B ^ n
map f 0 as = lift tt
map f 1 a = f a
map f (2+ n) (a , as) = f a , map f (suc n) as
ap : ∀ n → (A → B) ^ n → A ^ n → B ^ n
ap 0 fs ts = []
ap 1 f t = f t
ap (2+ n) (f , fs) (t , ts) = f t , ap (suc n) fs ts
module _ {a p} {A : Set a} {P : ℕ → Set p} where
foldr : P 0 → (A → P 1) → (∀ n → A → P (suc n) → P (2+ n)) →
∀ n → A ^ n → P n
foldr p0 p1 p2+ 0 as = p0
foldr p0 p1 p2+ 1 a = p1 a
foldr p0 p1 p2+ (2+ n) (a , as) = p2+ n a (foldr p0 p1 p2+ (suc n) as)
foldl : ∀ {a p} {A : Set a} (P : ℕ → Set p) →
P 0 → (A → P 1) → (∀ n → A → P (suc n) → P (2+ n)) →
∀ n → A ^ n → P n
foldl P p0 p1 p2+ 0 as = p0
foldl P p0 p1 p2+ 1 a = p1 a
foldl P p0 p1 p2+ (2+ n) (a , as) = let p1′ = p1 a in
foldl (P ∘′ suc) p1′ (λ a → p2+ 0 a p1′) (p2+ ∘ suc) (suc n) as
module _ {a} {A : Set a} where
reverse : ∀ n → A ^ n → A ^ n
reverse = foldl (A ^_) [] id (λ n → _,_)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
zipWith : (A → B → C) → ∀ n → A ^ n → B ^ n → C ^ n
zipWith f 0 as bs = []
zipWith f 1 a b = f a b
zipWith f (2+ n) (a , as) (b , bs) = f a b , zipWith f (suc n) as bs
unzipWith : (A → B × C) → ∀ n → A ^ n → B ^ n × C ^ n
unzipWith f 0 as = [] , []
unzipWith f 1 a = f a
unzipWith f (2+ n) (a , as) = P.zip _,_ _,_ (f a) (unzipWith f (suc n) as)
module _ {a b} {A : Set a} {B : Set b} where
zip : ∀ n → A ^ n → B ^ n → (A × B) ^ n
zip = zipWith _,_
unzip : ∀ n → (A × B) ^ n → A ^ n × B ^ n
unzip = unzipWith id
| {
"alphanum_fraction": 0.4374164811,
"avg_line_length": 30.3378378378,
"ext": "agda",
"hexsha": "6cd10fa451e3a74b4209ce4425dd81b366468fb9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/N-ary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/N-ary.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/N-ary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1744,
"size": 4490
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Concrete.System.Parameters
import LibraBFT.Concrete.Properties.VotesOnce as VO
import LibraBFT.Concrete.Properties.LockedRound as LR
open import LibraBFT.Yasm.Properties ConcSysParms
-- This module collects in one place the obligations an
-- implementation must meet in order to enjoy the properties
-- proved in Abstract.Properties.
module LibraBFT.Concrete.Obligations where
record ImplObligations : Set₁ where
field
-- Structural obligations:
sps-cor : StepPeerState-AllValidParts
-- Semantic obligations:
--
-- VotesOnce:
vo₁ : VO.ImplObligation₁
vo₂ : VO.ImplObligation₂
-- LockedRound:
lr₁ : LR.ImplObligation₁
| {
"alphanum_fraction": 0.7481481481,
"avg_line_length": 30.4838709677,
"ext": "agda",
"hexsha": "74727b839233b3302269d830bc0fa2bc5317349b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_forks_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_issues_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_stars_repo_path": "LibraBFT/Concrete/Obligations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 240,
"size": 945
} |
-- Andreas, 2016-11-03, issue #2291, reported by Aerate
-- {-# OPTIONS -v interaction.helper:100 #-}
record Foo : Set where
coinductive
field one : Foo
open Foo
someFoo : Foo
someFoo .one = {! {R} -> Foo.one R !}
-- WAS: C-c C-h gives:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/Syntax/Translation/ConcreteToAbstract.hs:1248
-- NOW:
-- Expected an argument of the form f e1 e2 .. en
-- when checking that the expression ? has type Foo
| {
"alphanum_fraction": 0.6891089109,
"avg_line_length": 25.25,
"ext": "agda",
"hexsha": "7024f83ff33d07acbba98725481d90c46a463259",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2291.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2291.agda",
"max_line_length": 85,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2291.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 148,
"size": 505
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Unit.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
open import Cubical.Data.Unit.Base
open import Cubical.Data.Prod.Base
isContrUnit : isContr Unit
isContrUnit = tt , λ {tt → refl}
isPropUnit : isProp Unit
isPropUnit _ _ i = tt -- definitionally equal to: isContr→isProp isContrUnit
isOfHLevelUnit : (n : ℕ) → isOfHLevel n Unit
isOfHLevelUnit n = isContr→isOfHLevel n isContrUnit
diagonal-unit : Unit ≡ Unit × Unit
diagonal-unit = isoToPath (iso (λ x → tt , tt) (λ x → tt) (λ {(tt , tt) i → tt , tt}) λ {tt i → tt})
where open import Cubical.Foundations.Isomorphism
| {
"alphanum_fraction": 0.7419354839,
"avg_line_length": 29.76,
"ext": "agda",
"hexsha": "95b20ffb667cce8bee897d1ba3a7b9958d7d0cc9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmester0/cubical",
"max_forks_repo_path": "Cubical/Data/Unit/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmester0/cubical",
"max_issues_repo_path": "Cubical/Data/Unit/Properties.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmester0/cubical",
"max_stars_repo_path": "Cubical/Data/Unit/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 227,
"size": 744
} |
module Axiom.FunctionExtensionality where
open import Level using (zero)
open import Relation.Binary.PropositionalEquality
postulate
fun-ext : Extensionality zero zero
| {
"alphanum_fraction": 0.8372093023,
"avg_line_length": 21.5,
"ext": "agda",
"hexsha": "2a73b2d90e06a0de880225485e2671979a2ec256",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Axiom/FunctionExtensionality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andreasabel/cubical",
"max_issues_repo_path": "src/Axiom/FunctionExtensionality.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Axiom/FunctionExtensionality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 37,
"size": 172
} |
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --show-implicit #-}
open import Oscar.Prelude
open import Oscar.Class
-- classes
open import Oscar.Class.Transitivity
-- data
open import Oscar.Data.Substitunction
open import Oscar.Data.Term
module Test.EquivalentCandidates where
module _
{a}
where
instance
𝓣ransitivityFunction₁ : Transitivity.class Function⟦ a ⟧
𝓣ransitivityFunction₁ .⋆ f g = g ∘ f
𝓣ransitivityFunction₂ : Transitivity.class Function⟦ a ⟧
𝓣ransitivityFunction₂ .⋆ f g = g ∘ f
module _ (𝔓 : Ø₀) where
open Substitunction 𝔓
open Term 𝔓
non-unique non-unique-2-hole unique-1-hole unsolved-meta :
∀ {m n} (f : Substitunction m n) → Substitunction m n
non-unique {m} {n} f = {!transitivity {𝔒 = Ø₀} f (¡ {𝔒 = Term n})!}
{-
Candidates:
[ 𝓣ransitivityFunction₁ : {a : Ł} → Transitivity.class Function⟦ a ⟧
, 𝓣ransitivityFunction₂ : {a : Ł} → Transitivity.class Function⟦ a ⟧ ]
-}
non-unique-2-hole f = {!transitivity {𝔒 = Ø₀} {!!} {!!}!}
{-
Candidates:
[ 𝓣ransitivityFunction₁ : {a : Ł} → Transitivity.class Function⟦ a ⟧
, 𝓣ransitivityFunction₂ : {a : Ł} → Transitivity.class Function⟦ a ⟧ ]
-}
unique-1-hole f = transitivity {_∼_ = Function} f {!!}
unsolved-meta {m} {n} f = transitivity {𝔒 = Ø₀} ⦃ {!!} ⦄ f (¡ {𝔒 = Term n})
| {
"alphanum_fraction": 0.6517789553,
"avg_line_length": 26.9591836735,
"ext": "agda",
"hexsha": "f5b94b3526c78bf399075e2bf535dc3a3cdca335",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test/EquivalentCandidates.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test/EquivalentCandidates.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test/EquivalentCandidates.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 469,
"size": 1321
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import MultiSorted.AlgebraicTheory
import MultiSorted.Interpretation as Interpretation
import MultiSorted.SyntacticCategory as SyntacticCategory
import MultiSorted.Substitution as Substitution
import Agda.Builtin.Equality as Eq
open import Relation.Binary.PropositionalEquality using (_≡_; refl ; cong)
module MultiSorted.UniversalInterpretation
{ℓt}
{𝓈 ℴ}
{Σ : Signature {𝓈} {ℴ}}
(T : Theory ℓt Σ) where
open Theory T
open Substitution T
open SyntacticCategory T
-- The universal interpretation in the syntactic category
interp-oper-𝒮 : ∀ (f : oper) → (prod-𝒮 (oper-arity f)) ⇒s (ctx-slot (oper-sort f))
interp-oper-𝒮 f _ = tm-oper f λ i → tm-var i
ℐ : Interpretation.Interpretation Σ cartesian-𝒮
ℐ =
record
{ interp-sort = ctx-slot
; interp-ctx = producted-𝒮
; interp-oper = interp-oper-𝒮
}
open Interpretation.Interpretation ℐ
interp-term-self : ∀ {Γ} {A} (t : Term Γ A) (y : var (interp-sort A)) → ⊢ Γ ∥ (interp-term t y) ≈ t ⦂ A
interp-term-self (tm-var x) _ = eq-refl
interp-term-self (tm-oper f xs) _ = eq-congr (λ i → interp-term-self (xs i) var-var)
| {
"alphanum_fraction": 0.6937553464,
"avg_line_length": 29.9743589744,
"ext": "agda",
"hexsha": "65a719342689f0c3f8196afd44af0f998ae0bd8a",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/MultiSorted/UniversalInterpretation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/MultiSorted/UniversalInterpretation.agda",
"max_line_length": 105,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/MultiSorted/UniversalInterpretation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 379,
"size": 1169
} |
import Level
open import Relation.Binary
using (Decidable ; Rel ; IsStrictTotalOrder ; Tri)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; cong ; sym ; module ≡-Reasoning ; inspect ; subst)
open import Data.Nat as Nat
using (ℕ ; suc ; zero ; _≤′_ ; _≤_ ; _+_ ; s≤s ; z≤n ; ≤′-refl ;
≤′-step)
open import Data.Nat.Properties as NatP
using (≤⇒≤′ ; ≤′⇒≤ ; m≤m+n ; s≤′s)
open import Data.Nat.Properties.Simple as NatPS
using (+-comm ; +-suc)
open import Data.Product using (∃)
open import Relation.Nullary using (¬_ ; Dec ; yes ; no)
import Relation.Unary as U
open import Data.MoreNatProp
module Data.OrderedListMap
(Key : Set)
(inject : Key → ℕ)
(Value : Set)
where
open import utility
open import Data.Maybe using (just ; nothing ; Maybe)
open import Function
using (_∘_ ; _∋_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _++_ ; [_] ; [] ; _∷_ ; map)
open import Data.List.All as All
using (All)
open import Data.Product
using (Σ ; Σ-syntax ; _,_ ; proj₁ ; proj₂ ; _×_ ; _,′_ ; ∃-syntax)
open import Data.Sum
using (inj₁ ; inj₂ ; _⊎_)
open import Data.Unit
using (⊤ ; tt)
open import Relation.Nullary
using (yes ; no ; ¬_)
open import Data.List.Any using (here ; there)
open import Data.List.Any.Properties using (∷↔ ; ⊥↔Any[])
renaming ( ++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ )
open import Function using (_∘_)
open import Function.Inverse using (_↔_ ; Inverse)
open import Function.Equality using (Π)
open import Data.Bool using (Bool ; true ; false)
infix 6 _U_
LMap : Set
LMap = List (Maybe Value)
m-insert : Maybe Value → ℕ → LMap → LMap
m-insert v zero [] = [ v ]
m-insert nothing zero (x ∷ l) = x ∷ l
m-insert (just v) zero (x ∷ l) = (just v) ∷ l
m-insert v (suc n) [] = nothing ∷ (m-insert v n [])
m-insert v (suc n) (x ∷ l) = x ∷ (m-insert v n l)
insert : Key → Value → LMap → LMap
insert k v l = m-insert (just v) (inject k) l
Dom' : LMap → List ℕ
Dom' [] = []
Dom' ((just _) ∷ l) = 0 ∷ (map suc (Dom' l))
Dom' (nothing ∷ l) = (map suc (Dom' l))
_U_ : LMap → LMap → LMap
[] U m2 = m2
(x ∷ m1) U [] = (x ∷ m1)
(just x ∷ m1) U (just x₁ ∷ m2) = just x₁ ∷ (m1 U m2)
(just x ∷ m1) U (nothing ∷ m2) = just x ∷ (m1 U m2)
(nothing ∷ m1) U (just x ∷ m2) = just x ∷ (m1 U m2)
(nothing ∷ m1) U (nothing ∷ m2) = nothing ∷ (m1 U m2)
dist'::b : ∀{V1 V2 S1 S2} → (distinct'{ℕ} (S1 ∷ V1) (S2 ∷ V2)) → (distinct' V1 V2)
dist'::b d = dist'-sym (dist':: (dist'-sym (dist':: d)))
dist-cons : ∀{k k' l l'} → distinct'{ℕ} (k ∷ l) (k' ∷ l') → ¬ k ≡ k'
dist-cons {k} d refl = d k (here refl) (here refl)
data dist-dom : LMap → LMap → Set where
el : ∀{l} → dist-dom [] l
le : ∀{l} → dist-dom l []
cl : ∀{l1 l2 v} → dist-dom l1 l2 → dist-dom (nothing ∷ l1) ((just v) ∷ l2)
lc : ∀{l1 l2 v} → dist-dom l1 l2 → dist-dom ((just v) ∷ l1) (nothing ∷ l2)
nn : ∀{l1 l2} → dist-dom l1 l2 → dist-dom (nothing ∷ l1) (nothing ∷ l2)
∈→⊥ : ∀{A} {z : A} → z ∈ [] → ⊥
∈→⊥{A}{z} ()
-- Π._⟨$⟩_ (Inverse.from (⊥↔Any[]{A = A}{P = _≡_ z})) x
dist-b : ∀{l l' x} → distinct' (x ∷ l) (x ∷ l') → ⊥
dist-b{x = x} d with (dist-cons d)
... | relf = d x (here refl) (here refl)
sucin : ∀{z n} → z ∈ n → (suc z) ∈ (map suc n)
sucin {z} {.(_ ∷ _)} (here px) rewrite px = here refl
sucin {z} {.(_ ∷ _)} (there I) = (there (sucin I))
suc≡ : ∀{z w} → suc z ≡ suc w → z ≡ w
suc≡ refl = refl
sucout : ∀{z n} → (suc z) ∈ (map suc n) → z ∈ n
sucout {z} {[]} ()
sucout {z} {x ∷ n} (here px) rewrite suc≡ px = (here refl)
sucout {z} {x ∷ n} (there I) = (there (sucout I))
dist-map : ∀{m n} → distinct' (map suc m) (map suc n) → distinct' m n
dist-map {[]} {[]} d = λ z x x₁ → ∈→⊥ x
dist-map {[]} {x ∷ n} d = λ z x₁ x₂ → ∈→⊥ x₁
dist-map {x ∷ m} {[]} d = λ z x₁ x₂ → ∈→⊥ x₂
dist-map {zero ∷ m} {zero ∷ n} d = ⊥-elim (dist-b d)
dist-map {zero ∷ m} {suc y ∷ n} d z x x₁ = d (suc z) (sucin x) (sucin x₁)
dist-map {suc y ∷ m} {zero ∷ n} d z x x₁ = d (suc z) (sucin x) (sucin x₁)
dist-map {suc _ ∷ m} {suc y ∷ n} d z x x₁ = d (suc z) (sucin x) (sucin x₁)
dist-in : ∀{m1 m2 x y} → distinct' (Dom' (x ∷ m1)) (Dom' (y ∷ m2)) → distinct' (Dom' m1) (Dom' m2)
dist-in {[]} {[]} {x} {y} dd = λ z x₁ x₂ → ∈→⊥ x₁
dist-in {[]} {x ∷ m2} {x₁} {y} dd = λ z x₂ x₃ → ∈→⊥ x₂
dist-in {x ∷ m1} {[]} {x₁} {y} dd = λ z x₂ x₃ → ∈→⊥ x₃
dist-in {h₁ ∷ m1} {h₂ ∷ m2} {just x} {just x₁} dd = ⊥-elim (dist-b dd)
dist-in {h₁ ∷ m1} {h₂ ∷ m2} {just x} {nothing} dd = λ z x₁ x₂ → (dist'-sym (dist':: (dist'-sym dd))) _ (sucin x₁) (sucin x₂)
dist-in {h₁ ∷ m1} {h₂ ∷ m2} {nothing} {just x} dd = λ z x₁ x₂ → (dist':: dd) _ (sucin x₁) (sucin x₂)
dist-in {h₁ ∷ m1} {h₂ ∷ m2} {nothing} {nothing} dd = dist-map dd
-- ((Π._⟨$⟩_ (Inverse.to (∷↔ (_≡_ _)))) (inj₂ x₂))
dist-gen : ∀{m1 m2} → distinct' (Dom' m1) (Dom' m2) → dist-dom m1 m2
dist-gen {[]} {[]} dd = el
dist-gen {[]} {x ∷ m2} dd = el
dist-gen {x ∷ m1} {[]} dd = le
dist-gen {just x ∷ m1} {just x₁ ∷ m2} dd = ⊥-elim (dist-b dd)
dist-gen {just x ∷ m1} {nothing ∷ m2} dd = lc (dist-gen (dist-in{m1}{m2}{just x}{nothing} dd))
dist-gen {nothing ∷ m1} {just x ∷ m2} dd = cl (dist-gen (dist-in{m1}{m2}{nothing}{just x} dd))
dist-gen {nothing ∷ m1} {nothing ∷ m2} dd = nn (dist-gen (dist-in{m1}{m2}{nothing}{nothing} dd))
U-comm' : ∀{m1 m2} → dist-dom m1 m2 → (m1 U m2) ≡ (m2 U m1)
U-comm' {.[]} {[]} el = refl
U-comm' {.[]} {x ∷ m2} el = refl
U-comm' {[]} {.[]} le = refl
U-comm' {x ∷ m1} {.[]} le = refl
U-comm' {.(nothing ∷ _)} {.(just _ ∷ _)} (cl dd) rewrite U-comm' dd = refl
U-comm' {.(just _ ∷ _)} {.(nothing ∷ _)} (lc dd) rewrite U-comm' dd = refl
U-comm' {.(nothing ∷ _)} {.(nothing ∷ _)} (nn dd) rewrite U-comm' dd = refl
U-comm : ∀{m1 m2} → distinct' (Dom' m1) (Dom' m2) → (m1 U m2) ≡ (m2 U m1)
U-comm{m1}{m2} dd = U-comm'{m1}{m2} (dist-gen dd)
U-assoc' : ∀ m1 m2 m3 → m1 U (m2 U m3) ≡ (m1 U m2) U m3
U-assoc' [] m2 m3 = refl
U-assoc' (x ∷ m1) [] m3 = refl
U-assoc' (x ∷ m1) (x₁ ∷ m2) []
rewrite U-comm {(x ∷ m1) U (x₁ ∷ m2)} {[]} (λ _ _ ()) = refl
U-assoc' (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (just x ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (just x ∷ m1) (nothing ∷ m2) (just x₁ ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (just x ∷ m1) (nothing ∷ m2) (nothing ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (nothing ∷ m1) (just x ∷ m2) (just x₁ ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (nothing ∷ m1) (just x ∷ m2) (nothing ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (nothing ∷ m1) (nothing ∷ m2) (just x ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc' (nothing ∷ m1) (nothing ∷ m2) (nothing ∷ m3) rewrite U-assoc' m1 m2 m3 = refl
U-assoc : ∀ m1 m2 m3 → m1 U (m2 U m3) ≡ (m1 U m2) U m3
U-assoc m1 m2 m3 = U-assoc' m1 m2 m3
0∈S : ∀{l} → 0 ∈ (map suc l) → ⊥
0∈S {[]} ()
0∈S {x ∷ l} (here ())
0∈S {x ∷ l} (there p) = 0∈S p
n∈S : ∀{n x l} → suc n ∈ Dom' (x ∷ l) → n ∈ Dom' l
n∈S {n} {just x} {[]} (here ())
n∈S {n} {just x} {[]} (there ())
n∈S {n} {just x} {x₁ ∷ l} (here ())
n∈S {n} {just x} {x₁ ∷ l} (there p) = sucout p
n∈S {n} {nothing} {[]} ()
n∈S {n} {nothing} {x ∷ l} p = sucout p
n+1∈S : ∀ {n x m} → n ∈ (Dom' m) → (suc n) ∈ (Dom' (x ∷ m))
n+1∈S {n} {just x} {m} n∈ = there (sucin n∈)
n+1∈S {n} {nothing} {m} n∈ = sucin n∈
deref : (n : ℕ) → (l : LMap) → n ∈ (Dom' l) → Value
deref zero [] ()
deref zero (just x ∷ l) p = x
deref zero (nothing ∷ l) p = ⊥-elim (0∈S p)
deref (suc n) [] ()
deref (suc n) (x ∷ l) p = deref n l (n∈S{n}{x}{l} p)
-- thrms
deref-∈-irr : ∀{k l} → (∈1 : k ∈ (Dom' l)) → (∈2 : k ∈ (Dom' l)) → deref k l ∈1 ≡ deref k l ∈2
deref-∈-irr {zero} {[]} () ∈2
deref-∈-irr {suc k} {[]} () ∈2
deref-∈-irr {zero} {just x ∷ l} ∈1 ∈2 = refl
deref-∈-irr {zero} {nothing ∷ l} ∈1 ∈2 = ⊥-elim (0∈S ∈1)
deref-∈-irr {suc k} {x ∷ l} ∈1 ∈2 = deref-∈-irr (n∈S{k}{x}{l} ∈1) (n∈S{k}{x}{l} ∈2)
insert-mono' : ∀{l d l' d' n n' v} → n ∈ d → d ≡ (Dom' l) → d' ≡ (Dom' l') → l' ≡ (m-insert (just v) n' l) → n ∈ d'
insert-mono' {[]} {.[]} {[]} {.[]} {zero} {zero} () refl refl l'eq
insert-mono' {[]} {.[]} {[]} {.[]} {zero} {suc n'} () refl refl l'eq
insert-mono' {[]} {.[]} {[]} {.[]} {suc n} {zero} () refl refl l'eq
insert-mono' {[]} {.[]} {[]} {.[]} {suc n} {suc n'} () refl refl l'eq
insert-mono' {[]} {.[]} {x ∷ l'} {.(Dom' (x ∷ l'))} {zero} {zero} () refl refl l'eq
insert-mono' {[]} {.[]} {x ∷ l'} {.(Dom' (x ∷ l'))} {zero} {suc n'} () refl refl l'eq
insert-mono' {[]} {.[]} {x ∷ l'} {.(Dom' (x ∷ l'))} {suc n} {zero} () refl refl l'eq
insert-mono' {[]} {.[]} {x ∷ l'} {.(Dom' (x ∷ l'))} {suc n} {suc n'} () refl refl l'eq
insert-mono' {x ∷ l} {.(Dom' (x ∷ l))} {[]} {.[]} {zero} {zero} n∈ refl refl ()
insert-mono' {x ∷ l} {.(Dom' (x ∷ l))} {[]} {.[]} {zero} {suc n'} n∈ refl refl ()
insert-mono' {x ∷ l} {.(Dom' (x ∷ l))} {[]} {.[]} {suc n} {zero} n∈ refl refl ()
insert-mono' {x ∷ l} {.(Dom' (x ∷ l))} {[]} {.[]} {suc n} {suc n'} n∈ refl refl ()
insert-mono' {just x₁ ∷ l} {.(0 ∷ map suc (Dom' l))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {zero} {zero} {v} N∈ refl refl l'eq = here refl
insert-mono' {just x₁ ∷ l} {.(0 ∷ map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {zero} {zero} {v} N∈ refl refl ()
insert-mono' {nothing ∷ .l'} {.(map suc (Dom' l'))} {.(just _) ∷ l'} {.(0 ∷ map suc (Dom' l'))} {zero} {zero} n∈ refl refl refl = here refl
insert-mono' {just x₁ ∷ l} {.(0 ∷ map suc (Dom' l))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {zero} {suc n'} n∈ refl refl l'eq = here refl
insert-mono' {nothing ∷ l} {.(map suc (Dom' l))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {zero} {suc n'} n∈ refl refl l'eq = here refl
insert-mono' {just x₁ ∷ .l'} {.(0 ∷ map suc (Dom' l'))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {suc n} {zero} (here ()) refl refl refl
insert-mono' {just x₁ ∷ .l'} {.(0 ∷ map suc (Dom' l'))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {suc n} {zero} (there n∈) refl refl refl
= there n∈
insert-mono' {nothing ∷ .l'} {.(map suc (Dom' l'))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {suc n} {zero} n∈ refl refl refl = there n∈
insert-mono' {just x ∷ l} {.(0 ∷ map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {suc n} {zero} n∈ refl refl ()
insert-mono' {nothing ∷ l} {.(map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {suc n} {zero} n∈ refl refl ()
insert-mono' {just x₁ ∷ l} {.(0 ∷ map suc (Dom' l))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {suc n} {suc n'} (here ()) refl refl l'eq
insert-mono' {just x₁ ∷ l} {.(0 ∷ map suc (Dom' l))} {just .x₁ ∷ .(m-insert (just _) n' l)} {.(0 ∷ map suc (Dom' (m-insert (just _) n' l)))} {suc n} {suc n'} {v} (there n∈) refl refl refl
= there (sucin (insert-mono'{l = l}{l' = (m-insert (just _) n' l)}{n = n}{n' = n'}{v} (sucout n∈) refl refl refl))
insert-mono' {just x ∷ l} {.(0 ∷ map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {suc n} {suc n'} (here ()) refl refl l'eq
insert-mono' {just x ∷ l} {.(0 ∷ map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {suc n} {suc n'} {v} (there n∈) refl refl ()
insert-mono' {nothing ∷ l} {.(map suc (Dom' l))} {just x ∷ l'} {.(0 ∷ map suc (Dom' l'))} {suc n} {suc n'} n∈ refl refl ()
insert-mono' {nothing ∷ l} {.(map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {suc n} {suc n'} {v} n∈ refl refl refl
= sucin (insert-mono'{l = l}{l' = l'}{n = n}{n' = n'}{v = v} (sucout n∈) refl refl refl)
insert-mono' {just x ∷ l} {.(0 ∷ map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {zero} {suc n'} n∈ refl refl ()
insert-mono' {nothing ∷ l} {.(map suc (Dom' l))} {nothing ∷ l'} {.(map suc (Dom' l'))} {zero} {suc n'} n∈ refl refl l'eq = ⊥-elim (0∈S n∈)
insert-mono : ∀{m n n' v} → n ∈ (Dom' m) → n ∈ (Dom' (m-insert (just v) n' m))
insert-mono{m}{n}{n'}{v} i = insert-mono'{m}{Dom' m}{(m-insert (just v) n' m)}{(Dom' (m-insert (just v) n' m))}{n}{n'}{v} i refl refl refl
U-mono : ∀{m m' n} → n ∈ (Dom' m) → n ∈ (Dom' (m U m'))
U-mono {[]} {m'} {n} ()
U-mono {just x ∷ m} {[]} {n} (here px) = here px
U-mono {just x ∷ m} {just x₁ ∷ m'} {n} (here px) = here px
U-mono {just x ∷ m} {nothing ∷ m'} {n} (here px) = here px
U-mono {just x ∷ m} {[]} {n} (there ∈) = there ∈
U-mono {just x ∷ m} {just x₁ ∷ m'} {zero} (there ∈) = here refl
U-mono {just x ∷ m} {nothing ∷ m'} {zero} (there ∈) = here refl
U-mono {just x ∷ m} {just x₁ ∷ m'} {suc n} (there ∈) = there (sucin (U-mono{m}{m'}{n} (sucout ∈)))
U-mono {just x ∷ m} {nothing ∷ m'} {suc n} (there ∈) = there (sucin (U-mono{m}{m'}{n} (sucout ∈)))
U-mono {nothing ∷ m} {[]} {n} ∈ = ∈
U-mono {nothing ∷ m} {just x ∷ m'} {zero} ∈ = here refl
U-mono {nothing ∷ m} {just x ∷ m'} {suc n} ∈ = there (sucin (U-mono{m}{m'}{n} (sucout ∈)))
U-mono {nothing ∷ m} {nothing ∷ m'} {zero} ∈ = ⊥-elim (0∈S ∈)
U-mono {nothing ∷ m} {nothing ∷ m'} {suc n} ∈ = (sucin (U-mono{m}{m'}{n} (sucout ∈)))
U⁻ : ∀ {m m' n} → n ∈ Dom' (m U m') → (n ∈ Dom' m) ⊎ (n ∈ Dom' m')
U⁻ {[]} {[]} {n} n∈Dom⟨mUm'⟩ = inj₁ n∈Dom⟨mUm'⟩
U⁻ {[]} {x ∷ m'} {n} n∈Dom⟨mUm'⟩ = inj₂ n∈Dom⟨mUm'⟩
U⁻ {x ∷ m} {[]} {n} n∈Dom⟨mUm'⟩ = inj₁ n∈Dom⟨mUm'⟩
U⁻ {just x ∷ m} {just x₁ ∷ m'} {zero} n∈Dom⟨mUm'⟩ = inj₁ (here refl)
U⁻ {just x ∷ m} {just x₁ ∷ m'} {suc n} (here ())
U⁻ {just x ∷ m} {just x₁ ∷ m'} {suc n} (there n∈Dom⟨mUm'⟩) with U⁻ {m} {m'} {n} (sucout n∈Dom⟨mUm'⟩)
... | inj₁ ∈Dom-m = inj₁ (there (sucin ∈Dom-m))
... | inj₂ ∈Dom-m' = inj₂ (there (sucin ∈Dom-m'))
U⁻ {just x ∷ m} {nothing ∷ m'} {zero} n∈Dom⟨mUm'⟩ = inj₁ (here refl)
U⁻ {just x ∷ m} {nothing ∷ m'} {suc n} (here ())
U⁻ {just x ∷ m} {nothing ∷ m'} {suc n} (there n∈Dom⟨mUm'⟩) with U⁻ {m} {m'} {n} (sucout n∈Dom⟨mUm'⟩)
... | inj₁ ∈Dom-m = inj₁ (there (sucin ∈Dom-m))
... | inj₂ ∈Dom-m' = inj₂ (sucin ∈Dom-m')
U⁻ {nothing ∷ m} {just x ∷ m'} {zero} n∈Dom⟨mUm'⟩ = inj₂ (here refl)
U⁻ {nothing ∷ m} {just x ∷ m'} {suc n} (here ())
U⁻ {nothing ∷ m} {just x ∷ m'} {suc n} (there n∈Dom⟨mUm'⟩) with U⁻ {m} {m'} {n} (sucout n∈Dom⟨mUm'⟩)
... | inj₁ ∈Dom-m = inj₁ (sucin ∈Dom-m)
... | inj₂ ∈Dom-m' = inj₂ (there (sucin ∈Dom-m'))
U⁻ {nothing ∷ m} {nothing ∷ m'} {zero} n∈Dom⟨mUm'⟩ = ⊥-elim (0∈S n∈Dom⟨mUm'⟩)
U⁻ {nothing ∷ m} {nothing ∷ m'} {suc n} n∈Dom⟨mUm'⟩ with U⁻ {m} {m'} {n} (sucout n∈Dom⟨mUm'⟩)
... | inj₁ ∈Dom-m = inj₁ (sucin ∈Dom-m)
... | inj₂ ∈Dom-m' = inj₂ (sucin ∈Dom-m')
Dom'-1map : ∀ n v → Dom' (m-insert (just v) n []) ≡ (n ∷ [])
Dom'-1map zero v = refl
Dom'-1map (suc n) v rewrite Dom'-1map n v = refl
Dom'-2map : ∀ n₁ v₁ n₂ v₂ →
(Dom' (m-insert (just v₂) n₂ (m-insert (just v₁) n₁ [])) ≡ n₁ ∷ [] × n₁ ≡ n₂) ⊎
(Dom' (m-insert (just v₂) n₂ (m-insert (just v₁) n₁ [])) ≡ n₁ ∷ n₂ ∷ []) ⊎
(Dom' (m-insert (just v₂) n₂ (m-insert (just v₁) n₁ [])) ≡ n₂ ∷ n₁ ∷ [])
Dom'-2map zero v₁ zero v₂ = inj₁ (refl , refl)
Dom'-2map zero v₁ (suc n₂) v₂ rewrite Dom'-1map n₂ v₂ = inj₂ (inj₁ refl)
Dom'-2map (suc n₁) v₁ zero v₂ rewrite Dom'-1map n₁ v₁ = inj₂ (inj₂ refl)
Dom'-2map (suc n₁) v₁ (suc n₂) v₂ with Dom'-2map n₁ v₁ n₂ v₂
... | inj₁ (xs≡[n₁] , refl) rewrite xs≡[n₁] = inj₁ (refl , refl)
... | inj₂ (inj₁ xs≡[n₁,n₂]) rewrite xs≡[n₁,n₂] = inj₂ (inj₁ refl)
... | inj₂ (inj₂ xs≡[n₂,n₁]) rewrite xs≡[n₂,n₁] = inj₂ (inj₂ refl)
negsucun : ∀{k k'} → ¬ (suc k ≡ suc k') → k ≡ k' → ⊥
negsucun neg = (λ eq → neg (cong suc eq))
-- sucout : ∀{z n} → (suc z) ∈ (map suc n) → z ∈ n
sucinout : ∀{k nn}
→ (kin : (suc k) ∈ (map suc nn))
→ sucin (sucout kin) ≡ kin
sucinout {zero} {[]} ()
sucinout {zero} {.0 ∷ nn₁} (here refl) = refl
sucinout {zero} {x ∷ nn₁} (there kin) rewrite (sucinout{zero}{nn₁} kin) = refl
sucinout {suc k} {[]} ()
sucinout {suc k} {.(suc k) ∷ nn₁} (here refl) = refl
sucinout {suc k} {x ∷ nn₁} (there kin) rewrite (sucinout{(suc k)}{nn₁} kin) = refl
domzero : ∀{m} → zero ∈ (Dom' (nothing ∷ m)) → ⊥
domzero {[]} = λ ()
domzero {x ∷ m} = 0∈S
domin : ∀{x m z} → x ∈ Dom' m → suc x ∈ Dom' (z ∷ m)
domin {x} {m} {just z} x∈Dom'm = there (sucin x∈Dom'm)
domin {x} {m} {nothing} x∈Dom'm = sucin x∈Dom'm
n∈Sbij : ∀{k x m} → ∀{kin : (suc k) ∈ (Dom' (x ∷ m))} → ∀{kin2 : (suc k) ∈ (Dom' (x ∷ m))} → (n∈S{k}{x}{m} kin) ≡ (n∈S{k}{x}{m} kin2) → kin ≡ kin2
n∈Sbij {k} {just x} {[]} {here ()} {kin2} eq
n∈Sbij {k} {just x} {[]} {there ()} {kin2} eq
n∈Sbij {k} {just x} {x₁ ∷ m} {here ()} {kin2} eq
n∈Sbij {k} {just x} {x₁ ∷ m} {there kin} {here ()} eq
n∈Sbij {k} {just x} {x₁ ∷ m} {there kin} {there kin2} eq with (cong sucin eq)
... | eq2 rewrite (sucinout kin) | (sucinout kin2) = cong there eq2
n∈Sbij {k} {nothing} {[]} {kin} {()} eq
n∈Sbij {k} {nothing} {x ∷ m} {kin} {kin2} eq with cong sucin eq
... | eq2 rewrite (sucinout kin) | (sucinout kin2) = eq2
ineq : ∀{k m} → (kin1 : k ∈ (Dom' m)) → (kin2 : k ∈ (Dom' m)) → kin1 ≡ kin2
ineq {zero} {[]} () kin2
ineq {zero} {just x ∷ m} (here refl) (here refl) = refl
ineq {zero} {just x ∷ m} (here refl) (there kin2) = ⊥-elim (0∈S kin2)
ineq {zero} {just x ∷ m} (there kin1) (here px) = ⊥-elim (0∈S kin1)
ineq {zero} {just x ∷ m} (there kin1) (there kin2) = ⊥-elim (0∈S kin1)
ineq {zero} {nothing ∷ m} kin1 kin2 = ⊥-elim (domzero{m} kin1)
ineq {suc k} {[]} () kin2
ineq {suc k} {just x ∷ m} (here ()) (here px₁)
ineq {suc k} {just x ∷ m} (here ()) (there kin2)
ineq {suc k} {just x ∷ m} (there kin1) (here ())
ineq {suc k} {just x ∷ m} (there kin1) (there kin2) rewrite sym (sucinout kin1) | sym (sucinout kin2) = cong there (cong sucin (ineq{k}{m} (sucout kin1) (sucout kin2)))
ineq {suc k} {nothing ∷ m} kin1 kin2 = n∈Sbij{k}{nothing}{m} (ineq{k}{m} (n∈S{x = nothing}{l = m} kin1) (n∈S{x = nothing}{l = m} kin2))
Dom'-comm : ∀ m1 m2 → Dom' (m1 U m2) ≡ Dom' (m2 U m1)
Dom'-comm [] m2 rewrite U-comm {m2} {[]} (λ _ _ ()) = refl
Dom'-comm (x ∷ m1) [] = refl
Dom'-comm (just x ∷ m1) (just x₁ ∷ m2) rewrite Dom'-comm m1 m2 = refl
Dom'-comm (just x ∷ m1) (nothing ∷ m2) rewrite Dom'-comm m1 m2 = refl
Dom'-comm (nothing ∷ m1) (just x ∷ m2) rewrite Dom'-comm m1 m2 = refl
Dom'-comm (nothing ∷ m1) (nothing ∷ m2) rewrite Dom'-comm m1 m2 = refl
Dom'-assoc-comm : ∀ m1 m2 m3 → Dom' ((m1 U m2) U m3) ≡ Dom' ((m1 U m3) U m2)
Dom'-assoc-comm [] m2 m3 = Dom'-comm m2 m3
Dom'-assoc-comm (x ∷ m1) [] m3 rewrite Dom'-comm ((x ∷ m1) U m3) [] = refl
Dom'-assoc-comm (x ∷ m1) (x₁ ∷ m2) [] rewrite Dom'-comm ((x ∷ m1) U (x₁ ∷ m2)) [] = refl
Dom'-assoc-comm (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (just x ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (just x ∷ m1) (nothing ∷ m2) (just x₁ ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (just x ∷ m1) (nothing ∷ m2) (nothing ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (nothing ∷ m1) (just x ∷ m2) (just x₁ ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (nothing ∷ m1) (just x ∷ m2) (nothing ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (nothing ∷ m1) (nothing ∷ m2) (just x ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
Dom'-assoc-comm (nothing ∷ m1) (nothing ∷ m2) (nothing ∷ m3)
rewrite Dom'-assoc-comm m1 m2 m3 = refl
putputget-neq : ∀{k k' m v v'}
→ ¬ (k ≡ k')
→ (kin : k ∈ (Dom' m))
→ (kin2 : k ∈ (Dom' (m-insert (just v') k' m)))
→ (deref k m kin) ≡ v
→ (deref k (m-insert (just v') k' m) kin2) ≡ v
putputget-neq {k} {k'} {[]} neq () kin2 eq
putputget-neq {.0} {zero} {just x ∷ m} neq (here refl) (here refl) refl = ⊥-elim (neq refl)
putputget-neq {.0} {zero} {just x ∷ m} neq (here refl) (there kin2) refl = ⊥-elim (neq refl)
putputget-neq {.0} {suc k'} {just x ∷ m} neq (here refl) (here refl) refl = refl
putputget-neq {.0} {suc k'} {just x ∷ m} neq (here refl) (there kin2) refl = refl
putputget-neq {zero} {zero} {just x ∷ m} neq (there kin) kin2 refl = ⊥-elim (neq refl)
putputget-neq {zero} {suc k'} {just x ∷ m} neq (there kin) kin2 refl = refl
putputget-neq {suc k} {suc k'} {just x ∷ m} neq (there kin) (here ()) refl
putputget-neq {zero} {zero} {nothing ∷ m} neq kin kin2 refl = ⊥-elim (neq refl)
putputget-neq {zero} {suc k'} {nothing ∷ m} neq kin kin2 refl = ⊥-elim (0∈S kin)
putputget-neq {suc k} {zero} {nothing ∷ m} neq kin (here ()) refl
putputget-neq {suc k} {suc k'} {just x ∷ m} {v} {v'} neq (there kin) (there kin2) refl
rewrite ineq{k}{m-insert (just v') k' m} (n∈S{k}{just x}{m-insert (just v') k' m} (there kin2)) (sucout kin2)
= putputget-neq{k}{k'}{m}{v}{v'} (negsucun neq) (sucout kin) (sucout kin2) (deref-∈-irr{k}{m} (sucout kin) (n∈S{k}{x = just x}{m} (there kin)))
putputget-neq {suc k} {suc k'} {nothing ∷ m} {v} {v'} neq kin kin2 refl
rewrite ineq{k}{m-insert (just v') k' m} (n∈S{k}{nothing}{m-insert (just v') k' m} kin2) (sucout kin2)
= putputget-neq{k}{k'}{m} (negsucun neq) (sucout kin) ((sucout kin2)) ((deref-∈-irr{k}{m} (sucout kin) (n∈S{k}{x = nothing}{m} kin)))
putputget-neq {suc k} {zero} {x ∷ m} {v} {v'} neq kin kin2 refl = deref-∈-irr{k}{m} (n∈S{k}{just v'}{m} kin2) (n∈S{k}{x}{m} kin)
putputget-eq : ∀ k m v v' →
(m-insert (just v') k (m-insert (just v) k m))
≡ (m-insert (just v') k m)
putputget-eq zero [] v v' = refl
putputget-eq zero (x ∷ m) v v' = refl
putputget-eq (suc k) [] v v' rewrite putputget-eq k [] v v' = refl
putputget-eq (suc k) (x ∷ m) v v' rewrite putputget-eq k m v v' = refl
getput : ∀ k m →
(kin : k ∈ Dom' m) →
m ≡ m-insert (just (deref k m kin)) k m
getput k [] ()
getput zero (just x ∷ m) kin = refl
getput zero (nothing ∷ m) kin = ⊥-elim (0∈S kin)
getput (suc k) (just x ∷ m) kin
rewrite sym (getput k m (n∈S {k} {just x} {m} kin))
= refl
getput (suc k) (nothing ∷ m) kin
rewrite sym (getput k m (n∈S {k} {nothing} {m} kin))
= refl
putget : ∀{k m v} → (kin : k ∈ (Dom' (m-insert (just v) k m))) → (deref k (m-insert (just v) k m) kin) ≡ v
putget {zero} {[]} {v} (here refl) = refl
putget {zero} {[]} {v} (there ())
putget {zero} {just x ∷ m} {v} (here refl) = refl
putget {zero} {just x ∷ m} {v} (there kin) = refl
putget {zero} {nothing ∷ m} {v} kin = refl
putget {suc k} {[]} {v} kin = putget{k}{[]}{v} ( (n∈S{k}{nothing}{(m-insert (just v) k [])} kin) )
putget {suc k} {x ∷ m} {v} kin = putget{k}{m}{v} ( (n∈S{k}{x} kin) )
put-U-U : ∀ k v m1 m2 →
(kin1 : k ∈ Dom' m1) →
(kin2 : k ∈ Dom' m2) →
m1 U m2 ≡
(m-insert (just v) k m1) U m2
put-U-U k v [] m2 () kin2
put-U-U k v (x ∷ m1) [] kin1 ()
put-U-U zero v (just x ∷ m1) (just x₁ ∷ m2) kin1 kin2 = refl
put-U-U zero v (just x ∷ m1) (nothing ∷ m2) kin1 kin2 = ⊥-elim (0∈S kin2)
put-U-U zero v (nothing ∷ m1) (x₁ ∷ m2) kin1 kin2 = ⊥-elim (0∈S kin1)
put-U-U (suc k) v (just x ∷ m1) (just x₁ ∷ m2) kin1 kin2
rewrite put-U-U k v m1 m2
(n∈S {k} {just x} {m1} kin1)
(n∈S {k} {just x₁} {m2} kin2)
= refl
put-U-U (suc k) v (just x ∷ m1) (nothing ∷ m2) kin1 kin2
rewrite put-U-U k v m1 m2
(n∈S {k} {just x} {m1} kin1)
(n∈S {k} {nothing} {m2} kin2)
= refl
put-U-U (suc k) v (nothing ∷ m1) (just x ∷ m2) kin1 kin2
rewrite put-U-U k v m1 m2
(n∈S {k} {nothing} {m1} kin1)
(n∈S {k} {just x} {m2} kin2)
= refl
put-U-U (suc k) v (nothing ∷ m1) (nothing ∷ m2) kin1 kin2
rewrite put-U-U k v m1 m2
(n∈S {k} {nothing} {m1} kin1)
(n∈S {k} {nothing} {m2} kin2)
= refl
insert-comm : ∀{m k1 k2 v1 v2}
→ ¬ k1 ≡ k2
→ (m-insert (just v2) k2 (m-insert (just v1) k1 m)) ≡ (m-insert (just v1) k1 (m-insert (just v2) k2 m))
insert-comm {m} {zero} {zero} {v1} {v2} ¬k1≡k2 = ⊥-elim (¬k1≡k2 refl)
insert-comm {[]} {zero} {suc k2} {v1} {v2} ¬k1≡k2 = refl
insert-comm {x ∷ m} {zero} {suc k2} {v1} {v2} ¬k1≡k2 = refl
insert-comm {[]} {suc k1} {zero} {v1} {v2} ¬k1≡k2 = refl
insert-comm {x ∷ m} {suc k1} {zero} {v1} {v2} ¬k1≡k2 = refl
insert-comm {[]} {suc k1} {suc k2} {v1} {v2} ¬k1≡k2 rewrite insert-comm{[]}{k1}{k2}{v1}{v2} (λ x → ¬k1≡k2 (cong suc x)) = refl
insert-comm {x ∷ m} {suc k1} {suc k2} {v1} {v2} ¬k1≡k2 rewrite insert-comm{m}{k1}{k2}{v1}{v2} (λ x → ¬k1≡k2 (cong suc x)) = refl
insert-U-comm : ∀ k v m m' →
¬ (k ∈ Dom' m') →
(m-insert (just v) k m) U m' ≡
m-insert (just v) k (m U m')
insert-U-comm k v m [] k∉Domm'
rewrite U-comm {m} {[]} (λ _ _ ())
| U-comm {m-insert (just v) k m} {[]} (λ _ _ ())
= refl
insert-U-comm zero v [] (just x ∷ m') k∉Domm' = ⊥-elim (k∉Domm' (here refl))
insert-U-comm zero v [] (nothing ∷ m') k∉Domm' = refl
insert-U-comm (suc k) v [] (just x ∷ m') k∉Domm'
rewrite insert-U-comm k v [] m' (k∉Domm' ∘ there ∘ sucin {k} {Dom' m'})
= refl
insert-U-comm (suc k) v [] (nothing ∷ m') k∉Domm'
rewrite insert-U-comm k v [] m' (k∉Domm' ∘ sucin {k} {Dom' m'})
= refl
insert-U-comm zero v (x ∷ m) (just x₁ ∷ m') k∉Domm' = ⊥-elim (k∉Domm' (here refl))
insert-U-comm zero v (just x ∷ m) (nothing ∷ m') k∉Domm' = refl
insert-U-comm zero v (nothing ∷ m) (nothing ∷ m') k∉Domm' = refl
insert-U-comm (suc k) v (just x ∷ m) (just x₁ ∷ m') k∉Domm'
rewrite insert-U-comm k v m m' (k∉Domm' ∘ there ∘ sucin {k} {Dom' m'})
= refl
insert-U-comm (suc k) v (nothing ∷ m) (just x₁ ∷ m') k∉Domm'
rewrite insert-U-comm k v m m' (k∉Domm' ∘ there ∘ sucin {k} {Dom' m'})
= refl
insert-U-comm (suc k) v (just x ∷ m) (nothing ∷ m') k∉Domm'
rewrite insert-U-comm k v m m' (k∉Domm' ∘ sucin {k} {Dom' m'})
= refl
insert-U-comm (suc k) v (nothing ∷ m) (nothing ∷ m') k∉Domm'
rewrite insert-U-comm k v m m' (k∉Domm' ∘ sucin {k} {Dom' m'})
= refl
deref-U-right-irr : ∀ k m1 m2 kin12 kin2 →
deref k (m1 U m2) kin12 ≡ deref k m2 kin2
deref-U-right-irr k m1 [] kin12 ()
deref-U-right-irr zero [] (x ∷ m2) kin12 kin2 = deref-∈-irr {l = x ∷ m2} kin12 kin2
deref-U-right-irr zero (just x ∷ m1) (just x₁ ∷ m2) kin12 kin2 = refl
deref-U-right-irr zero (nothing ∷ m1) (just x ∷ m2) kin12 kin2 = refl
deref-U-right-irr zero (x ∷ m1) (nothing ∷ m2) kin12 kin2 = ⊥-elim (0∈S kin2)
deref-U-right-irr (suc k) [] (x ∷ m2) kin12 kin2 =
deref-∈-irr {l = m2} (n∈S {k} {x} kin12) (n∈S {k} {x} kin2)
deref-U-right-irr (suc k) (just x ∷ m1) (just x₁ ∷ m2) kin12 kin2 =
deref-U-right-irr k m1 m2
(n∈S {k} {just x₁} {m1 U m2} kin12) (n∈S {k} {just x₁} {m2} kin2)
deref-U-right-irr (suc k) (nothing ∷ m1) (just x₁ ∷ m2) kin12 kin2 =
deref-U-right-irr k m1 m2
(n∈S {k} {just x₁} {m1 U m2} kin12) (n∈S {k} {just x₁} {m2} kin2)
deref-U-right-irr (suc k) (just x ∷ m1) (nothing ∷ m2) kin12 kin2 =
deref-U-right-irr k m1 m2
(n∈S {k} {just x} {m1 U m2} kin12) (n∈S {k} {nothing} {m2} kin2)
deref-U-right-irr (suc k) (nothing ∷ m1) (nothing ∷ m2) kin12 kin2 =
deref-U-right-irr k m1 m2
(n∈S {k} {nothing} {m1 U m2} kin12) (n∈S {k} {nothing} {m2} kin2)
∈-deref-U-irr : ∀ k m1 m2 m3 kin1 kin2 →
(kin3 : k ∈ Dom' m3) →
deref k (m1 U m3) kin1 ≡ deref k (m2 U m3) kin2
∈-deref-U-irr k [] m2 m3 kin1 kin2 kin3
rewrite deref-U-right-irr k m2 m3 kin2 kin3
= deref-∈-irr kin1 kin3
∈-deref-U-irr k (x ∷ m1) [] m3 kin1 kin2 kin3
rewrite deref-U-right-irr k (x ∷ m1) m3 kin1 kin3
= deref-∈-irr kin3 kin2
∈-deref-U-irr k (x ∷ m1) (x₁ ∷ m2) [] kin1 kin2 ()
∈-deref-U-irr zero (x ∷ m1) (x₁ ∷ m2) (nothing ∷ m3) kin1 kin2 kin3 = ⊥-elim (0∈S kin3)
∈-deref-U-irr zero (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 = refl
∈-deref-U-irr zero (just x ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 = refl
∈-deref-U-irr zero (nothing ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 = refl
∈-deref-U-irr zero (nothing ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 = refl
∈-deref-U-irr (suc k) (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x₂} {m1 U m3} kin1)
(n∈S {k} {just x₂} {m2 U m3} kin2)
(n∈S {k} {just x₂} {m3} kin3)
∈-deref-U-irr (suc k) (just x ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x₂} {m1 U m3} kin1)
(n∈S {k} {just x₂} {m2 U m3} kin2)
(n∈S {k} {just x₂} {m3} kin3)
∈-deref-U-irr (suc k) (nothing ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x₂} {m1 U m3} kin1)
(n∈S {k} {just x₂} {m2 U m3} kin2)
(n∈S {k} {just x₂} {m3} kin3)
∈-deref-U-irr (suc k) (nothing ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x₂} {m1 U m3} kin1)
(n∈S {k} {just x₂} {m2 U m3} kin2)
(n∈S {k} {just x₂} {m3} kin3)
∈-deref-U-irr (suc k) (just x ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x} {m1 U m3} kin1)
(n∈S {k} {just x₁} {m2 U m3} kin2)
(n∈S {k} {nothing} {m3} kin3)
∈-deref-U-irr (suc k) (just x ∷ m1) (nothing ∷ m2) (nothing ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {just x} {m1 U m3} kin1)
(n∈S {k} {nothing} {m2 U m3} kin2)
(n∈S {k} {nothing} {m3} kin3)
∈-deref-U-irr (suc k) (nothing ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {nothing} {m1 U m3} kin1)
(n∈S {k} {just x₁} {m2 U m3} kin2)
(n∈S {k} {nothing} {m3} kin3)
∈-deref-U-irr (suc k) (nothing ∷ m1) (nothing ∷ m2) (nothing ∷ m3) kin1 kin2 kin3 =
∈-deref-U-irr k m1 m2 m3
(n∈S {k} {nothing} {m1 U m3} kin1)
(n∈S {k} {nothing} {m2 U m3} kin2)
(n∈S {k} {nothing} {m3} kin3)
deref-U-both-irr : ∀ k m1 m2 m3 kin1 kin2 kin13 kin23 →
deref k m1 kin1 ≡ deref k m2 kin2 →
deref k (m1 U m3) kin13 ≡ deref k (m2 U m3) kin23
deref-U-both-irr k [] m2 m3 () kin2 kin13 kin23 m1[k]≡m2[k]
deref-U-both-irr k (x ∷ m1) [] m3 kin1 () kin13 kin23 m1[k]≡m2[k]
deref-U-both-irr k (x ∷ m1) (x₁ ∷ m2) [] kin1 kin2 kin13 kin23 m1[k]≡m2[k]
rewrite deref-∈-irr {l = x ∷ m1} kin13 kin1 | deref-∈-irr {l = x₁ ∷ m2} kin23 kin2
= m1[k]≡m2[k]
deref-U-both-irr zero (just x ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3) _ _ _ _ m1[k]≡m2[k] = m1[k]≡m2[k]
deref-U-both-irr zero (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3) _ _ _ _ _ = refl
deref-U-both-irr zero (just x ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) _ _ _ _ _ = refl
deref-U-both-irr zero (nothing ∷ m1) (just x ∷ m2) (just x₂ ∷ m3) _ _ _ _ _ = refl
deref-U-both-irr zero (nothing ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3) _ _ _ _ _ = refl
deref-U-both-irr zero (nothing ∷ m1) (just x ∷ m2) (nothing ∷ m3) kin1 _ _ _ _ = ⊥-elim (0∈S kin1)
deref-U-both-irr zero (nothing ∷ m1) (nothing ∷ m2) (nothing ∷ m3) kin1 _ _ _ _ = ⊥-elim (0∈S kin1)
deref-U-both-irr zero (just x ∷ m1) (nothing ∷ m2) (nothing ∷ m3) _ kin2 _ _ _ = ⊥-elim (0∈S kin2)
deref-U-both-irr (suc k) (just x ∷ m1) (just x₁ ∷ m2) (just x₂ ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {just x} {m1} kin1) (n∈S {k} {just x₁} {m2} kin2)
(n∈S {k} {just x₂} {m1 U m3} kin13) (n∈S {k} {just x₂} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (just x ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {just x} {m1} kin1) (n∈S {k} {nothing} {m2} kin2)
(n∈S {k} {just x₂} {m1 U m3} kin13) (n∈S {k} {just x₂} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (nothing ∷ m1) (just x ∷ m2) (just x₂ ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {nothing} {m1} kin1) (n∈S {k} {just x} {m2} kin2)
(n∈S {k} {just x₂} {m1 U m3} kin13) (n∈S {k} {just x₂} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (nothing ∷ m1) (nothing ∷ m2) (just x₂ ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {nothing} {m1} kin1) (n∈S {k} {nothing} {m2} kin2)
(n∈S {k} {just x₂} {m1 U m3} kin13) (n∈S {k} {just x₂} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (just x ∷ m1) (just x₁ ∷ m2) (nothing ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {just x} {m1} kin1) (n∈S {k} {just x₁} {m2} kin2)
(n∈S {k} {just x} {m1 U m3} kin13) (n∈S {k} {just x₁} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (just x ∷ m1) (nothing ∷ m2) (nothing ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {just x} {m1} kin1) (n∈S {k} {nothing} {m2} kin2)
(n∈S {k} {just x} {m1 U m3} kin13) (n∈S {k} {nothing} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (nothing ∷ m1) (just x ∷ m2) (nothing ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {nothing} {m1} kin1) (n∈S {k} {just x} {m2} kin2)
(n∈S {k} {nothing} {m1 U m3} kin13) (n∈S {k} {just x} {m2 U m3} kin23)
m1[k]≡m2[k]
deref-U-both-irr (suc k) (nothing ∷ m1) (nothing ∷ m2) (nothing ∷ m3)
kin1 kin2 kin13 kin23 m1[k]≡m2[k] =
deref-U-both-irr k m1 m2 m3
(n∈S {k} {nothing} {m1} kin1) (n∈S {k} {nothing} {m2} kin2)
(n∈S {k} {nothing} {m1 U m3} kin13) (n∈S {k} {nothing} {m2 U m3} kin23)
m1[k]≡m2[k]
U-domout : ∀ {k m₁ m₂} x x₁ → suc k ∈ Dom' ((x ∷ m₁) U (x₁ ∷ m₂)) → k ∈ Dom' (m₁ U m₂)
U-domout (just x₂) (just x₃) (here ())
U-domout (just x₂) (just x₃) (there suck∈'') = sucout suck∈''
U-domout (just x₂) nothing (here ())
U-domout (just x₂) nothing (there suck∈'') = sucout suck∈''
U-domout nothing (just x₂) (here ())
U-domout nothing (just x₂) (there suck∈'') = sucout suck∈''
U-domout nothing nothing suck∈'' = sucout suck∈''
U-∉-irr-get-help-help : ∀ k x x₁ m₁ m₂ →
(k∈ : suc k ∈ Dom' ((x ∷ m₁) U (x₁ ∷ m₂))) →
deref (suc k) ((x ∷ m₁) U (x₁ ∷ m₂)) k∈ ≡
deref k (m₁ U m₂) (U-domout x x₁ k∈)
U-∉-irr-get-help-help k (just x) (just x₁) m₁ m₂ (here ())
U-∉-irr-get-help-help k (just x) (just x₁) m₁ m₂ (there k∈) = deref-∈-irr {k} {m₁ U m₂} (n∈S {k} {just x₁} {m₁ U m₂} (there k∈)) (sucout k∈)
U-∉-irr-get-help-help k (just x) nothing m₁ m₂ (here ())
U-∉-irr-get-help-help k (just x) nothing m₁ m₂ (there k∈) = deref-∈-irr {k} {m₁ U m₂} (n∈S {k} {just x} {m₁ U m₂} (there k∈)) (sucout k∈)
U-∉-irr-get-help-help k nothing (just x) m₁ m₂ (here ())
U-∉-irr-get-help-help k nothing (just x) m₁ m₂ (there k∈) = deref-∈-irr {k} {m₁ U m₂} (n∈S {k} {just x} {m₁ U m₂} (there k∈)) (sucout k∈)
U-∉-irr-get-help-help k nothing nothing m₁ m₂ k∈ = deref-∈-irr {k} {m₁ U m₂} (n∈S {k} {nothing} {m₁ U m₂} k∈) (sucout k∈)
U-∉-irr-get-help : ∀ {m₁ m₂ k} → (k∈ : k ∈ Dom' m₁) → k ∉ Dom' m₂ → (k∈' : k ∈ Dom' (m₁ U m₂)) → deref k m₁ k∈ ≡ deref k (m₁ U m₂) k∈'
U-∉-irr-get-help {[]} {[]} {k} () k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩
U-∉-irr-get-help {[]} {x ∷ m₂} {k} () k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩
U-∉-irr-get-help {x ∷ m₁} {[]} {k} k∈Dom⟨m₁⟩ k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩
rewrite deref-∈-irr {k} {x ∷ m₁} k∈Dom⟨m₁⟩ k∈Dom⟨m₁Um₂⟩ = refl
U-∉-irr-get-help {x ∷ m₁} {just x₁ ∷ m₂} {zero} k∈Dom⟨m₁⟩ k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩ = ⊥-elim (k∉Dom⟨m₂⟩ (here refl))
U-∉-irr-get-help {just x ∷ m₁} {nothing ∷ m₂} {zero} k∈Dom⟨m₁⟩ k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩ = refl
U-∉-irr-get-help {nothing ∷ m₁} {nothing ∷ m₂} {zero} k∈Dom⟨m₁⟩ k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩ = ⊥-elim (0∈S k∈Dom⟨m₁⟩)
U-∉-irr-get-help {x ∷ m₁} {x₁ ∷ m₂} {suc k} k∈Dom⟨m₁⟩ k∉Dom⟨m₂⟩ k∈Dom⟨m₁Um₂⟩
with U-∉-irr-get-help {m₁} {m₂} {k} (n∈S {k} {x} k∈Dom⟨m₁⟩) (λ x₂ → k∉Dom⟨m₂⟩ (domin {k} {m₂} {x₁} x₂)) (U-domout x x₁ k∈Dom⟨m₁Um₂⟩)
... | eq rewrite U-∉-irr-get-help-help k x x₁ m₁ m₂ k∈Dom⟨m₁Um₂⟩ = eq
U-∉-irr-get : ∀ {m₁ m₂ k} → (k∈ : k ∈ Dom' m₁) → k ∉ Dom' m₂ → ∃ λ k∈' → deref k m₁ k∈ ≡ deref k (m₁ U m₂) k∈'
U-∉-irr-get {m₁} {m₂} {k} k∈Dom'm₁ k∉Dom'm₂ =
_ , U-∉-irr-get-help {m₁} {m₂} {k} k∈Dom'm₁ k∉Dom'm₂ (U-mono {m₁} {m₂} k∈Dom'm₁)
split : ∀{a b : ℕ} {l l'} → a ∷ l ≡ b ∷ l' → ((_≡_ a b) × (_≡_ l l'))
split refl = refl , refl
mapsuc≡ : ∀{l l'} → map suc l ≡ map suc l' → l ≡ l'
mapsuc≡ {[]} {[]} eq = refl
mapsuc≡ {[]} {x ∷ l'} ()
mapsuc≡ {x ∷ l} {[]} ()
mapsuc≡ {x ∷ l} {x₁ ∷ l'} eq with split eq
... | (a , b) rewrite (suc≡ a) | (mapsuc≡ b) = refl
U-=-irr : ∀ m m' → (Dom' m) ≡ (Dom' m') → ∀ k k∈ k∈2 → deref k (m U m') k∈ ≡ deref k m' k∈2
U-=-irr [] [] eq k ()
U-=-irr [] (nothing ∷ m') eq k x with (subst (λ l → k ∈ l) (sym eq) x)
... | ()
U-=-irr [] (just x ∷ m') ()
U-=-irr (just x ∷ m) [] ()
U-=-irr (nothing ∷ m) [] eq k k∈ ()
U-=-irr (just x ∷ m) (nothing ∷ m') eq = ⊥-elim (0∈S{Dom' m'} (subst (λ x → 0 ∈ x) eq ((0 ∈ (0 ∷ (map suc (Dom' m)))) ∋ (here refl))))
U-=-irr (nothing ∷ m) (just x ∷ m') eq = ⊥-elim (0∈S{Dom' m} (subst (λ x → 0 ∈ x) (sym eq) ((0 ∈ (0 ∷ (map suc (Dom' m')))) ∋ (here refl))))
U-=-irr (nothing ∷ m) (nothing ∷ m') eq zero k∈ k∈2 = ⊥-elim (0∈S k∈)
U-=-irr (nothing ∷ m) (nothing ∷ m') eq (suc k) k∈ k∈2 = U-=-irr m m' (mapsuc≡ eq) k (n∈S{k}{nothing}{m U m'} k∈) (n∈S{k}{nothing}{m'} k∈2)
U-=-irr (just x ∷ m) (just x₁ ∷ m') eq zero = λ k∈ k∈2 → refl
U-=-irr (just x ∷ m) (just x₁ ∷ m') eq (suc k) k∈ k∈2 = U-=-irr m m' ((mapsuc≡ (proj₂ (split eq)))) k (n∈S{k}{just x₁}{m U m'} k∈) (n∈S{k}{just x₁}{m'} k∈2)
U-single-overwrite : ∀ k v1 v2 → (m-insert (just v1) k []) U (m-insert (just v2) k []) ≡ (m-insert (just v2) k [])
U-single-overwrite zero v1 v2 = refl
U-single-overwrite (suc k) v1 v2 rewrite U-single-overwrite k v1 v2 = refl
set-single-val : ∀ k v k∈ → (deref k (m-insert (just v) k []) k∈) ≡ v
set-single-val zero v (here refl) = refl
set-single-val zero v (there ())
set-single-val (suc k) v k∈ = set-single-val k v (n∈S{k}{nothing}{(m-insert (just v) k [])} k∈)
overwrite-single-val : ∀ k v m → k ∈ (Dom' m) → ((m-insert (just v) k []) U m) ≡ m
overwrite-single-val zero v [] ()
overwrite-single-val zero v (just x ∷ m) k∈ = refl
overwrite-single-val zero v (nothing ∷ m) k∈ = ⊥-elim (0∈S k∈)
overwrite-single-val (suc k) v [] ()
overwrite-single-val (suc k) v (just x ∷ m) (here ())
overwrite-single-val (suc k) v (just x ∷ m) (there k∈) rewrite overwrite-single-val k v m (sucout k∈) = refl
overwrite-single-val (suc k) v (nothing ∷ m) k∈ rewrite overwrite-single-val k v m (sucout k∈) = refl
U-insert-eq : ∀ k v m → (m-insert (just v) k m) ≡ m U (m-insert (just v) k [])
U-insert-eq zero v [] = refl
U-insert-eq zero v (just x ∷ m) rewrite U-comm{m}{[]} (λ z _ → λ ()) = refl
U-insert-eq zero v (nothing ∷ m) rewrite U-comm{m}{[]} (λ z _ → λ ()) = refl
U-insert-eq (suc k) v [] = refl
U-insert-eq (suc k) v (just x ∷ m) rewrite U-insert-eq k v m = refl
U-insert-eq (suc k) v (nothing ∷ m) rewrite U-insert-eq k v m = refl
insert-domain-eq : ∀ k v m → k ∈ (Dom' m) → (Dom' m) ≡ (Dom' (m-insert (just v) k m))
insert-domain-eq zero v [] ()
insert-domain-eq zero v (just x ∷ m) k∈ = refl
insert-domain-eq zero v (nothing ∷ m) k∈ = ⊥-elim (0∈S k∈)
insert-domain-eq (suc k) v [] ()
insert-domain-eq (suc k) v (just x ∷ m) (here ())
insert-domain-eq (suc k) v (just x ∷ m) (there k∈) rewrite insert-domain-eq k v m (sucout k∈) = refl
insert-domain-eq (suc k) v (nothing ∷ m) k∈ rewrite insert-domain-eq k v m (sucout k∈) = refl
insert-in-domain : ∀ m k v → k ∈ (Dom' (m-insert (just v) k m))
insert-in-domain [] zero v = here refl
insert-in-domain (x ∷ m) zero v = here refl
insert-in-domain [] (suc k) v = sucin (insert-in-domain [] k v)
insert-in-domain (x ∷ m) (suc k) v = domin{z = x} (insert-in-domain m k v)
insert-one-eq : ∀ k v k∈ → (deref k (m-insert (just v) k []) k∈) ≡ v
insert-one-eq zero v k∈ = refl
insert-one-eq (suc k) v k∈ = insert-one-eq k v (n∈S{k}{nothing}{(m-insert (just v) k [])} k∈)
insert-two-eq-one : ∀ k1 k2 v k1∈ → (deref k1 (m-insert (just v) k2 (m-insert (just v) k1 [])) k1∈) ≡ v
insert-two-eq-one zero zero v k1∈ = refl
insert-two-eq-one zero (suc k2) v k1∈ = refl
insert-two-eq-one (suc k1) zero v k1∈
= insert-one-eq k1 v ( (n∈S{k1}{just v}{l = (m-insert (just v) k1 [])} k1∈) )
insert-two-eq-one (suc k1) (suc k2) v k1∈
= insert-two-eq-one k1 k2 v ( (n∈S{k1}{nothing}{(m-insert (just v) k2 (m-insert (just v) k1 []))} k1∈))
insert-two-eq-two : ∀ k1 k2 v k2∈ → (deref k2 (m-insert (just v) k2 (m-insert (just v) k1 [])) k2∈) ≡ v
insert-two-eq-two zero zero v k2∈ = refl
insert-two-eq-two zero (suc k2) v k2∈
= insert-one-eq k2 v ( (n∈S{k2}{just v}{l = (m-insert (just v) k2 [])} k2∈) )
insert-two-eq-two (suc k1) zero v k2∈ = refl
insert-two-eq-two (suc k1) (suc k2) v k2∈
= insert-two-eq-two k1 k2 v ( (n∈S{k2}{nothing}{(m-insert (just v) k2 (m-insert (just v) k1 []))} k2∈))
data AllMap {i} (F : Value → Set i) : LMap → Set i where
all : ∀ (m : LMap) → All (Data.Maybe.All F) m → AllMap F m
allMap : ∀ {i} m → {F : Value → Set i} → U.Decidable F → Dec (AllMap F m)
allMap m {F} dec with All.all (Data.Maybe.allDec dec) m
allMap m {F} dec | yes p = yes (all m p)
allMap m {F} dec | no ¬p = no (λ { (all _ x) → ¬p x})
-- All.all (Data.Maybe.allDec F) m
deref∈ : ∀ {m} → (n : ℕ) → (n∈ : n ∈ (Dom' m)) → just (deref n m n∈) ∈ m
deref∈ {[]} zero ()
deref∈ {[]} (suc n) ()
deref∈ {just x ∷ m} zero n∈ = here refl
deref∈ {nothing ∷ m} zero n∈ = ⊥-elim (0∈S n∈)
deref∈ {just x ∷ m} (suc n) n∈ = there (deref∈ n (n∈S{n}{just x}{m} n∈))
deref∈ {nothing ∷ m} (suc n) n∈ = there (deref∈ n (n∈S{n}{nothing}{m} n∈))
allMap-lookup : ∀ {i} {F : Value → Set i} {m} → AllMap F m → ∀ (n : ℕ) → (k∈ : n ∈ (Dom' m)) → (F (deref n m k∈ ))
allMap-lookup {i} {F} (all m x) n n∈ with (All.lookup x) {just (deref n m n∈)} (deref∈ n n∈)
allMap-lookup {i} {F} (all m x) n n∈ | just px = px
allMap-tabulate : ∀ {i} {F : Value → Set i} {m} → (∀ (n : ℕ) → (k∈ : n ∈ (Dom' m)) → (F (deref n m k∈ ))) → AllMap F m
allMap-tabulate {m = []} FF = all [] All.[]
allMap-tabulate {F = F} {m = just x ∷ m} FF
with allMap-tabulate{F = F} {m = m} (λ n k∈ → subst F (deref-∈-irr (n∈S{n}{just x}{m} (there (sucin k∈))) k∈) (FF (suc n) (n+1∈S{n}{just x}{m} k∈)))
allMap-tabulate {_} {F} {just x ∷ m} FF | all .m x₁ = all (just x ∷ m) ((just (FF 0 (here refl))) All.∷ x₁)
allMap-tabulate {F = F} {m = nothing ∷ m} FF
with allMap-tabulate {m = m} (λ n k∈ → subst F (deref-∈-irr (n∈S{n}{nothing}{m} (sucin k∈)) k∈) (FF (suc n) (n+1∈S{n}{nothing}{m} k∈)) )
allMap-tabulate {_} {_} {nothing ∷ m} FF | all .m x = all (nothing ∷ m) (nothing All.∷ x)
andmap : ∀ {i} {F : Value → Set i} → U.Decidable F → (m : LMap) → Dec ∀ (n : ℕ) → (n∈ : n ∈ (Dom' m)) → (F (deref n m n∈))
andmap Fp m with allMap m Fp
andmap Fp m | yes p = yes (allMap-lookup p)
andmap Fp m | no ¬p = no (λ x → ¬p (allMap-tabulate x))
ocount : (Value -> Bool) -> LMap -> ℕ
ocount p [] = 0
ocount p (just x ∷ m) with p x
ocount p (just x ∷ m) | false = ocount p m
ocount p (just x ∷ m) | true = suc (ocount p m)
ocount p (nothing ∷ m) = ocount p m
change-one-ocount-goes-down :
∀ (m : LMap) ->
(p : Value -> Bool) ->
(n : ℕ) ->
(k∈ : n ∈ (Dom' m)) ->
p (deref n m k∈) ≡ true ->
(v : Value) ->
p v ≡ false ->
ocount p m ≡ suc (ocount p (m-insert (just v) n m))
change-one-ocount-goes-down = f where
f : ∀ (m : LMap) ->
(p : Value -> Bool) ->
(n : ℕ) ->
(k∈ : n ∈ (Dom' m)) ->
p (deref n m k∈) ≡ true ->
(v : Value) ->
p v ≡ false ->
ocount p m ≡ suc (ocount p (m-insert (just v) n m))
f [] p zero () p[derefnmk∈]≡true v pv≡false
f (just x ∷ m) p zero k∈ p[derefnmk∈]≡true v pv≡false with p x
... | true with p v
f (just x ∷ m) p zero k∈ p[derefnmk∈]≡true v () | true | true
... | false = refl
f (just x ∷ m) p zero k∈ () v pv≡false | false
f (nothing ∷ m) p zero k∈ p[derefnmk∈]≡true v pv≡false = ⊥-elim (0∈S k∈)
f [] p (suc n) () p[derefnmk∈]≡true v pv≡false
f (just x ∷ m) p (suc n) k∈ p[derefnmk∈]≡true v pv≡false with p x
... | true = cong suc (f m p n
(n∈S{x = just x}{l = m} k∈)
p[derefnmk∈]≡true v pv≡false)
... | false = f m p n (n∈S{x = just x}{l = m} k∈)
p[derefnmk∈]≡true v pv≡false
f (nothing ∷ m) p (suc n) k∈ p[derefnmk∈]≡true v pv≡false
= f m p n (n∈S{x = nothing}{l = m} k∈) p[derefnmk∈]≡true v pv≡false
change-nothing-ocount-stays-same :
∀ (m : LMap) ->
(p : Value -> Bool) ->
(n : ℕ) ->
(k∈ : n ∈ (Dom' m)) ->
(v : Value) ->
p (deref n m k∈) ≡ p v ->
ocount p m ≡ ocount p (m-insert (just v) n m)
change-nothing-ocount-stays-same = f where
f : ∀ (m : LMap) ->
(p : Value -> Bool) ->
(n : ℕ) ->
(k∈ : n ∈ (Dom' m)) ->
(v : Value) ->
p (deref n m k∈) ≡ p v ->
ocount p m ≡ ocount p (m-insert (just v) n m)
f [] p zero () v pold≡pv
f (just x ∷ m) p zero k∈ v pold≡pv with p x | p v
f (just x ∷ m) p zero k∈ v pold≡pv | false | false = refl
f (just x ∷ m) p zero k∈ v () | false | true
f (just x ∷ m) p zero k∈ v () | true | false
f (just x ∷ m) p zero k∈ v pold≡pv | true | true = refl
f (nothing ∷ m) p zero k∈ v pold≡pv with p v
f (nothing ∷ m) p zero k∈ v pold≡pv | false = refl
f (nothing ∷ m) p zero k∈ v pold≡pv | true = ⊥-elim (0∈S k∈)
f [] p (suc n) () v pold≡pv
f (just x ∷ m) p (suc n) k∈ v pold≡pv with p x
f (just x ∷ m) p (suc n) k∈ v pold≡pv | true =
cong suc (f m p n (n∈S{x = just x}{l = m} k∈) v pold≡pv)
f (just x ∷ m) p (suc n) k∈ v pold≡pv | false =
f m p n (n∈S{x = just x}{l = m} k∈) v pold≡pv
f (nothing ∷ m) p (suc n) k∈ v pold≡pv =
f m p n (n∈S{x = nothing}{l = m} k∈) v pold≡pv
ocount-merge≤′sum-ocount :
∀ (m1 m2 : LMap) ->
(p : Value -> Bool) ->
ocount p (m1 U m2) ≤′ ocount p m1 + ocount p m2
ocount-merge≤′sum-ocount = f where
f : ∀ (m1 m2 : LMap) ->
(p : Value -> Bool) ->
ocount p (m1 U m2) ≤′ ocount p m1 + ocount p m2
f [] [] p = ≤′-refl
f [] (x ∷ m2) p = ≤′-refl
f (x ∷ m1) [] p = ≤⇒≤′ (m≤m+n (ocount p (x ∷ m1)) 0)
f (just x ∷ m1) (just x₁ ∷ m2) p with p x | p x₁ | f m1 m2 p
f (just x ∷ m1) (just x₁ ∷ m2) p | false | false | R = R
f (just x ∷ m1) (just x₁ ∷ m2) p | false | true | R =
≤′-trans {y = suc (ocount p m1 + ocount p m2)}
(s≤′s R) (≡is≤′ (sym (+-suc (ocount p m1) (ocount p m2))))
f (just x ∷ m1) (just x₁ ∷ m2) p | true | false | R =
≤′-step R
f (just x ∷ m1) (just x₁ ∷ m2) p | true | true | R =
s≤′s (≤′-trans {y = ocount p m1 + ocount p m2}
R
(≤′+r {ocount p m2} {suc (ocount p m2)} {ocount p m1} (≤′-step ≤′-refl)))
f (just x ∷ m1) (nothing ∷ m2) p with p x | f m1 m2 p
f (just x ∷ m1) (nothing ∷ m2) p | false | R = R
f (just x ∷ m1) (nothing ∷ m2) p | true | R = s≤′s R
f (nothing ∷ m1) (just x ∷ m2) p with p x | f m1 m2 p
f (nothing ∷ m1) (just x ∷ m2) p | false | R = R
f (nothing ∷ m1) (just x ∷ m2) p | true | R =
≤′-trans {y = suc (ocount p m1 + ocount p m2)}
(s≤′s R) (≡is≤′ (sym (+-suc (ocount p m1) (ocount p m2))))
f (nothing ∷ m1) (nothing ∷ m2) p with f m1 m2 p
... | R = R
Dom'+∈ : (L : LMap) → List (∃[ n ] (n ∈ (Dom' L)))
Dom'+∈ L = help (Dom' L)
where
help : (x : List ℕ) → (List (∃[ y ] (y ∈ x)))
help [] = []
help (x ∷ x₁) = (x , here refl) ∷ map (λ {(a , b) → a , there b}) (help x₁)
| {
"alphanum_fraction": 0.5347456716,
"avg_line_length": 49.62113127,
"ext": "agda",
"hexsha": "99b641b568276939e34479591206845158f5d3bc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/Data/OrderedListMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/Data/OrderedListMap.agda",
"max_line_length": 187,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/Data/OrderedListMap.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 22584,
"size": 46495
} |
------------------------------------------------------------------------------
-- Testing the class AgdaInternal.RemoveProofTerms.RemoveVar: Lam term
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module RemoveVar.LamTerm where
-- We add 3 to the fixities of the standard library.
infixr 8 _∷_
infixr 7 _,_
infix 7 _≡_ _≈_
infixr 5 _∧_
infix 5 ∃
------------------------------------------------------------------------------
postulate
D : Set
_∷_ : D → D → D
Stream : D → Set
_≈_ : D → D → Set
data _∧_ (A B : Set) : Set where
_,_ : A → B → A ∧ B
data ∃ (A : D → Set) : Set where
_,_ : (t : D) → A t → ∃ A
syntax ∃ (λ x → e) = ∃[ x ] e
data _≡_ (x : D) : D → Set where
refl : x ≡ x
postulate
Stream-gfp₂ : (P : D → Set) →
-- P is post-fixed point of StreamF.
(∀ {xs} → P xs → ∃[ x' ] ∃[ xs' ] P xs' ∧ xs ≡ x' ∷ xs') →
-- Stream is greater than P.
∀ {xs} → P xs → Stream xs
postulate
≈-gfp₁ : ∀ {xs ys} → xs ≈ ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs' ≈ ys' ∧ xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys'
{-# ATP axiom ≈-gfp₁ #-}
-- See Issue #81.
P : D → Set
P ws = ∃[ zs ] ws ≈ zs
{-# ATP definition P #-}
≈→Stream : ∀ {xs ys} → xs ≈ ys → Stream xs
≈→Stream {xs} {ys} xs≈ys = Stream-gfp₂ P helper (ys , xs≈ys)
where
postulate helper : ∀ {ws} → P ws → ∃[ w' ] ∃[ ws' ] P ws' ∧ ws ≡ w' ∷ ws'
{-# ATP prove helper #-}
| {
"alphanum_fraction": 0.4091189156,
"avg_line_length": 27.05,
"ext": "agda",
"hexsha": "cae833671d7ae7a4eea3b5479519df4cda2d8d48",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/RemoveVar/LamTerm.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/RemoveVar/LamTerm.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/RemoveVar/LamTerm.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 553,
"size": 1623
} |
module modal-lob-reduced where
data TYP : Set where
ARR : TYP → TYP → TYP -- the type of implications, or function types
BOX : TYP → TYP -- the modal □ operator, denoted to TERM
LӦB-SENTENCE : TYP → TYP -- the Lӧbian sentence "If this sentence is provable, then A"
-- this is the modal fixpoint of λ Ψ. □ Ψ → A
data TERM : TYP → Set where
k : {A : TYP} → TERM A → TERM (BOX A) -- from A, we deduce □ A
distr : {A B : TYP} → TERM (ARR (BOX (ARR A B)) (ARR (BOX A) (BOX B))) -- we deduce □ (A → B) → □ A → □ B
s4 : {A : TYP} → TERM (ARR (BOX A) (BOX (BOX A))) -- we deduce □ A → □ □ A
app : {A B : TYP} → TERM (ARR A B) → TERM A → TERM B -- from A → B, and A, we deduce B
lӧb→ : {A : TYP} → TERM (ARR (LӦB-SENTENCE A) (ARR (BOX (LӦB-SENTENCE A)) A)) -- LӦB-SENTENCE A is Ψ such that Ψ → (□ Ψ → A)
lӧb← : {A : TYP} → TERM (ARR (ARR (BOX (LӦB-SENTENCE A)) A) (LӦB-SENTENCE A)) -- LӦB-SENTENCE A is Ψ such that (□ Ψ → A) → Ψ
compose : {A B C : TYP} → TERM (ARR A B) → TERM (ARR B C) → TERM (ARR A C) -- from A → B and B → C, we deduce A → C
compose2 : {A B C : TYP} → TERM (ARR A B) → TERM (ARR A (ARR B C)) → TERM (ARR A C) -- from A → B and A → B → C, we deduce A → C
⟦_⟧ᵀ : TYP → Set
⟦ ARR A B ⟧ᵀ = ⟦ A ⟧ᵀ → ⟦ B ⟧ᵀ
⟦ BOX T ⟧ᵀ = TERM T
⟦ LӦB-SENTENCE A ⟧ᵀ = TERM (LӦB-SENTENCE A) → ⟦ A ⟧ᵀ
⟦_⟧ᵗ : {T : TYP} → TERM T → ⟦ T ⟧ᵀ
⟦ k e ⟧ᵗ = e
⟦ distr ⟧ᵗ box-a-b box-a = app box-a-b box-a
⟦ s4 ⟧ᵗ = k
⟦ app f x ⟧ᵗ = ⟦ f ⟧ᵗ ⟦ x ⟧ᵗ
⟦ lӧb→ ⟧ᵗ = λ x → x -- this implication is true because on denotation, the two are judgmentally equal
⟦ lӧb← ⟧ᵗ = λ x → x -- this implication is true because on denotation, the two are judgmentally equal
⟦ compose f g ⟧ᵗ = λ x → ⟦ g ⟧ᵗ (⟦ f ⟧ᵗ x)
⟦ compose2 f g ⟧ᵗ = λ x → ⟦ g ⟧ᵗ x (⟦ f ⟧ᵗ x)
Lӧb′s-Theorem : {A : TYP} → TERM (ARR (BOX A) A) → TERM A -- from □ A → A, we deduce A
Lӧb′s-Theorem {A} interp = app prog (k (app lӧb← prog))
where prog : TERM (ARR (BOX (LӦB-SENTENCE A)) A)
prog = compose (compose2 s4 (compose (app distr (k lӧb→)) distr)) interp
| {
"alphanum_fraction": 0.5543584721,
"avg_line_length": 55.1891891892,
"ext": "agda",
"hexsha": "72020ee26d973f71fa125658fc6191aa994e5e28",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JasonGross/lob",
"max_forks_repo_path": "internal/modal-logic-lob-reduced.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JasonGross/lob",
"max_issues_repo_path": "internal/modal-logic-lob-reduced.agda",
"max_line_length": 130,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JasonGross/lob",
"max_stars_repo_path": "internal/modal-logic-lob-reduced.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z",
"num_tokens": 958,
"size": 2042
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Notation for freely adding an infimum to any set
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Construct.Add.Infimum where
open import Relation.Nullary.Construct.Add.Point
renaming (Pointed to _₋; ∙ to ⊥₋)
public
| {
"alphanum_fraction": 0.4685990338,
"avg_line_length": 29.5714285714,
"ext": "agda",
"hexsha": "de90924eda5afd78259944d2e9e24ca251158533",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Nullary/Construct/Add/Infimum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Nullary/Construct/Add/Infimum.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Nullary/Construct/Add/Infimum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 75,
"size": 414
} |
{- Copyright © 1992–2002 The University of Glasgow
Copyright © 2015 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an ‘AS IS’ BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. -}
module B.Prelude.Monad where
import Category.Monad
import Data.List
import Data.Maybe
open import Function using (const)
open Category.Monad
using (RawMonad)
public
open Category.Monad.RawMonad ⦃...⦄
using (_>>=_; _>>_; return)
public
instance
Monad-List : ∀ {ℓ} → RawMonad (Data.List.List {ℓ})
Monad-List = Data.List.monad
Monad-Maybe : ∀ {ℓ} → RawMonad (Data.Maybe.Maybe {ℓ})
Monad-Maybe = Data.Maybe.monad
Monad-Function : ∀ {ℓ} {r : Set ℓ} → RawMonad (λ s → (r → s))
Monad-Function {r} = record { return = const {r}
; _>>=_ = λ f k → λ r → k (f r) r }
| {
"alphanum_fraction": 0.6991869919,
"avg_line_length": 30.75,
"ext": "agda",
"hexsha": "657dd55c64559b521fb9b33284f43a64b40b38c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "bbarenblat/B",
"max_forks_repo_path": "Prelude/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "bbarenblat/B",
"max_issues_repo_path": "Prelude/Monad.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "bbarenblat/B",
"max_stars_repo_path": "Prelude/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-30T15:59:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-30T15:59:38.000Z",
"num_tokens": 337,
"size": 1230
} |
------------------------------------------------------------------------
-- Up-to techniques via
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Up-to.Via where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Prelude.Size
open import Bijection equality-with-J as Bijection using (_↔_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level.Closure equality-with-J using (ext⁻¹)
open import Indexed-container
open import Indexed-container.Combinators
hiding (id) renaming (_∘_ to _⊚_)
open import Relation
open import Up-to
-- The property of being an up-to technique via another (or the same)
-- relation transformer. This is an adaptation of Definition 6.3.25 in
-- Pous and Sangiorgi's "Enhancements of the bisimulation proof
-- method".
Up-to-technique-via :
∀ {ℓ} {I : Type ℓ} →
Container I I → Trans ℓ I → Trans ℓ I → Type (lsuc ℓ)
Up-to-technique-via C F G =
Extensive G
×
(∀ R → R ⊆ ⟦ C ⟧ (F R) → G R ⊆ ⟦ C ⟧ (G R))
-- If F is an up-to technique via G, then F is an up-to technique.
--
-- A corresponding result is mentioned by Pous and Sangiorgi right
-- after Definition 6.3.25.
up-to-via→up-to :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F G} →
Up-to-technique-via C F G → Up-to-technique C F
up-to-via→up-to {C = C} {F} {G} up-to {R} =
R ⊆ ⟦ C ⟧ (F R) ↝⟨ proj₂ up-to _ ⟩
G R ⊆ ⟦ C ⟧ (G R) ↝⟨ unfold C ⟩
G R ⊆ ν C ∞ ↝⟨ (λ hyp {_} x → hyp (proj₁ up-to R x)) ⟩□
R ⊆ ν C ∞ □
-- If F is an up-to technique, then F is an up-to technique via
-- _∪ ν C ∞.
up-to→up-to-via :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F} →
Up-to-technique C F → Up-to-technique-via C F (_∪ ν C ∞)
up-to→up-to-via {C = C} {F} up-to =
(λ R →
R ⊆⟨ inj₁ ⟩∎
R ∪ ν C ∞ ∎)
, λ R →
R ⊆ ⟦ C ⟧ (F R) ↝⟨ up-to ⟩
R ⊆ ν C ∞ ↝⟨ (λ hyp {_} →
R ∪ ν C ∞ ⊆⟨ [ hyp {_} , id ] ⟩
ν C ∞ ⊆⟨ ν-out _ ⟩
⟦ C ⟧ (ν C ∞) ⊆⟨ map C inj₂ ⟩∎
⟦ C ⟧ (R ∪ ν C ∞) ∎) ⟩
R ∪ ν C ∞ ⊆ ⟦ C ⟧ (R ∪ ν C ∞) □
-- A lemma that corresponds to Pous and Sangiorgi's Lemma 6.3.27: If G
-- satisfies certain properties, then Up-to-technique-via C F is
-- closed under G ∘_.
up-to-via-∘ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F G H} →
Extensive G →
(∀ R → R ⊆ ⟦ C ⟧ R → G R ⊆ ⟦ C ⟧ (G R)) →
Up-to-technique-via C F H →
Up-to-technique-via C F (G ∘ H)
up-to-via-∘ {C = C} {F} {G} {H} extensive pres up-to =
(λ R →
R ⊆⟨ proj₁ up-to _ ⟩
H R ⊆⟨ extensive _ ⟩∎
G (H R) ∎)
, λ R →
R ⊆ ⟦ C ⟧ (F R) ↝⟨ proj₂ up-to _ ⟩
H R ⊆ ⟦ C ⟧ (H R) ↝⟨ pres _ ⟩□
G (H R) ⊆ ⟦ C ⟧ (G (H R)) □
mutual
-- If the container F is an up-to technique via a symmetric relation
-- transformer, then ν ⟷[ C ⊚ F ] ∞ is contained in ν ⟷[ C ] ∞. This
-- result corresponds to Pous and Sangiorgi's Proposition 6.3.28.
up-to-via→ν-∘⊆ν :
∀ {ℓ} {I : Type ℓ} {C : Container (I × I) (I × I)} {F G} →
Symmetric swap G →
Up-to-technique-via C ⟦ F ⟧ G →
ν ⟷[ C ⊚ F ] ∞ ⊆ ν ⟷[ C ] ∞
up-to-via→ν-∘⊆ν symm up-to = up-to-via²→ν-∘⊆ν refl symm up-to up-to
-- A generalisation of the result above.
up-to-via²→ν-∘⊆ν :
∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container I I} {F₁ F₂ G} {f : I → I} →
f ∘ f ≡ id →
Symmetric f G →
Up-to-technique-via C₁ ⟦ F₁ ⟧ G →
Up-to-technique-via C₂ ⟦ F₂ ⟧ G →
ν (C₁ ⊚ F₁ ⊗ reindex f (C₂ ⊚ F₂)) ∞ ⊆ ν (C₁ ⊗ reindex f C₂) ∞
up-to-via²→ν-∘⊆ν {ℓ} {I} {C₁} {C₂} {F₁} {F₂} {G} {f}
inv symm up-to₁ up-to₂ =
$⟨ (λ {_} → ν-out _) ⟩
R ⊆ ⟦ C₁ ⊚ F₁ ⊗ reindex f (C₂ ⊚ F₂) ⟧ R ↝⟨ ⊆-congʳ _ $ ⟦⊗⟧↔ _ (C₁ ⊚ F₁) (reindex f (C₂ ⊚ F₂)) ⟩
R ⊆ ⟦ C₁ ⊚ F₁ ⟧ R ∩ ⟦ reindex f (C₂ ⊚ F₂) ⟧ R ↝⟨ from-isomorphism implicit-ΠΣ-comm F.∘
implicit-∀-cong _ (from-isomorphism ΠΣ-comm) ⟩
R ⊆ ⟦ C₁ ⊚ F₁ ⟧ R × R ⊆ ⟦ reindex f (C₂ ⊚ F₂) ⟧ R ↝⟨ Σ-map lemma₁ lemma₂ ⟩
G R ⊆ ⟦ C₁ ⟧ (G R) × G R ⊆ ⟦ reindex f C₂ ⟧ (G R) ↝⟨ _⇔_.from (from-isomorphism implicit-ΠΣ-comm F.∘
implicit-∀-cong _ (from-isomorphism ΠΣ-comm)) ⟩
G R ⊆ ⟦ C₁ ⟧ (G R) ∩ ⟦ reindex f C₂ ⟧ (G R) ↝⟨ _⇔_.from $ ⊆-congʳ _ $ ⟦⊗⟧↔ _ C₁ (reindex f C₂) ⟩
G R ⊆ ⟦ C₁ ⊗ reindex f C₂ ⟧ (G R) ↝⟨ unfold (C₁ ⊗ reindex f C₂) ⟩
G R ⊆ ν (C₁ ⊗ reindex f C₂) ∞ ↝⟨ (λ hyp {_} x → hyp (proj₁ up-to₁ R x)) ⟩□
R ⊆ ν (C₁ ⊗ reindex f C₂) ∞ □
where
R = ν (C₁ ⊚ F₁ ⊗ reindex f (C₂ ⊚ F₂)) ∞
I↔I : I ↔ I
I↔I = Bijection.bijection-from-involutive-family
(λ _ _ → f) (λ _ _ → ext⁻¹ inv) tt tt
∘⊆⇔⊆∘ : {S₁ S₂ : Rel ℓ I} → S₁ ∘ f ⊆ S₂ ⇔ S₁ ⊆ S₂ ∘ f
∘⊆⇔⊆∘ {S₁ = S₁} {S₂} =
(∀ {p} → S₁ (f p) → S₂ p) ↔⟨ Bijection.implicit-Π↔Π ⟩
(∀ p → S₁ (f p) → S₂ p) ↝⟨ Π-cong _ I↔I (λ _ → →-cong _ F.id (≡⇒↝ _ $ cong S₂ $ ext⁻¹ (sym inv) _)) ⟩
(∀ p → S₁ p → S₂ (f p)) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
(∀ {p} → S₁ p → S₂ (f p)) □
lemma₁ =
R ⊆ ⟦ C₁ ⊚ F₁ ⟧ R ↝⟨ ⊆-congʳ _ (⟦∘⟧↔ _ C₁) ⟩
R ⊆ ⟦ C₁ ⟧ (⟦ F₁ ⟧ R) ↝⟨ proj₂ up-to₁ _ ⟩□
G R ⊆ ⟦ C₁ ⟧ (G R) □
lemma₂ =
R ⊆ ⟦ reindex f (C₂ ⊚ F₂) ⟧ R ↝⟨ ⊆-congʳ _ $ ⟦reindex⟧↔ _ (C₂ ⊚ F₂) ⟩
R ⊆ ⟦ C₂ ⊚ F₂ ⟧ (R ∘ f) ∘ f ↝⟨ ⊆-congʳ _ (⟦∘⟧↔ _ C₂) ⟩
R ⊆ ⟦ C₂ ⟧ (⟦ F₂ ⟧ (R ∘ f)) ∘ f ↝⟨ _⇔_.from ∘⊆⇔⊆∘ ⟩
R ∘ f ⊆ ⟦ C₂ ⟧ (⟦ F₂ ⟧ (R ∘ f)) ↝⟨ proj₂ up-to₂ _ ⟩
G (R ∘ f) ⊆ ⟦ C₂ ⟧ (G (R ∘ f)) ↝⟨ involution→other-symmetry G inv symm _ ⊆-cong-→ ⟦⟧-cong _ C₂ (symm _) ⟩
G R ∘ f ⊆ ⟦ C₂ ⟧ (G R ∘ f) ↝⟨ _⇔_.to ∘⊆⇔⊆∘ ⟩
G R ⊆ ⟦ C₂ ⟧ (G R ∘ f) ∘ f ↝⟨ _⇔_.from $ ⊆-congʳ _ $ ⟦reindex⟧↔ _ C₂ ⟩
G R ⊆ ⟦ reindex f C₂ ⟧ (G R) □
-- If F is monotone and compatible, then F is an up-to technique via
-- F ^ω_. This result corresponds to Pous and Sangiorgi's
-- Theorem 6.3.26.
monotone→compatible→up-to-via :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F} →
Monotone F →
Compatible C F → Up-to-technique-via C F (F ^ω_)
monotone→compatible→up-to-via {C = C} {F} mono comp =
(λ R →
R ⊆⟨ 0 ,_ ⟩∎
F ^ω R ∎)
, λ R R⊆ →
F ^ω R ⊆⟨ compatible→^ω-post-fixpoint _ mono comp R⊆ ⟩∎
⟦ C ⟧ (F ^ω R) ∎
| {
"alphanum_fraction": 0.4549705838,
"avg_line_length": 38.7660818713,
"ext": "agda",
"hexsha": "c341b578c7a435a0ac6ccfe978d562336e4d7530",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Up-to/Via.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Up-to/Via.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Up-to/Via.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3061,
"size": 6629
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.Concrete.System.Parameters
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Consensus.ConsensusTypes.Properties.QuorumCert as QuorumCertProps
import LibraBFT.Impl.Consensus.ConsensusTypes.Properties.VoteData as VoteDataProps
import LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.ConsensusTypes.VoteData as VoteData
open import LibraBFT.Impl.Consensus.SafetyRules.SafetyRules
import LibraBFT.Impl.Handle as Handle
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Types.LedgerInfoWithSignatures as LedgerInfoWithSignatures
open import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
import LibraBFT.ImplShared.Util.Crypto as Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Hash
open import Util.KVMap as Map
open import Util.Lemmas
open import Util.PKCS
open import Util.Prelude
open ParamsWithInitAndHandlers Handle.InitHandler.initAndHandlers
open import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms
Handle.InitHandler.initAndHandlers
PeerCanSignForPK PeerCanSignForPK-stable
open Invariants
open RoundManagerTransProps
module LibraBFT.Impl.Consensus.SafetyRules.Properties.SafetyRules where
module verifyAndUpdatePreferredRoundDefs (quorumCert : QuorumCert) (safetyData : SafetyData) where
preferredRound = safetyData ^∙ sdPreferredRound
oneChainRound = quorumCert ^∙ qcCertifiedBlock ∙ biRound
twoChainRound = quorumCert ^∙ qcParentBlock ∙ biRound
C₁ = oneChainRound < preferredRound
C₂ = twoChainRound > preferredRound
C₃ = twoChainRound < preferredRound
C₄ = twoChainRound ≡ preferredRound
safetyData' = safetyData & sdPreferredRound ∙~ twoChainRound
module verifyAndUpdatePreferredRoundMSpec (quorumCert : QuorumCert) (safetyData : SafetyData) where
open verifyAndUpdatePreferredRoundDefs quorumCert safetyData
module _ (pre : RoundManager) where
record setPR (sd : SafetyData) : Set where
field
cond : C₂
eff : sd ≡ safetyData'
record noChanges (sd : SafetyData) : Set where
field
noUpd : sd ≡ safetyData
record ConditionCorrectR (sd : SafetyData) : Set where
field
ep≡ : sd ≡L safetyData at sdEpoch
qcr≤pr : quorumCert ^∙ qcParentBlock ∙ biRound ≤ sd ^∙ sdPreferredRound
conds : noChanges sd ⊎ setPR sd
open ConditionCorrectR public
ConditionCorrect : Either ErrLog SafetyData → Set
ConditionCorrect (Left _) = ⊤
ConditionCorrect (Right sd) = ConditionCorrectR sd
record Contract (r : Either ErrLog SafetyData) (post : RoundManager) (outs : List Output) : Set where
constructor mkContract
field
noOuts : OutputProps.NoMsgs outs
noEff : post ≡ pre
condCorr : ConditionCorrect r
contract
: ∀ pre
→ LBFT-weakestPre (verifyAndUpdatePreferredRoundM quorumCert safetyData)
(Contract pre) pre
proj₁ (contract pre) _ = mkContract refl refl tt
proj₂ (contract pre) x rewrite x
with <-cmp twoChainRound preferredRound
...| tri< lt _ _ = λ where ._ refl ._ refl → mkContract refl refl
(record { ep≡ = refl
; qcr≤pr = <⇒≤ lt
; conds = inj₁ (record { noUpd = refl }) })
...| tri≈ _ refl _ = λ where ._ refl → mkContract refl refl
(record { ep≡ = refl
; qcr≤pr = ≤-refl
; conds = inj₁ (record { noUpd = refl }) })
...| tri> _ _ gt = λ where ._ refl ._ refl → mkContract refl refl
(record { ep≡ = refl
; qcr≤pr = ≤-refl
; conds = inj₂ (record { cond = gt ; eff = refl }) })
module extensionCheckSpec (voteProposal : VoteProposal) where
proposedBlock = voteProposal ^∙ vpBlock
obmAEP = voteProposal ^∙ vpAccumulatorExtensionProof
voteData =
(VoteData.new
(Block.genBlockInfo
proposedBlock
-- OBM-LBFT-DIFF: completely different
(Crypto.obmHashVersion (obmAEP ^∙ aepObmNumLeaves))
(obmAEP ^∙ aepObmNumLeaves)
(voteProposal ^∙ vpNextEpochState))
(proposedBlock ^∙ bQuorumCert ∙ qcCertifiedBlock))
contract -- TODO-1: refine (waiting on: extensionCheckM)
: ∀ {ℓ} (Post : Either ErrLog VoteData → Set ℓ)
→ (∀ e → Post (Left e))
→ (Post (pure voteData))
→ Post (extensionCheck voteProposal)
contract Post pfBail pfOk = pfOk
module constructLedgerInfoMSpec (proposedBlock : Block) (consensusDataHash : HashValue) where
-- This is a place-holder contract that requires refinement once
-- `constructLedgerInfoM is implemented.
postulate -- TODO-1: refine and prove
contract
: ∀ P pre
→ P (inj₁ fakeErr) pre []
→ (∀ ledgerInfo → P (inj₂ ledgerInfo) pre [])
→ LBFT-weakestPre (constructLedgerInfoM proposedBlock consensusDataHash) P pre
-- TUTORIAL: Weakest preconditions generated from conditionals, translating a
-- boolean equality test to proofs of (in)equality.
module verifyEpochMSpec (epoch : Epoch) (safetyData : SafetyData) where
-- The body of `verifyEpochM` is:
-- > ifM not ⌊ epoch ≟ℕ safetyData ^∙ sdEpoch ⌋
-- > then bail fakeErr -- log: error: incorrect epoch
-- > else ok unit
contract
: ∀ P pre
→ (epoch ≢ safetyData ^∙ sdEpoch → P (inj₁ fakeErr) pre [])
→ (epoch ≡ safetyData ^∙ sdEpoch → P (inj₂ unit) pre [])
→ LBFT-weakestPre (verifyEpochM epoch safetyData) P pre
-- The outermost node of the AST of `verifyEpochM` is `ifM_then_else_ ...`, so
-- our goal is to return a product: one proof corresponding to the "then" case
-- one and one proof corresponding to the "else" case.
--
-- 1. In the "then" case, we recieve a proof `e≢` that
-- > toBool (not ⌊ epoch ≟ℕ safetyData ^∙ sdEpoch ⌋) ≡ true
proj₁ (contract Post pre pfBail pfOk) e≢
-- - abstract over the expression that prevents us from analyzing this evidence
with epoch ≟ℕ safetyData ^∙ sdEpoch
-- - Agda can tell that `yes pf` is not an option, since e≢ would have type
-- `false ≡ true` in that case
...| no pf = pfBail pf
-- 2. In the "else" case, we receive a proof `e≡` that
-- > toBool (not ⌊ epoch ≟ℕ safetyData ^∙ sdEpoch ⌋) ≡ false
proj₂ (contract Post pre pfBail pfOk) e≡
-- - perform the same `with` abstraction as the previous case
with epoch ≟ℕ safetyData ^∙ sdEpoch
-- - Agda can tell that `no pf` is not an option
...| yes pf = pfOk pf
-- TUTORIAL: Translating boolean comparison tests to proofs.
module verifyAndUpdateLastVoteRoundMSpec (round : Round) (safetyData : SafetyData) where
safetyData' = safetyData & sdLastVotedRound ∙~ round
-- This example shows that we could have further simplified the proof of the
-- contract for `verifyEpochM`. In `Util.Prelude`, we define lemmas
-- > toWitnessT : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ true → P
-- > toWitnessF : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ false → ¬ P
-- which extract the underlying proof used to construct `d` given evidence
-- that "lowering" `d` to a boolean produces `true` or `false`.
contract
: ∀ P pre
→ ((r>lvr : round > safetyData ^∙ sdLastVotedRound) → P (Right safetyData') pre [])
→ ((r≤lvr : ¬ (round > safetyData ^∙ sdLastVotedRound)) → P (Left fakeErr) pre [])
→ LBFT-weakestPre (verifyAndUpdateLastVoteRoundM round safetyData) P pre
proj₁ (contract Post pre pfOk pfBail) r>lvr = pfOk (toWitnessT r>lvr)
proj₂ (contract Post pre pfOk pfBail) ¬r>lvr = pfBail (toWitnessF ¬r>lvr)
module verifyQcMSpec (self : QuorumCert) where
getVv : RoundManager → ValidatorVerifier
getVv = _^∙ (rmEpochState ∙ esVerifier)
-- See comment on contract below to understand the motivation for stating and proving the property
-- this way.
Contract : RoundManager → RWS-Post Output RoundManager (Either ErrLog Unit)
Contract pre (Left _) post outs = post ≡ pre × outs ≡ []
Contract pre (Right _) post outs = post ≡ pre × outs ≡ []
× QuorumCertProps.Contract self (getVv pre)
contract' : ∀ pre → RWS-weakestPre (verifyQcM self) (Contract pre) unit pre
contract' _ _ _ (Left x₂) _ = refl , refl
contract' pre vv refl (Right unit) x₁ = refl , refl , QuorumCertProps.contract self vv (Right unit) refl (sym x₁)
-- Suppose verifyQcM runs from prestate pre, and we wish to ensure that postcondition Post holds
-- afterwards. If P holds provided verifyQcM does not modify the state and does not produce any
-- Outputs, and, if verifyQcM succeeds (returns Right unit), P holds provided
-- QuorumCertProps.Contract holds for the given QuorumCert and the ValidatorVerifier of the
-- prestate, then verifyQcM ensures P holds. Proving this directly is painful because it's
-- difficult to construct a QuorumCertProps.Contract self (getVv pre) that Agda understands allows
-- us to invoke the rPrf (condition on P in case verifyQcM succeeds). Therefore, we restate the
-- conditions on P (as P', above) and prove that P' implies P, and then use LBFT-⇒ to achieve
-- the desired result.
contract
: ∀ P pre
→ (∀ {e} → P (Left e) pre []) -- verifyQcM does not emit any outputs, it just propagates a Left ErrLog, hence []
→ (QuorumCertProps.Contract self (getVv pre) → P (Right unit) pre [])
→ RWS-weakestPre (verifyQcM self) P unit pre
contract Post pre lPrf rPrf = LBFT-⇒ (verifyQcM self) pre
(contract' pre)
(λ { (Left x₁) st outs (refl , refl) → lPrf
; (Right unit) st outs (refl , refl , prf) → rPrf prf })
module constructAndSignVoteMSpec where
VoteResultCorrect : (pre post : RoundManager) (block : Block) (lvr≡? : Bool) (r : Either ErrLog Vote) → Set
VoteResultCorrect pre post block lvr≡? (Left e) = VoteNotGenerated pre post lvr≡?
VoteResultCorrect pre post block lvr≡? (Right vote) = Voting.VoteGeneratedCorrect pre post vote block
record Contract (pre : RoundManager) (block : Block) (r : Either ErrLog Vote) (post : RoundManager) (outs : List Output) : Set where
constructor mkContract
field
-- General properties / invariants
rmInv : Preserves RoundManagerInv pre post
noEpochChange : NoEpochChange pre post
noMsgOuts : OutputProps.NoMsgs outs
-- Voting
lvr≡? : Bool
voteResCorrect : VoteResultCorrect pre post block lvr≡? r
private
contractBail : ∀ {pre block e} outs → OutputProps.NoMsgs outs → Contract pre block (Left e) pre outs
contractBail{pre} outs noMsgs =
mkContract
reflPreservesRoundManagerInv
(reflNoEpochChange{pre})
noMsgs
true reflVoteNotGenerated
module continue2
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData : SafetyData) where
open constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock safetyData
record Requirements (pre : RoundManager) : Set where
constructor mkRequirements
field
es≡₁ : (pre ^∙ pssSafetyData-rm) ≡L safetyData at sdEpoch
es≡₂ : voteProposal ^∙ vpBlock ∙ bEpoch ≡ safetyData ^∙ sdEpoch
lv≡ : (pre ^∙ pssSafetyData-rm) ≡L safetyData at sdLastVote
lvr≡ : (pre ^∙ pssSafetyData-rm) ≡L safetyData at sdLastVotedRound
vp≡pb : proposedBlock ≡ voteProposal ^∙ vpBlock
contract'
: ∀ pre
→ Requirements pre
→ LBFT-weakestPre
(constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock safetyData)
(Contract pre proposedBlock) pre
contract' pre reqs =
verifyAndUpdateLastVoteRoundMSpec.contract (proposedBlock ^∙ bRound) safetyData
(RWS-weakestPre-ebindPost unit step₁ (Contract pre proposedBlock)) pre
contract-step₁
(λ r≤lvr → contractBail _ refl)
where
module _ (r>lvr : proposedBlock ^∙ bRound > safetyData ^∙ sdLastVotedRound) where
-- Shared definitions
module _ where
safetyData1 = verifyAndUpdateLastVoteRoundMSpec.safetyData' (proposedBlock ^∙ bRound) safetyData
preUpdatedSD = pre & pssSafetyData-rm ∙~ safetyData1
author = validatorSigner ^∙ vsAuthor
-- State invariants
module _ where
bsip₁ : Preserves BlockStoreInv (rm→BlockStore-EC pre) (rm→BlockStore-EC preUpdatedSD)
bsip₁ = id
emP : Preserves EpochsMatch pre preUpdatedSD
emP eq = trans eq (Requirements.es≡₁ reqs)
srPre = pre ^∙ lSafetyRules
srPost = preUpdatedSD ^∙ lSafetyRules
srP : Preserves SafetyRulesInv srPre srPost
srP = mkPreservesSafetyRulesInv λ where (mkSafetyDataInv epoch≡ round≤) →
mkSafetyDataInv (epoch≡P epoch≡) (round≤P round≤)
where
epoch≡P : Preserves (λ sd → Meta.getLastVoteEpoch sd ≡ sd ^∙ sdEpoch)
(srPre ^∙ (srPersistentStorage ∙ pssSafetyData))
(srPost ^∙ (srPersistentStorage ∙ pssSafetyData))
epoch≡P epoch≡
rewrite sym (Requirements.lv≡ reqs)
| sym (Requirements.es≡₁ reqs)
= epoch≡
round≤P : Preserves (λ sd → Meta.getLastVoteRound sd ≤ sd ^∙ sdLastVotedRound)
(srPre ^∙ (srPersistentStorage ∙ pssSafetyData))
(srPost ^∙ (srPersistentStorage ∙ pssSafetyData))
round≤P round≤
with pre ^∙ pssSafetyData-rm ∙ sdLastVote
| inspect (_^∙ pssSafetyData-rm ∙ sdLastVote) pre
...| nothing | [ lv≡ ] rewrite (trans (sym (Requirements.lv≡ reqs)) lv≡) = z≤n
...| just x | [ lv≡ ] rewrite (trans (sym (Requirements.lv≡ reqs)) lv≡) =
≤-trans round≤ (≤-trans (≡⇒≤ (Requirements.lvr≡ reqs)) (<⇒≤ r>lvr))
invP₁ : Preserves RoundManagerInv pre preUpdatedSD
invP₁ = mkPreservesRoundManagerInv id emP bsip₁ srP
-- Some lemmas
module _ where
lvr<pbr : pre ^∙ pssSafetyData-rm ∙ sdLastVotedRound < proposedBlock ^∙ bRound
lvr<pbr rewrite (Requirements.lvr≡ reqs) = r>lvr
vpr≡pbr : (voteProposal ^∙ vpBlock) ≡L proposedBlock at bRound
vpr≡pbr rewrite Requirements.vp≡pb reqs = refl
bailAfterSetSafetyData : ∀ e → Contract pre proposedBlock (Left e) preUpdatedSD []
bailAfterSetSafetyData e =
mkContract invP₁ refl refl false (mkVoteNotGenerated (Requirements.lv≡ reqs) lvr<pbr)
contract-step₁ : RWS-weakestPre-ebindPost unit step₁ (Contract pre proposedBlock) (Right _) pre []
contract-step₂ : RWS-weakestPre-ebindPost unit (step₂ safetyData1) (Contract pre proposedBlock) (Right _) preUpdatedSD []
contract-step₁ ._ refl ._ refl .unit refl =
extensionCheckSpec.contract voteProposal
(λ r → RWS-weakestPre-ebindPost unit (step₂ safetyData1) (Contract pre proposedBlock) r preUpdatedSD [])
bailAfterSetSafetyData contract-step₂
contract-step₂ voteData@._ refl =
constructLedgerInfoMSpec.contract proposedBlock (hashVD voteData)
(RWS-weakestPre-∙^∙Post unit (withErrCtx ("" ∷ []))
(RWS-weakestPre-ebindPost unit (step₃ safetyData1 voteData author) (Contract pre proposedBlock))) preUpdatedSD
(λ where .(Left fakeErr) refl → bailAfterSetSafetyData fakeErr)
contract-step₃
where
contract-step₃
: ∀ ledgerInfo
→ RWS-weakestPre-∙^∙Post unit (withErrCtx ("" ∷ []))
(RWS-weakestPre-ebindPost unit (step₃ safetyData1 _ author) (Contract pre proposedBlock))
(Right ledgerInfo) preUpdatedSD []
contract-step₃ ledgerInfo ._ refl ._ refl ._ refl .unit refl unit refl =
mkContract invP₂ refl refl false
(Voting.mkVoteGeneratedCorrect
(mkVoteGenerated refl
(inj₂ (mkVoteNewGenerated lvr<pbr vpr≡pbr)))
voteFromBlock)
where
vote = Vote.newWithSignature voteData author ledgerInfo (ValidatorSigner.sign validatorSigner ledgerInfo)
preUpdatedSD₂ = preUpdatedSD & pssSafetyData-rm ∙~ (safetyData1 & sdLastVote ?~ vote)
pb≡vpb = sym (Requirements.vp≡pb reqs)
voteFromBlock : Voting.VoteMadeFromBlock vote proposedBlock
voteFromBlock =
Voting.mkVoteMadeFromBlock
(cong (_^∙ bEpoch) pb≡vpb) (cong (_^∙ bRound) pb≡vpb) (cong (_^∙ bId) pb≡vpb)
-- State invariants
module _ where
bsiP₂ : Preserves BlockStoreInv (rm→BlockStore-EC pre) (rm→BlockStore-EC preUpdatedSD₂)
bsiP₂ = id
srP₂ : Preserves SafetyRulesInv (pre ^∙ lSafetyRules) (preUpdatedSD₂ ^∙ lSafetyRules)
srP₂ = mkPreservesSafetyRulesInv
(const $ mkSafetyDataInv (Requirements.es≡₂ reqs) (≡⇒≤ (cong (_^∙ bRound) pb≡vpb)))
invP₂ : Preserves RoundManagerInv pre preUpdatedSD₂
invP₂ = mkPreservesRoundManagerInv id emP bsiP₂ srP₂
contract
: ∀ pre Post
→ Requirements pre
→ RWS-Post-⇒ (Contract pre proposedBlock) Post
→ LBFT-weakestPre
(constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock safetyData)
Post pre
contract pre Post reqs pf =
LBFT-⇒ (constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock safetyData)
pre (contract' pre reqs) pf
module continue1
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData0 : SafetyData) where
open constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0
record Requirements (pre : RoundManager) : Set where
constructor mkRequirements
field
sd≡ : pre ^∙ pssSafetyData-rm ≡ safetyData0
es≡ : voteProposal ^∙ vpBlock ∙ bEpoch ≡ safetyData0 ^∙ sdEpoch
vp≡pb : proposedBlock ≡ voteProposal ^∙ vpBlock
contract
: ∀ pre → Requirements pre
→ LBFT-weakestPre (constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0)
(Contract pre proposedBlock) pre
contract pre reqs =
verifyQcMSpec.contract (proposedBlock ^∙ bQuorumCert)
(RWS-weakestPre-ebindPost unit (λ _ → step₁) (Contract pre proposedBlock)) pre
(contractBail _ refl)
contract-step₁
where
contract-step₁ : QuorumCertProps.Contract _ _ → RWS-weakestPre-ebindPost unit (const step₁) (Contract pre proposedBlock) (Right unit) pre []
contract-step₁ qcCon ._ refl validatorVerifier@._ refl
with Block.validateSignature proposedBlock validatorVerifier
... | Left e = contractBail _ refl
... | Right unit = λ where ._ refl → contract-step₃
where
contract-step₃ : RWS-weakestPre step₃ (Contract pre proposedBlock) unit pre
contract-step₃ =
LBFT-⇒ (verifyAndUpdatePreferredRoundM (proposedBlock ^∙ bQuorumCert) safetyData0) pre
(verifyAndUpdatePreferredRoundMSpec.contract (proposedBlock ^∙ bQuorumCert) safetyData0 pre) pf-step₃
-- verifyAndUpdatePreferredRoundMSpec.contract (proposedBlock ^∙ bQuorumCert) safetyData0
-- Pred pre (λ r≤pr → contractBail _ refl) cases
where
VAUPContract = verifyAndUpdatePreferredRoundMSpec.Contract (proposedBlock ^∙ bQuorumCert) safetyData0
Pred = RWS-weakestPre-ebindPost unit
(constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock)
(Contract pre proposedBlock)
reqs₁ : continue2.Requirements voteProposal validatorSigner proposedBlock safetyData0 pre
reqs₁
with Requirements.sd≡ reqs
...| refl = continue2.mkRequirements refl (Requirements.es≡ reqs) refl refl (Requirements.vp≡pb reqs)
reqs₂ : continue2.Requirements voteProposal validatorSigner proposedBlock
(verifyAndUpdatePreferredRoundDefs.safetyData' (proposedBlock ^∙ bQuorumCert) safetyData0)
pre
reqs₂
with Requirements.sd≡ reqs
...| refl = continue2.mkRequirements refl (Requirements.es≡ reqs) refl refl (Requirements.vp≡pb reqs)
pf-step₃ : ∀ r st outs → VAUPContract pre r st outs → Pred r st outs
pf-step₃ r st outs (verifyAndUpdatePreferredRoundMSpec.mkContract noOuts refl condCorr) = pf r condCorr
where
pf-Con++outs : RWS-Post-⇒ (Contract pre proposedBlock) (RWS-Post++ (Contract pre proposedBlock) outs)
pf-Con++outs r' st' outs' (mkContract rmInv noEpochChange noMsgOuts lvr≡? voteResCorrect) =
mkContract rmInv noEpochChange (OutputProps.++-NoMsgs outs outs' noOuts noMsgOuts) lvr≡? voteResCorrect
pf : (r : Either ErrLog SafetyData) (cc : verifyAndUpdatePreferredRoundMSpec.ConditionCorrect _ _ pre r) → Pred r st outs
pf (Left e) tt = contractBail outs noOuts
pf (Right .safetyData0) record { ep≡ = ep≡ ; qcr≤pr = qcr≤pr ; conds = (Left record { noUpd = refl }) } ._ refl =
continue2.contract voteProposal validatorSigner proposedBlock safetyData0 pre
(RWS-Post++ (Contract pre proposedBlock) outs) reqs₁
pf-Con++outs
pf (Right safetyData1@._) record { ep≡ = ep≡ ; qcr≤pr = qcr≤pr ; conds = (Right record { eff = refl }) } ._ refl =
continue2.contract voteProposal validatorSigner proposedBlock safetyData1 pre
(RWS-Post++ (Contract pre proposedBlock) outs)
reqs₂ pf-Con++outs
module continue0
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner) where
open constructAndSignVoteM-continue0 voteProposal validatorSigner
contract
: ∀ pre
→ LBFT-weakestPre
(constructAndSignVoteM-continue0 voteProposal validatorSigner) (Contract pre proposedBlock) pre
contract pre safetyData0@._ refl =
-- NOTE: There is a redundant check for this (that the proposal epoch
-- matches the safety data epoch) in `LibraBFT.Impl.Consensus.Network`
verifyEpochMSpec.contract (proposedBlock ^∙ bEpoch) safetyData0
(RWS-weakestPre-ebindPost unit (const (step₁ safetyData0)) (Contract pre proposedBlock)) pre
(λ e≢sde → contractBail _ refl)
contract-step₁
where
module _ (e≡sde : proposedBlock ^∙ bEpoch ≡ pre ^∙ pssSafetyData-rm ∙ sdEpoch) where
contract-step₁
: RWS-weakestPre-ebindPost unit (const (step₁ safetyData0)) (Contract pre proposedBlock) (Right unit) pre []
proj₁ (contract-step₁ .unit refl) ≡nothing =
continue1.contract voteProposal validatorSigner proposedBlock safetyData0 pre
(continue1.mkRequirements refl e≡sde refl)
proj₁ (proj₂ (contract-step₁ .unit refl) vote vote≡) lvr≡pbr =
mkContract reflPreservesRoundManagerInv (reflNoEpochChange{pre}) refl
true (Voting.mkVoteGeneratedCorrect
(mkVoteGenerated (sym vote≡)
(inj₁ reflVoteOldGenerated))
(toWitnessT lvr≡pbr))
proj₂ (proj₂ (contract-step₁ .unit refl) vote vote≡) lvr≢pbr =
continue1.contract voteProposal validatorSigner proposedBlock safetyData0 pre
(continue1.mkRequirements refl e≡sde refl)
module _ (maybeSignedVoteProposal : MaybeSignedVoteProposal) where
voteProposal = maybeSignedVoteProposal ^∙ msvpVoteProposal
proposedBlock = voteProposal ^∙ vpBlock
contract'
: ∀ pre
→ LBFT-weakestPre (constructAndSignVoteM maybeSignedVoteProposal) (Contract pre proposedBlock) pre
contract' pre nothing vs≡ =
mkContract
reflPreservesRoundManagerInv (reflNoEpochChange{pre})
refl true reflVoteNotGenerated
contract' pre (just validatorSigner) vs≡ = continue0.contract voteProposal validatorSigner pre
contract
: ∀ pre Post → RWS-Post-⇒ (Contract pre proposedBlock) Post
→ LBFT-weakestPre (constructAndSignVoteM maybeSignedVoteProposal) Post pre
contract pre Post pf =
RWS-⇒ (constructAndSignVoteM maybeSignedVoteProposal) unit pre (contract' pre) pf
private
module Tutorial
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData : SafetyData) where
-- After some experience with these proofs, it (allegedly)
-- becomes fairly straightforward to let Agda do a lot of the
-- work, and unfold the proof as we go. However, it is
-- important to understand what's going on under the hood to be
-- able to reliably do this. For the proof below, we do it in
-- excruciating detail "by hand" in comments as an example to
-- help ourselves understand.
-- For this example, we will prove that `step₃` of (and old version of)
-- `constructAndSignVoteM-continue2` produces no output.
Contract : LBFT-Post (Either ErrLog Vote)
Contract x post outs = outs ≡ []
step₃ : SafetyData → VoteData → Author → LedgerInfo → LBFT (Either ErrLog Vote)
step₃ safetyData1 voteData author ledgerInfo = do
let signature = ValidatorSigner.sign validatorSigner ledgerInfo
vote = Vote.newWithSignature voteData author ledgerInfo signature
pssSafetyData-rm ∙= (safetyData1 & sdLastVote ?~ vote)
ok vote
step₃-contract
: ∀ pre safetyData1 voteData author ledgerInfo
→ LBFT-weakestPre
(step₃ safetyData1 voteData author ledgerInfo)
Contract pre
step₃-contract pre safetyData1 voteData author ledgerInfo
{-
The proof can be as simple as this:
= λ _ _ _ _ → refl
Easy, right?! Oh, you want a little more detail? Sure here you go:
= λ where .pre refl →
λ where .unit refl →
refl -- Indenting important for parsing
Still not crystal clear? OK, let's explore in a little more detail.
The initial goal looks like this:
RWS-weakestPre-bindPost unit
(λ st →
RWS-put
(LibraBFT.ImplShared.Consensus.Types.s st
((λ { F rf f (SafetyRules∙new v vv vvv)
→ (rf Category.Functor.RawFunctor.<$>
(λ y' → SafetyRules∙new y' vv vvv))
(f v)
})
(λ x → x) Optics.Functorial.if
((λ { F rf f (PersistentSafetyStorage∙new v vv)
→ (rf Category.Functor.RawFunctor.<$>
(λ y' → PersistentSafetyStorage∙new y' vv))
(f v)
})
(λ x → x) Optics.Functorial.if
(λ _ →
safetyData1 &
sdLastVote ?~
Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo)))
(LibraBFT.ImplShared.Consensus.Types.g st))))
(RWS-weakestPre-bindPost unit
(λ _ →
RWS-return
(inj₂
(Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo))))
Contract)
pre pre []
It looks a bit ugly, but if we use C-u C-c C-, we get a more
readable version that is exactly what we expect:
LBFT-weakestPre (step₃ safetyData1 voteData author ledgerInfo)
Contract
pre
Let's start refining by hand to understand.
By desugaring the definition of "step₃ safetyData voteData author
ledgerInfo" a bit, we can see that it is (using some shorthand in
"quotes" to keep it concise at the expense of accuracy):
(RWS-bind
(RWS-bind
(RWS-gets id) -- Fetch the state.
(λ st → RWS-put (st & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")))-- Modify the state returned by RWS-get.
(λ _ → RWS-return (inj₂ "vote")) -- The Unit returned by RWS-bind
-- via RWS-put is ignored
Note that "vote" is: Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo)
Rewriting our goal with this yields (the annotations on the right
show how we instantiate the rules in the next step):
RWS-weakestPre
(RWS-bind
(RWS-bind = m
(RWS-gets id)
(λ st → RWS-put (st & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")))
(λ _ → RWS-return (inj₂ "vote")) = f
Contract = P
unit = ev
pre = st
Applying the definition of RWS-weakestPre (RWS-bind...), we need:
RWS-weakestPre
(RWS-bind
(RWS-gets id) = m
(λ st → RWS-put (st & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))) = f
(RWS-weakestPre-bindPost unit = P
(λ _ → RWS-return (inj₂ vote))
Contract)
unit = ev
pre = pre
Applying the definition of RWS-weakestPre (RWS-bind...) again, we have:
RWS-weakestPre
(RWS-gets id)
(RWS-weakestPre-bindPost unit = P
(λ st → RWS-put (st & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")))
(RWS-weakestPre-bindPost unit
(λ _ → RWS-return (inj₂ vote))
Contract))
unit = ev
pre = pre
Now applying the definition of RWS-weakestPre RWS-gets, we want:
(RWS-weakestPre-bindPost
unit = ev
(λ st → RWS-put (st & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))) = f
(RWS-weakestPre-bindPost unit = Post
(λ _ → RWS-return (inj₂ "vote"))
Contract))
pre = x
pre = post
[] = outs
Take a moment to compare this with our initial goal above. They
look identical, except for the shorthand.
Next, we apply the definition of RWS-weakestPre-bindPost:
∀ r → r ≡ pre →
RWS-weakestPre
(RWS-put (r & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")))
(RWS-Post++
(RWS-weakestPre-bindPost unit = P
(λ _ → RWS-return (inj₂ "vote"))
Contract)
[]) = outs
unit
pre
Notice that our "f" (the put operation) is applied to the quantified variable
"r". This is to reduce the size of the refined goal after substitution
(instead of "pre", in general "r" could be equal to a much more complex expression).
Applying the definition of RWS-Post++, we have:
∀ r → r ≡ pre →
RWS-weakestPre
(RWS-put (r & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")))
(λ x post outs₁ → (RWS-weakestPre-bindPost unit
(λ _ → RWS-return (inj₂ "vote"))
Contract) x post ([] ++ outs₁))
unit
pre
Our proof begins by peeling of the two first parameters, the first
of which must be pre, due to the second:
-}
= λ where .pre refl →
{-
At this point, our goal looks like (using C-u C-c C-,):
RWS-weakestPre
(RWS-put
(over pssSafetyData-rm
(λ _ →
safetyData1 &
sdLastVote ?~
Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo))
pre))
(λ x post outs₁ →
RWS-weakestPre-bindPost unit
(λ _ →
RWS-return
(inj₂
(Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo))))
Contract x post ([] ++ outs₁))
unit pre
We can see that this is a more precise version of what we have above (without the shorthand),
repeated here:
RWS-weakestPre
(RWS-put (pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))) = post
(λ x post outs₁ → (RWS-weakestPre-bindPost unit = P
(λ _ → RWS-return (inj₂ "vote"))
Contract) x post ([] ++ outs₁))
unit
pre
Next, we apply the definition of RWS-weakestPre (RWS-put ...)
(λ x post outs₁ → (RWS-weakestPre-bindPost unit
(λ _ → RWS-return (inj₂ "vote"))
Contract) x post ([] ++ outs₁))
unit
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))
[]
Instantiating,
RWS-weakestPre-bindPost
unit = ev
(λ _ → RWS-return (inj₂ "vote")) = f
Contract = Post
unit = x
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")) = post
([] ++ [])) = outs
Applying the definition of RWS-weakestPre-bindPost once again, we have:
∀ r → r ≡ unit → RWS-weakestPre
(RWS-return (inj₂ "vote"))
(RWS-Post++
Contract = P
([] ++ []))) = outs
unit
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))
And applying the definition of RWS-Post++ yields:
∀ r → r ≡ unit → RWS-weakestPre
(RWS-return (inj₂ "vote"))
(λ x post outs₁ → Contract rm x post ([] ++ [] ++ outs₁))
unit
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))
Peeling off another couple of parameters (the first must be unit because of the second):
-}
λ where .unit refl →
{-
The goal now looks like (using C-c C-,):
Contract
(inj₂
(Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo)))
(LibraBFT.ImplShared.Consensus.Types.s pre
((λ { F rf f (SafetyRules∙new v vv vvv)
→ (rf Category.Functor.RawFunctor.<$>
(λ y' → SafetyRules∙new y' vv vvv))
(f v)
})
(λ x → x) Optics.Functorial.if
((λ { F rf f (PersistentSafetyStorage∙new v vv)
→ (rf Category.Functor.RawFunctor.<$>
(λ y' → PersistentSafetyStorage∙new y' vv))
(f v)
})
(λ x → x) Optics.Functorial.if
(λ _ →
safetyData1 &
sdLastVote ?~
Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo)))
(LibraBFT.ImplShared.Consensus.Types.g pre)))
[]
Applying our shorthand, this yields:
Contract
(inj₂ "vote")
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))
[]
Or (using C-u C-c C-,), we have the following goal:
RWS-weakestPre
(RWS-return
(inj₂
(Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo))))
(λ x post outs₁ → Contract x post (([] ++ []) ++ outs₁)) unit
(over pssSafetyData-rm
(λ _ →
safetyData1 &
sdLastVote ?~
Vote.newWithSignature voteData author ledgerInfo
(ValidatorSigner.sign validatorSigner ledgerInfo))
pre)
Applying our shorthand, this yields:
RWS-weakestPre
(RWS-return (inj₂ "vote")) = x
(λ x post outs₁ → Contract x post ([] ++ [] ++ outs₁)) = P
unit = ev
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote")) = pre
Again, this looks like what we expect from above, so we can press
on. Now, applying the definition of RWS-weakestPre (RWS-return ...):
(λ x post outs₁ → Contract x post ([] ++ [] ++ outs₁))
(RWS-return (inj₂ "vote"))
(pre & pssSafetyData-rm ∙~ ("safetyData1" & sdLastVote ?~ "vote"))
[]
Finally, this reduces to the goal of:
[] ≡ []
which we prove with
-}
refl
| {
"alphanum_fraction": 0.5909620843,
"avg_line_length": 46.2014051522,
"ext": "agda",
"hexsha": "cf6dcc41020be720e217aefd3947a75c43d3a412",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/Properties/SafetyRules.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/Properties/SafetyRules.agda",
"max_line_length": 146,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/Properties/SafetyRules.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10295,
"size": 39456
} |
------------------------------------------------------------------------------
-- Propositional equality without using pattern matching on refl
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module
FOT.Common.FOL.Relation.Binary.PropositionalEquality.NoPatternMatchingOnRefl
where
open import Common.FOL.FOL using ( D )
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Relation/Binary/Core.agda).
infix 7 _≡_
------------------------------------------------------------------------------
-- The identity type on the universe of discourse.
data _≡_ (x : D) : D → Set where
refl : x ≡ x
-- Elimination rule.
subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y
subst A refl Ax = Ax
-- Identity properties
sym : ∀ {x y} → x ≡ y → y ≡ x
sym {x} h = subst (λ y' → y' ≡ x) h refl
trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z
trans {x} h₁ h₂ = subst (_≡_ x) h₂ h₁
trans₂ : ∀ {w x y z} → w ≡ x → x ≡ y → y ≡ z → w ≡ z
trans₂ h₁ h₂ h₃ = trans (trans h₁ h₂) h₃
subst₂ : (A : D → D → Set) → ∀ {x₁ x₂ y₁ y₂} →
x₁ ≡ y₁ → x₂ ≡ y₂ →
A x₁ x₂ →
A y₁ y₂
subst₂ A {x₁} {x₂} {y₁} {y₂} h₁ h₂ h₃ =
subst (λ y₁' → A y₁' y₂) h₁ (subst (A x₁) h₂ h₃)
cong : (f : D → D) → ∀ {x y} → x ≡ y → f x ≡ f y
cong f {x} h = subst (λ x' → f x ≡ f x') h refl
cong₂ : (f : D → D → D) → ∀ {x₁ x₂ y₁ y₂} → x₁ ≡ y₁ → x₂ ≡ y₂ →
f x₁ x₂ ≡ f y₁ y₂
cong₂ f {x₁} {x₂} {y₁} {y₂} h₁ h₂ =
subst (λ x₁' → f x₁ x₂ ≡ f x₁' y₂)
h₁
(subst (λ x₂' → f x₁ x₂ ≡ f x₁ x₂') h₂ refl)
| {
"alphanum_fraction": 0.4537521815,
"avg_line_length": 30.6964285714,
"ext": "agda",
"hexsha": "953ee33e98942cd93acf242cd2694cdc02d24e00",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/NoPatternMatchingOnRefl.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/NoPatternMatchingOnRefl.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/Common/FOL/Relation/Binary/PropositionalEquality/NoPatternMatchingOnRefl.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 638,
"size": 1719
} |
-- Andreas, 2015-11-17, issue reported by Martin Stone Davis
module _ where
module Sub (let open import oops) where
-- WAS: internal error
-- EXPECTED: Not a valid let-declaration
-- when scope checking the declaration
-- module Sub (let open import oops) where
| {
"alphanum_fraction": 0.7279411765,
"avg_line_length": 22.6666666667,
"ext": "agda",
"hexsha": "dfeb2eeaea3f135cb012a9d8b685283306437906",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1718.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1718.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1718.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 71,
"size": 272
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Equality over lists parameterised by some setoid
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Setoid)
module Data.List.Relation.Binary.Equality.Setoid {a ℓ} (S : Setoid a ℓ) where
open import Data.List.Base using (List)
open import Level
open import Relation.Binary renaming (Rel to Rel₂)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Data.List.Relation.Binary.Pointwise as PW using (Pointwise)
open Setoid S renaming (Carrier to A)
------------------------------------------------------------------------
-- Definition of equality
infix 4 _≋_
_≋_ : Rel₂ (List A) (a ⊔ ℓ)
_≋_ = Pointwise _≈_
open Pointwise public using ([]; _∷_)
------------------------------------------------------------------------
-- Relational properties
≋-refl : Reflexive _≋_
≋-refl = PW.refl refl
≋-reflexive : _≡_ ⇒ _≋_
≋-reflexive P.refl = ≋-refl
≋-sym : Symmetric _≋_
≋-sym = PW.symmetric sym
≋-trans : Transitive _≋_
≋-trans = PW.transitive trans
≋-isEquivalence : IsEquivalence _≋_
≋-isEquivalence = PW.isEquivalence isEquivalence
≋-setoid : Setoid _ _
≋-setoid = PW.setoid S
------------------------------------------------------------------------
-- Operations
open PW public using
( tabulate⁺
; tabulate⁻
; ++⁺
; concat⁺
)
| {
"alphanum_fraction": 0.5312075984,
"avg_line_length": 24.1639344262,
"ext": "agda",
"hexsha": "3893da3f99ab7696d4d8eb1ee61e2a6adf596f8e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Equality/Setoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Equality/Setoid.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Equality/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 378,
"size": 1474
} |
module plfa.part1.Midterm where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
-- you can add any import definitions that you need
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; _>_; z≤n; s≤s; _≤?_; _<?_; _^_)
open import Data.Nat.Properties using (+-assoc; +-suc; +-comm; *-comm)
open import Relation.Nullary using (yes; no; Dec)
-- used for rewrite
simplify : ∀ {A : Set} (x : A) → x ≡ x
simplify x = refl
sum : ℕ → ℕ
sum 0 = 0
sum n@(suc sn) = sum sn + n
-- Problem 1
-- remove the "postulate" and prove this theorem, which is a version of
-- sum n ≡ n * (n - 1) / 2
--- my solution from Induction HW, copied here instead of importing for ease of grading
*-distrib-+ : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-distrib-+ zero n p =
begin
(zero + n) * p
≡⟨⟩
n * p
≡⟨⟩
zero + n * p
≡⟨⟩
zero * p + n * p
∎
*-distrib-+ (suc m) n p =
begin
(suc m + n) * p
≡⟨⟩
(suc (m + n)) * p
≡⟨⟩
p + ((m + n) * p)
≡⟨ cong (λ x -> p + x) (*-distrib-+ m n p) ⟩
p + (m * p + n * p)
≡⟨ sym (+-assoc p (m * p) (n * p))⟩
(p + m * p) + n * p
≡⟨⟩
suc m * p + n * p
∎
1-suc : ∀ ( n : ℕ )
→ n + 1 ≡ suc n
1-suc (zero) = refl
1-suc (suc n) =
begin
suc n + 1
≡⟨ (+-comm (suc n) 1) ⟩
1 + suc n
≡⟨⟩
suc ( 1 + n)
≡⟨ cong suc (+-comm 1 n) ⟩
suc ( n + 1)
≡⟨ cong suc (1-suc n) ⟩
suc ( suc n )
∎
simple : ∀ (n : ℕ) → (sum n) * 2 ≡ (suc n) * n
simple zero = refl
simple (suc n) =
begin
(sum (suc n)) * 2
≡⟨⟩
((sum n) + (suc n)) * 2
≡⟨ cong (λ x -> x) (*-distrib-+ (sum n) (suc n) 2 )⟩
(sum n) * 2 + (suc n) * 2
≡⟨ cong (λ x -> x + (suc n) * 2) (simple (n))⟩
(suc n) * n + (suc n) * 2
≡⟨ cong (λ x → x + (suc n) * 2) (*-comm (suc n) n)⟩
n * (suc n) + (suc n) * 2
≡⟨ cong (λ x → n * (suc n) + x) (*-comm (suc n) 2)⟩
n * (suc n) + 2 * (suc n)
≡⟨ cong (λ x → x) (sym (*-distrib-+ n 2 (suc n)))⟩
(n + 2) * (suc n)
≡⟨⟩
(n + suc 1) * (suc n)
≡⟨ cong (λ x → x * (suc n)) (+-suc n 1)⟩
(suc (n + 1)) * (suc n)
≡⟨ cong (λ x → (suc (x)) * (suc n)) (1-suc n)⟩
(suc (suc n)) * (suc n)
∎
-- Problem 2
-- remove the postulate and implement this function, which gives an Natural
-- number approximation of square root
if_then_else_ : { A : Set }
→ Dec A
→ ℕ
→ ℕ
→ ℕ
if yes A then a else b = a
if no A then a else b = b
sqrt : ℕ → ℕ
rt_sub_ : ℕ → ℕ → ℕ
rt_sub_ n sqrtn = if ((suc n) <? (((sqrtn) + 1) ^ 2)) then (sqrtn) else ((sqrtn) + 1)
sqrt 0 = 0
sqrt (suc n) = rt n sub (sqrt n)
-- you can run these test cases
_ : sqrt 0 ≡ 0
_ = refl
_ : sqrt 1 ≡ 1
_ = refl
_ : sqrt 2 ≡ 1
_ = refl
_ : sqrt 3 ≡ 1
_ = refl
_ : sqrt 4 ≡ 2
_ = refl
_ : sqrt 5 ≡ 2
_ = refl
_ : sqrt 6 ≡ 2
_ = refl
_ : sqrt 7 ≡ 2
_ = refl
_ : sqrt 8 ≡ 2
_ = refl
_ : sqrt 9 ≡ 3
_ = refl
_ : sqrt 10 ≡ 3
_ = refl
_ : sqrt 11 ≡ 3
_ = refl
_ : sqrt 12 ≡ 3
_ = refl
_ : sqrt 13 ≡ 3
_ = refl
_ : sqrt 14 ≡ 3
_ = refl
_ : sqrt 15 ≡ 3
_ = refl
_ : sqrt 16 ≡ 4
_ = refl
_ : sqrt 17 ≡ 4
_ = refl
_ : sqrt 18 ≡ 4
_ = refl
_ : sqrt 19 ≡ 4
_ = refl
_ : sqrt 20 ≡ 4
_ = refl
_ : sqrt 21 ≡ 4
_ = refl
_ : sqrt 22 ≡ 4
_ = refl
_ : sqrt 23 ≡ 4
_ = refl
_ : sqrt 24 ≡ 4
_ = refl
_ : sqrt 24 ≡ 4
_ = refl
_ : sqrt 24 ≡ 4
_ = refl
_ : sqrt 25 ≡ 5
_ = refl
_ : sqrt 26 ≡ 5
_ = refl
_ : sqrt 27 ≡ 5
_ = refl
_ : sqrt 100 ≡ 10
_ = refl
_ : sqrt 101 ≡ 10
_ = refl
| {
"alphanum_fraction": 0.4941961695,
"avg_line_length": 19.1444444444,
"ext": "agda",
"hexsha": "27df10a43119b29b877295fbdeb8338b7f4456a5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "billyang98/plfa.github.io",
"max_forks_repo_path": "src/plfa/part1/Midterm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "billyang98/plfa.github.io",
"max_issues_repo_path": "src/plfa/part1/Midterm.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "billyang98/plfa.github.io",
"max_stars_repo_path": "src/plfa/part1/Midterm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1714,
"size": 3446
} |
-- Andreas, 2016-12-30, issue #1886, reported by nad
--
-- Change of parameter names is an error.
-- Reason: the parameter names become names of hidden arguments
-- in the constructors. There should be no ambiguity.
data D (X : Set) : Set
data D (Y : Set) where
c : Y → D Y
| {
"alphanum_fraction": 0.6810035842,
"avg_line_length": 25.3636363636,
"ext": "agda",
"hexsha": "2764c8065cd011d96be912134b0cfd0d2a51e1ac",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue1886-wrong-name.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue1886-wrong-name.agda",
"max_line_length": 63,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue1886-wrong-name.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 81,
"size": 279
} |
module Categories.Object.Zero where
| {
"alphanum_fraction": 0.8611111111,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "393678dacb153b3ba087998acd2809e96d7cfe5c",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/Zero.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/Zero.agda",
"max_line_length": 35,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Object/Zero.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 6,
"size": 36
} |
module Loop where
{-
data _=>_ (A, B : Set) : Set where
lam : (A -> B) -> A => B
app : {A, B : Set} -> (A => B) -> A -> B
app (lam f) = f
delta = lam (\x -> app x x)
loop = app delta delta
-}
lam : (A, B : Set) -> (A -> B) -> A -> B
lam A B f = f
app : (A, B : Set) -> (A -> B) -> A -> B
app A B f = f
postulate Nat : Set
zero : Nat
wrap : (F : Nat -> Set) -> F zero -> F zero
wrap F x = x
delta : (Nat -> Nat) -> Nat
delta = \x -> x (wrap _ x)
loop : Nat
loop = delta (wrap _ delta)
-- delta : _ -> _
-- delta = \x -> app _ _ x x -- lam _ _ (\x -> app _ _ x x)
--
-- loop = app _ _ delta (wrap _ delta)
| {
"alphanum_fraction": 0.4669887279,
"avg_line_length": 16.3421052632,
"ext": "agda",
"hexsha": "155282cae3046703055b786089b320b47a7714b5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "notes/papers/implicit/examples/Loop.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "notes/papers/implicit/examples/Loop.agda",
"max_line_length": 59,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "notes/papers/implicit/examples/Loop.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 244,
"size": 621
} |
------------------------------------------------------------------------------
-- Properties of the divisibility relation
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.Divisibility.NotBy0.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.PropertiesATP
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Divisibility.NotBy0
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.PropertiesATP
------------------------------------------------------------------------------
-- Any positive number divides 0.
postulate S∣0 : ∀ n → succ₁ n ∣ zero
{-# ATP prove S∣0 #-}
-- 0 doesn't divide any number.
postulate 0∤x : ∀ {n} → ¬ (zero ∣ n)
{-# ATP prove 0∤x #-}
-- The divisibility relation is reflexive for positive numbers.
--
-- For the proof using the ATPs we added the helper hypothesis
--
-- N (succ zero).
postulate ∣-refl-S-ah : ∀ {n} → N n → N (succ₁ zero) → succ₁ n ∣ succ₁ n
{-# ATP prove ∣-refl-S-ah *-leftIdentity #-}
∣-refl-S : ∀ {n} → N n → succ₁ n ∣ succ₁ n
∣-refl-S Nn = ∣-refl-S-ah Nn (nsucc nzero)
-- If x divides y and z then x divides y ∸ z.
postulate
x∣y→x∣z→x∣y∸z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * succ₁ m →
o ≡ k' * succ₁ m →
n ∸ o ≡ (k ∸ k') * succ₁ m
{-# ATP prove x∣y→x∣z→x∣y∸z-helper *∸-leftDistributive #-}
x∣y→x∣z→x∣y∸z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n ∸ o
x∣y→x∣z→x∣y∸z nzero _ _ (0≢0 , _) m∣o = ⊥-elim (0≢0 refl)
x∣y→x∣z→x∣y∸z (nsucc Nm) Nn No
(_ , k , Nk , h₁)
(_ , k' , Nk' , h₂) =
(λ S≡0 → ⊥-elim (S≢0 S≡0))
, k ∸ k' , ∸-N Nk Nk' , x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and z then x divides y + z.
postulate
x∣y→x∣z→x∣y+z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * succ₁ m →
o ≡ k' * succ₁ m →
n + o ≡ (k + k') * succ₁ m
{-# ATP prove x∣y→x∣z→x∣y+z-helper *+-leftDistributive #-}
x∣y→x∣z→x∣y+z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n + o
x∣y→x∣z→x∣y+z nzero _ _ (0≢0 , _) m∣o = ⊥-elim (0≢0 refl)
x∣y→x∣z→x∣y+z (nsucc Nm) Nn No
(_ , k , Nk , h₁)
(_ , k' , Nk' , h₂) =
(λ S≡0 → ⊥-elim (S≢0 S≡0))
, k + k' , +-N Nk Nk' , x∣y→x∣z→x∣y+z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and y is positive, then x ≤ y.
postulate x∣S→x≤S-ah₁ : ∀ {m n} → succ₁ n ≡ zero * succ₁ m → ⊥
{-# ATP prove x∣S→x≤S-ah₁ #-}
-- Nice proof by the ATP.
postulate x∣S→x≤S-ah₂ : ∀ {m n o} → N m → N n → N o →
succ₁ n ≡ succ₁ o * succ₁ m →
succ₁ m ≤ succ₁ n
{-# ATP prove x∣S→x≤S-ah₂ x≤x+y *-N #-}
x∣S→x≤S : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n
x∣S→x≤S nzero Nn (0≢0 , _) = ⊥-elim (0≢0 refl)
x∣S→x≤S (nsucc Nm) Nn (_ , .zero , nzero , Sn≡0*Sm) = ⊥-elim (x∣S→x≤S-ah₁ Sn≡0*Sm)
x∣S→x≤S (nsucc {m} Nm) Nn (_ , .(succ₁ k) , nsucc {k} Nk , Sn≡Sk*Sm) =
x∣S→x≤S-ah₂ Nm Nn Nk Sn≡Sk*Sm
| {
"alphanum_fraction": 0.47053407,
"avg_line_length": 37.4482758621,
"ext": "agda",
"hexsha": "9169fb48e1123a53df32bf0cea8620ef5a3d9f26",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/NotBy0/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/NotBy0/PropertiesATP.agda",
"max_line_length": 82,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/NotBy0/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1375,
"size": 3258
} |
------------------------------------------------------------------------
-- Unary and binary relations
------------------------------------------------------------------------
{-# OPTIONS --safe #-}
module Relation where
open import Equality.Propositional
open import Prelude
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Decision-procedures equality-with-J
import Equality.Groupoid equality-with-J as EG
open import Function-universe equality-with-J hiding (id; _∘_)
open import Groupoid equality-with-J
-- Unary relations.
Rel : ∀ {ℓ₁} ℓ₂ → Type ℓ₁ → Type (ℓ₁ ⊔ lsuc ℓ₂)
Rel ℓ A = A → Type ℓ
-- Homogeneous binary relations.
Rel₂ : ∀ {ℓ₁} ℓ₂ → Type ℓ₁ → Type (ℓ₁ ⊔ lsuc ℓ₂)
Rel₂ ℓ A = Rel ℓ (A × A)
-- One kind of unary relation transformer.
Trans : ∀ {a} ℓ → Type a → Type (a ⊔ lsuc ℓ)
Trans ℓ A = Rel ℓ A → Rel ℓ A
-- One kind of binary relation transformer.
Trans₂ : ∀ {a} ℓ → Type a → Type (a ⊔ lsuc ℓ)
Trans₂ ℓ A = Trans ℓ (A × A)
-- The converse of a binary relation.
infixr 10 _⁻¹
_⁻¹ : ∀ {a ℓ} {A : Type a} → Rel₂ ℓ A → Rel₂ ℓ A
R ⁻¹ = R ∘ swap
-- Composition of binary relations.
infixr 9 _⊙_
_⊙_ : ∀ {a ℓ₁ ℓ₂} {A : Type a} →
Rel₂ ℓ₁ A → Rel₂ ℓ₂ A → Rel₂ (a ⊔ ℓ₁ ⊔ ℓ₂) A
(R ⊙ S) (x , z) = ∃ λ y → R (x , y) × S (y , z)
-- Composition of a relation with itself, with the base case as a
-- parameter.
composition : ∀ {a} {A : Type a} →
Rel₂ a A → Rel₂ a A → ℕ → Rel₂ a A
composition R S zero = R
composition R S (suc n) = S ⊙ composition R S n
-- Composition of a binary relation with itself, with the relation
-- itself as the base case.
infix 10 _^^[1+_]
_^^[1+_] : ∀ {a} {A : Type a} →
Rel₂ a A → ℕ → Rel₂ a A
R ^^[1+ n ] = composition R R n
-- Composition of a binary relation with itself, with equality as the
-- base case.
infix 10 _^^_
_^^_ : ∀ {a} {A : Type a} →
Rel₂ a A → ℕ → Rel₂ a A
R ^^ n = composition (uncurry _≡_) R n
-- Intersection of relations.
infixr 8 _∩_
_∩_ : ∀ {a ℓ₁ ℓ₂} {A : Type a} →
Rel ℓ₁ A → Rel ℓ₂ A → Rel (ℓ₁ ⊔ ℓ₂) A
R ∩ S = λ x → R x × S x
-- Union of relations.
infixr 7 _∪_
_∪_ : ∀ {a ℓ₁ ℓ₂} {A : Type a} →
Rel ℓ₁ A → Rel ℓ₂ A → Rel (ℓ₁ ⊔ ℓ₂) A
R ∪ S = λ x → R x ⊎ S x
-- Reflexive closure of binary relations.
_⁼ : ∀ {a ℓ} {A : Type a} →
Rel₂ ℓ A → Rel₂ (a ⊔ ℓ) A
R ⁼ = R ∪ uncurry _≡_
-- Transitive closure of binary relations.
_⁺ : ∀ {a} {A : Type a} →
Rel₂ a A → Rel₂ a A
(R ⁺) x = ∃ λ n → (R ^^[1+ n ]) x
-- Reflexive transitive closure of binary relations.
_* : ∀ {a} {A : Type a} →
Rel₂ a A → Rel₂ a A
(R *) x = ∃ λ n → (R ^^ n) x
-- Repeated composition of a function with itself.
infix 10 _^[_]_
_^[_]_ : ∀ {a} {A : Type a} → (A → A) → ℕ → A → A
f ^[ zero ] x = x
f ^[ suc n ] x = f (f ^[ n ] x)
-- Unions of families of relation transformers.
⋃ : ∀ {a b} ℓ {A : Type a} {B : Type b} →
(A → Trans (a ⊔ ℓ) B) → Trans (a ⊔ ℓ) B
⋃ _ F R = λ b → ∃ λ a → F a R b
-- An analogue of ⋃ₙ Fⁿ.
infix 10 _^ω_
_^ω_ : ∀ {a ℓ} {A : Type a} → Trans ℓ A → Trans ℓ A
_^ω_ F = ⋃ _ (F ^[_]_)
-- Relation containment.
infix 4 _⊆_
_⊆_ : ∀ {a ℓ₁ ℓ₂} {A : Type a} →
Rel ℓ₁ A → Rel ℓ₂ A → Type (a ⊔ ℓ₁ ⊔ ℓ₂)
R ⊆ S = ∀ {x} → R x → S x
-- "Equational" reasoning combinators.
infix -1 finally-⊆
infixr -2 _⊆⟨_⟩_ _⊆⟨⟩_
_⊆⟨_⟩_ : ∀ {a p q r} {A : Type a}
(P : Rel p A) {Q : Rel q A} {R : Rel r A} →
P ⊆ Q → Q ⊆ R → P ⊆ R
_ ⊆⟨ P⊆Q ⟩ Q⊆R = Q⊆R ∘ P⊆Q
_⊆⟨⟩_ : ∀ {a p q} {A : Type a}
(P : Rel p A) {Q : Rel q A} →
P ⊆ Q → P ⊆ Q
_ ⊆⟨⟩ P⊆Q = P⊆Q
finally-⊆ : ∀ {a p q} {A : Type a}
(P : Rel p A) (Q : Rel q A) →
P ⊆ Q → P ⊆ Q
finally-⊆ _ _ P⊆Q = P⊆Q
syntax finally-⊆ P Q P⊆Q = P ⊆⟨ P⊆Q ⟩∎ Q ∎
-- Preservation lemmas for _⊆_.
infix 4 _⊆-cong-→_
⊆-cong :
∀ {k a r₁ r₂ s₁ s₂} {A : Type a}
{R₁ : Rel r₁ A} {S₁ : Rel s₁ A}
{R₂ : Rel r₂ A} {S₂ : Rel s₂ A} →
Extensionality? ⌊ k ⌋-sym (a ⊔ r₁ ⊔ r₂) (r₁ ⊔ r₂ ⊔ s₁ ⊔ s₂) →
(∀ {x} → R₁ x ↝[ ⌊ k ⌋-sym ] R₂ x) →
(∀ {x} → S₁ x ↝[ ⌊ k ⌋-sym ] S₂ x) →
R₁ ⊆ S₁ ↝[ ⌊ k ⌋-sym ] R₂ ⊆ S₂
⊆-cong {k} {a} {r₁} {r₂} ext R₁↝R₂ S₁↝S₂ =
implicit-∀-cong
(lower-extensionality? ⌊ k ⌋-sym (r₁ ⊔ r₂) lzero ext) $
→-cong (lower-extensionality? ⌊ k ⌋-sym a (r₁ ⊔ r₂) ext)
R₁↝R₂ S₁↝S₂
_⊆-cong-→_ :
∀ {a r₁ r₂ s₁ s₂} {A : Type a}
{R₁ : Rel r₁ A} {S₁ : Rel s₁ A}
{R₂ : Rel r₂ A} {S₂ : Rel s₂ A} →
R₂ ⊆ R₁ → S₁ ⊆ S₂ → R₁ ⊆ S₁ → R₂ ⊆ S₂
R₂→R₁ ⊆-cong-→ S₁→S₂ = implicit-∀-cong _ $ →-cong-→ R₂→R₁ S₁→S₂
⊆-congʳ :
∀ {k a r s₁ s₂} {A : Type a}
{R : Rel r A} {S₁ : Rel s₁ A} {S₂ : Rel s₂ A} →
Extensionality? k (a ⊔ r) (r ⊔ s₁ ⊔ s₂) →
(∀ {x} → S₁ x ↝[ k ] S₂ x) →
R ⊆ S₁ ↝[ k ] R ⊆ S₂
⊆-congʳ {k} {a} {r} ext S₁↝S₂ =
implicit-∀-cong (lower-extensionality? k r lzero ext) $
∀-cong (lower-extensionality? k a r ext) λ _ →
S₁↝S₂
-- Relation containment (_⊆_) is not antisymmetric (with respect to
-- propositional equality) if the index type is inhabited.
⊆-not-antisymmetric :
∀ {ℓ x} {X : Type x} →
X →
¬ ({R S : Rel ℓ X} → R ⊆ S → S ⊆ R → R ≡ S)
⊆-not-antisymmetric {ℓ} {X = X} x antisym = Bool.true≢false true≡false
where
R S : Rel ℓ X
R = λ _ → ↑ _ ⊤
S = λ _ → ↑ _ Bool
R≡S : R ≡ S
R≡S = antisym (λ _ → lift true) _
⊤≡Bool : ↑ _ ⊤ ≡ ↑ _ Bool
⊤≡Bool = cong (_$ x) R≡S
⊤↔Bool : ⊤ ↔ Bool
⊤↔Bool =
⊤ ↝⟨ inverse Bijection.↑↔ ⟩
↑ _ ⊤ ↝⟨ ≡⇒↝ _ ⊤≡Bool ⟩
↑ _ Bool ↝⟨ Bijection.↑↔ ⟩□
Bool □
true≡false : true ≡ false
true≡false =
true ≡⟨ sym $ _↔_.right-inverse-of ⊤↔Bool _ ⟩
_↔_.to ⊤↔Bool (_↔_.from ⊤↔Bool true) ≡⟨⟩
_↔_.to ⊤↔Bool tt ≡⟨⟩
_↔_.to ⊤↔Bool (_↔_.from ⊤↔Bool false) ≡⟨ _↔_.right-inverse-of ⊤↔Bool _ ⟩∎
false ∎
-- Monotonicity of relation transformers.
Monotone :
∀ {a ℓ} {A : Type a} →
Trans ℓ A → Type (a ⊔ lsuc ℓ)
Monotone F = ∀ {R S} → R ⊆ S → F R ⊆ F S
-- A relation transformer is extensive if the input is always
-- contained in the output.
Extensive : ∀ {ℓ} {I : Type ℓ} → Trans ℓ I → Type (lsuc ℓ)
Extensive G = ∀ R → R ⊆ G R
-- A definition that turns into a notion of symmetry if the first
-- argument is instantiated with the swap function. In that case this
-- definition is similar to one of those given by Pous and Sangiorgi
-- in Section 6.3.4.1 of "Enhancements of the bisimulation proof
-- method".
Symmetric : ∀ {ℓ} {I : Type ℓ} → (I → I) → Trans ℓ I → Type (lsuc ℓ)
Symmetric f F = ∀ R → F (R ∘ f) ⊆ F R ∘ f
-- If f is an involution, then the inclusion in Symmetric f F holds
-- also in the other direction.
involution→other-symmetry :
∀ {ℓ} {I : Type ℓ} (F : Trans ℓ I) {f : I → I} →
f ∘ f ≡ id → Symmetric f F → ∀ R → F R ∘ f ⊆ F (R ∘ f)
involution→other-symmetry F {f} inv symm R =
F R ∘ f ⊆⟨ (λ {x} → subst (λ g → F (R ∘ g) (f x)) (sym inv)) ⟩
F (R ∘ f ∘ f) ∘ f ⊆⟨ symm _ ⟩
F (R ∘ f) ∘ f ∘ f ⊆⟨ (λ {x} → subst (λ g → F (R ∘ f) (g x)) inv) ⟩∎
F (R ∘ f) ∎
-- Composition is associative.
⊙-assoc : ∀ {a ℓ₁ ℓ₂ ℓ₃} {A : Type a} →
(R₁ : Rel₂ ℓ₁ A) {R₂ : Rel₂ ℓ₂ A} (R₃ : Rel₂ ℓ₃ A) →
∀ p → (R₁ ⊙ (R₂ ⊙ R₃)) p ↔ ((R₁ ⊙ R₂) ⊙ R₃) p
⊙-assoc R₁ {R₂} R₃ (a , d) =
(∃ λ b → R₁ (a , b) × ∃ λ c → R₂ (b , c) × R₃ (c , d)) ↝⟨ ∃-cong (λ _ → ∃-comm) ⟩
(∃ λ b → ∃ λ c → R₁ (a , b) × R₂ (b , c) × R₃ (c , d)) ↝⟨ ∃-comm ⟩
(∃ λ c → ∃ λ b → R₁ (a , b) × R₂ (b , c) × R₃ (c , d)) ↝⟨ ∃-cong (λ _ → ∃-cong λ _ → Σ-assoc) ⟩
(∃ λ c → ∃ λ b → (R₁ (a , b) × R₂ (b , c)) × R₃ (c , d)) ↝⟨ ∃-cong (λ _ → Σ-assoc) ⟩□
(∃ λ c → (∃ λ b → R₁ (a , b) × R₂ (b , c)) × R₃ (c , d)) □
-- Several forms of composition preserve several kinds of functions.
⊙-cong :
∀ {k a r₁ r₂ s₁ s₂} {A : Type a} →
{R₁ : Rel₂ r₁ A} {R₂ : Rel₂ r₂ A} →
{S₁ : Rel₂ s₁ A} {S₂ : Rel₂ s₂ A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
(∀ p → S₁ p ↝[ k ] S₂ p) →
∀ p → (R₁ ⊙ S₁) p ↝[ k ] (R₂ ⊙ S₂) p
⊙-cong {R₁ = R₁} {R₂} {S₁} {S₂} R₁↝R₂ S₁↝S₂ (x , z) =
(∃ λ y → R₁ (x , y) × S₁ (y , z)) ↝⟨ ∃-cong (λ _ → R₁↝R₂ _ ×-cong S₁↝S₂ _) ⟩□
(∃ λ y → R₂ (x , y) × S₂ (y , z)) □
composition-cong :
∀ {k a} {A : Type a} {R₁ R₂ S₁ S₂ : Rel₂ a A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
(∀ p → S₁ p ↝[ k ] S₂ p) →
∀ n p → composition R₁ S₁ n p ↝[ k ] composition R₂ S₂ n p
composition-cong R₁↝R₂ S₁↝S₂ = λ where
zero → R₁↝R₂
(suc n) → ⊙-cong S₁↝S₂ (composition-cong R₁↝R₂ S₁↝S₂ n)
^^[1+]-cong :
∀ {k a} {A : Type a} {R₁ R₂ : Rel₂ a A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
∀ n p → (R₁ ^^[1+ n ]) p ↝[ k ] (R₂ ^^[1+ n ]) p
^^[1+]-cong R₁↝R₂ = composition-cong R₁↝R₂ R₁↝R₂
^^-cong :
∀ {k a} {A : Type a} {R₁ R₂ : Rel₂ a A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
∀ n p → (R₁ ^^ n) p ↝[ k ] (R₂ ^^ n) p
^^-cong R₁↝R₂ = composition-cong (λ _ → _ □) R₁↝R₂
⁺-cong :
∀ {k a} {A : Type a} {R₁ R₂ : Rel₂ a A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
∀ p → (R₁ ⁺) p ↝[ k ] (R₂ ⁺) p
⁺-cong R₁↝R₂ p = ∃-cong λ n → ^^[1+]-cong R₁↝R₂ n p
*-cong :
∀ {k a} {A : Type a} {R₁ R₂ : Rel₂ a A} →
(∀ p → R₁ p ↝[ k ] R₂ p) →
∀ p → (R₁ *) p ↝[ k ] (R₂ *) p
*-cong R₁↝R₂ p = ∃-cong λ n → ^^-cong R₁↝R₂ n p
-- Two lemmas relating composition and _⊙_.
composition-⊙-comm :
∀ {k a} {A : Type a} {R S : Rel₂ a A} →
(∀ p → (R ⊙ S) p ↝[ k ] (S ⊙ R) p) →
∀ n p → (composition R S n ⊙ S) p ↝[ k ] (S ⊙ composition R S n) p
composition-⊙-comm hyp zero = hyp
composition-⊙-comm {R = R} {S} hyp (suc n) = λ p →
((S ⊙ composition R S n) ⊙ S) p ↔⟨ inverse $ ⊙-assoc S S _ ⟩
(S ⊙ (composition R S n ⊙ S)) p ↝⟨ ⊙-cong (λ p → S p □) (composition-⊙-comm hyp n) _ ⟩□
(S ⊙ (S ⊙ composition R S n)) p □
composition⊙composition :
∀ {k a} {A : Type a} {R S : Rel₂ a A} m n₁ {n₂} →
(∀ p → (R ⊙ composition R S n₁) p ↝[ k ] composition R S n₂ p) →
∀ p → (composition R S m ⊙ composition R S n₁) p ↝[ k ]
composition R S (m + n₂) p
composition⊙composition {R = R} {S} = λ where
zero n₁ {n₂} hyp p →
(R ⊙ composition R S n₁) p ↝⟨ hyp _ ⟩
composition R S n₂ p □
(suc m) n₁ {n₂} hyp p →
((S ⊙ composition R S m) ⊙ composition R S n₁) p ↔⟨ inverse $ ⊙-assoc S (composition R S n₁) _ ⟩
(S ⊙ (composition R S m ⊙ composition R S n₁)) p ↝⟨ ⊙-cong (λ p → S p □) (composition⊙composition m n₁ hyp) _ ⟩□
(S ⊙ composition R S (m + n₂)) p □
-- The transitive closure is transitive.
⁺-trans : ∀ {a} {A : Type a} {R : Rel₂ a A} {x y z} →
(R ⁺) (x , y) → (R ⁺) (y , z) → (R ⁺) (x , z)
⁺-trans (m , xR¹⁺ᵐy) (n , yR¹⁺ⁿz) =
m + suc n
, composition⊙composition m n (λ _ → id) _ (_ , xR¹⁺ᵐy , yR¹⁺ⁿz)
-- The reflexive transitive closure is transitive.
*-trans : ∀ {a} {A : Type a} {R : Rel₂ a A} {x y z} →
(R *) (x , y) → (R *) (y , z) → (R *) (x , z)
*-trans {R = R} (m , xRᵐy) (n , yRⁿz) =
m + n , composition⊙composition m n lemma _ (_ , xRᵐy , yRⁿz)
where
lemma : ∀ p → (uncurry _≡_ ⊙ (R ^^ n)) p → (R ^^ n) p
lemma _ (_ , refl , r) = r
-- Lemmas relating different forms of composition and swap.
⊙-swap :
∀ {k a r s} {A : Type a} {R : Rel₂ r A} {S : Rel₂ s A} →
(∀ p → R p ↝[ k ] R (swap p)) →
(∀ p → S p ↝[ k ] S (swap p)) →
∀ p → (R ⊙ S) p ↝[ k ] (S ⊙ R) (swap p)
⊙-swap {R = R} {S} R↝ S↝ (x , z) =
(∃ λ y → R (x , y) × S (y , z)) ↝⟨ ∃-cong (λ _ → R↝ _ ×-cong S↝ _) ⟩
(∃ λ y → R (y , x) × S (z , y)) ↔⟨ ∃-cong (λ _ → ×-comm) ⟩□
(∃ λ y → S (z , y) × R (y , x)) □
composition-swap :
∀ {k a} {A : Type a} {R S : Rel₂ a A} →
(∀ p → R p ↝[ k ] R (swap p)) →
(∀ p → S p ↝[ k ] S (swap p)) →
(∀ p → (R ⊙ S) p ↝[ k ] (S ⊙ R) p) →
∀ n p → composition R S n p ↝[ k ] composition R S n (swap p)
composition-swap {R = R} {S} R↝ S↝ hyp = λ where
zero p → R p ↝⟨ R↝ _ ⟩□
R (swap p) □
(suc n) p → (S ⊙ composition R S n) p ↝⟨ ⊙-swap S↝ (composition-swap R↝ S↝ hyp n) _ ⟩
(composition R S n ⊙ S) (swap p) ↝⟨ composition-⊙-comm hyp n _ ⟩□
(S ⊙ composition R S n) (swap p) □
^^[1+]-swap :
∀ {k a} {A : Type a} {R : Rel₂ a A} →
(∀ p → R p ↝[ k ] R (swap p)) →
∀ n p → (R ^^[1+ n ]) p ↝[ k ] (R ^^[1+ n ]) (swap p)
^^[1+]-swap R↝ = composition-swap R↝ R↝ (λ _ → _ □)
^^-swap :
∀ {k a} {A : Type a} {R : Rel₂ a A} →
(∀ p → R p ↝[ k ] R (swap p)) →
∀ n p → (R ^^ n) p ↝[ k ] (R ^^ n) (swap p)
^^-swap {R = R} R↝ = composition-swap lemma₁ R↝ lemma₂
where
lemma₁ = λ { (x , y) →
x ≡ y ↔⟨ Groupoid.⁻¹-bijection (EG.groupoid _) ⟩□
y ≡ x □ }
lemma₂ = λ { (x , z) →
(∃ λ y → x ≡ y × R (y , z)) ↔⟨ ∃-cong (λ _ → ×-comm) ⟩
(∃ λ y → R (y , z) × x ≡ y) ↝⟨ ∃-cong (λ _ → ∃-cong λ _ → lemma₁ _) ⟩
(∃ λ y → R (y , z) × y ≡ x) ↔⟨ inverse $ ∃-intro _ _ ⟩
R (x , z) ↔⟨ ∃-intro _ _ ⟩□
(∃ λ y → R (x , y) × y ≡ z) □}
⁺-swap :
∀ {k a} {A : Type a} {R : Rel₂ a A} →
(∀ p → R p ↝[ k ] R (swap p)) →
∀ p → (R ⁺) p ↝[ k ] (R ⁺) (swap p)
⁺-swap {R = R} R↝ p =
(R ⁺) p ↔⟨⟩
(∃ λ n → (R ^^[1+ n ]) p) ↝⟨ ∃-cong (λ n → ^^[1+]-swap R↝ n _) ⟩
(∃ λ n → (R ^^[1+ n ]) (swap p)) ↔⟨⟩
(R ⁺) (swap p) □
*-swap :
∀ {k a} {A : Type a} {R : Rel₂ a A} →
(∀ p → R p ↝[ k ] R (swap p)) →
∀ p → (R *) p ↝[ k ] (R *) (swap p)
*-swap {R = R} R↝ p =
(R *) p ↔⟨⟩
(∃ λ n → (R ^^ n) p) ↝⟨ ∃-cong (λ n → ^^-swap R↝ n _) ⟩
(∃ λ n → (R ^^ n) (swap p)) ↔⟨⟩
(R *) (swap p) □
-- ⋃ constructs least upper bounds.
⊆-⋃ : ∀ {a b ℓ} {A : Type a} {B : Type b}
(F : A → Trans (a ⊔ ℓ) B) a →
∀ R → F a R ⊆ ⋃ ℓ F R
⊆-⋃ {ℓ = ℓ} F a R =
F a R ⊆⟨ a ,_ ⟩
(λ x → ∃ λ a → F a R x) ⊆⟨ id ⟩∎
⋃ ℓ F R ∎
⋃-⊆ : ∀ {a b ℓ} {A : Type a} {B : Type b}
(F : A → Trans (a ⊔ ℓ) B) (G : Trans (a ⊔ ℓ) B) →
(∀ {a} R → F a R ⊆ G R) →
∀ R → ⋃ ℓ F R ⊆ G R
⋃-⊆ {ℓ = ℓ} F G hyp R =
⋃ ℓ F R ⊆⟨⟩
(λ x → ∃ λ a → F a R x) ⊆⟨ hyp _ ∘ proj₂ ⟩∎
G R ∎
| {
"alphanum_fraction": 0.4593027418,
"avg_line_length": 30.6337719298,
"ext": "agda",
"hexsha": "85c4f7d7da268b8ac5c74c2045a0f2e02e33f5bd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Relation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Relation.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Relation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6864,
"size": 13969
} |
{-# OPTIONS --universe-polymorphism #-}
module LevelWithBug where
open import Common.Level
postulate
take : ∀ a → Set a → Set
a : Level
A : Set a
Goal : Set → Set
goal : ∀ X → Goal X
-- The meta got solved by Level (Max [Plus 0 (NeutralLevel a)]) which
-- didn't match the argument in the with expression which is simply a.
-- Now the level noise should go away when it's not useful.
foo : Goal (take _ A)
foo with take a A
... | z = goal z
-- Here's another more complicated one.
data List {a}(A : Set a) : Set a where
[] : List A
_∷_ : A → List A → List A
data _≡_ {a}{A : Set a}(x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
-- Sums commute with Any (for a fixed list).
data Any {a p} {A : Set a}
(P : A → Set p) : List A → Set (a ⊔ p) where
there : ∀ {x xs} (pxs : Any P xs) → Any P (x ∷ xs)
amap : ∀ {a p q} {A : Set a} {P : A → Set p} → {Q : A → Set q} →
(∀ {x} → P x → Q x) → ∀ {xs} → Any P xs → Any Q xs
amap g (there pxs) = there (amap g pxs)
data _+_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
inl : (x : A) → A + B
inr : (y : B) → A + B
smap : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
(A → C) → (B → D) → (A + B → C + D)
smap f g (inl x) = inl (f x)
smap f g (inr y) = inr (g y)
postulate
p q : Level
P : A → Set p
Q : A → Set q
to : ∀ xs → Any P xs + Any Q xs → Any (λ x → P x + Q x) xs
to xs (inl pxs) = amap inl pxs
to xs (inr pxs) = amap inr pxs
from : ∀ xs → Any (λ x → P x + Q x) xs → Any P xs + Any Q xs
from ._ (there p) = smap there there (from _ p)
-- Here the abstraction didn't work because a NeutralLevel was replaced
-- by an UnreducedLevel during abstraction.
fromto : ∀ xs (p : Any P xs + Any Q xs) → from xs (to xs p) ≡ p
fromto .(x ∷ xs) (inl (there {x}{xs} p)) rewrite fromto xs (inl p) = refl
fromto .(x ∷ xs) (inr (there {x}{xs} q)) rewrite fromto xs (inr q) = refl
| {
"alphanum_fraction": 0.5523465704,
"avg_line_length": 28.1014492754,
"ext": "agda",
"hexsha": "81167636f3d0e79aaac8071112370098a567e4b3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/LevelWithBug.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/LevelWithBug.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/LevelWithBug.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 762,
"size": 1939
} |
module Structure.Operator.Ring.Rings where
import Lvl
open import Structure.Operator.Ring
open import Structure.Setoid
open import Type
open import Type.Properties.Singleton
private variable ℓ ℓₑ : Lvl.Level
private variable T U : Type{ℓ}
postulate trivialRing : ∀{_+_ _⋅_ : U → U → U} → ⦃ equiv : Equiv{ℓₑ}(U) ⦄ ⦃ singleton : IsUnit(U) ⦄ → Ring(_+_)(_⋅_)
{-Ring.[+]-commutative-group trivialRing = {!!}
Ring.[⋅]-binary-operator trivialRing = {!!}
Ring.[⋅]-associativity trivialRing = {!!}
Ring.[⋅][+]-distributivityₗ trivialRing = {!!}
Ring.[⋅][+]-distributivityᵣ trivialRing = {!!}
-}
| {
"alphanum_fraction": 0.6771523179,
"avg_line_length": 31.7894736842,
"ext": "agda",
"hexsha": "c88490d5d643c7de35a322d9ba85b4d2dcb6ab87",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Ring/Rings.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Ring/Rings.agda",
"max_line_length": 116,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Ring/Rings.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 204,
"size": 604
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Bool.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Bool.Base
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
notnot : ∀ x → not (not x) ≡ x
notnot true = refl
notnot false = refl
notIsEquiv : isEquiv not
notIsEquiv = isoToIsEquiv (iso not not notnot notnot)
notEquiv : Bool ≃ Bool
notEquiv = (not , notIsEquiv)
notEq : Bool ≡ Bool
notEq = ua notEquiv
private
-- This computes to false as expected
nfalse : Bool
nfalse = transp (λ i → notEq i) i0 true
-- Sanity check
nfalsepath : nfalse ≡ false
nfalsepath = refl
isSetBool : isSet Bool
isSetBool = Discrete→isSet _≟_
true≢false : ¬ true ≡ false
true≢false p = subst (λ b → if b then Bool else ⊥) p true
false≢true : ¬ false ≡ true
false≢true p = subst (λ b → if b then ⊥ else Bool) p true
not≢const : ∀ x → ¬ not x ≡ x
not≢const false = true≢false
not≢const true = false≢true
zeroˡ : ∀ x → true or x ≡ true
zeroˡ false = refl
zeroˡ true = refl
zeroʳ : ∀ x → x or true ≡ true
zeroʳ false = refl
zeroʳ true = refl
or-identityˡ : ∀ x → false or x ≡ x
or-identityˡ false = refl
or-identityˡ true = refl
or-identityʳ : ∀ x → x or false ≡ x
or-identityʳ false = refl
or-identityʳ true = refl
or-comm : ∀ x y → x or y ≡ y or x
or-comm false y =
false or y ≡⟨ or-identityˡ y ⟩
y ≡⟨ sym (or-identityʳ y) ⟩
y or false ∎
or-comm true y =
true or y ≡⟨ zeroˡ y ⟩
true ≡⟨ sym (zeroʳ y) ⟩
y or true ∎
or-assoc : ∀ x y z → x or (y or z) ≡ (x or y) or z
or-assoc false y z =
false or (y or z) ≡⟨ or-identityˡ _ ⟩
y or z ≡[ i ]⟨ or-identityˡ y (~ i) or z ⟩
((false or y) or z) ∎
or-assoc true y z =
true or (y or z) ≡⟨ zeroˡ _ ⟩
true ≡⟨ sym (zeroˡ _) ⟩
true or z ≡[ i ]⟨ zeroˡ y (~ i) or z ⟩
(true or y) or z ∎
or-idem : ∀ x → x or x ≡ x
or-idem false = refl
or-idem true = refl
⊕-comm : ∀ x y → x ⊕ y ≡ y ⊕ x
⊕-comm false false = refl
⊕-comm false true = refl
⊕-comm true false = refl
⊕-comm true true = refl
⊕-assoc : ∀ x y z → x ⊕ (y ⊕ z) ≡ (x ⊕ y) ⊕ z
⊕-assoc false y z = refl
⊕-assoc true false z = refl
⊕-assoc true true z = notnot z
not-⊕ˡ : ∀ x y → not (x ⊕ y) ≡ not x ⊕ y
not-⊕ˡ false y = refl
not-⊕ˡ true y = notnot y
⊕-invol : ∀ x y → x ⊕ (x ⊕ y) ≡ y
⊕-invol false x = refl
⊕-invol true x = notnot x
isEquiv-⊕ : ∀ x → isEquiv (x ⊕_)
isEquiv-⊕ x = isoToIsEquiv (iso _ (x ⊕_) (⊕-invol x) (⊕-invol x))
| {
"alphanum_fraction": 0.6222876057,
"avg_line_length": 23.850877193,
"ext": "agda",
"hexsha": "fa87e2dede478aada74163d50c9f722ac1bf214f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1118,
"size": 2719
} |
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Theorems of ∧ connective.
------------------------------------------------------------------------------
open import Data.Nat using ( ℕ )
module Data.PropFormula.Theorems.Conjunction ( n : ℕ ) where
------------------------------------------------------------------------------
open import Data.PropFormula.Syntax n
open import Data.PropFormula.Theorems.Classical n
open import Function using ( _$_ ; _∘_ )
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-assoc₁
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ φ ∧ (ψ ∧ γ)
→ Γ ⊢ (φ ∧ ψ) ∧ γ
-- Proof.
∧-assoc₁ Γ⊢φ∧ψ∧γ =
∧-intro
(∧-intro
(∧-proj₁ Γ⊢φ∧ψ∧γ)
((∧-proj₁ ∘ ∧-proj₂) Γ⊢φ∧ψ∧γ))
((∧-proj₂ ∘ ∧-proj₂) Γ⊢φ∧ψ∧γ)
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-assoc₂
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ∧ ψ) ∧ γ
→ Γ ⊢ φ ∧ (ψ ∧ γ)
-- Proof.
∧-assoc₂ Γ⊢φ∧ψ∧γ =
∧-intro
(∧-proj₁ (∧-proj₁ Γ⊢φ∧ψ∧γ))
(∧-intro
(∧-proj₂ (∧-proj₁ Γ⊢φ∧ψ∧γ))
(∧-proj₂ Γ⊢φ∧ψ∧γ))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-assoc
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ∧ (ψ ∧ γ)) ⇔ ((φ ∧ ψ) ∧ γ)
-- Proof.
∧-assoc {Γ} {φ}{ψ}{γ} =
⇔-intro
(∧-assoc₁ (assume (φ ∧ (ψ ∧ γ))))
(∧-assoc₂ (assume (φ ∧ ψ ∧ γ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-comm
: ∀ {Γ} {φ ψ}
→ Γ ⊢ φ ∧ ψ
→ Γ ⊢ ψ ∧ φ
-- Proof.
∧-comm Γ⊢φ∧ψ =
∧-intro
(∧-proj₂ Γ⊢φ∧ψ)
(∧-proj₁ Γ⊢φ∧ψ)
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dist₁
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ φ ∧ (ψ ∨ γ)
→ Γ ⊢ (φ ∧ ψ) ∨ (φ ∧ γ)
-- Proof.
∧-dist₁ {φ = φ}{ψ}{γ} Γ⊢φ∧ψ∨γ =
⊃-elim
(⊃-intro $
∨-elim
(∨-intro₁ (φ ∧ γ)
(∧-intro
(weaken ψ (∧-proj₁ Γ⊢φ∧ψ∨γ))
(assume ψ)))
(∨-intro₂ (φ ∧ ψ)
(∧-intro
(weaken γ (∧-proj₁ Γ⊢φ∧ψ∨γ))
(assume γ))))
(∧-proj₂ Γ⊢φ∧ψ∨γ)
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dist₂
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ (φ ∧ ψ) ∨ (φ ∧ γ)
→ Γ ⊢ φ ∧ (ψ ∨ γ)
-- Proof.
∧-dist₂ {φ = φ}{ψ}{γ} =
⊃-elim
(⊃-intro
(∨-elim
(∧-intro
(∧-proj₁
(assume (φ ∧ ψ)))
(∨-intro₁ γ
(∧-proj₂
(assume (φ ∧ ψ)))))
(∧-intro
(∧-proj₁
(assume (φ ∧ γ)))
(∨-intro₂ ψ
(∧-proj₂
(assume (φ ∧ γ)))))))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dist
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ φ ∧ (ψ ∨ γ) ⇔ (φ ∧ ψ) ∨ (φ ∧ γ)
-- Proof.
∧-dist {φ = φ}{ψ}{γ} =
⇔-intro
(∧-dist₁ (assume (φ ∧ (ψ ∨ γ))))
(∧-dist₂ (assume (φ ∧ ψ ∨ (φ ∧ γ))))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dmorgan₁
: ∀ {Γ} {φ ψ}
→ Γ ⊢ ¬ (φ ∧ ψ)
→ Γ ⊢ ¬ φ ∨ ¬ ψ
¬∧-to-¬∨¬ = ∧-dmorgan₁
-- Proof.
∧-dmorgan₁ {Γ}{φ}{ψ} =
⊃-elim $
⊃-intro $
RAA $
¬-elim
(weaken (¬ (¬ φ ∨ ¬ ψ)) $
assume $ ¬ (φ ∧ ψ))
(∧-intro
(RAA
(¬-elim
(weaken (¬ φ) $
assume {Γ = Γ , ¬ (φ ∧ ψ)} $ ¬ (¬ φ ∨ ¬ ψ))
(∨-intro₁ (¬ ψ)
(assume {Γ = Γ , ¬ (φ ∧ ψ) , ¬ (¬ φ ∨ ¬ ψ)} $ ¬ φ))))
(RAA
(¬-elim {Γ = Γ , ¬ (φ ∧ ψ) , ¬ (¬ φ ∨ ¬ ψ) , ¬ ψ}
(weaken (¬ ψ) $
assume {Γ = Γ , ¬ (φ ∧ ψ)} $ ¬ (¬ φ ∨ ¬ ψ))
(∨-intro₂ (¬ φ)
(assume {Γ = Γ , ¬ (φ ∧ ψ) , ¬ (¬ φ ∨ ¬ ψ)} $ ¬ ψ )))))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dmorgan₂
: ∀ {Γ} {φ ψ}
→ Γ ⊢ ¬ φ ∨ ¬ ψ
→ Γ ⊢ ¬ (φ ∧ ψ)
¬∨¬-to-¬∧ = ∧-dmorgan₂
-- Proof.
∧-dmorgan₂ {Γ}{φ}{ψ} =
⊃-elim $
⊃-intro $
∨-elim {Γ = Γ}
(¬-intro $
¬-elim
(weaken (φ ∧ ψ) $
assume (¬ φ))
(∧-proj₁ $
assume {Γ = Γ , ¬ φ} (φ ∧ ψ)))
(¬-intro $
¬-elim
(weaken (φ ∧ ψ) $ assume (¬ ψ))
(∧-proj₂ $
assume {Γ = Γ , ¬ ψ} (φ ∧ ψ)))
-------------------------------------------------------------------------- ∎
-- Theorem.
∧-dmorgan
: ∀ {Γ} {φ ψ}
→ Γ ⊢ ¬ φ ∨ ¬ ψ ⇔ ¬ (φ ∧ ψ)
¬∨¬-⇔-¬∧ = ∧-dmorgan
-- Proof.
∧-dmorgan {Γ}{φ}{ψ} =
⇔-intro
(∧-dmorgan₂
(assume (¬ φ ∨ ¬ ψ)))
(∧-dmorgan₁
(assume (¬ (φ ∧ ψ))))
-------------------------------------------------------------------------- ∎
-- Theorem.
subst⊢∧₁
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ φ ⊃ γ
→ Γ ⊢ φ ∧ ψ
→ Γ ⊢ γ ∧ ψ
-- Proof.
subst⊢∧₁ Γ⊢φ⊃ψ Γ⊢φ∧ψ =
∧-intro
(⊃-elim (∧-proj₁ (∧-intro Γ⊢φ⊃ψ Γ⊢φ∧ψ)) (∧-proj₁ Γ⊢φ∧ψ))
(∧-proj₂ Γ⊢φ∧ψ)
-------------------------------------------------------------------------- ∎
-- Theorem.
subst⊢∧₂
: ∀ {Γ} {φ ψ γ}
→ Γ ⊢ ψ ⊃ γ
→ Γ ⊢ φ ∧ ψ
→ Γ ⊢ φ ∧ γ
-- Proof.
subst⊢∧₂ {Γ}{φ}{ψ} Γ⊢φ⊃ψ Γ⊢φ∧ψ =
∧-intro
(∧-proj₁ Γ⊢φ∧ψ)
(⊃-elim Γ⊢φ⊃ψ (∧-proj₂ Γ⊢φ∧ψ))
-------------------------------------------------------------------------- ∎
-- Theorem.
¬∧-to-⊥
: ∀ {Γ} {φ}
→ Γ ⊢ ¬ φ ∧ φ
→ Γ ⊢ ⊥
-- Proof.
¬∧-to-⊥ {Γ}{φ} Γ⊢φ = ¬-elim (∧-proj₁ Γ⊢φ) (∧-proj₂ Γ⊢φ)
-------------------------------------------------------------------------- ∎
| {
"alphanum_fraction": 0.2662397072,
"avg_line_length": 22.6763485477,
"ext": "agda",
"hexsha": "7ddec09b1e5f811dd269c3789ddd56dab39f3529",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z",
"max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jonaprieto/agda-prop",
"max_forks_repo_path": "src/Data/PropFormula/Theorems/Conjunction.agda",
"max_issues_count": 18,
"max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jonaprieto/agda-prop",
"max_issues_repo_path": "src/Data/PropFormula/Theorems/Conjunction.agda",
"max_line_length": 78,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jonaprieto/agda-prop",
"max_stars_repo_path": "src/Data/PropFormula/Theorems/Conjunction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z",
"num_tokens": 2251,
"size": 5465
} |
------------------------------------------------------------------------
-- Descending lists
--
-- Anders Mörtberg and Chuangjie Xu, October 2019
--
-- We define descending lists via simultaneous definitions and show
-- that they are isomorphic to finite multisets. The conversion from
-- finite multisets to descending lists is exactly insertion sort. We
-- obtain the concatenation operation on descending lists and its
-- properties by transporting those on finite multisets.
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
open import Cubical.Foundations.Everything
open import Cubical.Data.Empty
open import Cubical.Data.Unit
open import Cubical.Data.List using (List ; [] ; _∷_)
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.HITs.FiniteMultiset hiding ([_])
module Cubical.Data.DescendingList.Properties
(A : Type₀)
(_≥_ : A → A → Type₀)
where
open import Cubical.Data.DescendingList.Base A _≥_
toFMSet : DL → FMSet A
toFMSet [] = []
toFMSet (cons x u _) = x ∷ toFMSet u
toList : DL → List A
toList [] = []
toList (cons x u _) = x ∷ toList u
-- "x ≥ ALL the elements of u"
data _≥ᴬ_ (x : A) : List A → Type₀ where
≥ᴬ[] : x ≥ᴬ []
≥ᴬcons : {y : A} {u : List A} → x ≥ y → x ≥ᴬ u → x ≥ᴬ (y ∷ u)
data descending : List A → Type₀ where
[]-descending : descending []
cons-descending : {x : A} {u : List A} → x ≥ᴬ u → descending u → descending (x ∷ u)
module DescendingDL
(≥trans : {x y z : A} → x ≥ y → y ≥ z → x ≥ z)
where
≥≥ᴴtrans : {x y : A} {u : DL}
→ x ≥ y → y ≥ᴴ u → x ≥ᴴ u
≥≥ᴴtrans _ ≥ᴴ[] = ≥ᴴ[]
≥≥ᴴtrans x≥y (≥ᴴcons y≥z) = ≥ᴴcons (≥trans x≥y y≥z)
≥ᴴ→≥ᴬ : {x : A} {u : DL} → x ≥ᴴ u → x ≥ᴬ toList u
≥ᴴ→≥ᴬ ≥ᴴ[] = ≥ᴬ[]
≥ᴴ→≥ᴬ (≥ᴴcons {r = y≥u} x≥y) = ≥ᴬcons x≥y (≥ᴴ→≥ᴬ (≥≥ᴴtrans x≥y y≥u))
descendingDL : (u : DL) → descending (toList u)
descendingDL [] = []-descending
descendingDL (cons x u x≥u) = cons-descending (≥ᴴ→≥ᴬ x≥u) (descendingDL u)
------------------------------------------------------------------------
-- Descending lists are a set.
head≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v}
→ cons x u r ≡ cons y v s → x ≡ y
head≡ {x} = cong head
where
head : DL → A
head [] = x
head (cons z _ _) = z
tail≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v}
→ cons x u r ≡ cons y v s → u ≡ v
tail≡ = cong tail
where
tail : DL → DL
tail [] = []
tail (cons _ u _) = u
caseDL : ∀ {ℓ} → {X : Type ℓ} → (x y : X) → DL → X
caseDL x y [] = x
caseDL x y (cons _ _ _) = y
[]≢cons : {x : A} {u : DL} {r : x ≥ᴴ u} → ¬ ([] ≡ cons x u r)
[]≢cons p = subst (caseDL Unit ⊥) p tt
cons≢[] : {x : A} {u : DL} {r : x ≥ᴴ u} → ¬ (cons x u r ≡ [])
cons≢[] p = subst (caseDL ⊥ Unit) p tt
module isSetDL
(≥isPropValued : {x y : A} → isProp (x ≥ y))
(discreteA : Discrete A)
where
≥ᴴisPropValued : {x : A} {u : DL} → isProp (x ≥ᴴ u)
≥ᴴisPropValued ≥ᴴ[] ≥ᴴ[] = refl
≥ᴴisPropValued (≥ᴴcons x≥y) (≥ᴴcons x≥y') = cong ≥ᴴcons (≥isPropValued x≥y x≥y')
cons≡ : {x y : A} {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v}
→ x ≡ y → u ≡ v → cons x u r ≡ cons y v s
cons≡ {x} p = subst P p d
where
P : A → Type₀
P y = {u v : DL} {r : x ≥ᴴ u} {s : y ≥ᴴ v} → u ≡ v → cons x u r ≡ cons y v s
d : P x
d {u} q = subst Q q c
where
Q : (v : DL) → Type₀
Q v = {r : x ≥ᴴ u} {s : x ≥ᴴ v} → cons x u r ≡ cons x v s
c : Q u
c = cong (cons x u) (≥ᴴisPropValued _ _)
discreteDL : Discrete DL
discreteDL [] [] = yes refl
discreteDL [] (cons y v s) = no []≢cons
discreteDL (cons x u r) [] = no cons≢[]
discreteDL (cons x u r) (cons y v s) with discreteA x y
discreteDL (cons x u r) (cons y v s) | yes x≡y with discreteDL u v
discreteDL (cons x u r) (cons y v s) | yes x≡y | yes u≡v = yes (cons≡ x≡y u≡v)
discreteDL (cons x u r) (cons y v s) | yes x≡y | no u≢v = no (λ e → u≢v (tail≡ e))
discreteDL (cons x u r) (cons y v s) | no x≢y = no (λ e → x≢y (head≡ e))
isSetDL : isSet DL
isSetDL = Discrete→isSet discreteDL
------------------------------------------------------------------------
-- Descending lists are isomorphic to finite multisets.
module IsoToFMSet
(discreteA : Discrete A)
(≥dec : (x y : A) → Dec (x ≥ y))
(≥isPropValued : {x y : A} → isProp (x ≥ y))
(≥trans : {x y z : A} → x ≥ y → y ≥ z → x ≥ z)
(≰→≥ : {x y : A} → ¬ (x ≥ y) → y ≥ x)
(≤≥→≡ : {x y : A} → x ≥ y → y ≥ x → x ≡ y)
where
------------------------------------------------------------------------
-- The insert function
--
-- The type DL is defined simultaneously with the relation _≥ᴴ_.
-- Hence the insert function has to be defined by simultaneously
-- proving a property of _≥ᴴ_.
insert : A → DL → DL
≥ᴴinsert : {x y : A} {u : DL}
→ y ≥ᴴ u → ¬ (x ≥ y) → y ≥ᴴ insert x u
insert x [] = [ x ]
insert x (cons y u r) with ≥dec x y
insert x (cons y u r) | yes x≥y = cons x (cons y u r) (≥ᴴcons x≥y)
insert x (cons y u r) | no x≱y = cons y (insert x u) (≥ᴴinsert r x≱y)
≥ᴴinsert ≥ᴴ[] x≱y = ≥ᴴcons (≰→≥ x≱y)
≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y with ≥dec x z
≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y | yes x≥z = ≥ᴴcons (≰→≥ x≱y)
≥ᴴinsert {x} {y} {cons z u z≥u} (≥ᴴcons y≥z) x≱y | no x≱z = ≥ᴴcons y≥z
open isSetDL ≥isPropValued discreteA
insert-swap : (x y : A) (u : DL)
→ insert x (insert y u) ≡ insert y (insert x u)
insert-swap x y [] with ≥dec x y
insert-swap x y [] | yes x≥y with ≥dec y x
insert-swap x y [] | yes x≥y | yes y≥x = cons≡ (≤≥→≡ x≥y y≥x) (cons≡ (≤≥→≡ y≥x x≥y) refl)
insert-swap x y [] | yes x≥y | no y≱x = cons≡ refl (cons≡ refl refl)
insert-swap x y [] | no x≱y with ≥dec y x
insert-swap x y [] | no x≱y | yes y≥x = cons≡ refl (cons≡ refl refl)
insert-swap x y [] | no x≱y | no y≱x = ⊥-elim (x≱y (≰→≥ y≱x))
insert-swap x y (cons z u z≥u) with ≥dec y z
insert-swap x y (cons z u z≥u) | yes y≥z with ≥dec x y
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y with ≥dec x z
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z with ≥dec y x
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | yes y≥x = cons≡ (≤≥→≡ x≥y y≥x) (cons≡ (≤≥→≡ y≥x x≥y) refl)
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x with ≥dec y z
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x | yes y≥z' = cons≡ refl (cons≡ refl refl)
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | yes x≥z | no y≱x | no y≱z = ⊥-elim (y≱z y≥z)
insert-swap x y (cons z u z≥u) | yes y≥z | yes x≥y | no x≱z = ⊥-elim (x≱z (≥trans x≥y y≥z))
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y with ≥dec x z
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z with ≥dec y x
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z | yes y≥x = cons≡ refl (cons≡ refl refl)
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | yes x≥z | no y≱x = ⊥-elim (x≱y (≰→≥ y≱x))
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z with ≥dec y z
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z | yes y≥z' = cons≡ refl (cons≡ refl refl)
insert-swap x y (cons z u z≥u) | yes y≥z | no x≱y | no x≱z | no y≱z = ⊥-elim (y≱z y≥z)
insert-swap x y (cons z u z≥u) | no y≱z with ≥dec x z
insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z with ≥dec y x
insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | yes y≥x = ⊥-elim (y≱z (≥trans y≥x x≥z))
insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x with ≥dec y z
insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x | yes y≥z = ⊥-elim (y≱z y≥z)
insert-swap x y (cons z u z≥u) | no y≱z | yes x≥z | no y≱x | no y≱z' = cons≡ refl (cons≡ refl refl)
insert-swap x y (cons z u z≥u) | no y≱z | no x≱z with ≥dec y z
insert-swap x y (cons z u z≥u) | no y≱z | no x≱z | yes y≥z = ⊥-elim (y≱z y≥z)
insert-swap x y (cons z u z≥u) | no y≱z | no x≱z | no y≱z' = cons≡ refl (insert-swap x y u)
-- Insertion sort
toDL : FMSet A → DL
toDL = FMSetRec.f isSetDL [] insert insert-swap
{-
toDL [] = []
toDL (x ∷ u) = insert x (toDL u)
toDL (comm x y u i) = insert-swap x y (toDL u) i
toDL (trunc x y p q i j) = isSetDL (toDL x) (toDL y) (cong toDL p) (cong toDL q) i j
-}
insert-cons : (x : A) (u : DL) (r : x ≥ᴴ u)
→ insert x u ≡ cons x u r
insert-cons x [] _ = cons≡ refl refl
insert-cons x (cons y u _) _ with ≥dec x y
insert-cons x (cons y u _) _ | yes x≥y = cons≡ refl refl
insert-cons x (cons y u _) (≥ᴴcons x≥y) | no x≱y = ⊥-elim (x≱y x≥y)
toDL∘toFMSet≡id : (u : DL) → toDL (toFMSet u) ≡ u
toDL∘toFMSet≡id [] = refl
toDL∘toFMSet≡id (cons x u r) i =
hcomp (λ j → λ { (i = i0) → insert x (toDL∘toFMSet≡id u (~ j))
; (i = i1) → cons x u r })
(insert-cons x u r i)
insert-∷ : (x : A) (u : DL)
→ toFMSet (insert x u) ≡ x ∷ toFMSet u
insert-∷ x [] = refl
insert-∷ x (cons y u _) with ≥dec x y
insert-∷ x (cons y u _) | yes x≥y = refl
insert-∷ x (cons y u _) | no x≱y = cong (λ z → y ∷ z) (insert-∷ x u) ∙ comm y x (toFMSet u)
toFMSet∘toDL≡id : (u : FMSet A) → toFMSet (toDL u) ≡ u
toFMSet∘toDL≡id = FMSetElimProp.f (trunc _ _)
refl
(λ x {u} p → insert-∷ x (toDL u) ∙ cong (λ z → x ∷ z) p)
FMSet≡DL : FMSet A ≡ DL
FMSet≡DL = isoToPath (iso toDL toFMSet toDL∘toFMSet≡id toFMSet∘toDL≡id)
------------------------------------------------------------------------
-- Concatenation of sorted lists
--
-- Defined by transporting the one on finite multisets
infixr 30 _++ᴰᴸ_
_++ᴰᴸ_ : DL → DL → DL
_++ᴰᴸ_ = transport (λ i → FMSet≡DL i → FMSet≡DL i → FMSet≡DL i) _++_
[]Path : PathP (λ i → FMSet≡DL i) [] []
[]Path i = transp (λ j → FMSet≡DL (i ∧ j)) (~ i) []
++Path : PathP (λ i → FMSet≡DL i → FMSet≡DL i → FMSet≡DL i) _++_ _++ᴰᴸ_
++Path i = transp (λ j → FMSet≡DL (i ∧ j) → FMSet≡DL (i ∧ j) → FMSet≡DL (i ∧ j)) (~ i) _++_
unitl-++ᴰᴸ : ∀ u → [] ++ᴰᴸ u ≡ u
unitl-++ᴰᴸ = transport (λ i → (u : FMSet≡DL i) → ++Path i ([]Path i) u ≡ u) unitl-++
unitr-++ᴰᴸ : ∀ u → u ++ᴰᴸ [] ≡ u
unitr-++ᴰᴸ = transport (λ i → (u : FMSet≡DL i) → ++Path i u ([]Path i) ≡ u) unitr-++
assoc-++ᴰᴸ : ∀ u v w → u ++ᴰᴸ (v ++ᴰᴸ w) ≡ (u ++ᴰᴸ v) ++ᴰᴸ w
assoc-++ᴰᴸ = transport (λ i → (u v w : FMSet≡DL i)
→ ++Path i u (++Path i v w) ≡ ++Path i (++Path i u v) w)
assoc-++
comm-++ᴰᴸ : ∀ u v → u ++ᴰᴸ v ≡ v ++ᴰᴸ u
comm-++ᴰᴸ = transport (λ i → (u v : FMSet≡DL i) → ++Path i u v ≡ ++Path i v u) comm-++
------------------------------------------------------------------------
-- Converting multisets to (descending) lists
FMSet→List : FMSet A → List A
FMSet→List u = toList (toDL u)
| {
"alphanum_fraction": 0.5072091101,
"avg_line_length": 38.8892857143,
"ext": "agda",
"hexsha": "a7e5c0404e3fdd1838b89e438a1c650c2e8f616e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/DescendingList/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/DescendingList/Properties.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/DescendingList/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4849,
"size": 10889
} |
module main where
open import lib
import string-format
-- for parser for Cedille
open import cedille-types
-- for parser for options files
import options-types
import cedille-options
-- for parser for Cedille comments & whitespace
import cws-types
open import constants
open import general-util
createOptionsFile : (dot-ced-dir : string) → IO ⊤
createOptionsFile dot-ced-dir =
let ops-fp = combineFileNames dot-ced-dir options-file-name in
createDirectoryIfMissing ff (takeDirectory ops-fp) >>
withFile ops-fp WriteMode (flip hPutRope (cedille-options.options-to-rope cedille-options.default-options))
str-bool-to-𝔹 : options-types.str-bool → 𝔹
str-bool-to-𝔹 options-types.StrBoolTrue = tt
str-bool-to-𝔹 options-types.StrBoolFalse = ff
opts-to-options : filepath → options-types.opts → IO cedille-options.options
opts-to-options ofp (options-types.OptsCons (options-types.Lib fps) ops) =
opts-to-options ofp ops >>= λ ops → paths-to-stringset fps >>=r λ ip → record ops { include-path = ip }
where paths-to-stringset : options-types.paths → IO (𝕃 string × stringset)
paths-to-stringset (options-types.PathsCons fp fps) =
let rfp = combineFileNames (takeDirectory (takeDirectory ofp)) fp in
paths-to-stringset fps >>= λ ps →
doesDirectoryExist rfp >>= λ rfpₑ →
doesDirectoryExist fp >>= λ fpₑ →
(if rfpₑ
then (canonicalizePath rfp >>= λ rfp →
return (cedille-options.include-path-insert rfp ps))
else return ps) >>= λ ps →
if fpₑ
then (canonicalizePath fp >>= λ fp →
return (cedille-options.include-path-insert fp ps))
else return ps
paths-to-stringset options-types.PathsNil = return ([] , empty-stringset)
opts-to-options ofp (options-types.OptsCons (options-types.UseCedeFiles b) ops) =
opts-to-options ofp ops >>=r λ ops → record ops { use-cede-files = str-bool-to-𝔹 b }
opts-to-options ofp (options-types.OptsCons (options-types.MakeRktFiles b) ops) =
opts-to-options ofp ops >>=r λ ops → record ops { make-rkt-files = str-bool-to-𝔹 b }
opts-to-options ofp (options-types.OptsCons (options-types.GenerateLogs b) ops) =
opts-to-options ofp ops >>=r λ ops → record ops { generate-logs = str-bool-to-𝔹 b }
opts-to-options ofp (options-types.OptsCons (options-types.ShowQualifiedVars b) ops) =
opts-to-options ofp ops >>=r λ ops → record ops { show-qualified-vars = str-bool-to-𝔹 b }
opts-to-options ofp (options-types.OptsCons (options-types.EraseTypes b) ops) =
opts-to-options ofp ops >>=r λ ops → record ops { erase-types = str-bool-to-𝔹 b }
opts-to-options ofp options-types.OptsNil = return cedille-options.default-options
-- helper function to try to parse the options file
processOptions : filepath → string → IO (string ⊎ cedille-options.options)
processOptions filename s with options-types.scanOptions s
...| options-types.Left cs = return (inj₁ ("Parse error in file " ^ filename ^ " " ^ cs ^ "."))
...| options-types.Right (options-types.File oo) =
opts-to-options filename oo
>>= λ opts → if cedille-options.options.make-rkt-files opts
then return ∘ inj₁ $ "Racket compilation disabled, please set to false in " ^ filename ^ "."
else (return ∘ inj₂ $ opts)
getOptionsFile : (filepath : string) → string
getOptionsFile fp = combineFileNames (dot-cedille-directory fp) options-file-name
findOptionsFile : (filepath : string) → IO (maybe string)
findOptionsFile fp = h fp (pred (length (splitPath fp))) where
h : string → ℕ → IO (maybe string)
h fp 0 = return nothing
h fp (suc n) =
let fpc = getOptionsFile fp in
doesFileExist fpc >>= λ where
ff → h (takeDirectory fp) n
tt → return (just fpc)
readOptions : IO (string × cedille-options.options)
readOptions =
getCurrentDirectory >>=
canonicalizePath >>=
findOptionsFile >>= λ where
nothing →
getHomeDirectory >>=
canonicalizePath >>= λ home →
createOptionsFile (dot-cedille-directory home) >>r
dot-cedille-directory home , cedille-options.default-options
(just fp) → readFiniteFile fp >>= λ fc →
processOptions fp fc >>= λ where
(inj₁ err) →
putStrLn (global-error-string err) >>r
fp , cedille-options.default-options
(inj₂ ops) → return (fp , ops)
module main-with-options
(compileTime : UTC)
(options-filepath : filepath)
(options : cedille-options.options) where
open import ctxt
open import monad-instances
open import process-cmd options {IO}
open import parser
open import spans options {IO}
open import syntax-util
open import to-string options
open import toplevel-state options {IO}
import interactive-cmds
open import rkt options
open import elaboration options
logFilepath : IO filepath
logFilepath = getHomeDirectory >>=r λ home →
combineFileNames (dot-cedille-directory home) "log"
maybeClearLogFile : IO ⊤
maybeClearLogFile = if cedille-options.options.generate-logs options then
logFilepath >>= clearFile
else
return triv
logRope : rope → IO ⊤
logRope s with cedille-options.options.generate-logs options
...| ff = return triv
...| tt = getCurrentTime >>= λ time →
logFilepath >>= λ fn →
withFile fn AppendMode λ hdl →
hPutRope hdl ([[ "([" ^ utcToString time ^ "] " ]] ⊹⊹ s ⊹⊹ [[ ")\n" ]])
logMsg : (message : string) → IO ⊤
logMsg msg = logRope [[ msg ]]
sendProgressUpdate : string → IO ⊤
sendProgressUpdate msg = putStr "progress: " >> putStr msg >> putStr "\n"
progressUpdate : (filename : string) → (do-check : 𝔹) → IO ⊤
progressUpdate filename do-check =
sendProgressUpdate ((if do-check then "Checking " else "Skipping ") ^ filename)
fileBaseName : filepath → string
fileBaseName fn = base-filename (takeFileName fn)
{-------------------------------------------------------------------------------
.cede support
-------------------------------------------------------------------------------}
cede-suffix = ".cede"
rkt-suffix = ".rkt"
ced-aux-filename : (suffix ced-path : filepath) → filepath
ced-aux-filename sfx ced-path =
let dir = takeDirectory ced-path in
combineFileNames (dot-cedille-directory dir) (fileBaseName ced-path ^ sfx)
cede-filename = ced-aux-filename cede-suffix
rkt-filename = ced-aux-filename rkt-suffix
maybe-write-aux-file : include-elt → (create-dot-ced-if-missing : IO ⊤) → (filename file-suffix : filepath) → (cedille-options.options → 𝔹) → (include-elt → 𝔹) → rope → IO ⊤
maybe-write-aux-file ie mk-dot-ced fn sfx f f' r with f options && ~ f' ie
...| ff = return triv
...| tt = mk-dot-ced >>
logMsg ("Starting writing " ^ sfx ^ " file " ^ fn) >>
writeRopeToFile fn r >>
logMsg ("Finished writing " ^ sfx ^ " file " ^ fn)
write-aux-files : toplevel-state → filepath → IO ⊤
write-aux-files s filename with get-include-elt-if s filename
...| nothing = return triv
...| just ie =
let dot-ced = createDirectoryIfMissing ff (dot-cedille-directory (takeDirectory filename)) in
maybe-write-aux-file ie dot-ced (cede-filename filename) cede-suffix
cedille-options.options.use-cede-files
include-elt.cede-up-to-date
((if include-elt.err ie then [[ "e" ]] else [[]]) ⊹⊹ include-elt-spans-to-rope ie) >>
maybe-write-aux-file ie dot-ced (rkt-filename filename) rkt-suffix
cedille-options.options.make-rkt-files
include-elt.rkt-up-to-date
(to-rkt-file filename (toplevel-state.Γ s) ie rkt-filename)
-- we assume the cede file is known to exist at this point
read-cede-file : (ced-path : filepath) → IO (𝔹 × string)
read-cede-file ced-path =
let cede = cede-filename ced-path in
logMsg ("Started reading .cede file " ^ cede) >>
get-file-contents cede >>= finish >≯
logMsg ("Finished reading .cede file " ^ cede)
where finish : maybe string → IO (𝔹 × string)
finish nothing = return (tt , global-error-string ("Could not read the file " ^ cede-filename ced-path ^ "."))
finish (just ss) with string-to-𝕃char ss
finish (just ss) | ('e' :: ss') = forceFileRead ss >>r tt , 𝕃char-to-string ss'
finish (just ss) | _ = forceFileRead ss >>r ff , ss
add-cedille-extension : string → string
add-cedille-extension x = x ^ "." ^ cedille-extension
-- Allows you to say "import FOO.BAR.BAZ" rather than "import FOO/BAR/BAZ"
replace-dots : filepath → filepath
replace-dots s = 𝕃char-to-string (h (string-to-𝕃char s)) where
h : 𝕃 char → 𝕃 char
h ('.' :: '.' :: cs) = '.' :: '.' :: h cs
h ('.' :: cs) = pathSeparator :: h cs
h (c :: cs) = c :: h cs
h [] = []
find-imported-file : (dirs : 𝕃 filepath) → (unit-name : string) → IO (maybe filepath)
find-imported-file [] unit-name = return nothing
find-imported-file (dir :: dirs) unit-name =
let e = combineFileNames dir (add-cedille-extension unit-name) in
doesFileExist e >>= λ where
ff → find-imported-file dirs unit-name
tt → canonicalizePath e >>=r just
find-imported-files : (dirs : 𝕃 filepath) → (imports : 𝕃 string) → IO (𝕃 (string × filepath))
find-imported-files dirs (u :: us) =
find-imported-file dirs (replace-dots u) >>= λ where
nothing → logMsg ("Error finding file: " ^ replace-dots u) >> find-imported-files dirs us
(just fp) → logMsg ("Found import: " ^ fp) >> find-imported-files dirs us >>=r (u , fp) ::_
find-imported-files dirs [] = return []
{- new parser test integration -}
reparse : toplevel-state → filepath → IO toplevel-state
reparse st filename =
doesFileExist filename >>= λ b →
(if b then
(readFiniteFile filename >>= λ s → getCurrentTime >>= λ time → processText s >>=r λ ie → set-last-parse-time-include-elt ie time)
else return (error-include-elt ("The file " ^ filename ^ " could not be opened for reading.")))
>>=r set-include-elt st filename
where processText : string → IO include-elt
processText x with parseStart x
processText x | Left (Left cs) = return (error-span-include-elt ("Error in file " ^ filename ^ ".") "Lexical error." cs)
processText x | Left (Right cs) = return (error-span-include-elt ("Error in file " ^ filename ^ ".") "Parsing error." cs)
processText x | Right t with cws-types.scanComments x
processText x | Right t | t2 = find-imported-files (fst (cedille-options.include-path-insert (takeDirectory filename) (toplevel-state.include-path st)))
(get-imports t) >>= λ deps →
logMsg ("deps for file " ^ filename ^ ": " ^ 𝕃-to-string (λ {(a , b) → "short: " ^ a ^ ", long: " ^ b}) ", " deps) >>r
new-include-elt filename deps t t2 nothing
reparse-file : filepath → toplevel-state → IO toplevel-state
reparse-file filename s =
reparse s filename >>=r λ s →
set-include-elt s filename
(set-cede-file-up-to-date-include-elt
(set-do-type-check-include-elt
(get-include-elt s filename) tt) ff)
infixl 1 _&&>>_
_&&>>_ : IO 𝔹 → IO 𝔹 → IO 𝔹
(a &&>> b) = a >>= λ a → if a then b else return ff
aux-up-to-date : filepath → toplevel-state → IO toplevel-state
aux-up-to-date filename s =
let rkt = rkt-filename filename in
doesFileExist rkt &&>> fileIsOlder filename rkt >>=r
(set-include-elt s filename ∘ (set-rkt-file-up-to-date-include-elt (get-include-elt s filename)))
ie-up-to-date : filepath → include-elt → IO 𝔹
ie-up-to-date filename ie =
getModificationTime filename >>=r λ mt →
maybe-else ff (λ lpt → lpt utc-after mt) (include-elt.last-parse-time ie)
import-changed : toplevel-state → filepath → (import-file : string) → IO 𝔹
import-changed s filename import-file =
let dtc = include-elt.do-type-check (get-include-elt s import-file)
cede = cede-filename filename
cede' = cede-filename import-file in
case cedille-options.options.use-cede-files options of λ where
ff → return dtc
tt → doesFileExist cede &&>> doesFileExist cede' >>= λ where
ff → return ff
tt → fileIsOlder cede cede' >>=r λ fio → dtc || fio
any-imports-changed : toplevel-state → filepath → (imports : 𝕃 string) → IO 𝔹
any-imports-changed s filename [] = return ff
any-imports-changed s filename (h :: t) =
import-changed s filename h >>= λ where
tt → return tt
ff → any-imports-changed s filename t
file-after-compile : filepath → IO 𝔹
file-after-compile fn =
getModificationTime fn >>= λ mt →
case mt utc-after compileTime of λ where
tt → doesFileExist options-filepath &&>> fileIsOlder options-filepath fn
ff → return ff
ensure-ast-depsh : filepath → toplevel-state → IO toplevel-state
ensure-ast-depsh filename s with get-include-elt-if s filename
...| just ie = ie-up-to-date filename ie >>= λ where
ff → reparse-file filename s
tt → return s
...| nothing =
let cede = cede-filename filename in
return (cedille-options.options.use-cede-files options) &&>>
doesFileExist cede &&>>
fileIsOlder filename cede &&>>
file-after-compile cede >>= λ where
ff → reparse-file filename s
tt → reparse s filename >>= λ s →
read-cede-file filename >>= λ where
(err , ss) → return
(set-include-elt s filename
(set-do-type-check-include-elt
(set-need-to-add-symbols-to-context-include-elt
(set-spans-string-include-elt
(get-include-elt s filename) err ss) tt) ff))
{- helper function for update-asts, which keeps track of the files we have seen so
we avoid importing the same file twice, and also avoid following cycles in the import
graph. -}
{-# TERMINATING #-}
update-astsh : stringset {- seen already -} → toplevel-state → filepath →
IO (stringset {- seen already -} × toplevel-state)
update-astsh seen s filename =
if stringset-contains seen filename then return (seen , s)
else (ensure-ast-depsh filename s >>= aux-up-to-date filename >>= cont (stringset-insert seen filename))
where cont : stringset → toplevel-state → IO (stringset × toplevel-state)
cont seen s with get-include-elt s filename
cont seen s | ie with include-elt.deps ie
cont seen s | ie | ds =
proc seen s ds
where proc : stringset → toplevel-state → 𝕃 string → IO (stringset × toplevel-state)
proc seen s [] = any-imports-changed s filename ds >>=r λ changed →
seen , set-include-elt s filename (set-do-type-check-include-elt ie (include-elt.do-type-check ie || changed))
proc seen s (d :: ds) = update-astsh seen s d >>= λ p →
proc (fst p) (snd p) ds
{- this function updates the ast associated with the given filename in the toplevel state.
So if we do not have an up-to-date .cede file (i.e., there is no such file at all,
or it is older than the given file), reparse the file. We do this recursively for all
dependencies (i.e., imports) of the file. -}
update-asts : toplevel-state → filepath → IO toplevel-state
update-asts s filename = update-astsh empty-stringset s filename >>=r snd
log-files-to-check : toplevel-state → IO ⊤
log-files-to-check s = logRope ([[ "\n" ]] ⊹⊹ (h (trie-mappings (toplevel-state.is s)))) where
h : 𝕃 (string × include-elt) → rope
h [] = [[]]
h ((fn , ie) :: t) = [[ "file: " ]] ⊹⊹ [[ fn ]] ⊹⊹ [[ "\nadd-symbols: " ]] ⊹⊹ [[ 𝔹-to-string (include-elt.need-to-add-symbols-to-context ie) ]] ⊹⊹ [[ "\ndo-type-check: " ]] ⊹⊹ [[ 𝔹-to-string (include-elt.do-type-check ie) ]] ⊹⊹ [[ "\n\n" ]] ⊹⊹ h t
{- this function checks the given file (if necessary), updates .cede and .rkt files (again, if necessary), and replies on stdout if appropriate -}
checkFile : toplevel-state → filepath → (should-print-spans : 𝔹) → IO toplevel-state
checkFile s filename should-print-spans =
update-asts s filename >>= λ s →
log-files-to-check s >>
logMsg (𝕃-to-string (λ {(im , fn) → "im: " ^ im ^ ", fn: " ^ fn}) "; " (trie-mappings (include-elt.import-to-dep (get-include-elt s filename)))) >>
process-file progressUpdate s filename (fileBaseName filename) >>= finish
where
reply : toplevel-state → IO ⊤
reply s with get-include-elt-if s filename
reply s | nothing = putStrLn (global-error-string ("Internal error looking up information for file " ^ filename ^ "."))
reply s | just ie =
if should-print-spans then
putRopeLn (include-elt-spans-to-rope ie)
else return triv
finish : toplevel-state × mod-info → IO toplevel-state
finish (s @ (mk-toplevel-state ip mod is Γ) , ret-mod) =
logMsg ("Started reply for file " ^ filename) >> -- Lazy, so checking has not been calculated yet?
reply s >>
logMsg ("Finished reply for file " ^ filename) >>
logMsg ("Files with updated spans:\n" ^ 𝕃-to-string (λ x → x) "\n" mod) >>
let Γ = ctxt-set-current-mod Γ ret-mod in
writeo mod >>r -- Should process-file now always add files to the list of modified ones because now the cede-/rkt-up-to-date fields take care of whether to rewrite them?
mk-toplevel-state ip mod is Γ
where
writeo : 𝕃 string → IO ⊤
writeo [] = return triv
writeo (f :: us) =
writeo us >>
-- let ie = get-include-elt s f in
write-aux-files s f
-- (if cedille-options.options.make-rkt-files options && ~ include-elt.rkt-up-to-date ie then (write-rkt-file f (toplevel-state.Γ s) ie rkt-filename) else return triv)
-- this is the function that handles requests (from the frontend) on standard input
{-# TERMINATING #-}
readCommandsFromFrontend : toplevel-state → IO ⊤
readCommandsFromFrontend s =
getLine >>= λ input →
logMsg ("Frontend input: " ^ input) >>
let input-list : 𝕃 string
input-list = (string-split (undo-escape-string input) delimiter)
in (handleCommands input-list s) >>= λ s →
readCommandsFromFrontend s
where
delimiter : char
delimiter = '§'
errorCommand : 𝕃 string → toplevel-state → IO ⊤
errorCommand ls s = putStrLn (global-error-string "Invalid command sequence \\\\\"" ^ (𝕃-to-string (λ x → x) ", " ls) ^ "\\\\\".")
debugCommand : toplevel-state → IO ⊤
debugCommand s = putStrLn (escape-string (toplevel-state-to-string s))
checkCommand : 𝕃 string → toplevel-state → IO toplevel-state
checkCommand (input :: []) s = canonicalizePath input >>= λ input-filename →
checkFile (set-include-path s (cedille-options.include-path-insert (takeDirectory input-filename) (toplevel-state.include-path s)))
input-filename tt {- should-print-spans -}
checkCommand ls s = errorCommand ls s >>r s
{- findCommand : 𝕃 string → toplevel-state → IO toplevel-state
findCommand (symbol :: []) s = putStrLn (find-symbols-to-JSON symbol (toplevel-state-lookup-occurrences symbol s)) >>= λ x → return s
findCommand _ s = errorCommand s -}
handleCommands : 𝕃 string → toplevel-state → IO toplevel-state
handleCommands ("progress stub" :: xs) = return
handleCommands ("status ping" :: xs) s = putStrLn "idle" >> return s
handleCommands ("check" :: xs) s = checkCommand xs s
handleCommands ("debug" :: []) s = debugCommand s >>r s
handleCommands ("elaborate" :: x :: x' :: []) s = elab-all s x x' >>r s
handleCommands ("interactive" :: xs) s = interactive-cmds.interactive-cmd options xs s >>r s
-- handleCommands ("find" :: xs) s = findCommand xs s
handleCommands xs s = errorCommand xs s >>r s
-- function to process command-line arguments
processArgs : 𝕃 string → IO ⊤
-- this is the case for when we are called with a single command-line argument, the name of the file to process
processArgs (input-filename :: []) =
canonicalizePath input-filename >>= λ input-filename →
checkFile (new-toplevel-state (cedille-options.include-path-insert (takeDirectory input-filename) (cedille-options.options.include-path options)))
input-filename ff {- should-print-spans -} >>= finish input-filename
where finish : string → toplevel-state → IO ⊤
finish input-filename s = return triv
{- let ie = get-include-elt s input-filename in
if include-elt.err ie then (putRopeLn (include-elt-spans-to-rope ie)) else return triv
-}
-- this is the case where we will go into a loop reading commands from stdin, from the fronted
processArgs [] = readCommandsFromFrontend (new-toplevel-state (cedille-options.options.include-path options))
-- all other cases are errors
processArgs xs = putStrLn ("Run with the name of one file to process, or run with no command-line arguments and enter the\n"
^ "names of files one at a time followed by newlines (this is for the emacs mode).")
main' : IO ⊤
main' =
maybeClearLogFile >>
logMsg ("Started Cedille process (compiled at: " ^ utcToString compileTime ^ ")") >>
getArgs >>=
processArgs
postulate
initializeStdinToUTF8 : IO ⊤
setStdinNewlineMode : IO ⊤
compileTime : UTC
templatesDir : filepath
{-# FOREIGN GHC {-# LANGUAGE TemplateHaskell #-} #-}
{-# FOREIGN GHC import qualified System.IO #-}
{-# FOREIGN GHC import qualified Data.Time.Clock #-}
{-# FOREIGN GHC import qualified Data.Time.Format #-}
{-# FOREIGN GHC import qualified Data.Time.Clock.POSIX #-}
{-# FOREIGN GHC import qualified Language.Haskell.TH.Syntax #-}
{-# COMPILE GHC initializeStdinToUTF8 = System.IO.hSetEncoding System.IO.stdin System.IO.utf8 #-}
{-# COMPILE GHC setStdinNewlineMode = System.IO.hSetNewlineMode System.IO.stdin System.IO.universalNewlineMode #-}
{-# COMPILE GHC compileTime =
maybe (Data.Time.Clock.POSIX.posixSecondsToUTCTime (fromIntegral 0)) id
(Data.Time.Format.parseTimeM True Data.Time.Format.defaultTimeLocale "%s"
$(Language.Haskell.TH.Syntax.runIO
(Data.Time.Clock.getCurrentTime >>= \ t ->
return (Language.Haskell.TH.Syntax.LitE
(Language.Haskell.TH.Syntax.StringL
(Data.Time.Format.formatTime Data.Time.Format.defaultTimeLocale "%s" t)))))
:: Maybe Data.Time.Clock.UTCTime) #-}
-- main entrypoint for the backend
main : IO ⊤
main = initializeStdoutToUTF8 >>
initializeStdinToUTF8 >>
setStdoutNewlineMode >>
setStdinNewlineMode >>
setToLineBuffering >>
readOptions >>=
uncurry (main-with-options.main' compileTime)
| {
"alphanum_fraction": 0.6324940822,
"avg_line_length": 48.3056133056,
"ext": "agda",
"hexsha": "6c445e2e02226c3fdd5d4c769962b6ab818102e2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xoltar/cedille",
"max_issues_repo_path": "src/main.agda",
"max_line_length": 251,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/main.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6247,
"size": 23235
} |
{-# OPTIONS --without-K #-}
module Story where
{--
PiCat level 0:
Objects: Finite sets viewed as discrete-groupoids
Morphisms: Permutations between finite sets viewed as permutation-groupoids
Equivalence: Strong Equivalence of categories
Discrete-Groupoids:
Objects: Parameterized
Morphisms: Only id
Equivalence: ≡
Permutation-Groupoids: each permutation is a 1-1 function
Objects: Finite Sets (or Enumerations)
Morphisms: A morphism represents a swap of two elements by the permutation
Equivalence: ≡
------
PiCat level 1:
Objects: Finite sets viewed as discrete-groupoids
Morphisms: Permutations between finite sets viewed as permutation-groupoids
Equivalence: Equivalence-of-Permutations-groupoids
Discrete-Groupoids:
Objects: Parameterized
Morphisms: Only id
Equivalence: ≡
Permutation-Groupoids: each permutation is a 1-1 function
Objects: Finite Sets (or Enumerations)
Morphisms: A morphism represents a swap of two elements by the permutation
Equivalence: ≡
Equivalance-of-Permutations-Groupoids:
Objects: Permutation-Groupoids
Morphisms: ??
Equivalence: Strong Equivalence of categories
--}
| {
"alphanum_fraction": 0.7462437396,
"avg_line_length": 26.0434782609,
"ext": "agda",
"hexsha": "ce82272c7d96498e850ee9a38d763e028f6c42ea",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Story.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Story.agda",
"max_line_length": 79,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Story.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 309,
"size": 1198
} |
------------------------------------------------------------------------------
-- Testing the existential quantifier
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Existential where
postulate
D : Set
A : D → Set
∃ : (A : D → Set) → Set
postulate foo : (∃ λ x → A x) → (∃ λ x → A x)
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.3619047619,
"avg_line_length": 27.6315789474,
"ext": "agda",
"hexsha": "dc5a5bd85c61671e3b00a528ca64d81c3f0c1517",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/Existential.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/Existential.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/Existential.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 103,
"size": 525
} |
{-# OPTIONS --without-K #-}
module Homotopy where
open import GroupoidStructure
open import PathOperations
open import Types
infix 1 _∼_
_∼_ : ∀ {a b} {A : Set a} {B : Set b}
(f g : A → B) → Set _
f ∼ g = ∀ x → f x ≡ g x
naturality : ∀ {a b} {A : Set a} {B : Set b} {x y : A}
(f g : A → B) (H : f ∼ g) (p : x ≡ y) →
H x · ap g p ≡ ap f p · H y
naturality f g H = J
(λ x y p → H x · ap g p ≡ ap f p · H y)
(λ _ → p·id _) _ _
| {
"alphanum_fraction": 0.5056947608,
"avg_line_length": 21.95,
"ext": "agda",
"hexsha": "01ff81d2d11e8d7c15ce158970eb7a4c279fe19c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/Homotopy.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/Homotopy.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/Homotopy.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 197,
"size": 439
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.Equivalence2
open import lib.Relation2
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.TLevel
module lib.NType2 where
module _ {i} {A : Type i} where
abstract
has-dec-onesided-eq-is-prop : {x : A} → is-prop (has-dec-onesided-eq x)
has-dec-onesided-eq-is-prop {x = x} = inhab-to-prop-is-prop λ dec →
Π-level λ y → Dec-level (dec-onesided-eq-is-prop x dec y)
has-dec-eq-is-prop : is-prop (has-dec-eq A)
has-dec-eq-is-prop = Π-level (λ _ → has-dec-onesided-eq-is-prop)
module _ {i j} {A : Type i} {B : A → Type j} where
abstract
↓-level : {a b : A} {p : a == b} {u : B a} {v : B b} {n : ℕ₋₂}
→ has-level (S n) (B b) → has-level n (u == v [ B ↓ p ])
↓-level {p = idp} k = has-level-apply k _ _
↓-preserves-level : {a b : A} {p : a == b} {u : B a} {v : B b} {n : ℕ₋₂}
→ has-level n (B b) → has-level n (u == v [ B ↓ p ])
↓-preserves-level {p = idp} = =-preserves-level
prop-has-all-paths-↓ : {x y : A} {p : x == y} {u : B x} {v : B y}
{{_ : is-prop (B y)}} → u == v [ B ↓ p ]
prop-has-all-paths-↓ {p = idp} = prop-has-all-paths _ _
set-↓-has-all-paths-↓ : ∀ {k} {C : Type k}
{x y : C → A} {p : (t : C) → x t == y t} {u : (t : C) → B (x t)} {v : (t : C) → B (y t)}
{a b : C} {q : a == b} {α : u a == v a [ B ↓ p a ]} {β : u b == v b [ B ↓ p b ]}
{{_ : is-set (B (y a))}} → α == β [ (λ t → u t == v t [ B ↓ p t ]) ↓ q ]
set-↓-has-all-paths-↓ {q = idp} {{p}} = lemma _ p
where
lemma : {x y : A} (p : x == y) {u : B x} {v : B y} {α β : u == v [ B ↓ p ]}
→ is-set (B y) → α == β
lemma idp k = contr-center (has-level-apply (has-level-apply k _ _) _ _)
abstract
-- Every map between contractible types is an equivalence
contr-to-contr-is-equiv : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
→ (is-contr A → is-contr B → is-equiv f)
contr-to-contr-is-equiv f cA cB =
is-eq f (λ _ → contr-center cA) (λ b → ! (contr-path cB _) ∙ contr-path cB b) (contr-path cA)
is-contr-is-prop : ∀ {i} {A : Type i} → is-prop (is-contr A)
is-contr-is-prop {A = A} = all-paths-is-prop is-contr-is-prop-aux
where
lemma : (x : is-contr A) (b a : A) (p : b == a)
→ contr-path x a == contr-path x b ∙' p
lemma x b ._ idp = idp
is-contr-is-prop-aux : (x y : is-contr A) → x == y
is-contr-is-prop-aux x y =
ap has-level-in
(pair= (contr-path x (contr-center y))
(↓-Π-cst-app-in (λ a → ↓-idf=cst-in' (lemma x (contr-center y) a (contr-path y a)))))
has-level-is-prop : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ is-prop (has-level n A)
has-level-is-prop {n = ⟨-2⟩} = is-contr-is-prop
has-level-is-prop {n = S n} {A} = equiv-preserves-level e {{has-level-aux-prop}} where
has-level-aux-prop : is-prop (has-level-aux (S n) A)
has-level-aux-prop = Π-level (λ x → Π-level (λ y → has-level-is-prop))
e : has-level-aux (S n) A ≃ has-level (S n) A
fst e = has-level-in
is-equiv.g (snd e) = has-level-apply
is-equiv.f-g (snd e) = λ _ → idp
is-equiv.g-f (snd e) = λ _ → idp
is-equiv.adj (snd e) = λ _ → idp
instance
has-level-level : ∀ {i} {n m : ℕ₋₂} {A : Type i}
→ has-level (S m) (has-level n A)
has-level-level {m = ⟨-2⟩} = has-level-is-prop
has-level-level {m = S m} = raise-level _ has-level-level
{- Subtypes. -}
module _ {i j} {A : Type i} (P : SubtypeProp A j) where
private
module P = SubtypeProp P
instance
Subtype-level : ∀ {n : ℕ₋₂}
{{_ : has-level (S n) A}}
→ has-level (S n) (Subtype P)
Subtype-level = Σ-level ⟨⟩ (λ x → prop-has-level-S (P.level x))
Subtype= : (x y : Subtype P) → Type i
Subtype= x y = fst x == fst y
Subtype=-out : ∀ {x y : Subtype P} → Subtype= x y → x == y
Subtype=-out p = pair= p (prop-has-all-paths-↓ {{P.level _}})
Subtype=-β : {x y : Subtype P} (p : Subtype= x y)
→ fst= (Subtype=-out {x = x} {y = y} p) == p
Subtype=-β idp = fst=-β idp _
Subtype=-η : {x y : Subtype P} (p : x == y)
→ Subtype=-out (fst= p) == p
Subtype=-η idp = ap (pair= idp)
(contr-has-all-paths {{has-level-apply (P.level _) _ _}} _ _)
Subtype=-econv : (x y : Subtype P) → (Subtype= x y) ≃ (x == y)
Subtype=-econv x y = equiv Subtype=-out fst= Subtype=-η Subtype=-β
abstract
Subtype-∙ : ∀ {x y z : Subtype P}
(p : Subtype= x y) (q : Subtype= y z)
→ (Subtype=-out {x} {y} p ∙ Subtype=-out {y} {z} q)
== Subtype=-out {x} {z} (p ∙ q)
Subtype-∙ {x} {y} {z} p q =
Subtype=-out p ∙ Subtype=-out q
=⟨ Σ-∙ {p = p} {p' = q} (prop-has-all-paths-↓ {{P.level (fst y)}}) (prop-has-all-paths-↓ {{P.level (fst z)}}) ⟩
pair= (p ∙ q) (prop-has-all-paths-↓ {p = p} {{P.level (fst y)}} ∙ᵈ prop-has-all-paths-↓ {{P.level (fst z)}})
=⟨ contr-has-all-paths {{↓-level (P.level (fst z))}} _ (prop-has-all-paths-↓ {{P.level (fst z)}})
|in-ctx pair= (p ∙ q) ⟩
Subtype=-out (p ∙ q)
=∎
-- Groupoids
is-gpd : {i : ULevel} → Type i → Type i
is-gpd = has-level 1
-- Type of all n-truncated types
-- TODO: redefine it like that, so that instance arguments can work
-- record _-Type_ (n : ℕ₋₂) (i : ULevel) : Type (lsucc i) where
-- constructor _,_
-- field
-- El : Type i
-- {{El-level}} : has-level n El
-- open _-Type_ public
has-level-prop : ∀ {i} → ℕ₋₂ → SubtypeProp (Type i) i
has-level-prop n = has-level n , λ _ → has-level-is-prop
_-Type_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i)
n -Type i = Subtype (has-level-prop {i} n)
hProp : (i : ULevel) → Type (lsucc i)
hProp i = -1 -Type i
hSet : (i : ULevel) → Type (lsucc i)
hSet i = 0 -Type i
_-Type₀ : (n : ℕ₋₂) → Type₁
n -Type₀ = n -Type lzero
hProp₀ = hProp lzero
hSet₀ = hSet lzero
-- [n -Type] is an (n+1)-type
abstract
≃-contr : ∀ {i j} {A : Type i} {B : Type j}
→ is-contr A → is-contr B → is-contr (A ≃ B)
≃-contr pA pB = has-level-in
((cst (contr-center pB) , contr-to-contr-is-equiv _ pA pB)
, (λ e → pair= (λ= (λ _ → contr-path pB _))
(from-transp is-equiv _ (prop-path is-equiv-is-prop _ _))))
instance
≃-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j}
→ (has-level n A → has-level n B → has-level n (A ≃ B))
≃-level {n = ⟨-2⟩} = ≃-contr
≃-level {n = S n} pA pB = Σ-level ⟨⟩ ⟨⟩ where instance _ = pA; _ = pB
universe-=-level : ∀ {i} {n : ℕ₋₂} {A B : Type i}
→ (has-level n A → has-level n B → has-level n (A == B))
universe-=-level pA pB = equiv-preserves-level ua-equiv where instance _ = pA; _ = pB
module _ {i} {n} where
private
prop : SubtypeProp {lsucc i} (Type i) i
prop = has-level-prop n
nType= : (A B : n -Type i) → Type (lsucc i)
nType= = Subtype= prop
nType=-out : {A B : n -Type i} → nType= A B → A == B
nType=-out = Subtype=-out prop
abstract
nType=-β : {A B : n -Type i} (p : nType= A B)
→ fst= (nType=-out {A = A} {B = B} p) == p
nType=-β = Subtype=-β prop
nType=-η : {A B : n -Type i} (p : A == B)
→ nType=-out (fst= p) == p
nType=-η = Subtype=-η prop
nType=-econv : (A B : n -Type i) → (nType= A B) ≃ (A == B)
nType=-econv = Subtype=-econv prop
nType-∙ : {A B C : n -Type i}
(p : nType= A B) (q : nType= B C)
→ (nType=-out {A = A} p ∙ nType=-out {A = B} q)
== nType=-out {A = A} {B = C} (p ∙ q)
nType-∙ = Subtype-∙ prop
abstract
instance
_-Type-level_ : (n : ℕ₋₂) (i : ULevel)
→ has-level (S n) (n -Type i)
(n -Type-level i) = has-level-in (λ { (A , pA) (B , pB) → aux A B pA pB}) where
aux : (A B : Type i) (pA : has-level n A) (pB : has-level n B) → has-level n ((A , pA) == (B , pB))
aux A B pA pB = equiv-preserves-level (nType=-econv (A , ⟨⟩) (B , ⟨⟩)) where instance _ = pA; _ = pB
hProp-is-set : (i : ULevel) → is-set (hProp i)
hProp-is-set i = -1 -Type-level i
hSet-level : (i : ULevel) → has-level 1 (hSet i)
hSet-level i = 0 -Type-level i
{- The following two lemmas are in NType2 instead of NType because of cyclic
dependencies -}
module _ {i} {A : Type i} where
abstract
raise-level-<T : {m n : ℕ₋₂} → (m <T n) → has-level m A → has-level n A
raise-level-<T ltS = raise-level _
raise-level-<T (ltSR lt) = raise-level _ ∘ raise-level-<T lt
raise-level-≤T : {m n : ℕ₋₂} → (m ≤T n) → has-level m A → has-level n A
raise-level-≤T (inl p) = transport (λ t → has-level t A) p
raise-level-≤T (inr lt) = raise-level-<T lt
| {
"alphanum_fraction": 0.5313964386,
"avg_line_length": 35.1275720165,
"ext": "agda",
"hexsha": "873aeb0340226e68875c0729779f80ccf25f3e49",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/NType2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/NType2.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/NType2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3394,
"size": 8536
} |
{-# OPTIONS --without-K --safe #-}
module RealsRefactored where
open import Algebra
open import Data.Bool.Base using (Bool; if_then_else_)
open import Function.Base using (_∘_)
open import Data.Integer.Base as ℤ
using (ℤ; +_; +0; +[1+_]; -[1+_])
import Data.Integer.Properties as ℤP
open import Data.Integer.DivMod as ℤD
open import Data.Nat as ℕ using (ℕ; zero; suc)
open import Data.Nat.Properties as ℕP using (≤-step)
import Data.Nat.DivMod as ℕD
open import Level using (0ℓ)
open import Data.Product
open import Relation.Nullary
open import Relation.Nullary.Negation using (contraposition)
open import Relation.Nullary.Decidable
open import Relation.Unary using (Pred)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; refl; cong; sym; subst; trans; ≢-sym)
open import Relation.Binary
open import Data.Rational.Unnormalised as ℚ using (ℚᵘ; mkℚᵘ; _≢0; _/_; 0ℚᵘ; 1ℚᵘ; ↥_; ↧_; ↧ₙ_)
import Data.Rational.Unnormalised.Properties as ℚP
open import Algebra.Bundles
open import Algebra.Structures
open import Data.Empty
open import Data.Sum
open import Data.Maybe.Base
import NonReflectiveQ as ℚ-Solver
import NonReflectiveZ as ℤ-Solver
open import Data.List
open ℚᵘ
record ℝ : Set where
constructor mkℝ
field
-- No n≢0 condition for seq
seq : ℕ -> ℚᵘ
reg : ∀ (m n : ℕ) -> {m≢0 : m ≢0} -> {n≢0 : n ≢0} ->
ℚ.∣ seq m ℚ.- seq n ∣ ℚ.≤ ((+ 1) / m) {m≢0} ℚ.+ ((+ 1) / n) {n≢0}
open ℝ
infix 4 _≃_
data _≃_ : Rel ℝ 0ℓ where
*≃* : ∀ {x y : ℝ} -> (∀ (n : ℕ) -> {n≢0 : n ≢0} -> ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 2 / n) {n≢0}) -> x ≃ y
≃-refl : Reflexive _≃_
≃-refl {x} = *≃* λ { (suc k₁) → let n = suc k₁ in begin
ℚ.∣ seq x n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎}
where open ℚP.≤-Reasoning
∣p-q∣≃∣q-p∣ : ∀ p q -> ℚ.∣ p ℚ.- q ∣ ℚ.≃ ℚ.∣ q ℚ.- p ∣
∣p-q∣≃∣q-p∣ p q = begin-equality
ℚ.∣ p ℚ.- q ∣ ≈⟨ ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (p ℚ.- q)) ⟩
ℚ.∣ ℚ.- (p ℚ.- q) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ p q ->
(⊝ (p ⊖ q)) ⊜ (q ⊖ p)) ℚP.≃-refl p q) ⟩
ℚ.∣ q ℚ.- p ∣ ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
≃-symm : Symmetric _≃_
≃-symm {x} {y} (*≃* x₁) = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ seq y n ℚ.- seq x n ∣ ≈⟨ ∣p-q∣≃∣q-p∣ (seq y n) (seq x n) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x₁ n ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
≃-reflexive : ∀ {x y} -> (∀ n -> {n ≢0} -> seq x n ℚ.≃ seq y n) -> x ≃ y
≃-reflexive {x} {y} hyp = *≃* (λ {(suc n-1) -> let n = suc n-1 in begin
ℚ.∣ seq x n ℚ.- seq y n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq x n) (ℚP.-‿cong (ℚP.≃-sym (hyp n)))) ⟩
ℚ.∣ seq x n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
m≤∣m∣ : ∀ m -> m ℤ.≤ + ℤ.∣ m ∣
m≤∣m∣ (+_ n) = ℤP.≤-refl
m≤∣m∣ (-[1+_] n) = ℤ.-≤+
archimedean-ℚ : ∀ p r -> ℚ.Positive p -> ∃ λ (N : ℕ) -> r ℚ.< ((+ N) ℤ.* ↥ p) / (↧ₙ p)
archimedean-ℚ (mkℚᵘ +[1+ g ] q-1) (mkℚᵘ u v-1) posp = let p = suc g; q = suc q-1; v = suc v-1
; r = (u ℤ.* + q) modℕ (p ℕ.* v); t = (u ℤ.* + q) divℕ (p ℕ.* v) in
suc ℤ.∣ t ∣ , ℚ.*<* (begin-strict
u ℤ.* + q ≡⟨ a≡a%ℕn+[a/ℕn]*n (u ℤ.* + q) (p ℕ.* v) ⟩
+ r ℤ.+ t ℤ.* (+ p ℤ.* + v) <⟨ ℤP.+-monoˡ-< (t ℤ.* (+ p ℤ.* + v)) (ℤ.+<+ (n%d<d (u ℤ.* + q) (+ p ℤ.* + v))) ⟩
+ p ℤ.* + v ℤ.+ t ℤ.* (+ p ℤ.* + v) ≡⟨ solve 3 (λ p v t ->
((p ⊗ v) ⊕ (t ⊗ (p ⊗ v))) ⊜ ((Κ (+ 1) ⊕ t) ⊗ (p ⊗ v)))
refl (+ p) (+ v) t ⟩
(+ 1 ℤ.+ t) ℤ.* (+ p ℤ.* + v) ≤⟨ ℤP.*-monoʳ-≤-nonNeg (p ℕ.* v) (m≤∣m∣ (+ 1 ℤ.+ t)) ⟩
+ ℤ.∣ + 1 ℤ.+ t ∣ ℤ.* (+ p ℤ.* + v) ≤⟨ ℤP.*-monoʳ-≤-nonNeg (p ℕ.* v) (ℤ.+≤+ (ℤP.∣m+n∣≤∣m∣+∣n∣ (+ 1) t)) ⟩
+ suc ℤ.∣ t ∣ ℤ.* (+ p ℤ.* + v) ≡⟨ sym (ℤP.*-assoc (+ suc ℤ.∣ t ∣) (+ p) (+ v)) ⟩
(+ suc ℤ.∣ t ∣ ℤ.* + p) ℤ.* + v ∎)
where
open ℤP.≤-Reasoning
open ℤ-Solver
abstract
fast-archimedean-ℚ : ∀ p r -> ℚ.Positive p -> ∃ λ (N : ℕ) -> r ℚ.< ((+ N) ℤ.* ↥ p) / (↧ₙ p)
fast-archimedean-ℚ = archimedean-ℚ
q≤r⇒+p/r≤+p/q : ∀ p q r -> {q≢0 : q ≢0} -> {r≢0 : r ≢0} -> q ℕ.≤ r -> (+ p / r) {r≢0} ℚ.≤ (+ p / q) {q≢0}
q≤r⇒+p/r≤+p/q p (suc k₁) (suc k₂) q≤r = ℚ.*≤* (ℤP.*-monoˡ-≤-nonNeg p (ℤ.+≤+ q≤r))
q<r⇒+p/r<+p/q : ∀ p q r -> {p ≢0} -> {q≢0 : q ≢0} -> {r≢0 : r ≢0} -> q ℕ.< r -> (+ p / r) {r≢0} ℚ.< (+ p / q) {q≢0}
q<r⇒+p/r<+p/q (suc k₁) (suc k₂) (suc k₃) q<r = ℚ.*<* (ℤP.*-monoˡ-<-pos k₁ (ℤ.+<+ q<r))
p≤q⇒p/r≤q/r : ∀ (p q : ℤ) -> ∀ (r : ℕ) -> {r≢0 : r ≢0} -> p ℤ.≤ q -> (p / r) {r≢0} ℚ.≤ (q / r) {r≢0}
p≤q⇒p/r≤q/r p q (suc k₁) p≤q = ℚ.*≤* (ℤP.*-monoʳ-≤-nonNeg (suc k₁) p≤q)
archimedean-ℚ₂ : ∀ (p : ℚᵘ) -> ∀ (r : ℤ) -> ℚ.Positive p -> ∃ λ (N-1 : ℕ) -> r / (suc N-1) ℚ.< p
archimedean-ℚ₂ (mkℚᵘ (+_ p) q-1) r posp/q = let q = suc q-1; N-1 = proj₁ (fast-archimedean-ℚ (+ p / q) (r / 1) posp/q); N = suc N-1 in N-1 , (begin-strict
r / N ≈⟨ ℚ.*≡* (sym (ℤP.*-assoc r (+ 1) (+ N))) ⟩
r / 1 ℚ.* (+ 1 / N) <⟨ ℚP.*-monoˡ-<-pos _ (proj₂ (fast-archimedean-ℚ (+ p / q) (r / 1) posp/q)) ⟩
(+ N-1 ℤ.* + p) / q ℚ.* (+ 1 / N) ≤⟨ ℚP.*-monoˡ-≤-nonNeg _ (p≤q⇒p/r≤q/r (+ N-1 ℤ.* + p) (+ N ℤ.* + p) q (ℤP.*-monoʳ-≤-nonNeg p (ℤ.+≤+ (ℕP.n≤1+n N-1)))) ⟩
(+ N ℤ.* + p) / q ℚ.* (+ 1 / N) ≈⟨ ℚ.*≡* (solve 3 (λ N p q ->
(((N ⊗ p) ⊗ Κ (+ 1)) ⊗ q) ⊜ (p ⊗ (q ⊗ N))) refl (+ N) (+ p) (+ q)) ⟩
+ p / q ∎)
where
open ℚP.≤-Reasoning
open ℤ-Solver
abstract
fast-archimedean-ℚ₂ : ∀ (p : ℚᵘ) -> ∀ (r : ℤ) -> ℚ.Positive p -> ∃ λ (N-1 : ℕ) -> r / (suc N-1) ℚ.< p
fast-archimedean-ℚ₂ = archimedean-ℚ₂
equality-lemma-if : ∀ x y -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
equality-lemma-if x y (*≃* x₁) (suc k₁) = let j = suc k₁ in 2 ℕ.* j , let N = 2 ℕ.* j in λ { (suc k₂) n≥N → let n = suc k₂ in begin
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x₁ n ⟩
+ 2 / n ≤⟨ ℚ.*≤* (ℤP.*-monoˡ-≤-nonNeg 2 (ℤ.+≤+ n≥N)) ⟩
+ 2 / N ≈⟨ ℚ.*≡* (sym (ℤP.*-identityˡ (+ 2 ℤ.* + j))) ⟩
+ 1 / j ∎}
where open ℚP.≤-Reasoning
abstract
fast-equality-lemma-if : ∀ x y -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
fast-equality-lemma-if = equality-lemma-if
p<q⇒0<q-p : ∀ p q -> p ℚ.< q -> 0ℚᵘ ℚ.< q ℚ.- p
p<q⇒0<q-p p q p<q = begin-strict
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ p) ⟩
p ℚ.- p <⟨ ℚP.+-monoˡ-< (ℚ.- p) p<q ⟩
q ℚ.- p ∎
where open ℚP.≤-Reasoning
equality-lemma-onlyif : ∀ x y ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}) ->
x ≃ y
equality-lemma-onlyif x y hyp1 = *≃* λ { n {n≢0} -> lem n {n≢0} (∣xₙ-yₙ∣≤2/n+3/j n {n≢0})}
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
∣xₙ-yₙ∣≤2/n+3/j : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 2 / n) {n≢0} ℚ.+ (+ 3 / j) {j≢0}
∣xₙ-yₙ∣≤2/n+3/j (suc k₁) (suc k₂) = let n = suc k₁; j = suc k₂; Nⱼ = suc (proj₁ (hyp1 j)); m = j ℕ.⊔ Nⱼ in begin
ℚ.∣ seq x n ℚ.- seq y n ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ xₘ yₘ xₙ yₙ ->
(xₙ ⊖ yₙ) ⊜ ((xₙ ⊖ xₘ) ⊕ (xₘ ⊖ yₘ) ⊕ (yₘ ⊖ yₙ)))
ℚP.≃-refl (seq x m) (seq y m) (seq x n) (seq y n)) ⟩
ℚ.∣ seq x n ℚ.- seq x m ℚ.+
(seq x m ℚ.- seq y m) ℚ.+
(seq y m ℚ.- seq y n) ∣ ≤⟨ ℚP.≤-trans
(ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq x m ℚ.+ (seq x m ℚ.- seq y m)) (seq y m ℚ.- seq y n))
(ℚP.+-monoˡ-≤ ℚ.∣ seq y m ℚ.- seq y n ∣
(ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq x m) (seq x m ℚ.- seq y m))) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+
ℚ.∣ seq x m ℚ.- seq y m ∣ ℚ.+
ℚ.∣ seq y m ℚ.- seq y n ∣ ≤⟨ ℚP.+-mono-≤
(ℚP.+-mono-≤ (reg x n m) (proj₂ (hyp1 j) m
(ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred Nⱼ)) (ℕP.m≤n⊔m j Nⱼ))))
(reg y m n) ⟩
(+ 1 / n ℚ.+ + 1 / m) ℚ.+
+ 1 / j ℚ.+
(+ 1 / m ℚ.+ + 1 / n) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ j m n ->
(((κ (+ 1) :* m :+ κ (+ 1) :* n) :* j :+ κ (+ 1) :* (n :* m)) :* (m :* n) :+
((κ (+ 1) :* n :+ κ (+ 1) :* m) :* (n :* m :* j))) :* (n :* (m :* j)) :=
(κ (+ 2) :* (m :* j) :+ (κ (+ 2) :* j :+ κ (+ 1) :* m) :* n) :* ((n :* m :* j) :* (m :* n)))
refl (+ j) (+ m) (+ n)) ⟩
+ 2 / n ℚ.+ (+ 2 / m ℚ.+ + 1 / j) ≤⟨ ℚP.+-monoʳ-≤ (+ 2 / n) {+ 2 / m ℚ.+ + 1 / j} {+ 3 / j}
(ℚP.≤-respʳ-≃ {+ 2 / m ℚ.+ + 1 / j} {+ 2 / j ℚ.+ + 1 / j} {+ 3 / j}
(ℚ.*≡* {+ 2 / j ℚ.+ + 1 / j} {+ 3 / j}
(ℤsolve 1 (λ j -> (κ (+ 2) :* j :+ κ (+ 1) :* j) :* j := κ (+ 3) :* (j :* j)) refl (+ j)))
(ℚP.+-monoˡ-≤ (+ 1 / j) {+ 2 / m} {+ 2 / j} (ℚ.*≤* (ℤP.*-monoˡ-≤-nonNeg 2 (ℤP.i≤i⊔j (+ j) (+ Nⱼ)))))) ⟩
+ 2 / n ℚ.+ + 3 / j ∎
lem : ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 2 / n) {n≢0} ℚ.+ (+ 3 / j) {j≢0}) ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ (+ 2 / n) {n≢0}
lem (suc k₂) hyp2 = let n = suc k₂ in
ℚP.≮⇒≥ (λ {hyp3 -> let arch = fast-archimedean-ℚ₂ (ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.- + 2 / n) (+ 3)
(ℚ.positive (p<q⇒0<q-p (+ 2 / n) ℚ.∣ seq x n ℚ.- seq y n ∣ hyp3))
; j = suc (proj₁ arch)
; Nⱼ = suc (proj₁ (hyp1 j))
; m = j ℕ.⊔ Nⱼ in
ℚP.<-irrefl ℚP.≃-refl (begin-strict
+ 2 / n ℚ.+ + 3 / j ≈⟨ ℚP.+-comm (+ 2 / n) (+ 3 / j) ⟩
+ 3 / j ℚ.+ + 2 / n <⟨ ℚP.+-monoˡ-< (+ 2 / n) (proj₂ arch) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.- + 2 / n ℚ.+ + 2 / n ≈⟨ solve 2 (λ a b -> a ⊖ b ⊕ b ⊜ a) ℚP.≃-refl
ℚ.∣ seq x n ℚ.- seq y n ∣ (+ 2 / n) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ ∣xₙ-yₙ∣≤2/n+3/j n j ⟩
+ 2 / n ℚ.+ + 3 / j ∎)})
≃-trans : Transitive _≃_
≃-trans {x} {y} {z} x≃y y≃z = equality-lemma-onlyif x z (λ { (suc k₁) ->
let j = suc k₁; eqxy = fast-equality-lemma-if x y x≃y; eqyz = fast-equality-lemma-if y z y≃z
; N₁ = proj₁ (eqxy (2 ℕ.* j)); N₂ = proj₁ (eqyz (2 ℕ.* j)); N = suc (N₁ ℕ.⊔ N₂) in
N , λ { (suc k₂) n≥N → let n = suc k₂
; N₁⊔N₂≤n = ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N)) n≥N in begin
ℚ.∣ seq x n ℚ.- seq z n ∣ ≈⟨ ℚP.∣-∣-cong (solve 3 (λ xₙ yₙ zₙ ->
xₙ ⊖ zₙ ⊜ (xₙ ⊖ yₙ ⊕ (yₙ ⊖ zₙ)))
ℚP.≃-refl (seq x n) (seq y n) (seq z n)) ⟩
ℚ.∣ seq x n ℚ.- seq y n ℚ.+ (seq y n ℚ.- seq z n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq y n) (seq y n ℚ.- seq z n) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.+ ℚ.∣ seq y n ℚ.- seq z n ∣ ≤⟨ ℚP.+-mono-≤
(proj₂ (eqxy (2 ℕ.* j)) n (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N₁⊔N₂≤n))
(proj₂ (eqyz (2 ℕ.* j)) n (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N₁⊔N₂≤n)) ⟩
+ 1 / (2 ℕ.* j) ℚ.+ + 1 / (2 ℕ.* j) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ j ->
(κ (+ 1) :* (κ (+ 2) :* j) :+ κ (+ 1) :* (κ (+ 2) :* j)) :* j :=
κ (+ 1) :* ((κ (+ 2) :* j) :* (κ (+ 2) :* j)))
refl (+ j)) ⟩
+ 1 / j ∎}})
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
≃-isEquivalence : IsEquivalence _≃_
≃-isEquivalence = record
{ refl = ≃-refl
; sym = ≃-symm
; trans = ≃-trans
}
≃-setoid : Setoid 0ℓ 0ℓ
≃-setoid = record
{ isEquivalence = ≃-isEquivalence
}
module ≃-Reasoning where
open import Relation.Binary.Reasoning.Setoid ≃-setoid
public
antidensity-ℤ : ¬(∃ λ (n : ℤ) -> + 0 ℤ.< n × n ℤ.< + 1)
antidensity-ℤ (.(+[1+ n ]) , ℤ.+<+ {n = suc n} m<n , ℤ.+<+ (ℕ.s≤s ()))
p≤∣p∣ : ∀ p -> p ℚ.≤ ℚ.∣ p ∣
p≤∣p∣ (mkℚᵘ (+_ n) denominator-2) = ℚP.≤-refl
p≤∣p∣ (mkℚᵘ (-[1+_] n) denominator-2) = ℚ.*≤* ℤ.-≤+
infixl 6 _+_ _-_ _⊔_ _⊓_ _⊓₂_
infixl 7 _*_
infix 8 -_ _⋆
--_⁻¹
_+_ : ℝ -> ℝ -> ℝ
seq (x + y) n = seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)
reg (x + y) (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂ in begin
ℚ.∣ seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ℚ.-
(seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ xₘ yₘ xₙ yₙ ->
xₘ ⊕ yₘ ⊖ (xₙ ⊕ yₙ) ⊜ (xₘ ⊖ xₙ ⊕ (yₘ ⊖ yₙ)))
ℚP.≃-refl (seq x (2 ℕ.* m)) (seq y (2 ℕ.* m)) (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n) ℚ.+
(seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n)) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n)) (seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n)) ⟩
ℚ.∣ seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n) ∣ ℚ.+
ℚ.∣ seq y (2 ℕ.* m) ℚ.- seq y (2 ℕ.* n) ∣ ≤⟨ ℚP.+-mono-≤ (reg x (2 ℕ.* m) (2 ℕ.* n)) (reg y (2 ℕ.* m) (2 ℕ.* n)) ⟩
+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n) ℚ.+
(+ 1 / (2 ℕ.* m) ℚ.+ + 1 / (2 ℕ.* n)) ≈⟨ ℚ.*≡* (ℤsolve 2 (λ m n ->
(((κ (+ 1) :* (κ (+ 2) :* n) :+ κ (+ 1) :* (κ (+ 2) :* m))
:* ((κ (+ 2) :* m) :* (κ (+ 2) :* n))) :+
(κ (+ 1) :* (κ (+ 2) :* n) :+ κ (+ 1) :* (κ (+ 2) :* m))
:* ((κ (+ 2) :* m) :* (κ (+ 2) :* n))) :* (m :* n) :=
(κ (+ 1) :* n :+ κ (+ 1) :* m) :*
(((κ (+ 2) :* m) :* (κ (+ 2) :* n)) :*
(((κ (+ 2) :* m) :* (κ (+ 2) :* n)))))
_≡_.refl (+ m) (+ n)) ⟩
+ 1 / m ℚ.+ + 1 / n ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
-_ : ℝ -> ℝ
seq (- x) n = ℚ.- seq x n
reg (- x) (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂ in begin
ℚ.∣ ℚ.- seq x m ℚ.- ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-sym (ℚP.≃-reflexive (ℚP.neg-distrib-+ (seq x m) (ℚ.- seq x n)))) ⟩
ℚ.∣ ℚ.- (seq x m ℚ.- seq x n) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x m ℚ.- seq x n))) (reg x m n) ⟩
+ 1 / m ℚ.+ + 1 / n ∎
where open ℚP.≤-Reasoning
_-_ : ℝ -> ℝ -> ℝ
x - y = x + (- y)
_⊔_ : ℝ -> ℝ -> ℝ
seq (x ⊔ y) n = (seq x n) ℚ.⊔ (seq y n)
reg (x ⊔ y) (suc k₁) (suc k₂) = [ left , right ]′ (ℚP.≤-total (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))
where
open ℚP.≤-Reasoning
open ℚ-Solver
m = suc k₁
n = suc k₂
lem : ∀ (a b c d : ℚᵘ) -> a ℚ.≤ b -> ∀ (r s : ℕ) -> {r≢0 : r ≢0} -> {s≢0 : s ≢0} ->
ℚ.∣ b ℚ.- d ∣ ℚ.≤ ((+ 1) / r) {r≢0} ℚ.+ ((+ 1) / s) {s≢0} ->
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ℚ.≤ ((+ 1) / r) {r≢0} ℚ.+ ((+ 1) / s) {s≢0}
lem a b c d a≤b r s hyp = begin
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ≤⟨ ℚP.+-monoʳ-≤ (a ℚ.⊔ b) (ℚP.neg-mono-≤ (ℚP.p≤q⊔p c d)) ⟩
(a ℚ.⊔ b) ℚ.- d ≈⟨ ℚP.+-congˡ (ℚ.- d) (ℚP.p≤q⇒p⊔q≃q a≤b) ⟩
b ℚ.- d ≤⟨ p≤∣p∣ (b ℚ.- d) ⟩
ℚ.∣ b ℚ.- d ∣ ≤⟨ hyp ⟩
((+ 1) / r) ℚ.+ ((+ 1) / s) ∎
left : seq x m ℚ.⊔ seq y m ℚ.≤ seq x n ℚ.⊔ seq y n ->
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
left hyp1 = [ xn≤yn , yn≤xn ]′ (ℚP.≤-total (seq x n) (seq y n))
where
xn≤yn : seq x n ℚ.≤ seq y n -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
xn≤yn hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> (⊝ (a ⊖ b)) ⊜ (b ⊖ a))
ℚP.≃-refl (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))) ⟩
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ≤⟨ lem (seq x n) (seq y n) (seq x m) (seq y m) hyp2 m n
(ℚP.≤-respʳ-≃ (ℚP.+-comm (+ 1 / n) (+ 1 / m)) (reg y n m)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
yn≤xn : seq y n ℚ.≤ seq x n -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
yn≤xn hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> (⊝ (a ⊖ b)) ⊜ (b ⊖ a))
ℚP.≃-refl (seq x m ℚ.⊔ seq y m) (seq x n ℚ.⊔ seq y n))) ⟩
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x n ℚ.⊔ seq y n) ℚ.- (seq x m ℚ.⊔ seq y m) ≈⟨ ℚP.≃-trans (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n)
(ℚP.-‿cong {seq x m ℚ.⊔ seq y m} {seq y m ℚ.⊔ seq x m} (ℚP.⊔-comm (seq x m) (seq y m))))
(ℚP.+-congˡ (ℚ.- (seq y m ℚ.⊔ seq x m)) (ℚP.⊔-comm (seq x n) (seq y n))) ⟩
(seq y n ℚ.⊔ seq x n) ℚ.- (seq y m ℚ.⊔ seq x m)
≤⟨ lem (seq y n) (seq x n) (seq y m) (seq x m) hyp2 m n
(ℚP.≤-respʳ-≃ (ℚP.+-comm (+ 1 / n) (+ 1 / m)) (reg x n m)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
right : seq x n ℚ.⊔ seq y n ℚ.≤ seq x m ℚ.⊔ seq y m ->
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
right hyp1 = [ xm≤ym , ym≤xm ]′ (ℚP.≤-total (seq x m) (seq y m))
where
xm≤ym : seq x m ℚ.≤ seq y m -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
xm≤ym hyp2 = ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1))) (lem (seq x m) (seq y m) (seq x n) (seq y n) hyp2 m n (reg y m n))
ym≤xm : seq y m ℚ.≤ seq x m -> ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ℚ.≤ ((+ 1) / m) ℚ.+ ((+ 1) / n)
ym≤xm hyp2 = begin
ℚ.∣ (seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq x m ℚ.⊔ seq y m) ℚ.- (seq x n ℚ.⊔ seq y n) ≈⟨ ℚP.≃-trans (ℚP.+-congˡ (ℚ.- (seq x n ℚ.⊔ seq y n)) (ℚP.⊔-comm (seq x m) (seq y m)))
(ℚP.+-congʳ (seq y m ℚ.⊔ seq x m)
(ℚP.-‿cong {seq x n ℚ.⊔ seq y n} {seq y n ℚ.⊔ seq x n} (ℚP.⊔-comm (seq x n) (seq y n)))) ⟩
(seq y m ℚ.⊔ seq x m) ℚ.- (seq y n ℚ.⊔ seq x n) ≤⟨ lem (seq y m) (seq x m) (seq y n) (seq x n) hyp2 m n (reg x m n) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
-- Alternative definition of minimum for convenience. Equivalent to Bishop's, of course.
_⊓_ : ℝ -> ℝ -> ℝ
seq (x ⊓ y) n = seq x n ℚ.⊓ seq y n
reg (x ⊓ y) (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂; xₘ = seq x m; yₘ = seq y m; xₙ = seq x n; yₙ = seq y n in begin
ℚ.∣ xₘ ℚ.⊓ yₘ ℚ.- xₙ ℚ.⊓ yₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.⊓-cong (ℚP.≃-sym (ℚP.neg-involutive xₘ)) (ℚP.≃-sym (ℚP.neg-involutive yₘ)))
(ℚP.-‿cong (ℚP.⊓-cong (ℚP.≃-sym (ℚP.neg-involutive xₙ)) (ℚP.≃-sym (ℚP.neg-involutive yₙ))))) ⟩
ℚ.∣ ((ℚ.- (ℚ.- xₘ)) ℚ.⊓ (ℚ.- (ℚ.- yₘ))) ℚ.-
((ℚ.- (ℚ.- xₙ)) ℚ.⊓ (ℚ.- (ℚ.- yₙ))) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.≃-sym (ℚP.neg-distrib-⊔-⊓ (ℚ.- xₘ) (ℚ.- yₘ)))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.neg-distrib-⊔-⊓ (ℚ.- xₙ) (ℚ.- yₙ))))) ⟩
ℚ.∣ ℚ.- ((ℚ.- xₘ) ℚ.⊔ (ℚ.- yₘ)) ℚ.-
(ℚ.- ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ))) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ m n -> ((⊝ m) ⊖ (⊝ n)) ⊜ (n ⊖ m)) ℚP.≃-refl ((ℚ.- xₘ) ℚ.⊔ (ℚ.- yₘ)) ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ))) ⟩
ℚ.∣ ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ)) ℚ.-
((ℚ.- xₘ) ℚ.⊔ (ℚ.- yₘ)) ∣ ≤⟨ reg (- x ⊔ - y) n m ⟩
+ 1 / n ℚ.+ + 1 / m ≈⟨ ℚP.+-comm (+ 1 / n) (+ 1 / m) ⟩
+ 1 / m ℚ.+ + 1 / n ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
_⊓₂_ : ℝ -> ℝ -> ℝ
x ⊓₂ y = - ((- x) ⊔ (- y))
∣∣p∣-∣q∣∣≤∣p-q∣ : ∀ p q -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
∣∣p∣-∣q∣∣≤∣p-q∣ p q = [ left p q , right p q ]′ (ℚP.≤-total ℚ.∣ q ∣ ℚ.∣ p ∣)
where
open ℚP.≤-Reasoning
open ℚ-Solver
left : ∀ p q -> ℚ.∣ q ∣ ℚ.≤ ℚ.∣ p ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
left p q hyp = begin
ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp) ⟩
ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ≈⟨ ℚP.+-congˡ (ℚ.- ℚ.∣ q ∣) (ℚP.∣-∣-cong (solve 2 (λ p q ->
p ⊜ (p ⊖ q ⊕ q)) ℚP.≃-refl p q)) ⟩
ℚ.∣ p ℚ.- q ℚ.+ q ∣ ℚ.- ℚ.∣ q ∣ ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- ℚ.∣ q ∣) (ℚP.∣p+q∣≤∣p∣+∣q∣ (p ℚ.- q) q) ⟩
ℚ.∣ p ℚ.- q ∣ ℚ.+ ℚ.∣ q ∣ ℚ.- ℚ.∣ q ∣ ≈⟨ solve 2 (λ x y -> x ⊕ y ⊖ y ⊜ x)
ℚP.≃-refl ℚ.∣ p ℚ.- q ∣ ℚ.∣ q ∣ ⟩
ℚ.∣ p ℚ.- q ∣ ∎
right : ∀ p q -> ℚ.∣ p ∣ ℚ.≤ ℚ.∣ q ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
right p q hyp = begin
ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣))) (ℚP.∣-∣-cong
(solve 2 (λ p q -> ⊝ (p ⊖ q) ⊜ (q ⊖ p)) ℚP.≃-refl ℚ.∣ p ∣ ℚ.∣ q ∣)) ⟩
ℚ.∣ ℚ.∣ q ∣ ℚ.- ℚ.∣ p ∣ ∣ ≤⟨ left q p hyp ⟩
ℚ.∣ q ℚ.- p ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (q ℚ.- p))) (ℚP.∣-∣-cong
(solve 2 (λ p q -> ⊝ (q ⊖ p) ⊜ (p ⊖ q)) ℚP.≃-refl p q)) ⟩
ℚ.∣ p ℚ.- q ∣ ∎
least-ℤ>ℚ : ∀ (p : ℚᵘ) -> ∃ λ (K : ℤ) ->
p ℚ.< K / 1 × ∀ (n : ℤ) -> p ℚ.< n / 1 -> K ℤ.≤ n
least-ℤ>ℚ p/q = let p = ↥ p/q; q = ↧ₙ p/q; r = p modℕ q; t = p divℕ q in + 1 ℤ.+ t , greater , least
where
open ℤP.≤-Reasoning
open ℤ-Solver
greater : p/q ℚ.< (+ 1 ℤ.+ (↥ p/q divℕ ↧ₙ p/q)) / 1
greater = let p = ↥ p/q; q = ↧ₙ p/q; r = p modℕ q; t = p divℕ q in ℚ.*<* (begin-strict
p ℤ.* + 1 ≡⟨ trans (ℤP.*-identityʳ p) (a≡a%ℕn+[a/ℕn]*n p q) ⟩
+ r ℤ.+ t ℤ.* + q <⟨ ℤP.+-monoˡ-< (t ℤ.* (+ q)) (ℤ.+<+ (n%ℕd<d p q)) ⟩
+ q ℤ.+ t ℤ.* + q ≡⟨ solve 2 (λ q t -> q ⊕ t ⊗ q ⊜ (Κ (+ 1) ⊕ t) ⊗ q) _≡_.refl (+ q) t ⟩
(+ 1 ℤ.+ t) ℤ.* + q ∎)
least : ∀ (n : ℤ) -> p/q ℚ.< n / 1 -> + 1 ℤ.+ (↥ p/q divℕ ↧ₙ p/q) ℤ.≤ n
least n p/q<n = ℤP.≮⇒≥ (λ {hyp -> antidensity-ℤ (n ℤ.- (↥ p/q divℕ ↧ₙ p/q) , 0<n-t hyp , n-t<1 hyp)})
where
0<n-t : n ℤ.< + 1 ℤ.+ (↥ p/q divℕ ↧ₙ p/q) -> + 0 ℤ.< n ℤ.- (↥ p/q divℕ ↧ₙ p/q)
0<n-t hyp = let p = ↥ p/q; q = ↧ₙ p/q; r = p modℕ q; t = p divℕ q in ℤP.*-cancelʳ-<-nonNeg q (begin-strict
+ 0 ℤ.* + q ≡⟨ ℤP.*-zeroˡ (+ q) ⟩
+ 0 ≤⟨ ℤ.+≤+ ℕ.z≤n ⟩
+ r ≡⟨ solve 3 (λ r t q -> r ⊜ (r ⊕ t ⊗ q ⊖ t ⊗ q)) _≡_.refl (+ r) t (+ q) ⟩
+ r ℤ.+ t ℤ.* + q ℤ.- t ℤ.* + q ≡⟨ cong (λ x -> x ℤ.- t ℤ.* + q) (sym (a≡a%ℕn+[a/ℕn]*n p q)) ⟩
p ℤ.- t ℤ.* + q <⟨ ℤP.+-monoˡ-< (ℤ.- (t ℤ.* + q)) (subst (ℤ._< n ℤ.* + q) (ℤP.*-identityʳ p) (ℚP.drop-*<* p/q<n)) ⟩
n ℤ.* + q ℤ.- t ℤ.* + q ≡⟨ solve 3 (λ n t q -> n ⊗ q ⊖ t ⊗ q ⊜ (n ⊖ t) ⊗ q) _≡_.refl n t (+ q) ⟩
(n ℤ.- t) ℤ.* + q ∎)
n-t<1 : n ℤ.< + 1 ℤ.+ (↥ p/q divℕ ↧ₙ p/q) -> n ℤ.- (↥ p/q divℕ ↧ₙ p/q) ℤ.< + 1
n-t<1 hyp = let t = ↥ p/q divℕ ↧ₙ p/q in begin-strict
n ℤ.- t <⟨ ℤP.+-monoˡ-< (ℤ.- t) hyp ⟩
+ 1 ℤ.+ t ℤ.- t ≡⟨ solve 1 (λ t -> Κ (+ 1) ⊕ t ⊖ t ⊜ Κ (+ 1)) _≡_.refl t ⟩
+ 1 ∎
2ℚᵘ : ℚᵘ
2ℚᵘ = + 2 / 1
K : ℝ -> ℕ
K x = let p = ↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ); q = ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) in suc ℤ.∣ p divℕ q ∣
private
abstract
Kx=1+t : ∀ x -> + K x ≡ + 1 ℤ.+ ((↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)))
Kx=1+t x = let t = (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) in begin-equality
+ K x ≡⟨ _≡_.refl ⟩
+ 1 ℤ.+ + ℤ.∣ t ∣ ≡⟨ cong (λ x -> + 1 ℤ.+ x) (ℤP.0≤n⇒+∣n∣≡n (0≤n⇒0≤n/ℕd (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) (↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))
(ℚP.≥0⇒↥≥0 (ℚP.≤-trans (ℚP.0≤∣p∣ (seq x 1)) (ℚP.p≤p+q {ℚ.∣ seq x 1 ∣} {2ℚᵘ} _))))) ⟩
+ 1 ℤ.+ t ∎
where
open ℤP.≤-Reasoning
-- We could do a rewrite Kx=1+t here to get a one-line proof, but the performance becomes abysmal
-- (Around 30sec to typecheck rewrite).
abstract
canonical-well-defined : ∀ (x : ℝ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< + K x / 1 ×
∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n
canonical-well-defined x = left , right
where
left : ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< + K x / 1
left = let t = ↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) in begin-strict
ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ <⟨ proj₁ (proj₂ (least-ℤ>ℚ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))) ⟩
(+ 1 ℤ.+ t) / 1 ≈⟨ ℚP.≃-reflexive (ℚP./-cong (sym (Kx=1+t x)) _≡_.refl _ _) ⟩
+ K x / 1 ∎
where open ℚP.≤-Reasoning
right : ∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n
right n hyp = let t = ↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) in begin
+ K x ≡⟨ Kx=1+t x ⟩
+ 1 ℤ.+ t ≤⟨ proj₂ (proj₂ (least-ℤ>ℚ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))) n hyp ⟩
n ∎
where open ℤP.≤-Reasoning
1/n≤1 : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> (+ 1 / n) {n≢0} ℚ.≤ 1ℚᵘ
1/n≤1 (suc k₁) = let n = suc k₁ in ℚ.*≤* (ℤP.*-monoˡ-≤-nonNeg 1 {+ 1} {+ n} (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n)))
canonical-strict-upper-bound : ∀ (x : ℝ) -> ∀ (n : ℕ) -> {n ≢0} -> ℚ.∣ seq x n ∣ ℚ.< + K x / 1
canonical-strict-upper-bound x (suc k₁) = let n = suc k₁ in begin-strict
ℚ.∣ seq x n ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ xₙ x₁ ->
xₙ ⊜ (x₁ ⊕ (xₙ ⊖ x₁))) ℚP.≃-refl (seq x n) (seq x 1)) ⟩
ℚ.∣ seq x 1 ℚ.+ (seq x n ℚ.- seq x 1)∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x 1) (seq x n ℚ.- seq x 1) ⟩
ℚ.∣ seq x 1 ∣ ℚ.+ ℚ.∣ seq x n ℚ.- seq x 1 ∣ ≤⟨ ℚP.+-monoʳ-≤ ℚ.∣ seq x 1 ∣ (reg x n 1) ⟩
ℚ.∣ seq x 1 ∣ ℚ.+ (+ 1 / n ℚ.+ ℚ.1ℚᵘ) ≤⟨ ℚP.+-monoʳ-≤ ℚ.∣ seq x 1 ∣ (ℚP.+-monoˡ-≤ ℚ.1ℚᵘ {+ 1 / n} {1ℚᵘ} (1/n≤1 n)) ⟩
ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ <⟨ proj₁ (canonical-well-defined x) ⟩
+ K x / 1 ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
p≤r⇒p/q≤r/q : ∀ (p r : ℤ) -> ∀ (q : ℕ) -> {q≢0 : q ≢0} -> p ℤ.≤ r -> (p / q) {q≢0} ℚ.≤ (r / q) {q≢0}
p≤r⇒p/q≤r/q p r (suc k₁) p≤r = let q = suc k₁ in ℚ.*≤* (ℤP.*-monoʳ-≤-nonNeg q p≤r)
_*_ : ℝ -> ℝ -> ℝ
seq (x * y) n = seq x (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ℚ.* seq y (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n)
reg (x * y) (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂; k = K x ℕ.⊔ K y; 2km = 2 ℕ.* k ℕ.* m; 2kn = 2 ℕ.* k ℕ.* n
; x₂ₖₘ = seq x 2km; y₂ₖₘ = seq y 2km; x₂ₖₙ = seq x 2kn; y₂ₖₙ = seq y 2kn
; ∣x₂ₖₘ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-strict-upper-bound x 2km)) (p≤r⇒p/q≤r/q (+ K x) (+ k) 1 (ℤP.i≤i⊔j (+ K x) (+ K y)))
; ∣y₂ₖₙ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-strict-upper-bound y 2kn)) (p≤r⇒p/q≤r/q (+ K y) (+ k) 1 (ℤP.i≤j⊔i (+ K x) (+ K y))) in
begin
ℚ.∣ x₂ₖₘ ℚ.* y₂ₖₘ ℚ.- x₂ₖₙ ℚ.* y₂ₖₙ ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ xm ym xn yn ->
(xm ⊗ ym ⊖ xn ⊗ yn) ⊜
(xm ⊗ (ym ⊖ yn) ⊕ yn ⊗ (xm ⊖ xn)))
ℚP.≃-refl x₂ₖₘ y₂ₖₘ x₂ₖₙ y₂ₖₙ) ⟩
ℚ.∣ x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ) ℚ.+
y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ))
(y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ)) ⟩
ℚ.∣ x₂ₖₘ ℚ.* (y₂ₖₘ ℚ.- y₂ₖₙ) ∣ ℚ.+
ℚ.∣ y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣ ≈⟨ ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₖₘ (y₂ₖₘ ℚ.- y₂ₖₙ)) (ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ₖₙ (x₂ₖₘ ℚ.- x₂ₖₙ)) ⟩
ℚ.∣ x₂ₖₘ ∣ ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.+-mono-≤
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣} _ ∣x₂ₖₘ∣≤k)
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣} _ ∣y₂ₖₙ∣≤k) ⟩
(+ k / 1) ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
(+ k / 1) ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.+-mono-≤
(ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (reg y 2km 2kn))
(ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (reg x 2km 2kn)) ⟩
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+
(+ 1 / 2kn)) ℚ.+
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+
(+ 1 / 2kn)) ≈⟨ ℚP.≃-sym (ℚP.*-distribˡ-+ (+ k / 1) ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn)) ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn))) ⟩
(+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn)
ℚ.+ ((+ 1 / 2km) ℚ.+ (+ 1 / 2kn))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ k m n ->
{- Function for the solver -}
((k :* ((((κ (+ 1) :* (κ (+ 2) :* k :* n)) :+ (κ (+ 1) :* (κ (+ 2) :* k :* m))) :* ((κ (+ 2) :* k :* m) :* (κ (+ 2) :* k :* n))) :+
(((κ (+ 1) :* (κ (+ 2) :* k :* n)) :+ (κ (+ 1) :* (κ (+ 2) :* k :* m))) :* ((κ (+ 2) :* k :* m) :* (κ (+ 2) :* k :* n)))))
:* (m :* n)) :=
((κ (+ 1) :* n :+ κ (+ 1) :* m) :*
(κ (+ 1) :* (((κ (+ 2) :* k :* m) :* (κ (+ 2) :* k :* n)):* ((κ (+ 2) :* k :* m) :* (κ (+ 2) :* k :* n))))))
-- Other solver inputs
refl (+ k) (+ m) (+ n)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
_⋆ : ℚᵘ -> ℝ
seq (p ⋆) n = p
reg (p ⋆) (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂ in begin
ℚ.∣ p ℚ.- p ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ p) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 1 / m ℚ.+ + 1 / n ∎
where
open ℚP.≤-Reasoning
-- Properties of _+_
+-cong : Congruent₂ _≃_ _+_
+-cong {x} {z} {y} {w} (*≃* x₁) (*≃* x₂) = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n) ℚ.-
(seq z (2 ℕ.* n) ℚ.+ seq w (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ x y z w ->
(x ⊕ y ⊖ (z ⊕ w)) ⊜ ((x ⊖ z) ⊕ (y ⊖ w)))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) (seq z (2 ℕ.* n)) (seq w (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq z (2 ℕ.* n) ℚ.+
(seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n)) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* n) ℚ.- seq z (2 ℕ.* n)) (seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n)) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq z (2 ℕ.* n) ∣ ℚ.+
ℚ.∣ seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n) ∣ ≤⟨ ℚP.+-mono-≤ (x₁ (2 ℕ.* n)) (x₂ (2 ℕ.* n)) ⟩
+ 2 / (2 ℕ.* n) ℚ.+ + 2 / (2 ℕ.* n) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ n ->
(κ (+ 2) :* (κ (+ 2) :* n) :+ κ (+ 2) :* (κ (+ 2) :* n)) :* n :=
(κ (+ 2) :* ((κ (+ 2) :* n) :* (κ (+ 2) :* n)))) refl (+ n)) ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
+-congʳ : ∀ x {y z} -> y ≃ z -> x + y ≃ x + z
+-congʳ x y≃z = +-cong ≃-refl y≃z
+-congˡ : ∀ x {y z} -> y ≃ z -> y + x ≃ z + x
+-congˡ x y≃z = +-cong y≃z ≃-refl
+-comm : Commutative _≃_ _+_
+-comm x y = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ℚ.-
(seq y (2 ℕ.* n) ℚ.+ seq x (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y ->
(x ⊕ y) ⊖ (y ⊕ x) ⊜ Κ 0ℚᵘ)
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
(+ 2) / n ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
+-assoc : Associative _≃_ _+_
+-assoc x y z = *≃* (λ { (suc k₁) -> let n = suc k₁; 2n = 2 ℕ.* n; 4n = 2 ℕ.* 2n in begin
ℚ.∣ ((seq x 4n ℚ.+ seq y 4n) ℚ.+ seq z 2n) ℚ.-
(seq x 2n ℚ.+ (seq y 4n ℚ.+ seq z 4n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 5 (λ x4 y4 z2 x2 z4 ->
(((x4 ⊕ y4) ⊕ z2) ⊖ (x2 ⊕ (y4 ⊕ z4))) ⊜
((x4 ⊖ x2) ⊕ (z2 ⊖ z4)))
ℚP.≃-refl (seq x 4n) (seq y 4n) (seq z 2n) (seq x 2n) (seq z 4n)) ⟩
ℚ.∣ (seq x 4n ℚ.- seq x 2n) ℚ.+ (seq z 2n ℚ.- seq z 4n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x 4n ℚ.- seq x 2n) (seq z 2n ℚ.- seq z 4n) ⟩
ℚ.∣ seq x 4n ℚ.- seq x 2n ∣ ℚ.+ ℚ.∣ seq z 2n ℚ.- seq z 4n ∣ ≤⟨ ℚP.+-mono-≤ (reg x 4n 2n) (reg z 2n 4n) ⟩
((+ 1 / 4n) ℚ.+ (+ 1 / 2n)) ℚ.+ ((+ 1 / 2n) ℚ.+ (+ 1 / 4n)) ≈⟨ ℚ.*≡* (ℤsolve 1 ((λ 2n ->
((κ (+ 1) :* 2n :+ κ (+ 1) :* (κ (+ 2) :* 2n)) :*
(2n :* (κ (+ 2) :* 2n)) :+
(κ (+ 1) :* (κ (+ 2) :* 2n) :+ κ (+ 1) :* 2n) :*
((κ (+ 2) :* 2n) :* 2n)) :* 2n :=
κ (+ 3) :* (((κ (+ 2) :* 2n) :* 2n) :*
(2n :* (κ (+ 2) :* 2n)))))
refl (+ 2n)) ⟩
+ 3 / 2n ≤⟨ ℚ.*≤* (ℤP.*-monoʳ-≤-nonNeg 2n (ℤ.+≤+ (ℕ.s≤s (ℕ.s≤s (ℕ.s≤s (ℕ.z≤n {1})))))) ⟩
+ 4 / 2n ≈⟨ ℚ.*≡* (ℤsolve 1 (λ n ->
κ (+ 4) :* n := κ (+ 2) :* (κ (+ 2) :* n))
refl (+ n)) ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
0ℝ : ℝ
0ℝ = 0ℚᵘ ⋆
1ℝ : ℝ
1ℝ = 1ℚᵘ ⋆
+-identityˡ : LeftIdentity _≃_ 0ℝ _+_
+-identityˡ x = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ (0ℚᵘ ℚ.+ seq x (2 ℕ.* n)) ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- seq x n) (ℚP.+-identityˡ (seq x (2 ℕ.* n)))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq x n ∣ ≤⟨ reg x (2 ℕ.* n) n ⟩
(+ 1 / (2 ℕ.* n)) ℚ.+ (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(Κ (+ 1) ⊗ n ⊕ Κ (+ 1) ⊗ (Κ (+ 2) ⊗ n)) ⊗ (Κ (+ 2) ⊗ n) ⊜
Κ (+ 3) ⊗ ((Κ (+ 2) ⊗ n) ⊗ n))
refl (+ n)) ⟩
+ 3 / (2 ℕ.* n) ≤⟨ ℚ.*≤* (ℤP.*-monoʳ-≤-nonNeg (2 ℕ.* n) (ℤ.+≤+ (ℕ.s≤s (ℕ.s≤s (ℕ.s≤s (ℕ.z≤n {1})))))) ⟩
+ 4 / (2 ℕ.* n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
Κ (+ 4) ⊗ n ⊜ Κ (+ 2) ⊗ (Κ (+ 2) ⊗ n))
refl (+ n)) ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℤ-Solver
+-identityʳ : RightIdentity _≃_ 0ℝ _+_
+-identityʳ x = ≃-trans (+-comm x 0ℝ) (+-identityˡ x)
+-identity : Identity _≃_ 0ℝ _+_
+-identity = +-identityˡ , +-identityʳ
+-inverseʳ : RightInverse _≃_ 0ℝ -_ _+_
+-inverseʳ x = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ (seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ℚ.+ 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (solve 1 (λ x -> x ⊖ x ⊕ Κ 0ℚᵘ ⊜ Κ 0ℚᵘ)
ℚP.≃-refl (seq x (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ ℚ.*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (ℤ.+≤+ ℕ.z≤n)) ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
+-inverseˡ : LeftInverse _≃_ 0ℝ -_ _+_
+-inverseˡ x = ≃-trans (+-comm (- x) x) (+-inverseʳ x)
+-inverse : Inverse _≃_ 0ℝ -_ _+_
+-inverse = +-inverseˡ , +-inverseʳ
-- Properties of _⋆
⋆-cong : ∀ {p} {q} -> p ℚ.≃ q -> p ⋆ ≃ q ⋆
⋆-cong {p} {q} p≃q = *≃* (λ {(suc k₁) -> let n = suc k₁ in begin
ℚ.∣ p ℚ.- q ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.p≃q⇒p-q≃0 p q p≃q) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
⋆-distrib-+ : ∀ (p r : ℚᵘ) -> (p ℚ.+ r) ⋆ ≃ p ⋆ + r ⋆
⋆-distrib-+ x y = *≃* (λ { (suc k₁) -> let n = suc k₁; p = ↥ x; q = ↧ₙ x; u = ↥ y; v = ↧ₙ y in begin
ℚ.∣ ((p / q) ℚ.+ (u / v)) ℚ.- ((p / q) ℚ.+ (u / v)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ((p / q) ℚ.+ (u / v))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
(+ 2) / n ∎})
where open ℚP.≤-Reasoning
⋆-distrib-* : ∀ p q -> (p ℚ.* q) ⋆ ≃ p ⋆ * q ⋆
⋆-distrib-* p q = *≃* (λ {(suc n-1) -> let n = suc n-1 in begin
ℚ.∣ p ℚ.* q ℚ.- p ℚ.* q ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (p ℚ.* q)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
⋆-distrib-neg : ∀ (p : ℚᵘ) -> (ℚ.- p) ⋆ ≃ - (p ⋆)
⋆-distrib-neg p = *≃* λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.- p ℚ.- (ℚ.- p) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (ℚ.- p)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
(+ 2) / n ∎}
where open ℚP.≤-Reasoning
-- Properties of _*_
regular⇒cauchy : ∀ (x : ℝ) -> ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (m n : ℕ) ->
m ℕ.≥ N -> n ℕ.≥ N -> ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
regular⇒cauchy x (suc k₁) = let j = suc k₁ in 2 ℕ.* j , λ { (suc k₂) (suc k₃) m≥N n≥N → let m = suc k₂; n = suc k₃ in begin
ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ reg x m n ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ≤⟨ ℚP.+-mono-≤ (q≤r⇒+p/r≤+p/q 1 (2 ℕ.* j) m m≥N) (q≤r⇒+p/r≤+p/q 1 (2 ℕ.* j) n n≥N) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(Κ (+ 1) ⊗ (Κ (+ 2) ⊗ j) ⊕ Κ (+ 1) ⊗ (Κ (+ 2) ⊗ j)) ⊗ j ⊜
(Κ (+ 1) ⊗ ((Κ (+ 2) ⊗ j) ⊗ (Κ (+ 2) ⊗ j)))) refl (+ j)) ⟩
+ 1 / j ∎}
where
open ℚP.≤-Reasoning
open ℤ-Solver
abstract
fast-regular⇒cauchy : ∀ (x : ℝ) -> ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (m n : ℕ) ->
m ℕ.≥ N -> n ℕ.≥ N -> ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
fast-regular⇒cauchy = regular⇒cauchy
equals-to-cauchy : ∀ x y -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (m n : ℕ) -> m ℕ.≥ N -> n ℕ.≥ N ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
equals-to-cauchy x y x≃y (suc k₁) = let j = suc k₁; N₁ = suc (proj₁ (fast-equality-lemma-if x y x≃y (2 ℕ.* j)))
; N₂ = proj₁ (regular⇒cauchy x (2 ℕ.* j)); N = N₁ ℕ.⊔ N₂ in
N , λ { (suc k₂) (suc k₃) m≥N n≥N -> let m = suc k₂; n = suc k₃ in begin
ℚ.∣ seq x m ℚ.- seq y n ∣ ≈⟨ ℚP.∣-∣-cong (solve 3 (λ xm yn xn ->
(xm ⊖ yn) ⊜ ((xm ⊖ xn) ⊕ (xn ⊖ yn)))
ℚP.≃-refl (seq x m) (seq y n) (seq x n)) ⟩
ℚ.∣ (seq x m ℚ.- seq x n) ℚ.+
(seq x n ℚ.- seq y n) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x m ℚ.- seq x n)
(seq x n ℚ.- seq y n) ⟩
ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.+
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ ℚP.+-mono-≤
(proj₂ (regular⇒cauchy x (2 ℕ.* j)) m n (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) m≥N) (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) n≥N))
(proj₂ (fast-equality-lemma-if x y x≃y (2 ℕ.* j)) n (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N₁)) (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) n≥N))) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+
(+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ j ->
(κ (+ 1) :* (κ (+ 2) :* j) :+ (κ (+ 1) :* (κ (+ 2) :* j))) :* j :=
(κ (+ 1) :* ((κ (+ 2) :* j) :* (κ (+ 2) :* j))))
refl (+ j)) ⟩
+ 1 / j ∎}
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
abstract
fast-equals-to-cauchy : ∀ x y -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (m n : ℕ) -> m ℕ.≥ N -> n ℕ.≥ N ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
fast-equals-to-cauchy = equals-to-cauchy
*-cong : Congruent₂ _≃_ _*_
*-cong {x} {z} {y} {w} x≃z y≃w = equality-lemma-onlyif (x * y) (z * w) partA
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
partA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
partA (suc k₁) = N , partB
where
j = suc k₁
r = K x ℕ.⊔ K y
t = K z ℕ.⊔ K w
N₁ = proj₁ (fast-equals-to-cauchy x z x≃z (K y ℕ.* (2 ℕ.* j)))
N₂ = proj₁ (fast-equals-to-cauchy y w y≃w (K z ℕ.* (2 ℕ.* j)))
N = suc (N₁ ℕ.⊔ N₂)
partB : ∀ (n : ℕ) -> n ℕ.≥ N -> ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j)
partB (suc k₂) n≥N = let n = suc k₂
; x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
; y₂ᵣₙ = seq y (2 ℕ.* r ℕ.* n)
; z₂ₜₙ = seq z (2 ℕ.* t ℕ.* n)
; w₂ₜₙ = seq w (2 ℕ.* t ℕ.* n) in begin
ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ℚ.- z₂ₜₙ ℚ.* w₂ₜₙ ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ x y z w ->
(x ⊗ y ⊖ z ⊗ w) ⊜ (y ⊗ (x ⊖ z) ⊕ z ⊗ (y ⊖ w)))
ℚP.≃-refl x₂ᵣₙ y₂ᵣₙ z₂ₜₙ w₂ₜₙ) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ) ℚ.+
z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ))
(z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- z₂ₜₙ) ∣ ℚ.+
ℚ.∣ z₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- w₂ₜₙ) ∣ ≈⟨ ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ᵣₙ ((x₂ᵣₙ ℚ.- z₂ₜₙ)))
(ℚP.∣p*q∣≃∣p∣*∣q∣ z₂ₜₙ (y₂ᵣₙ ℚ.- w₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- z₂ₜₙ ∣ ℚ.+
ℚ.∣ z₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ᵣₙ ℚ.- w₂ₜₙ ∣ ≤⟨ ℚP.+-mono-≤ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- z₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound y (2 ℕ.* r ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (fast-equals-to-cauchy x z x≃z (K y ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₁≤ (2 ℕ.* r ℕ.* n) (N≤2kn r))
(N₁≤ (2 ℕ.* t ℕ.* n) (N≤2kn t)))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ᵣₙ ℚ.- w₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound z (2 ℕ.* t ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (fast-equals-to-cauchy y w y≃w (K z ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₂≤ (2 ℕ.* r ℕ.* n) (N≤2kn r))
(N₂≤ (2 ℕ.* t ℕ.* n) (N≤2kn t))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (2 ℕ.* j))) ℚ.+
(+ K z / 1) ℚ.* (+ 1 / (K z ℕ.* (2 ℕ.* j))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ Ky Kz j ->
-- Function for solver
((Ky :* κ (+ 1)) :* (κ (+ 1) :* (Kz :* (κ (+ 2) :* j))) :+ (Kz :* κ (+ 1) :* (κ (+ 1) :* (Ky :* (κ (+ 2) :* j))))) :* j :=
κ (+ 1) :* ((κ (+ 1) :* (Ky :* (κ (+ 2) :* j))) :* (κ (+ 1) :* (Kz :* (κ (+ 2) :* j)))))
refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
N≤2kn : ∀ (k : ℕ) -> {k ≢0} -> N ℕ.≤ 2 ℕ.* k ℕ.* (suc k₂)
N≤2kn (suc k) = ℕP.≤-trans n≥N (ℕP.m≤n*m (suc k₂) {2 ℕ.* (suc k)} ℕP.0<1+n)
N₁≤ : ∀ (k : ℕ) -> N ℕ.≤ k -> N₁ ℕ.≤ k
N₁≤ k N≤k = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N)) N≤k)
N₂≤ : ∀ (k : ℕ) -> N ℕ.≤ k -> N₂ ℕ.≤ k
N₂≤ k N≤k = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N)) N≤k)
*-congˡ : LeftCongruent _≃_ _*_
*-congˡ y≃z = *-cong ≃-refl y≃z
*-congʳ : RightCongruent _≃_ _*_
*-congʳ y≃z = *-cong y≃z ≃-refl
*-comm : Commutative _≃_ _*_
*-comm x y = *≃* λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ seq (x * y) n ℚ.- seq (y * x) n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq (x * y) n)
(ℚP.-‿cong (ℚP.≃-sym (xyℚ≃yxℚ n)))) ⟩
ℚ.∣ seq (x * y) n ℚ.- seq (x * y) n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq (x * y) n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎}
where
open ℚP.≤-Reasoning
xyℚ≃yxℚ : ∀ (n : ℕ) -> seq (x * y) n ℚ.≃ seq (y * x) n
xyℚ≃yxℚ n = begin-equality
seq x (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ℚ.*
seq y (2 ℕ.* (K x ℕ.⊔ K y) ℕ.* n) ≡⟨ cong (λ r ->
seq x (2 ℕ.* r ℕ.* n) ℚ.* seq y (2 ℕ.* r ℕ.* n))
(ℕP.⊔-comm (K x) (K y)) ⟩
seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ℚ.*
seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ≈⟨ ℚP.*-comm (seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n))
(seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n)) ⟩
seq y (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ℚ.*
seq x (2 ℕ.* (K y ℕ.⊔ K x) ℕ.* n) ∎
*-assoc : Associative _≃_ _*_
*-assoc x y z = equality-lemma-onlyif (x * y * z) (x * (y * z)) lemA
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq (x * y * z) n ℚ.- seq (x * (y * z)) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j = suc k₁
N₁ = proj₁ (fast-regular⇒cauchy x (K y ℕ.* K z ℕ.* (3 ℕ.* j)))
N₂ = proj₁ (fast-regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
N₃ = proj₁ (fast-regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
N = suc (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃)
lemB : ∀ (n : ℕ) -> n ℕ.≥ N -> ℚ.∣ seq (x * y * z) n ℚ.- seq (x * (y * z)) n ∣ ℚ.≤ + 1 / j
lemB (suc k₂) n≥N = begin
ℚ.∣ x₄ᵣₛₙ ℚ.* y₄ᵣₛₙ ℚ.* z₂ₛₙ ℚ.- x₂ᵤₙ ℚ.* (y₄ₜᵤₙ ℚ.* z₄ₜᵤₙ) ∣ ≈⟨ ℚP.∣-∣-cong (solve 6 (λ a b c d e f ->
(a ⊗ b ⊗ c ⊖ d ⊗ (e ⊗ f)) ⊜
((b ⊗ c) ⊗ (a ⊖ d) ⊕ d ⊗ (c ⊗ (b ⊖ e) ⊕ e ⊗ (c ⊖ f))))
ℚP.≃-refl x₄ᵣₛₙ y₄ᵣₛₙ z₂ₛₙ x₂ᵤₙ y₄ₜᵤₙ z₄ₜᵤₙ) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ℚ.+
x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+
y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ ((y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ))
(x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ))) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ℚ.* (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+
y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.≃-sym (ℚP.+-congʳ ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ᵤₙ (z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ℚ.+ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ)))))
(ℚP.+-monoʳ-≤ ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣
(ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ x₂ᵤₙ ∣} _ (ℚP.∣p+q∣≤∣p∣+∣q∣
(z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ)) (y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ))))) ⟩
ℚ.∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) ℚ.* (x₄ᵣₛₙ ℚ.- x₂ᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≈⟨ ℚP.+-congˡ
(ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+ ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣))
(ℚP.≃-trans (ℚP.∣p*q∣≃∣p∣*∣q∣ (y₄ᵣₛₙ ℚ.* z₂ₛₙ) (x₄ᵣₛₙ ℚ.- x₂ᵤₙ))
(ℚP.*-congʳ (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ᵣₛₙ z₂ₛₙ))) ⟩
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* (ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≈⟨ ℚP.+-congʳ (ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣)
(ℚP.*-distribˡ-+ ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣
ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ⟩
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.+
(ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.+
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣) ≤⟨ ℚP.≤-trans (ℚP.+-monoʳ-≤ (ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣)
(ℚP.≤-trans (ℚP.+-monoʳ-≤ (ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣) part3)
(ℚP.+-monoˡ-≤ (+ 1 / (3 ℕ.* j)) part2)))
(ℚP.+-monoˡ-≤ (+ 1 / (3 ℕ.* j) ℚ.+ + 1 / (3 ℕ.* j)) part1) ⟩
(+ 1 / (3 ℕ.* j)) ℚ.+ ((+ 1 / (3 ℕ.* j)) ℚ.+ (+ 1 / (3 ℕ.* j))) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ j ->
(κ (+ 1) :* ((κ (+ 3) :* j) :* (κ (+ 3) :* j)) :+ ((κ (+ 1) :* (κ (+ 3) :* j)) :+ (κ (+ 1) :* (κ (+ 3) :* j))) :* (κ (+ 3) :* j)) :* j :=
(κ (+ 1) :* ((κ (+ 3) :* j) :* ((κ (+ 3) :* j) :* (κ (+ 3) :* j)))))
refl (+ j)) ⟩
+ 1 / j ∎
where
n = suc k₂
r = K x ℕ.⊔ K y
s = K (x * y) ℕ.⊔ K z
u = K x ℕ.⊔ K (y * z)
t = K y ℕ.⊔ K z
x₄ᵣₛₙ = seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
y₄ᵣₛₙ = seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
z₂ₛₙ = seq z (2 ℕ.* s ℕ.* n)
x₂ᵤₙ = seq x (2 ℕ.* u ℕ.* n)
y₄ₜᵤₙ = seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
z₄ₜᵤₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N≤2an : ∀ (a : ℕ) -> {a ≢0} -> N ℕ.≤ 2 ℕ.* a ℕ.* n
N≤2an (suc a) = ℕP.≤-trans n≥N (ℕP.m≤n*m n {2 ℕ.* (suc a)} ℕP.0<1+n)
N≤4abn : ∀ (a b : ℕ) -> {a ≢0} -> {b ≢0} -> N ℕ.≤ 2 ℕ.* a ℕ.* (2 ℕ.* b ℕ.* n)
N≤4abn (suc a) (suc b) = let a = suc a; b = suc b in
ℕP.≤-trans (N≤2an b) (ℕP.m≤n*m (2 ℕ.* b ℕ.* n) {2 ℕ.* a} ℕP.0<1+n)
N₁≤_ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) (ℕP.n≤1+n (ℕ.pred N)))) N≤m
N₂≤_ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤_ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) (ℕP.n≤1+n (ℕ.pred N)))) N≤m
N₃≤ : {m : ℕ} -> N ℕ.≤ m -> N₃ ℕ.≤ m
N₃≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) (ℕP.n≤1+n (ℕ.pred N))) N≤m
part1 : ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part1 = begin
ℚ.∣ y₄ᵣₛₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ∣} _ (ℚP.<⇒≤
(canonical-strict-upper-bound y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {(+ K y) / 1} _ (ℚP.<⇒≤
(canonical-strict-upper-bound z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K y ℕ.* K z) / 1} _
(proj₂ (fast-regular⇒cauchy x (K y ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* u ℕ.* n)
(N₁≤ (N≤4abn r s))
(N₁≤ (N≤2an u))) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* (+ 1 / (K y ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ Ky Kz j ->
((Ky :* Kz) :* κ (+ 1)) :* (κ (+ 3) :* j) :=
(κ (+ 1) :* (κ (+ 1) :* (Ky :* Kz :* (κ (+ 3) :* j)))))
refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
part2 : ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part2 = begin
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.* (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ) ∣ ≈⟨ ℚP.≃-trans (ℚP.*-congˡ {ℚ.∣ x₂ᵤₙ ∣} (ℚP.∣p*q∣≃∣p∣*∣q∣ z₂ₛₙ (y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ)))
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ z₂ₛₙ ∣ ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣)) ⟩
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ∣ ℚ.* ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-strict-upper-bound z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.* ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K z) / 1} _
(proj₂ (fast-regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
(N₂≤ (N≤4abn r s))
(N₂≤ (N≤4abn t u))) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.*
(+ 1 / (K x ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ Kx Kz j ->
(Kx :* Kz :* κ (+ 1)) :* (κ (+ 3) :* j) :=
(κ (+ 1) :* (κ (+ 1) :* (Kx :* Kz :* (κ (+ 3) :* j)))))
refl (+ K x) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
part3 : ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣ ℚ.≤ + 1 / (3 ℕ.* j)
part3 = begin
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ℚ.* (z₂ₛₙ ℚ.- z₄ₜᵤₙ) ∣ ≈⟨ ℚP.≃-trans (ℚP.*-congˡ {ℚ.∣ x₂ᵤₙ ∣} (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ₜᵤₙ (z₂ₛₙ ℚ.- z₄ₜᵤₙ)))
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ x₂ᵤₙ ∣ ℚ.∣ y₄ₜᵤₙ ∣ ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣)) ⟩
ℚ.∣ x₂ᵤₙ ∣ ℚ.* ℚ.∣ y₄ₜᵤₙ ∣ ℚ.* ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣} _ (ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ₜᵤₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-strict-upper-bound y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))))) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.* ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K y) / 1} _
(proj₂ (fast-regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
(2 ℕ.* s ℕ.* n) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
(N₃≤ (N≤2an s))
(N₃≤ (N≤4abn t u))) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.*
(+ 1 / (K x ℕ.* K y ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ Kx Ky j ->
(((Kx :* Ky) :* κ (+ 1)) :* (κ (+ 3) :* j)) :=
(κ (+ 1) :* (κ (+ 1) :* (Kx :* Ky :* (κ (+ 3) :* j)))))
refl (+ K x) (+ K y) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
*-distribˡ-+ : _DistributesOverˡ_ _≃_ _*_ _+_
*-distribˡ-+ x y z = equality-lemma-onlyif (x * (y + z)) ((x * y) + (x * z)) lemA
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq (x * (y + z)) n ℚ.- seq ((x * y) + (x * z)) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j = suc k₁
r = K x ℕ.⊔ K (y + z)
s = K x ℕ.⊔ K y
t = K x ℕ.⊔ K z
N₁ = proj₁ (fast-regular⇒cauchy x (K y ℕ.* (4 ℕ.* j)))
N₂ = proj₁ (fast-regular⇒cauchy y (K x ℕ.* (4 ℕ.* j)))
N₃ = proj₁ (fast-regular⇒cauchy x (K z ℕ.* (4 ℕ.* j)))
N₄ = proj₁ (fast-regular⇒cauchy z (K x ℕ.* (4 ℕ.* j)))
N = suc (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃ ℕ.⊔ N₄)
lemB : ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ seq (x * (y + z)) n ℚ.- seq ((x * y) + (x * z)) n ∣ ℚ.≤ + 1 / j
lemB (suc k₂) n≥N = let x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
; x₄ₛₙ = seq x (2 ℕ.* s ℕ.* (2 ℕ.* n))
; x₄ₜₙ = seq x (2 ℕ.* t ℕ.* (2 ℕ.* n))
; y₄ᵣₙ = seq y (2 ℕ.* (2 ℕ.* r ℕ.* n))
; y₄ₛₙ = seq y (2 ℕ.* s ℕ.* (2 ℕ.* n))
; z₄ᵣₙ = seq z (2 ℕ.* (2 ℕ.* r ℕ.* n))
; z₄ₜₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* n)) in begin
ℚ.∣ x₂ᵣₙ ℚ.* (y₄ᵣₙ ℚ.+ z₄ᵣₙ) ℚ.-
(x₄ₛₙ ℚ.* y₄ₛₙ ℚ.+ x₄ₜₙ ℚ.* z₄ₜₙ) ∣ ≈⟨ ℚP.∣-∣-cong (solve 7 (λ a b c d e f g ->
(a ⊗ (b ⊕ c) ⊖ (d ⊗ e ⊕ f ⊗ g)) ⊜
((b ⊗ (a ⊖ d) ⊕ (d ⊗ (b ⊖ e)) ⊕
((c ⊗ (a ⊖ f)) ⊕ (f ⊗ (c ⊖ g))))))
ℚP.≃-refl
x₂ᵣₙ y₄ᵣₙ z₄ᵣₙ x₄ₛₙ y₄ₛₙ x₄ₜₙ z₄ₜₙ) ⟩
ℚ.∣ y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ℚ.+
x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ) ℚ.+
(z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ℚ.+
x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)) ∣ ≤⟨ ℚP.≤-trans (ℚP.∣p+q∣≤∣p∣+∣q∣
(y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ℚ.+ x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ))
(z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ℚ.+ x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)))
(ℚP.+-mono-≤
(ℚP.∣p+q∣≤∣p∣+∣q∣ (y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ)) ( x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ)))
(ℚP.∣p+q∣≤∣p∣+∣q∣ (z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ)) ( x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ)))) ⟩
ℚ.∣ y₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₛₙ) ∣ ℚ.+
ℚ.∣ x₄ₛₙ ℚ.* (y₄ᵣₙ ℚ.- y₄ₛₙ) ∣ ℚ.+
(ℚ.∣ z₄ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₄ₜₙ) ∣ ℚ.+
ℚ.∣ x₄ₜₙ ℚ.* (z₄ᵣₙ ℚ.- z₄ₜₙ) ∣) ≈⟨ ℚP.+-cong (ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ y₄ᵣₙ (x₂ᵣₙ ℚ.- x₄ₛₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₄ₛₙ (y₄ᵣₙ ℚ.- y₄ₛₙ)))
(ℚP.+-cong (ℚP.∣p*q∣≃∣p∣*∣q∣ z₄ᵣₙ (x₂ᵣₙ ℚ.- x₄ₜₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₄ₜₙ (z₄ᵣₙ ℚ.- z₄ₜₙ))) ⟩
ℚ.∣ y₄ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₄ₛₙ ∣ ℚ.+
ℚ.∣ x₄ₛₙ ∣ ℚ.* ℚ.∣ y₄ᵣₙ ℚ.- y₄ₛₙ ∣ ℚ.+
(ℚ.∣ z₄ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₄ₜₙ ∣ ℚ.+
ℚ.∣ x₄ₜₙ ∣ ℚ.* ℚ.∣ z₄ᵣₙ ℚ.- z₄ₜₙ ∣) ≤⟨ ℚP.+-mono-≤
(ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₄ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound y
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (fast-regular⇒cauchy x (K y ℕ.* (4 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* s ℕ.* (2 ℕ.* n))
(N₁≤ N≤2rn) (N₁≤ N≤4sn))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₄ᵣₙ ℚ.- y₄ₛₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound x
(2 ℕ.* s ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (fast-regular⇒cauchy y (K x ℕ.* (4 ℕ.* j)))
(2 ℕ.* (2 ℕ.* r ℕ.* n)) (2 ℕ.* s ℕ.* (2 ℕ.* n))
(N₂≤ N≤4rn) (N₂≤ N≤4sn)))))
(ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₄ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound z
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (fast-regular⇒cauchy x (K z ℕ.* (4 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* (2 ℕ.* n))
(N₃≤ N≤2rn) (N₃≤ N≤4tn))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ z₄ᵣₙ ℚ.- z₄ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-strict-upper-bound x
(2 ℕ.* t ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (fast-regular⇒cauchy z (K x ℕ.* (4 ℕ.* j)))
(2 ℕ.* (2 ℕ.* r ℕ.* n)) (2 ℕ.* t ℕ.* (2 ℕ.* n))
(N₄≤ N≤4rn) (N₄≤ N≤4tn))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (4 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (4 ℕ.* j))) ℚ.+
((+ K z / 1) ℚ.* (+ 1 / (K z ℕ.* (4 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (4 ℕ.* j)))) ≈⟨ ℚ.*≡* (ℤsolve 4 (λ Kx Ky Kz j ->
{- Function for solver -}
(((Ky :* κ (+ 1)) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j))) :+ ((Kx :* κ (+ 1)) :* (κ (+ 1) :* (Ky :* (κ (+ 4) :* j))))) :*
((κ (+ 1) :* (Kz :* (κ (+ 4) :* j))) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j)))) :+
(((Kz :* κ (+ 1)) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j)))) :+ ((Kx :* κ (+ 1)) :* (κ (+ 1) :* (Kz :* (κ (+ 4) :* j))))) :*
((κ (+ 1) :* (Ky :* (κ (+ 4) :* j))) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j))))) :* j :=
κ (+ 1) :* (((κ (+ 1) :* (Ky :* (κ (+ 4) :* j))) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j)))) :*
((κ (+ 1) :* (Kz :* (κ (+ 4) :* j))) :* (κ (+ 1) :* (Kx :* (κ (+ 4) :* j))))))
refl (+ K x) (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
N≤2rn : N ℕ.≤ 2 ℕ.* r ℕ.* n
N≤2rn = ℕP.≤-trans n≥N (ℕP.m≤n*m n {2 ℕ.* r} ℕP.0<1+n)
N≤4sn : N ℕ.≤ 2 ℕ.* s ℕ.* (2 ℕ.* n)
N≤4sn = ℕP.≤-trans (ℕP.≤-trans n≥N (ℕP.m≤n*m n {2} ℕP.0<1+n)) (ℕP.m≤n*m (2 ℕ.* n) {2 ℕ.* s} ℕP.0<1+n)
N≤4rn : N ℕ.≤ 2 ℕ.* (2 ℕ.* r ℕ.* n)
N≤4rn = ℕP.≤-trans (ℕP.≤-trans n≥N (ℕP.m≤n*m n {2 ℕ.* r} ℕP.0<1+n)) (ℕP.m≤n*m (2 ℕ.* r ℕ.* n) {2} ℕP.0<1+n)
N≤4tn : N ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* n)
N≤4tn = ℕP.≤-trans (ℕP.≤-trans n≥N (ℕP.m≤n*m n {2} ℕP.0<1+n)) (ℕP.m≤n*m (2 ℕ.* n) {2 ℕ.* t} ℕP.0<1+n)
N₁≤_ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) (ℕP.n≤1+n (ℕ.pred N)))) N≤m
N₂≤_ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) (ℕP.n≤1+n (ℕ.pred N)))) N≤m
N₃≤_ : {m : ℕ} -> N ℕ.≤ m -> N₃ ℕ.≤ m
N₃≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄))
(ℕP.n≤1+n (ℕ.pred N))) N≤m
N₄≤_ : {m : ℕ} -> N ℕ.≤ m -> N₄ ℕ.≤ m
N₄≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) (ℕP.n≤1+n (ℕ.pred N))) N≤m
*-distribʳ-+ : _DistributesOverʳ_ _≃_ _*_ _+_
*-distribʳ-+ x y z = begin
(y + z) * x ≈⟨ *-comm (y + z) x ⟩
x * (y + z) ≈⟨ *-distribˡ-+ x y z ⟩
x * y + x * z ≈⟨ +-cong (*-comm x y) (*-comm x z) ⟩
y * x + z * x ∎
where open ≃-Reasoning
*-distrib-+ : _DistributesOver_ _≃_ _*_ _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
*-identityˡ : LeftIdentity _≃_ 1ℝ _*_
*-identityˡ x = *≃* (λ { (suc k₁) → let n = suc k₁; k = K 1ℝ ℕ.⊔ K x in begin
ℚ.∣ ℚ.1ℚᵘ ℚ.* seq x (2 ℕ.* k ℕ.* n) ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- seq x n) (ℚP.*-identityˡ (seq x (2 ℕ.* k ℕ.* n)))) ⟩
ℚ.∣ seq x (2 ℕ.* k ℕ.* n) ℚ.- seq x n ∣ ≤⟨ reg x (2 ℕ.* k ℕ.* n) n ⟩
(+ 1 / (2 ℕ.* k ℕ.* n)) ℚ.+ (+ 1 / n) ≤⟨ ℚP.+-monoˡ-≤ (+ 1 / n) {+ 1 / (2 ℕ.* k ℕ.* n)} {+ 1 / n} (ℚ.*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (ℤ.+≤+ (ℕP.m≤n*m n {2 ℕ.* k} ℕP.0<1+n)))) ⟩
(+ 1 / n) ℚ.+ (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
((Κ (+ 1) ⊗ n ⊕ Κ (+ 1) ⊗ n) ⊗ n) ⊜ (Κ (+ 2) ⊗ (n ⊗ n)))
refl (+ n)) ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℤ-Solver
*-identityʳ : RightIdentity _≃_ 1ℝ _*_
*-identityʳ x = ≃-trans (*-comm x 1ℝ) (*-identityˡ x)
*-identity : Identity _≃_ 1ℝ _*_
*-identity = *-identityˡ , *-identityʳ
-‿cong : Congruent₁ _≃_ (-_)
-‿cong {x} {y} (*≃* x₁) = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.- seq x n ℚ.- (ℚ.- seq y n) ∣ ≡⟨ trans (cong (λ x → ℚ.∣ x ∣) (sym (ℚP.neg-distrib-+ (seq x n) (ℚ.- seq y n))))
(ℚP.∣-p∣≡∣p∣ (seq x n ℚ.- seq y n)) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x₁ n ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
*-zeroˡ : LeftZero _≃_ 0ℝ _*_
*-zeroˡ x = *≃* (λ { (suc k₁) -> let n = suc k₁; k = K 0ℝ ℕ.⊔ K x in begin
ℚ.∣ 0ℚᵘ ℚ.* seq x (2 ℕ.* k ℕ.* n) ℚ.- 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- 0ℚᵘ) (ℚP.*-zeroˡ (seq x (2 ℕ.* k ℕ.* n)))) ⟩
0ℚᵘ ≤⟨ ℚ.*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (ℤ.+≤+ ℕ.z≤n)) ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
*-zeroʳ : RightZero _≃_ 0ℝ _*_
*-zeroʳ x = ≃-trans (*-comm x 0ℝ) (*-zeroˡ x)
*-zero : Zero _≃_ 0ℝ _*_
*-zero = *-zeroˡ , *-zeroʳ
-- Algebraic structures
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _+_
}
+-rawMonoid : RawMonoid 0ℓ 0ℓ
+-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
}
+-0-rawGroup : RawGroup 0ℓ 0ℓ
+-0-rawGroup = record
{ Carrier = ℝ
; _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
; _⁻¹ = -_
}
+-*-rawSemiring : RawSemiring 0ℓ 0ℓ
+-*-rawSemiring = record
{ Carrier = ℝ
; _≈_ = _≃_
; _+_ = _+_
; _*_ = _*_
; 0# = 0ℝ
; 1# = 1ℝ
}
+-*-rawRing : RawRing 0ℓ 0ℓ
+-*-rawRing = record
{ Carrier = ℝ
; _≈_ = _≃_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0ℝ
; 1# = 1ℝ
}
abstract
≃-isEquivalence₂ = ≃-isEquivalence
+-cong₂ : Congruent₂ _≃_ _+_
+-cong₂ = +-cong
-‿cong₂ : Congruent₁ _≃_ (-_)
-‿cong₂ = -‿cong
+-inverse₂ : Inverse _≃_ 0ℝ -_ _+_
+-inverse₂ = +-inverse
+-identity₂ : Identity _≃_ 0ℝ _+_
+-identity₂ = +-identity
+-assoc₂ : Associative _≃_ _+_
+-assoc₂ = +-assoc
+-comm₂ : Commutative _≃_ _+_
+-comm₂ = +-comm
+-isMagma : IsMagma _≃_ _+_
+-isMagma = record
{ isEquivalence = ≃-isEquivalence₂
; ∙-cong = +-cong₂
}
+-isSemigroup : IsSemigroup _≃_ _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc₂
}
+-0-isMonoid : IsMonoid _≃_ _+_ 0ℝ
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity₂
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _≃_ _+_ 0ℝ
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = +-comm
}
+-0-isGroup : IsGroup _≃_ _+_ 0ℝ (-_)
+-0-isGroup = record
{ isMonoid = +-0-isMonoid
; inverse = +-inverse₂
; ⁻¹-cong = -‿cong₂
}
+-0-isAbelianGroup : IsAbelianGroup _≃_ _+_ 0ℝ (-_)
+-0-isAbelianGroup = record
{ isGroup = +-0-isGroup
; comm = +-comm₂
}
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
+-0-group : Group 0ℓ 0ℓ
+-0-group = record
{ isGroup = +-0-isGroup
}
+-0-abelianGroup : AbelianGroup 0ℓ 0ℓ
+-0-abelianGroup = record
{ isAbelianGroup = +-0-isAbelianGroup
}
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _*_
}
*-rawMonoid : RawMonoid 0ℓ 0ℓ
*-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _*_
; ε = 1ℝ
}
abstract
*-cong₂ : Congruent₂ _≃_ _*_
*-cong₂ = *-cong
*-isMagma : IsMagma _≃_ _*_
*-isMagma = record
{ isEquivalence = ≃-isEquivalence₂
; ∙-cong = *-cong₂
}
abstract
*-assoc₂ : Associative _≃_ _*_
*-assoc₂ = *-assoc
*-isSemigroup : IsSemigroup _≃_ _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc₂
}
abstract
*-identity₂ : Identity _≃_ 1ℝ _*_
*-identity₂ = *-identity
*-1-isMonoid : IsMonoid _≃_ _*_ 1ℝ
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≃_ _*_ 1ℝ
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = *-comm
}
abstract
*-distrib-+₂ : (_≃_ DistributesOver _*_) _+_
*-distrib-+₂ = *-distrib-+
*-zero₂ : Zero _≃_ 0ℝ _*_
*-zero₂ = *-zero
*-comm₂ : Commutative _≃_ _*_
*-comm₂ = *-comm
+-*-isRing : IsRing _≃_ _+_ _*_ -_ 0ℝ 1ℝ
+-*-isRing = record
{ +-isAbelianGroup = +-0-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+₂
; zero = *-zero₂
}
+-*-isCommutativeRing : IsCommutativeRing _≃_ _+_ _*_ -_ 0ℝ 1ℝ
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = *-comm₂
}
+-*-isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _≃_ _+_ _*_ 0ℝ 1ℝ
+-*-isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
}
+-*-isSemiring : IsSemiring _≃_ _+_ _*_ 0ℝ 1ℝ
+-*-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = +-*-isSemiringWithoutAnnihilatingZero
; zero = *-zero
}
+-*-isCommutativeSemiring : IsCommutativeSemiring _≃_ _+_ _*_ 0ℝ 1ℝ
+-*-isCommutativeSemiring = record
{ isSemiring = +-*-isSemiring
; *-comm = *-comm
}
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
+-*-semiring : Semiring 0ℓ 0ℓ
+-*-semiring = record
{ isSemiring = +-*-isSemiring
}
+-*-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
+-*-commutativeSemiring = record
{ isCommutativeSemiring = +-*-isCommutativeSemiring
}
+-*-ring : Ring 0ℓ 0ℓ
+-*-ring = record
{ isRing = +-*-isRing
}
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ
+-*-commutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
}
{-
module ℝ-+-*-Solver =
Solver +-*-rawRing (ACR.fromCommutativeRing +-*-commutativeRing) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing +-*-commutativeRing)) (λ x y -> nothing)
{-
The ring solver for ℝ is very weak! It cannot even solve involution of negatives, while the solver for ℚ can.
-}
{-
testing : ∀ x -> - (- x) ≃ x
testing x = solve 1 (λ x -> :- (:- x) := x) {!≃-refl!} {!!}
where
open ℝ-+-*-Solver
test : ∀ p -> ℚ.- (ℚ.- p) ℚ.≃ p
test p = solve 1 (λ p -> :- (:- p) := p) ℚP.≃-refl p
where
open ℚ-Solver.+-*-Solver
-}-}
--Properties of -_
neg-involutive : Involutive _≃_ (-_)
neg-involutive x = *≃* λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.- (ℚ.- seq x n) ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseˡ (ℚ.- seq x n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎}
where open ℚP.≤-Reasoning
neg-distrib-+ : ∀ x y -> - (x + y) ≃ (- x) + (- y)
neg-distrib-+ x y = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.- (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ℚ.-
(ℚ.- seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y ->
(⊝ (x ⊕ y) ⊖ (⊝ x ⊖ y)) ⊜ Κ (0ℚᵘ)) ℚP.≃-refl
(seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
--Properties of _⊔_
⊔-cong : Congruent₂ _≃_ _⊔_
⊔-cong {x} {z} {y} {w} (*≃* x≃z) (*≃* y≃w) = *≃* partA
where
partA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ℚ.∣ seq (x ⊔ y) n ℚ.- seq (z ⊔ w) n ∣ ℚ.≤ (+ 2 / n) {n≢0}
partA (suc k₁) = [ left , right ]′ (ℚP.≤-total (seq x n ℚ.⊔ seq y n) (seq z n ℚ.⊔ seq w n))
where
open ℚP.≤-Reasoning
open ℚ-Solver
n = suc k₁
partB : ∀ a b c d -> a ℚ.≤ b -> ℚ.∣ b ℚ.- d ∣ ℚ.≤ + 2 / n ->
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ℚ.≤ + 2 / n
partB a b c d a≤b hyp = begin
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ≤⟨ ℚP.+-mono-≤ (ℚP.≤-reflexive (ℚP.p≤q⇒p⊔q≃q a≤b)) (ℚP.neg-mono-≤ (ℚP.p≤q⊔p c d)) ⟩
b ℚ.- d ≤⟨ p≤∣p∣ (b ℚ.- d) ⟩
ℚ.∣ b ℚ.- d ∣ ≤⟨ hyp ⟩
+ 2 / n ∎
left : seq x n ℚ.⊔ seq y n ℚ.≤ seq z n ℚ.⊔ seq w n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
left hyp1 = [ zn≤wn , wn≤zn ]′ (ℚP.≤-total (seq z n) (seq w n))
where
first : ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≃ (seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n)
first = begin-equality
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ ((seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> (⊝ (a ⊖ b)) ⊜ (b ⊖ a))
ℚP.≃-refl (seq x n ℚ.⊔ seq y n) (seq z n ℚ.⊔ seq w n))) ⟩
ℚ.∣ (seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ∎
zn≤wn : seq z n ℚ.≤ seq w n -> ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
zn≤wn hyp2 = begin
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ first ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ≤⟨ partB (seq z n) (seq w n) (seq x n) (seq y n) hyp2
(ℚP.≤-respˡ-≃ (∣p-q∣≃∣q-p∣ (seq y n) (seq w n)) (y≃w n)) ⟩
+ 2 / n ∎
wn≤zn : seq w n ℚ.≤ seq z n -> ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
wn≤zn hyp2 = begin
ℚ.∣ (seq x n ℚ.⊔ seq y n) ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ first ⟩
(seq z n ℚ.⊔ seq w n) ℚ.- (seq x n ℚ.⊔ seq y n) ≈⟨ ℚP.+-cong (ℚP.⊔-comm (seq z n) (seq w n)) (ℚP.-‿cong (ℚP.⊔-comm (seq x n) (seq y n))) ⟩
(seq w n ℚ.⊔ seq z n) ℚ.- (seq y n ℚ.⊔ seq x n) ≤⟨ partB (seq w n) (seq z n) (seq y n) (seq x n) hyp2
(ℚP.≤-respˡ-≃ (∣p-q∣≃∣q-p∣ (seq x n) (seq z n)) (x≃z n)) ⟩
+ 2 / n ∎
right : seq z n ℚ.⊔ seq w n ℚ.≤ seq x n ℚ.⊔ seq y n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
right hyp1 = [ xn≤yn , yn≤xn ]′ (ℚP.≤-total (seq x n) (seq y n))
where
xn≤yn : seq x n ℚ.≤ seq y n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
xn≤yn hyp2 = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ≤⟨ partB (seq x n) (seq y n) (seq z n) (seq w n) hyp2 (y≃w n) ⟩
+ 2 / n ∎
yn≤xn : seq y n ℚ.≤ seq x n -> ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ℚ.≤ + 2 / n
yn≤xn hyp2 = begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp1) ⟩
seq x n ℚ.⊔ seq y n ℚ.- (seq z n ℚ.⊔ seq w n) ≈⟨ ℚP.+-cong (ℚP.⊔-comm (seq x n) (seq y n)) (ℚP.-‿cong (ℚP.⊔-comm (seq z n) (seq w n))) ⟩
seq y n ℚ.⊔ seq x n ℚ.- (seq w n ℚ.⊔ seq z n) ≤⟨ partB (seq y n) (seq x n) (seq w n) (seq z n) hyp2 (x≃z n) ⟩
+ 2 / n ∎
⊔-congˡ : LeftCongruent _≃_ _⊔_
⊔-congˡ y≃z = ⊔-cong ≃-refl y≃z
⊔-congʳ : RightCongruent _≃_ _⊔_
⊔-congʳ y≃z = ⊔-cong y≃z ≃-refl
⊔-comm : Commutative _≃_ _⊔_
⊔-comm x y = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq y n ℚ.⊔ seq x n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n) (ℚP.-‿cong (ℚP.⊔-comm (seq y n) (seq x n)))) ⟩
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.- (seq x n ℚ.⊔ seq y n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n ℚ.⊔ seq y n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
⊔-assoc : Associative _≃_ _⊔_
⊔-assoc x y z = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n ℚ.- (seq x n ℚ.⊔ (seq y n ℚ.⊔ seq z n)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n)
(ℚP.-‿cong (ℚP.≃-sym (ℚP.⊔-assoc (seq x n) (seq y n) (seq z n))))) ⟩
ℚ.∣ seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n ℚ.- (seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n ℚ.⊔ seq y n ℚ.⊔ seq z n)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
-- Properties of _⊓_
x⊓y≃x⊓₂y : ∀ x y -> x ⊓ y ≃ x ⊓₂ y
x⊓y≃x⊓₂y x y = *≃* (λ { (suc k₁) -> let n = suc k₁; xₙ = seq x n; yₙ = seq y n in begin
ℚ.∣ xₙ ℚ.⊓ yₙ ℚ.- ℚ.- ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (xₙ ℚ.⊓ yₙ)
(ℚP.-‿cong (ℚP.≃-trans (ℚP.neg-distrib-⊔-⊓ (ℚ.- xₙ) (ℚ.- yₙ))
(ℚP.⊓-cong (ℚP.neg-involutive xₙ) (ℚP.neg-involutive yₙ))))) ⟩
ℚ.∣ xₙ ℚ.⊓ yₙ ℚ.- xₙ ℚ.⊓ yₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (xₙ ℚ.⊓ yₙ)) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
⊓₂-cong : Congruent₂ _≃_ _⊓₂_
⊓₂-cong x≃y u≃v = -‿cong (⊔-cong (-‿cong x≃y) (-‿cong u≃v))
⊓₂-congˡ : LeftCongruent _≃_ _⊓₂_
⊓₂-congˡ y≃z = ⊓₂-cong ≃-refl y≃z
⊓₂-congʳ : RightCongruent _≃_ _⊓₂_
⊓₂-congʳ y≃z = ⊓₂-cong y≃z ≃-refl
⊓₂-comm : Commutative _≃_ _⊓₂_
⊓₂-comm x y = -‿cong (⊔-comm (- x) (- y))
⊓₂-assoc : Associative _≃_ _⊓₂_
⊓₂-assoc x y z = -‿cong (begin
(- (- (- x ⊔ - y))) ⊔ (- z) ≈⟨ ⊔-congʳ (neg-involutive (- x ⊔ - y)) ⟩
(- x ⊔ - y) ⊔ (- z) ≈⟨ ⊔-assoc (- x) (- y) (- z) ⟩
(- x) ⊔ (- y ⊔ - z) ≈⟨ ⊔-congˡ (≃-symm (neg-involutive (- y ⊔ - z))) ⟩
(- x) ⊔ (- (- (- y ⊔ - z))) ∎)
where open ≃-Reasoning
⊓-cong : Congruent₂ _≃_ _⊓_
⊓-cong {x} {u} {y} {v} x≃u y≃v = begin
x ⊓ y ≈⟨ x⊓y≃x⊓₂y x y ⟩
x ⊓₂ y ≈⟨ ⊓₂-cong x≃u y≃v ⟩
u ⊓₂ v ≈⟨ ≃-symm (x⊓y≃x⊓₂y u v) ⟩
u ⊓ v ∎
where open ≃-Reasoning
⊓-congˡ : LeftCongruent _≃_ _⊓_
⊓-congˡ y≃z = ⊓-cong ≃-refl y≃z
⊓-congʳ : RightCongruent _≃_ _⊓_
⊓-congʳ y≃z = ⊓-cong y≃z ≃-refl
⊓-comm : Commutative _≃_ _⊓_
⊓-comm x y = begin
x ⊓ y ≈⟨ x⊓y≃x⊓₂y x y ⟩
x ⊓₂ y ≈⟨ ⊓₂-comm x y ⟩
y ⊓₂ x ≈⟨ ≃-symm (x⊓y≃x⊓₂y y x) ⟩
y ⊓ x ∎
where open ≃-Reasoning
⊓-assoc : Associative _≃_ _⊓_
⊓-assoc x y z = begin
x ⊓ y ⊓ z ≈⟨ ≃-trans (⊓-congʳ (x⊓y≃x⊓₂y x y)) (x⊓y≃x⊓₂y (x ⊓₂ y) z) ⟩
x ⊓₂ y ⊓₂ z ≈⟨ ⊓₂-assoc x y z ⟩
x ⊓₂ (y ⊓₂ z) ≈⟨ ≃-trans (⊓₂-congˡ (≃-symm (x⊓y≃x⊓₂y y z))) (≃-symm (x⊓y≃x⊓₂y x (y ⊓ z))) ⟩
x ⊓ (y ⊓ z) ∎
where open ≃-Reasoning
-- Alternative definition than Bishop's, but equivalent.
∣_∣ : ℝ -> ℝ
seq ∣ x ∣ n = ℚ.∣ seq x n ∣
reg ∣ x ∣ (suc k₁) (suc k₂) = let m = suc k₁; n = suc k₂ in begin
ℚ.∣ ℚ.∣ seq x m ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≤⟨ ∣∣p∣-∣q∣∣≤∣p-q∣ (seq x m) (seq x n) ⟩
ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ reg x m n ⟩
+ 1 / m ℚ.+ + 1 / n ∎
where open ℚP.≤-Reasoning
∣-∣-cong : Congruent₁ _≃_ ∣_∣
∣-∣-cong {x} {y} (*≃* x≃y) = *≃* (λ { (suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- ℚ.∣ seq y n ∣ ∣ ≤⟨ ∣∣p∣-∣q∣∣≤∣p-q∣ (seq x n) (seq y n) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x≃y n ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
∣x*y∣≃∣x∣*∣y∣ : ∀ x y -> ∣ x * y ∣ ≃ ∣ x ∣ * ∣ y ∣
∣x*y∣≃∣x∣*∣y∣ x y = *≃* (λ { (suc k₁) -> let n = suc k₁; r = K x ℕ.⊔ K y in begin
ℚ.∣ ℚ.∣ seq (x * y) n ∣ ℚ.- seq (∣ x ∣ * ∣ y ∣) n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ ℚ.∣ seq (x * y) n ∣
(ℚP.-‿cong (ℚP.≃-sym (ℚP.∣p*q∣≃∣p∣*∣q∣ (seq x (2 ℕ.* r ℕ.* n)) (seq y (2 ℕ.* r ℕ.* n)))))) ⟩
ℚ.∣ ℚ.∣ seq (x * y) n ∣ ℚ.- ℚ.∣ seq (x * y) n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ℚ.∣ seq (x * y) n ∣) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
-- Sign predicates
data Positive : Pred ℝ 0ℓ where
pos* : ∀ {x} -> (∃ λ (n-1 : ℕ) -> seq x (suc n-1) ℚ.> + 1 / (suc n-1)) -> Positive x
data NonNegative : Pred ℝ 0ℓ where
nonNeg* : ∀ {x} -> (∀ (n : ℕ) -> {n≢0 : n ≢0} -> seq x n ℚ.≥ ℚ.- ((+ 1 / n) {n≢0})) -> NonNegative x
-- Compare this to lemma2-8-1a in Reals.agda. This is much more readable and it's shorter!
lemma-2-8-1-if : ∀ {x} -> Positive x -> ∃ λ (N-1 : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N-1 -> seq x m ℚ.≥ + 1 / (suc N-1)
lemma-2-8-1-if {x} (pos* (n-1 , posx)) = let n = suc n-1
; arch = fast-archimedean-ℚ₂ (seq x n ℚ.- + 1 / n) (+ 2) (ℚ.positive (p<q⇒0<q-p (+ 1 / n) (seq x n) posx))
; N = suc (proj₁ arch) in ℕ.pred N , λ { (suc k₁) m≥N -> let m = suc k₁ in begin
+ 1 / N ≈⟨ ℚ.*≡* (ℤsolve 1 (λ N ->
κ (+ 1) :* (N :* N) := ((κ (+ 2) :* N :- κ (+ 1) :* N) :* N))
refl (+ N)) ⟩
+ 2 / N ℚ.- + 1 / N ≤⟨ ℚP.+-mono-≤ (ℚP.<⇒≤ (proj₂ arch)) (ℚP.neg-mono-≤ (q≤r⇒+p/r≤+p/q 1 N m m≥N)) ⟩
seq x n ℚ.- + 1 / n ℚ.- + 1 / m ≈⟨ solve 3 (λ xₙ n⁻¹ m⁻¹ -> (xₙ ⊖ n⁻¹ ⊖ m⁻¹) ⊜ (xₙ ⊖ (n⁻¹ ⊕ m⁻¹))) ℚP.≃-refl (seq x n) (+ 1 / n) (+ 1 / m) ⟩
seq x n ℚ.- (+ 1 / n ℚ.+ + 1 / m) ≤⟨ ℚP.+-monoʳ-≤ (seq x n) (ℚP.neg-mono-≤ (reg x n m)) ⟩
seq x n ℚ.- ℚ.∣ seq x n ℚ.- seq x m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x n) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x n ℚ.- seq x m))) ⟩
seq x n ℚ.- (seq x n ℚ.- seq x m) ≈⟨ solve 2 (λ xₙ xₘ -> (xₙ ⊖ (xₙ ⊖ xₘ)) ⊜ xₘ) ℚP.≃-refl (seq x n) (seq x m) ⟩
seq x m ∎}
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊖_ to _:-_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
abstract
fast-lemma-2-8-1-if : ∀ {x} -> Positive x -> ∃ λ (N-1 : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N-1 -> seq x m ℚ.≥ + 1 / (suc N-1)
fast-lemma-2-8-1-if = lemma-2-8-1-if
lemma-2-8-1-onlyif : ∀ {x : ℝ} -> (∃ λ (N-1 : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N-1 -> seq x m ℚ.≥ + 1 / (suc N-1)) -> Positive x
lemma-2-8-1-onlyif {x} (N-1 , proof) = let N = suc N-1 in pos* (N , (begin-strict
+ 1 / (suc N) <⟨ ℚ.*<* (ℤP.*-monoˡ-<-pos 0 (ℤ.+<+ (ℕP.n<1+n N))) ⟩
+ 1 / N ≤⟨ proof (suc N) (ℕP.n≤1+n N) ⟩
seq x (suc N) ∎))
where open ℚP.≤-Reasoning
lemma-2-8-2-if : ∀ {x : ℝ} -> NonNegative x -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 × (∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lemma-2-8-2-if {x} (nonNeg* nonx) (suc k₁) = let n = suc k₁ in n , _ , λ {(suc k₂) m≥n -> let m = suc k₂ in begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.neg-mono-≤ (q≤r⇒+p/r≤+p/q 1 n m m≥n) ⟩
ℚ.- (+ 1 / m) ≤⟨ nonx m ⟩
seq x m ∎}
where open ℚP.≤-Reasoning
abstract
fast-lemma-2-8-2-if : ∀ {x : ℝ} -> NonNegative x -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 × (∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
fast-lemma-2-8-2-if = lemma-2-8-2-if
p-q≤j⁻¹⇒p≤q : ∀ {p q : ℚᵘ} ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} -> p ℚ.- q ℚ.≤ (+ 1 / j) {j≢0}) -> p ℚ.≤ q
p-q≤j⁻¹⇒p≤q {p} {q} hyp = ℚP.≮⇒≥ λ q<p -> let arch = fast-archimedean-ℚ₂ (p ℚ.- q) (+ 1) (ℚ.positive (p<q⇒0<q-p q p q<p)); j = suc (proj₁ arch) in
ℚP.<⇒≱ (proj₂ arch) (hyp j)
p-j⁻¹≤q⇒p≤q : ∀ {p q : ℚᵘ} -> (∀ (j : ℕ) -> {j≢0 : j ≢0} -> p ℚ.- (+ 1 / j) {j≢0} ℚ.≤ q) -> p ℚ.≤ q
p-j⁻¹≤q⇒p≤q {p} {q} hyp = p-q≤j⁻¹⇒p≤q λ { (suc k₁) -> let j = suc k₁ in begin
p ℚ.- q ≈⟨ solve 3 (λ p q j⁻¹ ->
(p ⊖ q) ⊜ (p ⊖ j⁻¹ ⊖ q ⊕ j⁻¹))
ℚP.≃-refl p q (+ 1 / j) ⟩
p ℚ.- + 1 / j ℚ.- q ℚ.+ + 1 / j ≤⟨ ℚP.+-monoˡ-≤ (+ 1 / j) (ℚP.+-monoˡ-≤ (ℚ.- q) (hyp j)) ⟩
q ℚ.- q ℚ.+ + 1 / j ≈⟨ solve 2 (λ q j⁻¹ -> (q ⊖ q ⊕ j⁻¹) ⊜ j⁻¹) ℚP.≃-refl q (+ 1 / j) ⟩
+ 1 / j ∎}
where
open ℚP.≤-Reasoning
open ℚ-Solver
lemma-2-8-2-onlyif : ∀ {x : ℝ} -> (∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})) -> NonNegative x
lemma-2-8-2-onlyif {x} hyp = nonNeg* (λ { (suc k₁) -> let n = suc k₁ in p-j⁻¹≤q⇒p≤q (λ { (suc k₂) ->
let j = suc k₂; N₂ⱼ = suc (proj₁ (hyp (2 ℕ.* j))); m = N₂ⱼ ℕ.⊔ (2 ℕ.* j) in begin
ℚ.- (+ 1 / n) ℚ.- (+ 1 / j) ≈⟨ ℚP.+-congʳ (ℚ.- (+ 1 / n)) {ℚ.- (+ 1 / j)} {ℚ.- (+ 1 / (2 ℕ.* j) ℚ.+ + 1 / (2 ℕ.* j))}
(ℚP.-‿cong (ℚ.*≡* (ℤsolve 1 (λ j ->
κ (+ 1) :* (κ (+ 2) :* j :* (κ (+ 2) :* j)) :=
(((κ (+ 1) :* (κ (+ 2) :* j) :+ κ (+ 1) :* (κ (+ 2) :* j)) :* j)))
refl (+ j)))) ⟩
ℚ.- (+ 1 / n) ℚ.- (+ 1 / (2 ℕ.* j) ℚ.+ + 1 / (2 ℕ.* j)) ≤⟨ ℚP.+-monoʳ-≤ (ℚ.- (+ 1 / n))
(ℚP.neg-mono-≤ (ℚP.+-monoˡ-≤ (+ 1 / (2 ℕ.* j))
(q≤r⇒+p/r≤+p/q 1 (2 ℕ.* j) m (ℕP.m≤n⊔m N₂ⱼ (2 ℕ.* j))))) ⟩
ℚ.- (+ 1 / n) ℚ.- (+ 1 / m ℚ.+ + 1 / (2 ℕ.* j)) ≈⟨ solve 3 (λ n⁻¹ m⁻¹ k⁻¹ ->
(⊝ n⁻¹ ⊖ (m⁻¹ ⊕ k⁻¹)) ⊜ (⊝ k⁻¹ ⊖ (m⁻¹ ⊕ n⁻¹)))
ℚP.≃-refl (+ 1 / n) (+ 1 / m) (+ 1 / (2 ℕ.* j)) ⟩
ℚ.- (+ 1 / (2 ℕ.* j)) ℚ.- (+ 1 / m ℚ.+ + 1 / n) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ (hyp (2 ℕ.* j))) m (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N₂ⱼ)) (ℕP.m≤m⊔n N₂ⱼ (2 ℕ.* j))))
(ℚP.neg-mono-≤ (reg x m n)) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq x n))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq x n) ≈⟨ solve 2 (λ xₘ xₙ -> (xₘ ⊖ (xₘ ⊖ xₙ)) ⊜ xₙ) ℚP.≃-refl (seq x m) (seq x n) ⟩
seq x n ∎})})
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
pos-cong : ∀ {x y} -> x ≃ y -> Positive x -> Positive y
pos-cong {x} {y} x≃y posx = let fromPosx = fast-lemma-2-8-1-if posx; N₁ = suc (proj₁ fromPosx); fromx≃y = fast-equality-lemma-if x y x≃y (2 ℕ.* N₁)
; N₂ = suc (proj₁ fromx≃y); N = N₁ ℕ.⊔ N₂ in
lemma-2-8-1-onlyif {y} (ℕ.pred (2 ℕ.* N) , λ { (suc k₁) m≥2N -> let m = suc k₁ in begin
+ 1 / (2 ℕ.* N) ≤⟨ q≤r⇒+p/r≤+p/q 1 (2 ℕ.* N₁) (2 ℕ.* N) (ℕP.*-monoʳ-≤ 2 (ℕP.m≤m⊔n N₁ N₂)) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ N₁ ->
κ (+ 1) :* (N₁ :* (κ (+ 2) :* N₁)) :=
(κ (+ 1) :* (κ (+ 2) :* N₁) :+ (:- κ (+ 1)) :* N₁) :* (κ (+ 2) :* N₁))
refl (+ N₁)) ⟩
+ 1 / N₁ ℚ.- + 1 / (2 ℕ.* N₁) ≤⟨ ℚP.+-mono-≤
(proj₂ fromPosx m (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m N {2} ℕP.0<1+n) m≥2N)))
(ℚP.neg-mono-≤ (proj₂ fromx≃y m
(ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N₂)) (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m N {2} ℕP.0<1+n) m≥2N))))) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq y m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq y m))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq y m) ≈⟨ solve 2 (λ xₘ yₘ -> (xₘ ⊖ (xₘ ⊖ yₘ)) ⊜ yₘ) ℚP.≃-refl (seq x m) (seq y m) ⟩
seq y m ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; ⊝_ to :-_
; _⊜_ to _:=_
; Κ to κ
)
pos⇒nonNeg : ∀ {x} -> Positive x -> NonNegative x
pos⇒nonNeg {x} posx = let fromPosx = fast-lemma-2-8-1-if posx; N = suc (proj₁ fromPosx) in
lemma-2-8-2-onlyif (λ { (suc k₁) -> let n = suc k₁ in N , _ , λ { (suc k₂) m≥N -> let m = suc k₂ in
begin
ℚ.- (+ 1 / n) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ fromPosx m m≥N ⟩
seq x m ∎}})
where open ℚP.≤-Reasoning
posx,y⇒posx+y : ∀ {x y} -> Positive x -> Positive y -> Positive (x + y)
posx,y⇒posx+y {x} {y} posx posy = let fromPosx = fast-lemma-2-8-1-if posx; fromPosy = fast-lemma-2-8-1-if posy
; N₁ = suc (proj₁ fromPosx); N₂ = suc (proj₁ fromPosy); N = N₁ ℕ.⊔ N₂ in
lemma-2-8-1-onlyif (ℕ.pred N , λ { (suc k₁) m≥N -> let m = suc k₁ in begin
+ 1 / N ≤⟨ ℚP.p≤p+q {+ 1 / N} {+ 1 / N} _ ⟩
+ 1 / N ℚ.+ + 1 / N ≤⟨ ℚP.+-mono-≤
(q≤r⇒+p/r≤+p/q 1 N₁ N (ℕP.m≤m⊔n N₁ N₂))
(q≤r⇒+p/r≤+p/q 1 N₂ N (ℕP.m≤n⊔m N₁ N₂)) ⟩
+ 1 / N₁ ℚ.+ + 1 / N₂ ≤⟨ ℚP.+-mono-≤
(proj₂ fromPosx (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) m≥N) (ℕP.m≤n*m m {2} ℕP.0<1+n)))
(proj₂ fromPosy (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) m≥N) (ℕP.m≤n*m m {2} ℕP.0<1+n))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎})
where open ℚP.≤-Reasoning
nonNegx,y⇒nonNegx+y : ∀ {x y} -> NonNegative x -> NonNegative y -> NonNegative (x + y)
nonNegx,y⇒nonNegx+y {x} {y} nonx nony = lemma-2-8-2-onlyif (λ { (suc k₁) ->
let n = suc k₁; fromNonx = fast-lemma-2-8-2-if nonx (2 ℕ.* n); fromNony = fast-lemma-2-8-2-if nony (2 ℕ.* n)
; Nx = proj₁ fromNonx; Ny = proj₁ fromNony; N = suc (Nx ℕ.⊔ Ny)
; Nx≤N = ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) (ℕP.n≤1+n (ℕ.pred N))
; Ny≤N = ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) (ℕP.n≤1+n (ℕ.pred N)) in
N , _ , λ { (suc k₂) m≥N -> let m = suc k₂; m≤2m = ℕP.m≤n*m m {2} ℕP.0<1+n in begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(⊝ Κ (+ 1)) ⊗ (Κ (+ 2) ⊗ n ⊗ (Κ (+ 2) ⊗ n)) ⊜
(((⊝ Κ (+ 1)) ⊗ (Κ (+ 2) ⊗ n) ⊕ ((⊝ Κ (+ 1)) ⊗ (Κ (+ 2) ⊗ n))) ⊗ n))
refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ fromNonx) (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans Nx≤N m≥N) m≤2m))
(proj₂ (proj₂ fromNony) (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans Ny≤N m≥N) m≤2m)) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎}})
where
open ℚP.≤-Reasoning
open ℤ-Solver
nonNeg-cong : ∀ {x y} -> x ≃ y -> NonNegative x -> NonNegative y
nonNeg-cong {x} {y} x≃y nonx = lemma-2-8-2-onlyif λ { (suc k₁) ->
let n = suc k₁; fromNonx = fast-lemma-2-8-2-if nonx (2 ℕ.* n); fromx≃y = fast-equality-lemma-if x y x≃y (2 ℕ.* n)
; N₁ = proj₁ fromNonx; N₂ = proj₁ fromx≃y; N = suc (N₁ ℕ.⊔ N₂)
; N₁≤N = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.n≤1+n (ℕ.pred N))
; N₂≤N = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.n≤1+n (ℕ.pred N)) in
N , _ , λ { (suc k₂) m≥N -> let m = suc k₂ in begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (ℤsolve 1 (λ n ->
(:- κ (+ 1)) :* (κ (+ 2) :* n :* (κ (+ 2) :* n)) :=
(((:- κ (+ 1)) :* (κ (+ 2) :* n) :+ ((:- κ (+ 1)) :* (κ (+ 2) :* n))) :* n))
refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ fromNonx) m (ℕP.≤-trans N₁≤N m≥N))
(ℚP.neg-mono-≤ (proj₂ fromx≃y m (ℕP.≤-trans N₂≤N m≥N))) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq y m ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq y m))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq y m) ≈⟨ solve 2 (λ x y -> (x ⊖ (x ⊖ y)) ⊜ y) ℚP.≃-refl (seq x m) (seq y m) ⟩
seq y m ∎}}
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; ⊝_ to :-_
; _⊜_ to _:=_
; Κ to κ
)
posx∧nonNegy⇒posx+y : ∀ {x y} -> Positive x -> NonNegative y -> Positive (x + y)
posx∧nonNegy⇒posx+y {x} {y} posx nony = let fromPosx = fast-lemma-2-8-1-if posx; N₁ = suc (proj₁ fromPosx)
; fromNony = fast-lemma-2-8-2-if nony (2 ℕ.* N₁)
; N₂ = suc (proj₁ fromNony); N = 2 ℕ.* (N₁ ℕ.⊔ N₂)
; N₁≤N = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n)
; N₂-1≤N = ℕP.≤-trans (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N₂)) (ℕP.m≤n⊔m N₁ N₂))
(ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n) in
lemma-2-8-1-onlyif (ℕ.pred N , (λ { (suc k₁) m≥N -> let m = suc k₁ in begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 (2 ℕ.* N₁) N (ℕP.*-monoʳ-≤ 2 (ℕP.m≤m⊔n N₁ N₂)) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (solve 1 (λ N₁ ->
Κ (+ 1) ⊗ (N₁ ⊗ (Κ (+ 2) ⊗ N₁)) ⊜
(Κ (+ 1) ⊗ (Κ (+ 2) ⊗ N₁) ⊕ (⊝ Κ (+ 1)) ⊗ N₁) ⊗ (Κ (+ 2) ⊗ N₁))
refl (+ N₁)) ⟩
+ 1 / N₁ ℚ.- + 1 / (2 ℕ.* N₁) ≤⟨ ℚP.+-mono-≤
(proj₂ fromPosx (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans N₁≤N m≥N) (ℕP.m≤n*m m {2} ℕP.0<1+n)))
(proj₂ (proj₂ fromNony) (2 ℕ.* m) (ℕP.≤-trans (ℕP.≤-trans N₂-1≤N m≥N) (ℕP.m≤n*m m {2} ℕP.0<1+n))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎}))
where
open ℚP.≤-Reasoning
open ℤ-Solver
nonNeg∣x∣ : ∀ x -> NonNegative ∣ x ∣
nonNeg∣x∣ x = nonNeg* (λ { (suc k₁) -> let n = suc k₁ in ℚP.≤-trans (ℚP.nonPositive⁻¹ _) (ℚP.0≤∣p∣ (seq x n))})
nonNegx⇒∣x∣≃x : ∀ {x} -> NonNegative x -> ∣ x ∣ ≃ x
nonNegx⇒∣x∣≃x {x} nonx = equality-lemma-onlyif ∣ x ∣ x partA
where
open ℚP.≤-Reasoning
open ℤ-Solver
partA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> n ℕ.≥ N ->
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
partA (suc k₁) = N , partB
where
j = suc k₁
fromNonx = fast-lemma-2-8-2-if nonx (2 ℕ.* j)
N = suc (proj₁ fromNonx)
partB : ∀ (n : ℕ) -> n ℕ.≥ N -> ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ℚ.≤ + 1 / j
partB (suc k₂) n≥N = [ left , right ]′ (ℚP.≤-total (seq x n) 0ℚᵘ)
where
n = suc k₂
-xₙ≤1/2j = begin
ℚ.- seq x n ≤⟨ ℚP.neg-mono-≤ (proj₂ (proj₂ fromNonx) n (ℕP.≤-trans (ℕP.n≤1+n (ℕ.pred N)) n≥N)) ⟩
ℚ.- (ℚ.- (+ 1 / (2 ℕ.* j))) ≈⟨ ℚP.neg-involutive (+ 1 / (2 ℕ.* j)) ⟩
+ 1 / (2 ℕ.* j) ∎
left : seq x n ℚ.≤ 0ℚᵘ -> ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ℚ.≤ + 1 / j
left hyp = begin
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p≤∣p∣ (seq x n))) ⟩
ℚ.∣ seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x n))) ⟩
ℚ.∣ ℚ.- seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.0≤p⇒∣p∣≃p (ℚP.neg-mono-≤ hyp)) ⟩
ℚ.- seq x n ℚ.- seq x n ≤⟨ ℚP.+-mono-≤ -xₙ≤1/2j -xₙ≤1/2j ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(Κ (+ 1) ⊗ (Κ (+ 2) ⊗ j) ⊕ Κ (+ 1) ⊗ (Κ (+ 2) ⊗ j)) ⊗ j ⊜
(Κ (+ 1) ⊗ (Κ (+ 2) ⊗ j ⊗ (Κ (+ 2) ⊗ j))))
refl (+ j)) ⟩
+ 1 / j ∎
right : 0ℚᵘ ℚ.≤ seq x n -> ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ℚ.≤ + 1 / j
right hyp = begin
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- seq x n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p≤∣p∣ (seq x n))) ⟩
ℚ.∣ seq x n ∣ ℚ.- seq x n ≈⟨ ℚP.+-congˡ (ℚ.- seq x n) (ℚP.0≤p⇒∣p∣≃p hyp) ⟩
seq x n ℚ.- seq x n ≈⟨ ℚP.+-inverseʳ (seq x n) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 1 / j ∎
nonNegx,y⇒nonNegx*y : ∀ {x y} -> NonNegative x -> NonNegative y -> NonNegative (x * y)
nonNegx,y⇒nonNegx*y {x} {y} nonx nony = nonNeg-cong lem (nonNeg∣x∣ (x * y))
where
open ≃-Reasoning
lem : ∣ x * y ∣ ≃ x * y
lem = begin
∣ x * y ∣ ≈⟨ ∣x*y∣≃∣x∣*∣y∣ x y ⟩
∣ x ∣ * ∣ y ∣ ≈⟨ *-cong (nonNegx⇒∣x∣≃x nonx) (nonNegx⇒∣x∣≃x nony) ⟩
x * y ∎
ℚ-*-mono-≤ : ∀ {p q r s} -> ℚ.NonNegative p -> ℚ.NonNegative r ->
p ℚ.≤ q -> r ℚ.≤ s -> p ℚ.* r ℚ.≤ q ℚ.* s
ℚ-*-mono-≤ {p} {q} {r} {s} nonp nonr p≤q r≤s = begin
p ℚ.* r ≤⟨ ℚP.*-monoˡ-≤-nonNeg nonr p≤q ⟩
q ℚ.* r ≤⟨ ℚP.*-monoʳ-≤-nonNeg {q} (ℚ.nonNegative (ℚP.≤-trans (ℚP.nonNegative⁻¹ nonp) p≤q)) r≤s ⟩
q ℚ.* s ∎
where open ℚP.≤-Reasoning
posx,y⇒posx*y : ∀ {x y} -> Positive x -> Positive y -> Positive (x * y)
posx,y⇒posx*y {x} {y} posx posy = let k = K x ℕ.⊔ K y; fromPosx = fast-lemma-2-8-1-if posx; fromPosy = fast-lemma-2-8-1-if posy
; N₁ = suc (proj₁ fromPosx); N₂ = suc (proj₁ fromPosy); N = N₁ ℕ.⊔ N₂
; N₁≤N² = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤n*m N {N} ℕP.0<1+n)
; N₂≤N² = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.m≤n*m N {N} ℕP.0<1+n) in
lemma-2-8-1-onlyif (ℕ.pred (N ℕ.* N) , λ {(suc k₁) m≥N² ->
let m = suc k₁; N²≤2km = ℕP.≤-trans m≥N² (ℕP.m≤n*m m {2 ℕ.* k} ℕP.0<1+n) in begin
+ 1 / N ℚ.* (+ 1 / N) ≤⟨ q≤r⇒+p/r≤+p/q 1 (N₁ ℕ.* N₂) (N ℕ.* N) (ℕP.*-mono-≤ (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤n⊔m N₁ N₂)) ⟩
+ 1 / N₁ ℚ.* (+ 1 / N₂) ≤⟨ ℚ-*-mono-≤ _ _
(proj₂ fromPosx (2 ℕ.* k ℕ.* m) (ℕP.≤-trans N₁≤N² N²≤2km))
(proj₂ fromPosy (2 ℕ.* k ℕ.* m) (ℕP.≤-trans N₂≤N² N²≤2km)) ⟩
seq x (2 ℕ.* k ℕ.* m) ℚ.* seq y (2 ℕ.* k ℕ.* m) ∎})
where open ℚP.≤-Reasoning
posx⇒posx⊔y : ∀ {x y} -> Positive x -> Positive (x ⊔ y)
posx⇒posx⊔y {x} {y} posx = let fromPosx = fast-lemma-2-8-1-if posx; N = suc (proj₁ fromPosx) in
lemma-2-8-1-onlyif (ℕ.pred N , λ {(suc k₁) m≥N -> let m = suc k₁ in begin
+ 1 / N ≤⟨ proj₂ fromPosx m m≥N ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎})
where open ℚP.≤-Reasoning
nonNegx⇒nonNegx⊔y : ∀ {x y} -> NonNegative x -> NonNegative (x ⊔ y)
nonNegx⇒nonNegx⊔y {x} {y} nonx = lemma-2-8-2-onlyif (λ {(suc k₁) ->
let n = suc k₁; fromNonx = fast-lemma-2-8-2-if nonx n
; N = proj₁ fromNonx in
N , proj₁ (proj₂ fromNonx) , λ m m≥N -> begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ fromNonx) m m≥N ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎})
where open ℚP.≤-Reasoning
nonNegx,y⇒nonNegx⊓y : ∀ {x y} -> NonNegative x -> NonNegative y -> NonNegative (x ⊓ y)
nonNegx,y⇒nonNegx⊓y {x} {y} nonx nony = lemma-2-8-2-onlyif partA
where
open ℚP.≤-Reasoning
partA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊓ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
partA (suc k₁) = N , _ , partB
where
n = suc k₁
fromNonx = fast-lemma-2-8-2-if nonx n
Nx = proj₁ fromNonx
fromNony = fast-lemma-2-8-2-if nony n
Ny = proj₁ fromNony
N = suc (Nx ℕ.⊔ Ny)
Nx≤N = ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) (ℕP.n≤1+n (ℕ.pred N))
Ny≤N = ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) (ℕP.n≤1+n (ℕ.pred N))
partB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x ⊓ y) m ℚ.≥ ℚ.- (+ 1 / n)
partB m m≥N = [ left , right ]′ (ℚP.≤-total (seq x m) (seq y m))
where
left : seq x m ℚ.≤ seq y m -> seq (x ⊓ y) m ℚ.≥ ℚ.- (+ 1 / n)
left hyp = begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ fromNonx) m (ℕP.≤-trans Nx≤N m≥N) ⟩
seq x m ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊓q≃p hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
right : seq y m ℚ.≤ seq x m -> seq (x ⊓ y) m ℚ.≥ ℚ.- (+ 1 / n)
right hyp = begin
ℚ.- (+ 1 / n) ≤⟨ proj₂ (proj₂ fromNony) m (ℕP.≤-trans Ny≤N m≥N) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
posx,y⇒posx⊓y : ∀ x y -> Positive x -> Positive y -> Positive (x ⊓ y)
posx,y⇒posx⊓y x y posx posy = lemma-2-8-1-onlyif (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
fromPosx = fast-lemma-2-8-1-if posx
Nx = suc (proj₁ fromPosx)
fromPosy = fast-lemma-2-8-1-if posy
Ny = suc (proj₁ fromPosy)
N = Nx ℕ.⊔ Ny
Nx≤N = ℕP.m≤m⊔n Nx Ny
Ny≤N = ℕP.m≤n⊔m Nx Ny
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x ⊓ y) m ℚ.≥ + 1 / N
lem m m≥N = [ left , right ]′ (ℚP.≤-total (seq x m) (seq y m))
where
left : seq x m ℚ.≤ seq y m -> seq (x ⊓ y) m ℚ.≥ + 1 / N
left hyp = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 Nx N Nx≤N ⟩
+ 1 / Nx ≤⟨ proj₂ fromPosx m (ℕP.≤-trans Nx≤N m≥N) ⟩
seq x m ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊓q≃p hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
right : seq y m ℚ.≤ seq x m -> seq (x ⊓ y) m ℚ.≥ + 1 / N
right hyp = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 Ny N Ny≤N ⟩
+ 1 / Ny ≤⟨ proj₂ fromPosy m (ℕP.≤-trans Ny≤N m≥N) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
module ℝ-Solver where
open import Data.Bool.Base
open import Tactic.RingSolver.Core.Polynomial.Parameters
open import Tactic.RingSolver.Core.AlmostCommutativeRing
open import Data.Maybe.Base using (nothing)
ℚ-isZero : ℚᵘ -> Bool
ℚ-isZero p with p ℚP.≃? 0ℚᵘ
... | .true because ofʸ p₁ = true
... | .false because ofⁿ ¬p = false
ℚ-coeff : RawCoeff _ _
ℚ-coeff = record
{ rawRing = ℚP.+-*-rawRing
; isZero = ℚ-isZero
}
abstract
⋆-distrib-+₂ = ⋆-distrib-+
⋆-distrib-*₂ = ⋆-distrib-*
⋆-distrib-neg₂ = ⋆-distrib-neg
getMorphism : _-Raw-AlmostCommutative⟶_ ℚP.+-*-rawRing (fromCommutativeRing +-*-commutativeRing (λ x -> nothing))
getMorphism = record
{ ⟦_⟧ = λ p -> p ⋆
; +-homo = ⋆-distrib-+₂
; *-homo = ⋆-distrib-*₂
; -‿homo = ⋆-distrib-neg₂
; 0-homo = ≃-refl
; 1-homo = ≃-refl
}
zero-checker : ∀ p -> T (ℚ-isZero p) -> 0ℝ ≃ p ⋆
zero-checker p hyp with p ℚP.≃? 0ℚᵘ
... | .true because ofʸ p₁ = ⋆-cong (ℚP.≃-sym p₁)
homo : Homomorphism _ _ _ _
homo = record
{ from = ℚ-coeff
; to = fromCommutativeRing +-*-commutativeRing (λ x -> nothing)
; morphism = getMorphism
; Zero-C⟶Zero-R = zero-checker
}
open import NonReflective homo public
open import Tactic.RingSolver.Core.Expression public
infix 4 _<_ _>_ _≤_ _≥_
_<_ : Rel ℝ 0ℓ
x < y = Positive (y - x)
_>_ : Rel ℝ 0ℓ
x > y = y < x
_≤_ : Rel ℝ 0ℓ
x ≤ y = NonNegative (y - x)
_≥_ : Rel ℝ 0ℓ
x ≥ y = y ≤ x
Negative : Pred ℝ 0ℓ
Negative x = Positive (- x)
neg-cong : ∀ {x y} -> x ≃ y -> Negative x -> Negative y
neg-cong x≃y negx = pos-cong (-‿cong x≃y) negx
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ {x} {y} x<y = pos⇒nonNeg x<y
-- Helper lemmas often used in the next few order property proofs
private
z-y+y-x≃z-x : ∀ {x y z} -> (z - y) + (y - x) ≃ z - x
z-y+y-x≃z-x {x} {y} {z} = solve 3 (λ x y z -> ((z ⊖ y) ⊕ (y ⊖ x)) ⊜ (z ⊖ x)) ≃-refl x y z
where open ℝ-Solver
z-x+t-y≃z+t-x+y : ∀ {x y z t} -> (z - x) + (t - y) ≃ (z + t) - (x + y)
z-x+t-y≃z+t-x+y {x} {y} {z} {t} = solve 4 (λ x y z t -> ((z ⊖ x) ⊕ (t ⊖ y)) ⊜ ((z ⊕ t) ⊖ (x ⊕ y))) ≃-refl x y z t
where open ℝ-Solver
<-≤-trans : Trans _<_ _≤_ _<_
<-≤-trans {x} {y} {z} x<y y≤z = pos-cong (≃-trans (+-comm (y - x) (z - y)) z-y+y-x≃z-x) (posx∧nonNegy⇒posx+y x<y y≤z)
≤-<-trans : Trans _≤_ _<_ _<_
≤-<-trans {x} {y} {z} x≤y y<z = pos-cong z-y+y-x≃z-x (posx∧nonNegy⇒posx+y y<z x≤y)
<-trans : Transitive _<_
<-trans = ≤-<-trans ∘ <⇒≤
≤-trans : Transitive _≤_
≤-trans {x} {y} {z} x≤y y≤z = nonNeg-cong z-y+y-x≃z-x (nonNegx,y⇒nonNegx+y y≤z x≤y)
nonNeg0 : NonNegative 0ℝ
nonNeg0 = nonNeg* (λ {(suc k₁) -> ℚP.<⇒≤ (ℚP.negative⁻¹ _)})
nonNeg-refl : ∀ {x} -> NonNegative (x - x)
nonNeg-refl {x} = nonNeg-cong (≃-symm (+-inverseʳ x)) nonNeg0
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ x≤z y≤t = nonNeg-cong z-x+t-y≃z+t-x+y (nonNegx,y⇒nonNegx+y x≤z y≤t)
+-monoʳ-≤ : ∀ (x : ℝ) -> (_+_ x) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ x y≤z = +-mono-≤ nonNeg-refl y≤z
+-monoˡ-≤ : ∀ (x : ℝ) -> (_+ x) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ x y≤z = +-mono-≤ y≤z nonNeg-refl
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< x<z y<t = pos-cong z-x+t-y≃z+t-x+y (posx,y⇒posx+y x<z y<t)
+-monoʳ-< : ∀ x -> (_+_ x) Preserves _<_ ⟶ _<_
+-monoʳ-< x {y} {z} y<z = pos-cong (solve 3 (λ x y z -> (z ⊖ y) ⊜ (x ⊕ z ⊖ (x ⊕ y))) ≃-refl x y z) y<z
where open ℝ-Solver
+-monoˡ-< : ∀ x → (_+ x) Preserves _<_ ⟶ _<_
+-monoˡ-< x {y} {z} y<z = pos-cong (+-cong (+-comm x z) (-‿cong (+-comm x y))) (+-monoʳ-< x y<z)
neg-distribˡ-* : ∀ x y -> - (x * y) ≃ - x * y
neg-distribˡ-* = solve 2 (λ x y -> (⊝ (x ⊗ y)) ⊜ ((⊝ x) ⊗ y)) ≃-refl
where open ℝ-Solver
neg-distribʳ-* : ∀ x y -> - (x * y) ≃ x * (- y)
neg-distribʳ-* = solve 2 (λ x y -> (⊝ (x ⊗ y)) ⊜ (x ⊗ (⊝ y))) ≃-refl
where open ℝ-Solver
≤-reflexive : _≃_ ⇒ _≤_
≤-reflexive {x} x≃y = nonNeg-cong (+-congˡ (- x) x≃y) nonNeg-refl
≤-refl : Reflexive _≤_
≤-refl = ≤-reflexive ≃-refl
≤-isPreorder : IsPreorder _≃_ _≤_
≤-isPreorder = record
{ isEquivalence = ≃-isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-respʳ-≃ : _≤_ Respectsʳ _≃_
≤-respʳ-≃ {x} {y} {z} y≃z x≤y = nonNeg-cong (+-congˡ (- x) y≃z) x≤y
≤-respˡ-≃ : _≤_ Respectsˡ _≃_
≤-respˡ-≃ {x} {y} {z} y≃z y≤x = nonNeg-cong (+-congʳ x (-‿cong y≃z)) y≤x
<-respʳ-≃ : _<_ Respectsʳ _≃_
<-respʳ-≃ y≃z x<y = <-≤-trans x<y (≤-reflexive y≃z)
<-respˡ-≃ : _<_ Respectsˡ _≃_
<-respˡ-≃ y≃z y<x = ≤-<-trans (≤-reflexive (≃-symm y≃z)) y<x
<-resp-≃ : _<_ Respects₂ _≃_
<-resp-≃ = <-respʳ-≃ , <-respˡ-≃
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder
<-trans
<-resp-≃
<⇒≤
<-≤-trans
≤-<-trans
public
*-monoʳ-≤-nonNeg : ∀ {x y z} -> x ≤ z -> NonNegative y -> x * y ≤ z * y
*-monoʳ-≤-nonNeg {x} {y} {z} x≤z nony = nonNeg-cong
(solve 3 (λ x y z -> ((z ⊖ x) ⊗ y) ⊜ (z ⊗ y ⊖ x ⊗ y)) ≃-refl x y z)
(nonNegx,y⇒nonNegx*y x≤z nony)
where open ℝ-Solver
*-monoˡ-≤-nonNeg : ∀ {x y z} -> x ≤ z -> NonNegative y -> y * x ≤ y * z
*-monoˡ-≤-nonNeg {x} {y} {z} x≤z nony = begin
y * x ≈⟨ *-comm y x ⟩
x * y ≤⟨ *-monoʳ-≤-nonNeg x≤z nony ⟩
z * y ≈⟨ *-comm z y ⟩
y * z ∎
where open ≤-Reasoning
*-monoʳ-<-pos : ∀ {y} -> Positive y -> (_*_ y) Preserves _<_ ⟶ _<_
*-monoʳ-<-pos {y} posy {x} {z} x<z = pos-cong
(solve 3 (λ x y z -> (y ⊗ (z ⊖ x)) ⊜ (y ⊗ z ⊖ y ⊗ x)) ≃-refl x y z)
(posx,y⇒posx*y posy x<z)
where open ℝ-Solver
*-monoˡ-<-pos : ∀ {y} -> Positive y -> (_* y) Preserves _<_ ⟶ _<_
*-monoˡ-<-pos {y} posy {x} {z} x<z = begin-strict
x * y ≈⟨ *-comm x y ⟩
y * x <⟨ *-monoʳ-<-pos posy x<z ⟩
y * z ≈⟨ *-comm y z ⟩
z * y ∎
where
open ≤-Reasoning
neg-mono-< : -_ Preserves _<_ ⟶ _>_
neg-mono-< {x} {y} x<y = pos-cong
(solve 2 (λ x y -> (y ⊖ x) ⊜ (⊝ x ⊖ (⊝ y))) ≃-refl x y)
x<y
where open ℝ-Solver
neg-mono-≤ : -_ Preserves _≤_ ⟶ _≥_
neg-mono-≤ {x} {y} x≤y = nonNeg-cong
(solve 2 (λ x y -> (y ⊖ x) ⊜ (⊝ x ⊖ (⊝ y))) ≃-refl x y)
x≤y
where open ℝ-Solver
x≤x⊔y : ∀ x y -> x ≤ x ⊔ y
x≤x⊔y x y = nonNeg* (λ {(suc k₁) -> let n = suc k₁ in begin (
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (seq x (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- seq x (2 ℕ.* n)) (ℚP.p≤p⊔q (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.⊔ seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ∎)})
where open ℚP.≤-Reasoning
x≤y⊔x : ∀ x y -> x ≤ y ⊔ x
x≤y⊔x x y = begin
x ≤⟨ x≤x⊔y x y ⟩
x ⊔ y ≈⟨ ⊔-comm x y ⟩
y ⊔ x ∎
where
open ≤-Reasoning
x⊓y≤x : ∀ x y -> x ⊓ y ≤ x
x⊓y≤x x y = nonNeg* λ {(suc k₁) -> let n = suc k₁ in begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (seq x (2 ℕ.* n))) ⟩
seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ≤⟨ ℚP.+-monoʳ-≤ (seq x (2 ℕ.* n)) (ℚP.neg-mono-≤ (ℚP.p⊓q≤p (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)))) ⟩
seq x (2 ℕ.* n) ℚ.- seq (x ⊓ y) (2 ℕ.* n) ∎}
where open ℚP.≤-Reasoning
x⊓y≤y : ∀ x y -> x ⊓ y ≤ y
x⊓y≤y x y = begin
x ⊓ y ≈⟨ ⊓-comm x y ⟩
y ⊓ x ≤⟨ x⊓y≤x y x ⟩
y ∎
where
open ≤-Reasoning
≤-antisym : Antisymmetric _≃_ _≤_
≤-antisym {x} {y} (nonNeg* x≤y) (nonNeg* y≤x) = ≃-symm partB
where
partA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ℚ.∣ seq (x - y) n ℚ.- 0ℚᵘ ∣ ℚ.≤ (+ 2 / n) {n≢0}
partA (suc k₁) = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ℚ.- 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-identityʳ (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≤⟨ [ left , right ]′ (ℚP.≤-total (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
n = suc k₁
left : seq x (2 ℕ.* n) ℚ.≤ seq y (2 ℕ.* n) -> ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ℚ.≤ + 2 / n
left hyp = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n))))
(ℚP.0≤p⇒∣p∣≃p (ℚP.neg-mono-≤ (ℚP.p≤q⇒p-q≤0 hyp))) ⟩
ℚ.- (seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n)) ≤⟨ ℚP.≤-respʳ-≃ (ℚP.neg-involutive (+ 1 / n)) (ℚP.neg-mono-≤ (y≤x n)) ⟩
+ 1 / n ≤⟨ p≤q⇒p/r≤q/r (+ 1) (+ 2) n (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n)) ⟩
+ 2 / n ∎
right : seq y (2 ℕ.* n) ℚ.≤ seq x (2 ℕ.* n) -> ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ℚ.≤ + 2 / n
right hyp = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p hyp) ⟩
seq x (2 ℕ.* n) ℚ.- seq y (2 ℕ.* n) ≈⟨ solve 2 (λ x y -> (x ⊖ y) ⊜ (⊝ (y ⊖ x))) ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) ⟩
ℚ.- (seq y (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ≤⟨ ℚP.≤-respʳ-≃ (ℚP.neg-involutive (+ 1 / n)) (ℚP.neg-mono-≤ (x≤y n)) ⟩
+ 1 / n ≤⟨ p≤q⇒p/r≤q/r (+ 1) (+ 2) n (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n)) ⟩
+ 2 / n ∎
partB : y ≃ x
partB = begin
y ≈⟨ ≃-symm (+-identityʳ y) ⟩
y + 0ℝ ≈⟨ +-congʳ y (≃-symm (*≃* partA)) ⟩
y + (x - y) ≈⟨ +-congʳ y (+-comm x (- y)) ⟩
y + (- y + x) ≈⟨ ≃-symm (+-assoc y (- y) x) ⟩
y - y + x ≈⟨ +-congˡ x (+-inverseʳ y) ⟩
0ℝ + x ≈⟨ +-identityˡ x ⟩
x ∎
where open ≃-Reasoning
-- Strange new interaction: 0 = -0 is no longer provable by reflexivity.
0≃-0 : 0ℝ ≃ - 0ℝ
0≃-0 = ⋆-distrib-neg 0ℚᵘ
private
-- Helper for the next few proofs
x-0≃x : ∀ {x} -> x - 0ℝ ≃ x
x-0≃x {x} = ≃-trans (+-congʳ x (≃-symm 0≃-0)) (+-identityʳ x)
0<x⇒posx : ∀ {x} -> 0ℝ < x -> Positive x
0<x⇒posx {x} 0<x = pos-cong x-0≃x 0<x
posx⇒0<x : ∀ {x} -> Positive x -> 0ℝ < x
posx⇒0<x {x} posx = pos-cong (≃-symm x-0≃x) posx
0≤x⇒nonNegx : ∀ {x} -> 0ℝ ≤ x -> NonNegative x
0≤x⇒nonNegx {x} 0≤x = nonNeg-cong x-0≃x 0≤x
nonNegx⇒0≤x : ∀ {x} -> NonNegative x -> 0ℝ ≤ x
nonNegx⇒0≤x {x} nonx = nonNeg-cong (≃-symm x-0≃x) nonx
x<0⇒negx : ∀ {x} -> x < 0ℝ -> Negative x
x<0⇒negx {x} x<0 = pos-cong (+-identityˡ (- x)) x<0
negx⇒x<0 : ∀ {x} -> Negative x -> x < 0ℝ
negx⇒x<0 {x} negx = pos-cong (≃-symm (+-identityˡ (- x))) negx
0≤∣x∣ : ∀ x -> 0ℝ ≤ ∣ x ∣
0≤∣x∣ x = nonNegx⇒0≤x (nonNeg∣x∣ x)
∣x+y∣≤∣x∣+∣y∣ : ∀ x y -> ∣ x + y ∣ ≤ ∣ x ∣ + ∣ y ∣
∣x+y∣≤∣x∣+∣y∣ x y = nonNeg* (λ {(suc k₁) ->
let n = suc k₁; ∣x₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ∣
; ∣y₄ₙ∣ = ℚ.∣ seq y (2 ℕ.* (2 ℕ.* n)) ∣
; ∣x₄ₙ+y₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ℚ.+ seq y (2 ℕ.* (2 ℕ.* n)) ∣ in begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.+-inverseʳ (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣)) ⟩
∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣ ℚ.- (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣) ≤⟨ ℚP.+-monoʳ-≤ (∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣)
(ℚP.neg-mono-≤ (ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x (2 ℕ.* (2 ℕ.* n))) (seq y (2 ℕ.* (2 ℕ.* n))))) ⟩
∣x₄ₙ∣ ℚ.+ ∣y₄ₙ∣ ℚ.- ∣x₄ₙ+y₄ₙ∣ ∎})
where open ℚP.≤-Reasoning
-- Should I use a constructor here too?
_≄_ : Rel ℝ 0ℓ
x ≄ y = x < y ⊎ y < x
_≄0 : ℝ -> Set
x ≄0 = x ≄ 0ℝ
x≤∣x∣ : ∀ {x} -> x ≤ ∣ x ∣
x≤∣x∣ {x} = nonNeg* (λ {(suc k₁) -> let n = suc k₁ in begin
ℚ.- (+ 1 / n) ≤⟨ ℚP.nonPositive⁻¹ _ ⟩
0ℚᵘ ≤⟨ ℚP.p≤q⇒0≤q-p (p≤∣p∣ (seq x (2 ℕ.* n))) ⟩
ℚ.∣ seq x (2 ℕ.* n) ∣ ℚ.- seq x (2 ℕ.* n) ∎})
where open ℚP.≤-Reasoning
∣-x∣≃∣x∣ : ∀ {x} -> ∣ - x ∣ ≃ ∣ x ∣
∣-x∣≃∣x∣ {x} = *≃* λ {(suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.∣ ℚ.- seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- ℚ.∣ seq x n ∣) (ℚP.∣-p∣≃∣p∣ (seq x n))) ⟩
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ℚ.∣ seq x n ∣) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎}
where open ℚP.≤-Reasoning
x≄0⇒0<∣x∣ : ∀ {x} -> x ≄0 -> 0ℝ < ∣ x ∣
x≄0⇒0<∣x∣ {x} (inj₁ x<0) = begin-strict
0ℝ ≈⟨ 0≃-0 ⟩
- 0ℝ <⟨ neg-mono-< x<0 ⟩
- x ≤⟨ x≤∣x∣ ⟩
∣ - x ∣ ≈⟨ ∣-x∣≃∣x∣ ⟩
∣ x ∣ ∎
where open ≤-Reasoning
x≄0⇒0<∣x∣ {x} (inj₂ 0<x) = <-≤-trans 0<x x≤∣x∣
x≄0⇒pos∣x∣ : ∀ {x} -> x ≄0 -> Positive ∣ x ∣
x≄0⇒pos∣x∣ {x} x≄0 = 0<x⇒posx (x≄0⇒0<∣x∣ x≄0)
ℚ≠-helper : ∀ p -> p ℚ.> 0ℚᵘ ⊎ p ℚ.< 0ℚᵘ -> p ℚ.≠ 0ℚᵘ
ℚ≠-helper p hyp1 = [ (λ p>0 p≃0 -> ℚP.<-irrefl (ℚP.≃-sym p≃0) p>0) , (λ p<0 p≃0 -> ℚP.<-irrefl p≃0 p<0) ]′ hyp1
Nₐ : (x : ℝ) -> (x≄0 : x ≄0) -> ℕ
Nₐ x x≄0 = suc (proj₁ (fast-lemma-2-8-1-if {∣ x ∣} (x≄0⇒pos∣x∣ {x} x≄0)))
abstract
not0-helper : ∀ (x : ℝ) -> (x≄0 : x ≄0) -> ∀ (n : ℕ) ->
ℤ.∣ ↥ (seq x ((n ℕ.+ (Nₐ x x≄0)) ℕ.* ((Nₐ x x≄0) ℕ.* (Nₐ x x≄0)))) ∣ ≢0
not0-helper x x≄0 n = ℚP.p≄0⇒∣↥p∣≢0 xₛ (ℚ≠-helper xₛ ([ left , right ]′ (ℚP.∣p∣≡p∨∣p∣≡-p xₛ)))
where
open ℚP.≤-Reasoning
N = Nₐ x x≄0
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
0<∣xₛ∣ : 0ℚᵘ ℚ.< ℚ.∣ xₛ ∣
0<∣xₛ∣ = begin-strict
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ (fast-lemma-2-8-1-if {∣ x ∣} (x≄0⇒pos∣x∣ {x} x≄0)) ((n ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.m≤n*m N {N} ℕP.0<1+n) (ℕP.m≤n*m (N ℕ.* N) {n ℕ.+ N} (subst (0 ℕ.<_) (ℕP.+-comm N n) ℕP.0<1+n))) ⟩
ℚ.∣ xₛ ∣ ∎
left : ℚ.∣ xₛ ∣ ≡ xₛ -> xₛ ℚ.> 0ℚᵘ ⊎ xₛ ℚ.< 0ℚᵘ
left hyp = inj₁ (begin-strict
0ℚᵘ <⟨ 0<∣xₛ∣ ⟩
ℚ.∣ xₛ ∣ ≡⟨ hyp ⟩
xₛ ∎)
right : ℚ.∣ xₛ ∣ ≡ ℚ.- xₛ -> xₛ ℚ.> 0ℚᵘ ⊎ xₛ ℚ.< 0ℚᵘ
right hyp = inj₂ (begin-strict
xₛ ≈⟨ ℚP.≃-sym (ℚP.neg-involutive xₛ) ⟩
ℚ.- (ℚ.- xₛ) ≡⟨ cong ℚ.-_ (sym hyp) ⟩
ℚ.- ℚ.∣ xₛ ∣ <⟨ ℚP.neg-mono-< 0<∣xₛ∣ ⟩
0ℚᵘ ∎)
abstract
inverse-helper : ∀ (x : ℝ) -> (x≄0 : x ≄0) -> ∀ (n : ℕ) ->
ℚ.∣ (ℚ.1/ seq x ((n ℕ.+ (Nₐ x x≄0)) ℕ.* (Nₐ x x≄0 ℕ.* Nₐ x x≄0))) {not0-helper x x≄0 n} ∣ ℚ.≤ + (Nₐ x x≄0) / 1
inverse-helper x x≄0 n = begin
ℚ.∣ xₛ⁻¹ ∣ ≈⟨ ℚP.≃-sym (ℚP.*-identityʳ ℚ.∣ xₛ⁻¹ ∣) ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* 1ℚᵘ ≈⟨ ℚP.*-congˡ {ℚ.∣ xₛ⁻¹ ∣} (ℚP.≃-sym (ℚP.*-inverseˡ (+ N / 1))) ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* (+ 1 / N ℚ.* (+ N / 1)) ≈⟨ ℚP.≃-sym (ℚP.*-assoc ℚ.∣ xₛ⁻¹ ∣ (+ 1 / N) (+ N / 1)) ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* (+ 1 / N) ℚ.* (+ N / 1) ≤⟨ ℚP.*-monoˡ-≤-nonNeg {+ N / 1} _ (ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ xₛ⁻¹ ∣} _ lesser-helper-2) ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* ℚ.∣ xₛ ∣ ℚ.* (+ N / 1) ≈⟨ ℚP.*-congʳ {+ N / 1} helper ⟩
1ℚᵘ ℚ.* (+ N / 1) ≈⟨ ℚP.*-identityˡ (+ N / 1) ⟩
+ N / 1 ∎
where
open ℚP.≤-Reasoning
N = Nₐ x x≄0
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
xₛ≢0 = not0-helper x x≄0 n
xₛ⁻¹ = (ℚ.1/ seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))) {xₛ≢0}
helper : ℚ.∣ xₛ⁻¹ ∣ ℚ.* ℚ.∣ xₛ ∣ ℚ.≃ ℚ.1ℚᵘ
helper = begin-equality
ℚ.∣ xₛ⁻¹ ∣ ℚ.* ℚ.∣ xₛ ∣ ≈⟨ ℚP.≃-sym (ℚP.∣p*q∣≃∣p∣*∣q∣ xₛ⁻¹ xₛ) ⟩
ℚ.∣ xₛ⁻¹ ℚ.* xₛ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.*-inverseˡ xₛ {xₛ≢0}) ⟩
ℚ.1ℚᵘ ∎
lesser-helper : N ℕ.≤ (n ℕ.+ N) ℕ.* (N ℕ.* N)
lesser-helper = ℕP.≤-trans (ℕP.m≤n+m N n) (ℕP.m≤m*n (n ℕ.+ N) {N ℕ.* N} ℕP.0<1+n)
lesser-helper-2 : + 1 / N ℚ.≤ ℚ.∣ xₛ ∣
lesser-helper-2 = proj₂ (fast-lemma-2-8-1-if {∣ x ∣} (x≄0⇒pos∣x∣ {x} x≄0)) ((n ℕ.+ N) ℕ.* (N ℕ.* N)) lesser-helper
_⁻¹ : (x : ℝ) -> (x≄0 : x ≄ 0ℝ) -> ℝ
seq ((x ⁻¹) x≄0) n = (ℚ.1/ xₛ) {not0-helper x x≄0 n}
where
open ℚP.≤-Reasoning
N = Nₐ x x≄0
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
reg ((x ⁻¹) x≄0) (suc k₁) (suc k₂) = begin
ℚ.∣ yₘ ℚ.- yₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-cong
(ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ yₘ)) (ℚP.*-congˡ {yₘ} (ℚP.≃-sym (ℚP.*-inverseˡ xₙ {xₖ≢0 n}))))
(ℚP.-‿cong (ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ yₙ)) (ℚP.*-congˡ {yₙ} (ℚP.≃-sym (ℚP.*-inverseˡ xₘ {xₖ≢0 m})))))) ⟩
ℚ.∣ yₘ ℚ.* (yₙ ℚ.* xₙ) ℚ.- yₙ ℚ.* (yₘ ℚ.* xₘ) ∣ ≈⟨ ℚP.∣-∣-cong (solve 4 (λ xₘ xₙ yₘ yₙ ->
(yₘ ⊗ (yₙ ⊗ xₙ) ⊖ yₙ ⊗ (yₘ ⊗ xₘ)) ⊜ (yₘ ⊗ yₙ ⊗ (xₙ ⊖ xₘ)))
ℚP.≃-refl xₘ xₙ yₘ yₙ) ⟩
ℚ.∣ yₘ ℚ.* yₙ ℚ.* (xₙ ℚ.- xₘ) ∣ ≈⟨ ℚP.∣p*q∣≃∣p∣*∣q∣ (yₘ ℚ.* yₙ) (xₙ ℚ.- xₘ) ⟩
ℚ.∣ yₘ ℚ.* yₙ ∣ ℚ.* ℚ.∣ xₙ ℚ.- xₘ ∣ ≤⟨ ℚP.≤-trans
(ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ yₘ ℚ.* yₙ ∣} _ (reg x ((n ℕ.+ N) ℕ.* (N ℕ.* N)) ((m ℕ.+ N) ℕ.* (N ℕ.* N))))
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / ((n ℕ.+ N) ℕ.* (N ℕ.* N)) ℚ.+ + 1 / ((m ℕ.+ N) ℕ.* (N ℕ.* N))} _ ∣yₘ*yₙ∣≤N²) ⟩
(+ N / 1) ℚ.* (+ N / 1) ℚ.*
((+ 1 / ((n ℕ.+ N) ℕ.* (N ℕ.* N))) ℚ.+
(+ 1 / ((m ℕ.+ N) ℕ.* (N ℕ.* N)))) ≈⟨ ℚ.*≡* (ℤsolve 3 (λ m n N ->
((N :* N) :* ((κ (+ 1) :* ((m :+ N) :* (N :* N))) :+
(κ (+ 1) :* ((n :+ N) :* (N :* N))))) :* ((m :+ N) :* (n :+ N)) :=
(κ (+ 1) :* (n :+ N) :+ κ (+ 1) :* (m :+ N)) :* (κ (+ 1) :* κ (+ 1) :*
(((n :+ N) :* (N :* N)) :* ((m :+ N) :* (N :* N)))))
refl (+ m) (+ n) (+ N)) ⟩
(+ 1 / (m ℕ.+ N)) ℚ.+ (+ 1 / (n ℕ.+ N)) ≤⟨ ℚP.+-mono-≤
(q≤r⇒+p/r≤+p/q 1 m (m ℕ.+ N) (ℕP.m≤m+n m N))
(q≤r⇒+p/r≤+p/q 1 n (n ℕ.+ N) (ℕP.m≤m+n n N)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
N = Nₐ x x≄0
m = suc k₁
n = suc k₂
xₘ = seq x ((m ℕ.+ N) ℕ.* (N ℕ.* N))
xₙ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
xₖ≢0 : ∀ (k : ℕ) -> ℤ.∣ ↥ seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N)) ∣ ≢0
xₖ≢0 k = not0-helper x x≄0 k
yₘ = (ℚ.1/ xₘ) {xₖ≢0 m}
yₙ = (ℚ.1/ xₙ) {xₖ≢0 n}
∣yₘ*yₙ∣≤N² : ℚ.∣ yₘ ℚ.* yₙ ∣ ℚ.≤ (+ N / 1) ℚ.* (+ N / 1)
∣yₘ*yₙ∣≤N² = begin
ℚ.∣ yₘ ℚ.* yₙ ∣ ≈⟨ ℚP.∣p*q∣≃∣p∣*∣q∣ yₘ yₙ ⟩
ℚ.∣ yₘ ∣ ℚ.* ℚ.∣ yₙ ∣ ≤⟨ ℚ-*-mono-≤ {ℚ.∣ yₘ ∣} {+ N / 1} {ℚ.∣ yₙ ∣} {+ N / 1} _ _
(inverse-helper x x≄0 m) (inverse-helper x x≄0 n) ⟩
(+ N / 1) ℚ.* (+ N / 1) ∎
+p≤+q⇒1/q≤1/p : ∀ {p q} -> (posp : ℚ.Positive p) -> (posq : ℚ.Positive q) -> p ℚ.≤ q ->
(ℚ.1/ q) {ℚP.p≄0⇒∣↥p∣≢0 q (ℚ≠-helper q (inj₁ (ℚP.positive⁻¹ posq)))} ℚ.≤ (ℚ.1/ p) {ℚP.p≄0⇒∣↥p∣≢0 p (ℚ≠-helper p (inj₁ (ℚP.positive⁻¹ posp)))}
+p≤+q⇒1/q≤1/p {mkℚᵘ (+ suc p-1) q-1} {mkℚᵘ (+ suc u-1) v-1} posp/q posu/v p/q≤u/v = let p = + suc p-1; q = + suc q-1; u = + suc u-1; v = + suc v-1 in
ℚ.*≤* (begin
v ℤ.* p ≡⟨ ℤP.*-comm v p ⟩
p ℤ.* v ≤⟨ ℚP.drop-*≤* p/q≤u/v ⟩
u ℤ.* q ≡⟨ ℤP.*-comm u q ⟩
q ℤ.* u ∎)
where open ℤP.≤-Reasoning
{-
Proposition:
If x≠0, then x * x⁻¹ = 1.
Proof:
Kₓ ≤ max{Kₓ, Kᵣ} = k ⇒ Kₓ/k ≤ 1
Let k = max{Kx, K(x⁻¹)}, let m = N², and let r = n + N. Then:
∣x₂ₖₙ * x⁻¹₂ₖᵣₘ - 1∣ = ∣x₂ₖᵣₘ∣⁻¹∣x₂ₖₙ - x₂ₖᵣₘ∣
≤ ∣x₂ₖᵣₘ∣⁻¹((2kn)⁻¹ + (2k(n+N)N²)⁻¹)
≤ k((2kn)⁻¹ + (2kn)⁻¹)
= n⁻¹
≤ 2n⁻¹.
Hence x * x⁻¹ = 1. □
-}
*-inverseʳ : ∀ x -> (x≄0 : x ≄0) -> x * ((x ⁻¹) x≄0) ≃ 1ℝ
*-inverseʳ x x≄0 = *≃* λ {(suc k₁) ->
let n = suc k₁; x⁻¹ = (x ⁻¹) x≄0; k = K x ℕ.⊔ K x⁻¹
; N = Nₐ x x≄0; x₂ₖₙ = seq x (2 ℕ.* k ℕ.* n)
; xₛ = seq x ((2 ℕ.* k ℕ.* n ℕ.+ N) ℕ.* (N ℕ.* N))
; y₂ₖₙ = (ℚ.1/ xₛ) {not0-helper x x≄0 (2 ℕ.* k ℕ.* n)} in begin
ℚ.∣ x₂ₖₙ ℚ.* y₂ₖₙ ℚ.- 1ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ (x₂ₖₙ ℚ.* y₂ₖₙ) (ℚP.-‿cong
(ℚP.≃-sym (ℚP.*-inverseʳ xₛ {not0-helper x x≄0 (2 ℕ.* k ℕ.* n)})))) ⟩
ℚ.∣ x₂ₖₙ ℚ.* y₂ₖₙ ℚ.- xₛ ℚ.* y₂ₖₙ ∣ ≈⟨ ℚP.≃-trans
(ℚP.∣-∣-cong (solve 3 (λ x₂ₖₙ xₛ y₂ₖₙ ->
(x₂ₖₙ ⊗ y₂ₖₙ ⊖ xₛ ⊗ y₂ₖₙ) ⊜ (y₂ₖₙ ⊗ (x₂ₖₙ ⊖ xₛ)))
ℚP.≃-refl x₂ₖₙ xₛ y₂ₖₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ₖₙ (x₂ₖₙ ℚ.- xₛ))⟩
ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₙ ℚ.- xₛ ∣ ≤⟨ ℚ-*-mono-≤ _ _
(ℚP.≤-trans (ℚP.<⇒≤ (canonical-strict-upper-bound x⁻¹ (2 ℕ.* k ℕ.* n)))
(p≤q⇒p/r≤q/r (+ K x⁻¹) (+ k) 1 (ℤ.+≤+ (ℕP.m≤n⊔m (K x) (K x⁻¹)))))
(reg x (2 ℕ.* k ℕ.* n) ((2 ℕ.* k ℕ.* n ℕ.+ N) ℕ.* (N ℕ.* N))) ⟩
+ k / 1 ℚ.* (+ 1 / (2 ℕ.* k ℕ.* n) ℚ.+
+ 1 / ((2 ℕ.* k ℕ.* n ℕ.+ N) ℕ.* (N ℕ.* N))) ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (ℚP.+-monoʳ-≤ (+ 1 / (2 ℕ.* k ℕ.* n))
(q≤r⇒+p/r≤+p/q 1 (2 ℕ.* k ℕ.* n) ((2 ℕ.* k ℕ.* n ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.m≤m+n (2 ℕ.* k ℕ.* n) N) (ℕP.m≤m*n (2 ℕ.* k ℕ.* n ℕ.+ N) {N ℕ.* N} ℕP.0<1+n)))) ⟩
+ k / 1 ℚ.* (+ 1 / (2 ℕ.* k ℕ.* n) ℚ.+ + 1 / (2 ℕ.* k ℕ.* n)) ≈⟨ ℚ.*≡* (ℤsolve 2 (λ k n ->
(k :* (κ (+ 1) :* (κ (+ 2) :* k :* n) :+ κ (+ 1) :* (κ (+ 2) :* k :* n))) :* n :=
κ (+ 1) :* (κ (+ 1) :* (κ (+ 2) :* k :* n :* (κ (+ 2) :* k :* n))))
refl (+ k) (+ n)) ⟩
+ 1 / n ≤⟨ p≤q⇒p/r≤q/r (+ 1) (+ 2) n (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n)) ⟩
+ 2 / n ∎}
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; _⊜_ to _:=_
; Κ to κ
)
*-inverseˡ : ∀ x -> (x≄0 : x ≄0) -> ((x ⁻¹) x≄0) * x ≃ 1ℝ
*-inverseˡ x x≄0 = let x⁻¹ = (x ⁻¹) x≄0 in begin
x⁻¹ * x ≈⟨ *-comm x⁻¹ x ⟩
x * x⁻¹ ≈⟨ *-inverseʳ x x≄0 ⟩
1ℝ ∎
where open ≃-Reasoning
abstract
⁻¹-unique : ∀ t x -> (x≄0 : x ≄0) -> t * x ≃ 1ℝ -> t ≃ (x ⁻¹) x≄0
⁻¹-unique t x x≄0 tx=1 = let x⁻¹ = (x ⁻¹) x≄0 in begin
t ≈⟨ ≃-symm (*-identityʳ t) ⟩
t * 1ℝ ≈⟨ *-congˡ (≃-symm (*-inverseʳ x x≄0)) ⟩
t * (x * x⁻¹) ≈⟨ ≃-symm (*-assoc t x x⁻¹) ⟩
(t * x) * x⁻¹ ≈⟨ *-congʳ tx=1 ⟩
1ℝ * x⁻¹ ≈⟨ *-identityˡ x⁻¹ ⟩
x⁻¹ ∎
where open ≃-Reasoning
⁻¹-cong : ∀ {x y} -> (x≄0 : x ≄0) -> (y≄0 : y ≄0) -> x ≃ y -> (x ⁻¹) x≄0 ≃ (y ⁻¹) y≄0
⁻¹-cong {x} {y} x≄0 y≄0 x≃y = ⁻¹-unique x⁻¹ y y≄0 lem
where
open ≃-Reasoning
x⁻¹ = (x ⁻¹) x≄0
y⁻¹ = (y ⁻¹) y≄0
lem : x⁻¹ * y ≃ 1ℝ
lem = begin
x⁻¹ * y ≈⟨ *-congˡ (≃-symm x≃y) ⟩
x⁻¹ * x ≈⟨ *-inverseˡ x x≄0 ⟩
1ℝ ∎
{-
Proposition:
If x is positive, then so is x⁻¹.
Proof:
Recall that
x is positive ⇔ There is N∈ℕ such that m ≥ N implies xₘ ≥ N⁻¹ (Lemma 2.8.1).
Then, since x is positive, we get, for n ≥ max{Kₓ, N},
0 < N⁻¹ < xₛₙ = ∣xₛₙ∣ < Kₓ (1).
Thus
0 < (max{Kₓ, N})⁻¹ ≤ Kₓ⁻¹ < yₙ
for n ≥ max{Kₓ, N}. By Lemma 2.8.1, x⁻¹ ≡ (yₙ) is positive. □
-}
posx⇒posx⁻¹ : ∀ {x} -> (x≄0 : x ≄0) -> Positive x -> Positive ((x ⁻¹) x≄0)
posx⇒posx⁻¹ {x} x≄0 posx = let fromPosx = fast-lemma-2-8-1-if posx; M = suc (proj₁ fromPosx) in
lemma-2-8-1-onlyif (ℕ.pred (K x ℕ.⊔ M) , λ {(suc k₁) m≥Kₓ⊔M ->
let m = suc k₁; N = Nₐ x x≄0; xₛ = seq x ((m ℕ.+ N) ℕ.* (N ℕ.* N)); yₘ = (ℚ.1/ xₛ) {not0-helper x x≄0 m} in begin
+ 1 / (K x ℕ.⊔ M) ≤⟨ q≤r⇒+p/r≤+p/q 1 (K x) (K x ℕ.⊔ M) (ℕP.m≤m⊔n (K x) M) ⟩
+ 1 / (K x) ≤⟨ +p≤+q⇒1/q≤1/p {xₛ} {+ K x / 1}
(ℚ.positive (ℚP.<-≤-trans (ℚP.positive⁻¹ {+ 1 / M} _) (proj₂ fromPosx ((m ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (K x) M) m≥Kₓ⊔M) (ℕP.m≤m+n m N)) (ℕP.m≤m*n (m ℕ.+ N) {N ℕ.* N} ℕP.0<1+n))))) _
(ℚP.≤-trans (p≤∣p∣ xₛ) (ℚP.<⇒≤ (canonical-strict-upper-bound x ((m ℕ.+ N) ℕ.* (N ℕ.* N))))) ⟩
yₘ ∎})
where open ℚP.≤-Reasoning
0<x⇒0<x⁻¹ : ∀ {x} -> (x≄0 : x ≄0) -> 0ℝ < x -> 0ℝ < (x ⁻¹) x≄0
0<x⇒0<x⁻¹ {x} x≄0 0<x = posx⇒0<x {(x ⁻¹) x≄0} (posx⇒posx⁻¹ {x} x≄0 (0<x⇒posx 0<x))
{-
The x argument could be left implicit in this function, but doing so can drastically decrease performance.
Maybe changing _≄_ to a constructor will help?
-}
x≄0⇒-x≄0 : ∀ x -> x ≄0 -> (- x) ≄0
x≄0⇒-x≄0 x (inj₁ x<0) = inj₂ (pos-cong (≃-trans (+-comm 0ℝ (- x)) (+-congʳ (- x) 0≃-0)) x<0)
x≄0⇒-x≄0 x (inj₂ 0<x) = inj₁ (pos-cong (≃-trans (≃-trans (+-comm x (- 0ℝ)) (+-congˡ x (≃-symm 0≃-0))) (+-congʳ 0ℝ (≃-symm (neg-involutive x)))) 0<x)
neg-distrib-⁻¹ : ∀ {x} -> (x≄0 : x ≄0) -> - ((x ⁻¹) x≄0) ≃ ((- x) ⁻¹) (x≄0⇒-x≄0 x x≄0)
neg-distrib-⁻¹ {x} x≄0 = let x⁻¹ = (x ⁻¹) x≄0 in ⁻¹-unique (- x⁻¹) (- x) (x≄0⇒-x≄0 x x≄0) (begin
(- x⁻¹) * (- x) ≈⟨ ≃-symm (neg-distribˡ-* x⁻¹ (- x)) ⟩
- (x⁻¹ * (- x)) ≈⟨ -‿cong (≃-symm (neg-distribʳ-* x⁻¹ x)) ⟩
- - (x⁻¹ * x) ≈⟨ neg-involutive (x⁻¹ * x) ⟩
x⁻¹ * x ≈⟨ *-inverseˡ x x≄0 ⟩
1ℝ ∎)
where open ≃-Reasoning
{-
Proposition:
If x is negative, then so is x⁻¹. Alternatively, if -x is positive, then so is -x⁻¹.
Proof:
Since -x is positive, (-x)⁻¹ is positive. As -x⁻¹ = (-x)⁻¹, -x⁻¹ is positive. Thus x⁻¹ is negative. □
-}
negx⇒negx⁻¹ : ∀ {x} -> (x≄0 : x ≄0) -> Negative x -> Negative ((x ⁻¹) x≄0)
negx⇒negx⁻¹ {x} x≄0 negx = let x⁻¹ = (x ⁻¹) x≄0; -x⁻¹ = ((- x) ⁻¹) (x≄0⇒-x≄0 x x≄0) in
pos-cong { -x⁻¹} { - x⁻¹} (≃-symm (neg-distrib-⁻¹ {x} x≄0)) (posx⇒posx⁻¹ { - x} (x≄0⇒-x≄0 x x≄0) negx)
x<0⇒x⁻¹<0 : ∀ {x} -> (x≄0 : x ≄0) -> x < 0ℝ -> (x ⁻¹) x≄0 < 0ℝ
x<0⇒x⁻¹<0 {x} x≄0 x<0 = let x⁻¹ = (x ⁻¹) x≄0 in
negx⇒x<0 {x⁻¹} (negx⇒negx⁻¹ {x} x≄0 (x<0⇒negx {x} x<0))
m<n*m : ∀ {m n} -> 0 ℕ.< m -> 1 ℕ.< n -> m ℕ.< n ℕ.* m
m<n*m {m} {n} 0<m 1<n = subst (m ℕ.<_) (ℕP.*-comm m n) (ℕP.m<m*n 0<m 1<n)
{- It seems easier to write the inverse of a rational p in its (p⁻¹)⋆ form. The alternative is writing
it in the form (p⋆)⁻¹. They're equivalent, but then you need to provide a proof that p⋆ ≄0 every time you call on (p⋆)⁻¹,
whereas in the former case you need only show that p's denominator is not 0. Since naturals (in this case,
the denominator of p) actually compute and reals don't, the (p⁻¹)⋆ form is easier to deal with.
-}
lemma-2-14 : ∀ x -> ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∣ x - (seq x n) ⋆ ∣ ≤ ((+ 1 / n) {n≢0}) ⋆
lemma-2-14 x (suc k₁) = nonNeg* (λ {(suc k₂) -> let n = suc k₁; m = suc k₂; x₄ₘ = seq x (2 ℕ.* (2 ℕ.* m)); xₙ = seq x n in begin
ℚ.- (+ 1 / m) <⟨ ℚP.neg-mono-< (q<r⇒+p/r<+p/q 1 m (2 ℕ.* (2 ℕ.* m))
(ℕP.<-trans (m<n*m ℕP.0<1+n ℕP.≤-refl)
(m<n*m ℕP.0<1+n ℕP.≤-refl))) ⟩
ℚ.- (+ 1 / (2 ℕ.* (2 ℕ.* m))) ≈⟨ solve 2 (λ 4m n -> (⊝ 4m) ⊜ (n ⊖ (4m ⊕ n))) ℚP.≃-refl (+ 1 / (2 ℕ.* (2 ℕ.* m))) (+ 1 / n) ⟩
+ 1 / n ℚ.- (+ 1 / (2 ℕ.* (2 ℕ.* m)) ℚ.+ + 1 / n) ≤⟨ ℚP.+-monoʳ-≤ (+ 1 / n) (ℚP.neg-mono-≤ (reg x (2 ℕ.* (2 ℕ.* m)) n)) ⟩
+ 1 / n ℚ.- ℚ.∣ x₄ₘ ℚ.- xₙ ∣ ∎})
where
open ℚP.≤-Reasoning
open ℚ-Solver
_<_<_ : (x y z : ℝ) -> Set
x < y < z = (x < y) × (y < z)
_<_≤_ : (x y z : ℝ) -> Set
x < y ≤ z = (x < y) × (y ≤ z)
_≤_<_ : (x y z : ℝ) -> Set
x ≤ y < z = (x ≤ y) × (y < z)
_≤_≤_ : (x y z : ℝ) -> Set
x ≤ y ≤ z = (x ≤ y) × (y ≤ z)
0<y-x⇒x<y : ∀ x y -> 0ℝ < y - x -> x < y
0<y-x⇒x<y x y 0<y-x = pos-cong (≃-trans (+-congʳ (y - x) (≃-symm 0≃-0)) (+-identityʳ (y - x))) 0<y-x
x<y⇒0<y-x : ∀ x y -> x < y -> 0ℝ < y - x
x<y⇒0<y-x x y x<y = pos-cong (≃-trans (≃-symm (+-identityʳ (y - x))) (+-congʳ (y - x) 0≃-0)) x<y
⋆-distrib-to-p⋆-q⋆ : ∀ p q -> (p ℚ.- q) ⋆ ≃ p ⋆ - (q ⋆)
⋆-distrib-to-p⋆-q⋆ p q = solve 0 (Κ (p ℚ.- q) ⊜ (Κ p ⊖ Κ q)) ≃-refl
where open ℝ-Solver
0<p⇒0<p⋆ : ∀ p -> ℚ.Positive p -> Positive (p ⋆)
0<p⇒0<p⋆ (mkℚᵘ +[1+ p ] q-1) posp/q = let q = suc q-1 in pos* (q , ℚ.*<* (begin-strict
+ 1 ℤ.* + q ≡⟨ ℤP.*-identityˡ (+ q) ⟩
+ q <⟨ ℤ.+<+ (ℕP.n<1+n q) ⟩
+ suc q ≤⟨ ℤ.+≤+ (ℕP.m≤n*m (suc q) {suc p} ℕP.0<1+n) ⟩
+[1+ p ] ℤ.* + suc q ∎))
where open ℤP.≤-Reasoning
p<q⇒p⋆<q⋆ : ∀ p q -> p ℚ.< q -> p ⋆ < q ⋆
p<q⇒p⋆<q⋆ p q p<q = pos-cong (⋆-distrib-to-p⋆-q⋆ q p) (0<p⇒0<p⋆ (q ℚ.- p) (ℚ.positive (p<q⇒0<q-p p q p<q)))
∣x-y∣≃∣y-x∣ : ∀ x y -> ∣ x - y ∣ ≃ ∣ y - x ∣
∣x-y∣≃∣y-x∣ x y = begin
∣ x - y ∣ ≈⟨ ≃-symm ∣-x∣≃∣x∣ ⟩
∣ - (x - y) ∣ ≈⟨ ∣-∣-cong (solve 2 (λ x y -> (⊝ (x ⊖ y)) ⊜ (y ⊖ x)) ≃-refl x y) ⟩
∣ y - x ∣ ∎
where
open ℝ-Solver
open ≃-Reasoning
{-
density-of-ℚ is very slow. It's typically much more convenient to use fast-density-of-ℚ, which is its abstract version.
-}
density-of-ℚ : ∀ x y -> x < y -> ∃ λ (α : ℚᵘ) -> x < α ⋆ < y
density-of-ℚ x y (pos* (n-1 , y₂ₙ-x₂ₙ>n⁻¹)) = α , 0<y-x⇒x<y x (α ⋆) (begin-strict
0ℝ <⟨ lemA ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ((+ 1 / (2 ℕ.* n)) ⋆) ≤⟨ +-monoʳ-≤ ((+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆) (neg-mono-≤ (lemma-2-14 x (2 ℕ.* n))) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ∣ x - (x₂ₙ ⋆) ∣ ≈⟨ +-congˡ (- ∣ x - x₂ₙ ⋆ ∣) (⋆-cong (lemB y₂ₙ x₂ₙ)) ⟩
(((+ 1 / 2) ℚ.* (x₂ₙ ℚ.+ y₂ₙ) ℚ.- x₂ₙ) ⋆) - ∣ x - (x₂ₙ ⋆) ∣ ≈⟨ +-congˡ (- ∣ x - x₂ₙ ⋆ ∣) (⋆-distrib-to-p⋆-q⋆ α x₂ₙ) ⟩
(α ⋆) - (x₂ₙ ⋆) - ∣ x - (x₂ₙ ⋆) ∣ ≤⟨ +-monoʳ-≤ (α ⋆ - (x₂ₙ ⋆)) (neg-mono-≤ x≤∣x∣) ⟩
(α ⋆) - (x₂ₙ ⋆) - (x - (x₂ₙ ⋆)) ≈⟨ +-assoc (α ⋆) (- (x₂ₙ ⋆)) (- (x - (x₂ₙ ⋆))) ⟩
α ⋆ + (- (x₂ₙ ⋆) - (x - x₂ₙ ⋆)) ≈⟨ +-congʳ (α ⋆) (≃-trans (≃-symm (neg-distrib-+ (x₂ₙ ⋆) (x - x₂ₙ ⋆)))
(-‿cong (helper x (x₂ₙ ⋆)))) ⟩
(α ⋆) - x ∎) ,
0<y-x⇒x<y (α ⋆) y (begin-strict
0ℝ <⟨ lemA ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ((+ 1 / (2 ℕ.* n)) ⋆) ≤⟨ +-monoʳ-≤ ((+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆) (neg-mono-≤ (lemma-2-14 y (2 ℕ.* n))) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ∣ y - y₂ₙ ⋆ ∣ ≤⟨ +-monoʳ-≤ ((+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆)
(neg-mono-≤ (≤-respʳ-≃ (∣x-y∣≃∣y-x∣ (y₂ₙ ⋆) y) x≤∣x∣)) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - (y₂ₙ ⋆ - y) ≈⟨ +-congʳ ((+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆) (neg-distrib-+ (y₂ₙ ⋆) (- y)) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ + (- (y₂ₙ ⋆) - (- y)) ≈⟨ ≃-trans
(≃-symm (+-assoc ((+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆) (- (y₂ₙ ⋆)) (- (- y))))
(+-congˡ (- (- y)) (≃-symm (⋆-distrib-to-p⋆-q⋆ (+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) y₂ₙ))) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ) ℚ.- y₂ₙ) ⋆ - (- y) ≈⟨ +-cong (⋆-cong (lemC y₂ₙ x₂ₙ)) (neg-involutive y) ⟩
(ℚ.- α) ⋆ + y ≈⟨ ≃-trans (+-comm ((ℚ.- α) ⋆) y) (+-congʳ y (⋆-distrib-neg α)) ⟩
y - α ⋆ ∎)
where
open ≤-Reasoning
open ℤ-Solver
n = suc n-1
x₂ₙ = seq x (2 ℕ.* n)
y₂ₙ = seq y (2 ℕ.* n)
α = (+ 1 / 2) ℚ.* (x₂ₙ ℚ.+ y₂ₙ)
lemA : 0ℝ < (+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ((+ 1 / (2 ℕ.* n)) ⋆)
lemA = begin-strict
0ℝ ≈⟨ ⋆-cong (ℚP.≃-sym (ℚP.+-inverseʳ (+ 1 / (2 ℕ.* n)))) ⟩
(+ 1 / (2 ℕ.* n) ℚ.- (+ 1 / (2 ℕ.* n))) ⋆ <⟨ p<q⇒p⋆<q⋆
(+ 1 / (2 ℕ.* n) ℚ.- (+ 1 / (2 ℕ.* n)))
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ) ℚ.- (+ 1 / (2 ℕ.* n)))
(ℚP.+-monoˡ-< (ℚ.- (+ 1 / (2 ℕ.* n)))
(ℚP.*-monoʳ-<-pos {+ 1 / 2} _ y₂ₙ-x₂ₙ>n⁻¹)) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ) ℚ.- (+ 1 / (2 ℕ.* n))) ⋆ ≈⟨ ⋆-distrib-to-p⋆-q⋆ (+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) (+ 1 / (2 ℕ.* n)) ⟩
(+ 1 / 2 ℚ.* (y₂ₙ ℚ.- x₂ₙ)) ⋆ - ((+ 1 / (2 ℕ.* n)) ⋆) ∎
helper : ∀ x y -> y + (x - y) ≃ x
helper x y = begin-equality
y + (x - y) ≈⟨ +-congʳ y (+-comm x (- y)) ⟩
y + (- y + x) ≈⟨ ≃-symm (+-assoc y (- y) x) ⟩
(y - y) + x ≈⟨ +-congˡ x (+-inverseʳ y) ⟩
0ℝ + x ≈⟨ +-identityˡ x ⟩
x ∎
lemB : ∀ p q -> + 1 / 2 ℚ.* (p ℚ.- q) ℚ.≃ + 1 / 2 ℚ.* (q ℚ.+ p) ℚ.- q
lemB p/q u/v = let p = ↥ p/q; q = ↧ p/q; u = ↥ u/v; v = ↧ u/v in
ℚ.*≡* (solve 4 (λ p q u v ->
(Κ (+ 1) ⊗ (p ⊗ v ⊕ (⊝ u) ⊗ q)) ⊗ (Κ (+ 2) ⊗ (v ⊗ q) ⊗ v) ⊜
((Κ (+ 1) ⊗ (u ⊗ q ⊕ p ⊗ v)) ⊗ v ⊕ (⊝ u) ⊗ (Κ (+ 2) ⊗ (v ⊗ q))) ⊗ (Κ (+ 2) ⊗ (q ⊗ v)))
refl p q u v)
lemC : ∀ p q -> + 1 / 2 ℚ.* (p ℚ.- q) ℚ.- p ℚ.≃ ℚ.- (+ 1 / 2 ℚ.* (q ℚ.+ p))
lemC p/q u/v = let p = ↥ p/q; q = ↧ p/q; u = ↥ u/v; v = ↧ u/v in
ℚ.*≡* (solve 4 (λ p q u v ->
((Κ (+ 1) ⊗ (p ⊗ v ⊕ (⊝ u) ⊗ q)) ⊗ q ⊕ (⊝ p) ⊗ (Κ (+ 2) ⊗ (q ⊗ v))) ⊗ (Κ (+ 2) ⊗ (v ⊗ q)) ⊜
(⊝ (Κ (+ 1) ⊗ (u ⊗ q ⊕ p ⊗ v))) ⊗ ((Κ (+ 2) ⊗ (q ⊗ v)) ⊗ q))
refl p q u v)
abstract
fast-density-of-ℚ : ∀ x y -> x < y -> ∃ λ (α : ℚᵘ) -> x < α ⋆ < y
fast-density-of-ℚ = density-of-ℚ
∣x∣<y⇒-y<x<y : ∀ x y -> ∣ x ∣ < y -> (- y) < x < y
∣x∣<y⇒-y<x<y x y ∣x∣<y = (begin-strict
- y <⟨ neg-mono-< ∣x∣<y ⟩
- ∣ x ∣ ≈⟨ -‿cong (≃-symm ∣-x∣≃∣x∣) ⟩
- ∣ - x ∣ ≤⟨ neg-mono-≤ x≤∣x∣ ⟩
- (- x) ≈⟨ neg-involutive x ⟩
x ∎) , (begin-strict
x ≤⟨ x≤∣x∣ ⟩
∣ x ∣ <⟨ ∣x∣<y ⟩
y ∎)
where open ≤-Reasoning
x<z∧y<z⇒x⊔y<z : ∀ x y z -> x < z -> y < z -> x ⊔ y < z
x<z∧y<z⇒x⊔y<z x y z x<z y<z = lemma-2-8-1-onlyif (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
fromx<z = fast-lemma-2-8-1-if x<z
N₁ = suc (proj₁ fromx<z)
fromy<z = fast-lemma-2-8-1-if y<z
N₂ = suc (proj₁ fromy<z)
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (z - (x ⊔ y)) m ℚ.≥ + 1 / N
lem m m≥N = [ left , right ]′ (ℚP.≤-total (seq y (2 ℕ.* m)) (seq x (2 ℕ.* m)))
where
left : seq x (2 ℕ.* m) ℚ.≥ seq y (2 ℕ.* m) -> seq (z - (x ⊔ y)) m ℚ.≥ + 1 / N
left x₂ₘ≥y₂ₘ = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 N₁ N (ℕP.m≤m⊔n N₁ N₂) ⟩
+ 1 / N₁ ≤⟨ proj₂ fromx<z m
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) m≥N) ⟩
seq z (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ≈⟨ ℚP.+-congʳ (seq z (2 ℕ.* m))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.p≥q⇒p⊔q≃p x₂ₘ≥y₂ₘ))) ⟩
seq z (2 ℕ.* m) ℚ.- (seq x (2 ℕ.* m) ℚ.⊔ seq y (2 ℕ.* m)) ∎
right : seq y (2 ℕ.* m) ℚ.≥ seq x (2 ℕ.* m) -> seq (z - (x ⊔ y)) m ℚ.≥ + 1 / N
right y₂ₘ≥x₂ₘ = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 N₂ N (ℕP.m≤n⊔m N₁ N₂) ⟩
+ 1 / N₂ ≤⟨ proj₂ fromy<z m
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) m≥N) ⟩
seq z (2 ℕ.* m) ℚ.- seq y (2 ℕ.* m) ≈⟨ ℚP.+-congʳ (seq z (2 ℕ.* m))
(ℚP.-‿cong (ℚP.≃-sym (ℚP.p≤q⇒p⊔q≃q y₂ₘ≥x₂ₘ))) ⟩
seq z (2 ℕ.* m) ℚ.- (seq x (2 ℕ.* m) ℚ.⊔ seq y (2 ℕ.* m)) ∎
∣p∣≃p⊔-p : ∀ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
∣p∣≃p⊔-p p = [ left , right ]′ (ℚP.≤-total 0ℚᵘ p)
where
open ℚP.≤-Reasoning
left : 0ℚᵘ ℚ.≤ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ ℚ.- p
left 0≤p = let ∣p∣≃p = ℚP.0≤p⇒∣p∣≃p 0≤p in begin-equality
ℚ.∣ p ∣ ≈⟨ ∣p∣≃p ⟩
p ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊔q≃p
(ℚP.≤-respʳ-≃ ∣p∣≃p (ℚP.≤-respʳ-≃ (ℚP.∣-p∣≃∣p∣ p) (p≤∣p∣ (ℚ.- p))))) ⟩
p ℚ.⊔ ℚ.- p ∎
right : p ℚ.≤ 0ℚᵘ -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ ℚ.- p
right p≤0 = let ∣p∣≃-p = ℚP.≃-trans (ℚP.≃-sym (ℚP.∣-p∣≃∣p∣ p)) (ℚP.0≤p⇒∣p∣≃p (ℚP.neg-mono-≤ p≤0)) in begin-equality
ℚ.∣ p ∣ ≈⟨ ∣p∣≃-p ⟩
ℚ.- p ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊔q≃q (ℚP.≤-respʳ-≃ ∣p∣≃-p (p≤∣p∣ p))) ⟩
p ℚ.⊔ ℚ.- p ∎
∣x∣≃x⊔-x : ∀ x -> ∣ x ∣ ≃ x ⊔ (- x)
∣x∣≃x⊔-x x = *≃* λ {(suc k₁) -> let n = suc k₁ in begin
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- (seq x n ℚ.⊔ ℚ.- seq x n) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ ℚ.∣ seq x n ∣
(ℚP.-‿cong (ℚP.≃-sym (∣p∣≃p⊔-p (seq x n))))) ⟩
ℚ.∣ ℚ.∣ seq x n ∣ ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ℚ.∣ seq x n ∣) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎}
where
open ℚP.≤-Reasoning
-y<x<y⇒∣x∣<y : ∀ x y -> (- y) < x < y -> ∣ x ∣ < y
-y<x<y⇒∣x∣<y x y -y<x<y = begin-strict
∣ x ∣ ≈⟨ ∣x∣≃x⊔-x x ⟩
x ⊔ (- x) <⟨ x<z∧y<z⇒x⊔y<z x (- x) y
(proj₂ -y<x<y)
(<-respʳ-≃ (neg-involutive y) (neg-mono-< (proj₁ -y<x<y))) ⟩
y ∎
where open ≤-Reasoning
corollary-2-15 : ∀ (x r : ℝ) -> Positive r -> ∃ λ (α : ℚᵘ) -> ∣ x - α ⋆ ∣ < r
corollary-2-15 x r posr = α , <-respˡ-≃ (∣x-y∣≃∣y-x∣ (α ⋆) x) (-y<x<y⇒∣x∣<y (α ⋆ - x) r (-r<α-x , α-x<r))
where
open ℝ-Solver
open ≤-Reasoning
-r+x<r+x : - r + x < r + x
-r+x<r+x = +-monoˡ-< x (begin-strict
- r <⟨ neg-mono-< (posx⇒0<x posr) ⟩
- 0ℝ ≈⟨ ≃-symm 0≃-0 ⟩
0ℝ <⟨ posx⇒0<x posr ⟩
r ∎)
αp = fast-density-of-ℚ (- r + x) (r + x) -r+x<r+x
α = proj₁ αp
-r<α-x : - r < α ⋆ - x
-r<α-x = begin-strict
- r ≈⟨ solve 2 (λ r x -> (⊝ r) ⊜ (⊝ r ⊕ x ⊖ x)) ≃-refl r x ⟩
- r + x - x <⟨ +-monoˡ-< (- x) (proj₁ (proj₂ αp)) ⟩
α ⋆ - x ∎
α-x<r : α ⋆ - x < r
α-x<r = begin-strict
α ⋆ - x <⟨ +-monoˡ-< (- x) (proj₂ (proj₂ αp)) ⟩
r + x - x ≈⟨ solve 2 (λ r x -> (r ⊕ x ⊖ x) ⊜ r) ≃-refl r x ⟩
r ∎
abstract
fast-corollary-2-15 : ∀ (x r : ℝ) -> Positive r -> ∃ λ (α : ℚᵘ) -> ∣ x - α ⋆ ∣ < r
fast-corollary-2-15 = corollary-2-15
≤⇒≡∨< : ∀ (m n : ℕ) -> m ℕ.≤ n -> m ≡ n ⊎ m ℕ.< n
≤⇒≡∨< zero zero m≤n = inj₁ _≡_.refl
≤⇒≡∨< zero (suc n) m≤n = inj₂ ℕP.0<1+n
≤⇒≡∨< (suc m) (suc n) (ℕ.s≤s m≤n) = [ (λ m≡n -> inj₁ (cong suc m≡n)) , (λ m<n -> inj₂ (ℕ.s≤s m<n)) ]′ (≤⇒≡∨< m n m≤n)
-- Finite sums over a sequence
∑₀ : (ℕ -> ℝ) -> ℕ -> ℝ
∑₀ a 0 = 0ℝ
∑₀ a (suc n) = ∑₀ a n + a n
∑ : (ℕ -> ℝ) -> ℕ -> ℕ -> ℝ
∑ a 0 n = ∑₀ a n
∑ a (suc i) n = ∑₀ a n - ∑₀ a (suc i)
∑-distrib-+ : ∀ (xs ys : ℕ -> ℝ) -> ∀ i n ->
∑ (λ k -> xs k + ys k) i n ≃ ∑ xs i n + ∑ ys i n
∑-distrib-+ xs ys 0 n = lem n
where
open ≃-Reasoning
open ℝ-Solver
{-
If you just case split on n in ∑-distrib-+ and don't use this lemma, Agda's termination checker gives an error
for the (suc i) n case when the induction hypothesis is used.
-}
lem : ∀ n -> ∑₀ (λ k -> xs k + ys k) n ≃ ∑₀ xs n + ∑₀ ys n
lem 0 = ≃-reflexive (λ {(suc n-1) -> ℚP.≃-refl})
lem (suc n) = begin
∑₀ (λ k -> xs k + ys k) n + (xs n + ys n) ≈⟨ +-congˡ (xs n + ys n) (lem n) ⟩
∑₀ xs n + ∑₀ ys n + (xs n + ys n) ≈⟨ solve 4 (λ a b c d -> (a ⊕ c ⊕ (b ⊕ d)) ⊜ (a ⊕ b ⊕ (c ⊕ d)))
≃-refl (∑₀ xs n) (xs n) (∑₀ ys n) (ys n) ⟩
∑₀ xs n + xs n + (∑₀ ys n + ys n) ∎
∑-distrib-+ xs ys (suc i) n = begin
∑₀ (λ k -> xs k + ys k) n -
(∑₀ (λ k -> xs k + ys k) i + (xs i + ys i)) ≈⟨ +-cong
(∑-distrib-+ xs ys 0 n)
(-‿cong (+-congˡ (xs i + ys i) (∑-distrib-+ xs ys 0 i))) ⟩
∑₀ xs n + ∑₀ ys n - (∑₀ xs i + ∑₀ ys i + (xs i + ys i)) ≈⟨ solve 6 (λ a b c d e f ->
(a ⊕ b ⊖ (c ⊕ d ⊕ (e ⊕ f))) ⊜ (a ⊖ (c ⊕ e) ⊕ (b ⊖ (d ⊕ f))))
≃-refl (∑₀ xs n) (∑₀ ys n) (∑₀ xs i) (∑₀ ys i) (xs i) (ys i) ⟩
∑₀ xs n - (∑₀ xs i + xs i) + (∑₀ ys n - (∑₀ ys i + ys i)) ∎
where
open ≃-Reasoning
open ℝ-Solver
neg-distrib-∑ : ∀ xs -> ∀ i n -> - ∑ xs i n ≃ ∑ (λ j -> - xs j) i n
neg-distrib-∑ xs 0 n = lem n
where
open ≃-Reasoning
lem : ∀ n -> - ∑₀ xs n ≃ ∑₀ (λ j -> - xs j) n
lem 0 = ≃-symm 0≃-0
lem (suc n) = begin
- (∑₀ xs n + xs n) ≈⟨ neg-distrib-+ (∑₀ xs n) (xs n) ⟩
- ∑₀ xs n - xs n ≈⟨ +-congˡ (- xs n) (lem n) ⟩
∑₀ (λ j -> - xs j) n - xs n ∎
neg-distrib-∑ xs (suc i) n = begin
- (∑₀ xs n - (∑₀ xs i + xs i)) ≈⟨ neg-distrib-+ (∑₀ xs n) (- (∑₀ xs i + xs i)) ⟩
- ∑₀ xs n - (- (∑₀ xs i + xs i)) ≈⟨ +-cong
(neg-distrib-∑ xs 0 n)
(-‿cong (≃-trans
(neg-distrib-+ (∑₀ xs i) (xs i))
(+-congˡ (- xs i) (neg-distrib-∑ xs 0 i)))) ⟩
∑₀ (λ j -> - xs j) n - (∑₀ (λ j -> - xs j) i - xs i) ∎
where open ≃-Reasoning
≤∨> : ∀ p q -> p ℚ.≤ q ⊎ q ℚ.< p
≤∨> p q with p ℚP.≤? q
... | .Bool.true because ofʸ p₁ = inj₁ p₁
... | .Bool.false because ofⁿ ¬p = inj₂ (ℚP.≰⇒> ¬p)
p+q>r⇒p>2⁻¹r∨q>2⁻¹r : ∀ p q r -> p ℚ.+ q ℚ.> r -> p ℚ.> (+ 1 / 2) ℚ.* r ⊎ q ℚ.> (+ 1 / 2) ℚ.* r
p+q>r⇒p>2⁻¹r∨q>2⁻¹r p q r p+q>r = [ (λ hyp -> inj₁ (lem hyp)) , (λ hyp -> inj₂ hyp) ]′ (≤∨> q ((+ 1 / 2) ℚ.* r))
where
open ℚP.≤-Reasoning
open ℚ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; ⊝_ to :-_
; _⊜_ to _:=_
; Κ to κ
)
lem : q ℚ.≤ (+ 1 / 2) ℚ.* r -> p ℚ.> (+ 1 / 2) ℚ.* r
lem hyp = begin-strict
(+ 1 / 2) ℚ.* r ≈⟨ ℚ.*≡* (ℤsolve 2 (λ n d ->
(κ (+ 1) :* n) :* (d :* (κ (+ 2) :* d)) :=
(n :* (κ (+ 2) :* d) :+ (:- (κ (+ 1) :* n)) :* d) :* (κ (+ 2) :* d))
refl (↥ r) (↧ r)) ⟩
r ℚ.- (+ 1 / 2) ℚ.* r <⟨ ℚP.+-monoˡ-< (ℚ.- ((+ 1 / 2) ℚ.* r)) p+q>r ⟩
(p ℚ.+ q) ℚ.- (+ 1 / 2) ℚ.* r ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- (+ 1 / 2 ℚ.* r)) (ℚP.+-monoʳ-≤ p hyp) ⟩
(p ℚ.+ (+ 1 / 2) ℚ.* r) ℚ.- (+ 1 / 2) ℚ.* r ≈⟨ solve 2 (λ p 2⁻¹r -> (p ⊕ 2⁻¹r ⊖ 2⁻¹r) ⊜ p) ℚP.≃-refl p ((+ 1 / 2) ℚ.* r) ⟩
p ∎
0<q-p⇒p<q : ∀ p q -> 0ℚᵘ ℚ.< q ℚ.- p -> p ℚ.< q
0<q-p⇒p<q p q 0<q-p = begin-strict
p ≈⟨ ℚP.≃-sym (ℚP.+-identityʳ p) ⟩
p ℚ.+ 0ℚᵘ <⟨ ℚP.+-monoʳ-< p 0<q-p ⟩
p ℚ.+ (q ℚ.- p) ≈⟨ solve 2 (λ p q -> (p ⊕ (q ⊖ p)) ⊜ q) ℚP.≃-refl p q ⟩
q ∎
where
open ℚP.≤-Reasoning
open ℚ-Solver
p⋆<q⋆⇒p<q : ∀ p q -> p ⋆ < q ⋆ -> p ℚ.< q
p⋆<q⋆⇒p<q p q (pos* (n , p⋆<q⋆)) = 0<q-p⇒p<q p q (begin-strict
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 1 / (suc n) <⟨ p⋆<q⋆ ⟩
q ℚ.- p ∎)
where open ℚP.≤-Reasoning
posp⇒posp⋆ : ∀ p -> ℚ.Positive p -> Positive (p ⋆)
posp⇒posp⋆ p posp = 0<x⇒posx (p<q⇒p⋆<q⋆ 0ℚᵘ p (ℚP.positive⁻¹ posp))
{-
Proposition:
If x + y > 0, then x > 0 or y > 0.
Proof:
This proof is the n=2 special case of Bishop's proof of Proposition 2.16.
Let α∈ℚᵘ such that 0 < α < x + y. By Corollay 2.15, there is X,Y∈ℚᵘ such that
∣x - X∣ < 4̂⁻¹α and
∣y - Y∣ < 4⁻¹α.
We have
X + Y = (x + y) - (x - X) - (y - Y)
≥ (x + y) - ∣x - X∣ - ∣y - Y∣
≥ α - 4⁻¹α - 4⁻¹α
= 2̂⁻¹α.
Thus X + Y > 2⁻¹α, and so X > 4⁻¹α or Y > 4⁻¹α. Let Z be the value X or Y such that Z > 4⁻¹α and let
z be the corresponding x or y value. Then
z = Z - (Z - z)
≥ Z - ∣z - Z∣
> 4⁻¹α - 4⁻¹α
= 0.
Hence z > 0, so x > 0 or y > 0. □
-}
x+y>0⇒x>0∨y>0 : ∀ x y -> x + y > 0ℝ -> x > 0ℝ ⊎ y > 0ℝ
x+y>0⇒x>0∨y>0 x y x+y>0 = [ (λ hyp -> inj₁ (lem x X (proj₂ X-generator) (ℚP.<-respˡ-≃ 2⁻¹*2⁻¹α≃4⁻¹α hyp))) ,
(λ hyp -> inj₂ (lem y Y (proj₂ Y-generator) (ℚP.<-respˡ-≃ 2⁻¹*2⁻¹α≃4⁻¹α hyp))) ]′
(p+q>r⇒p>2⁻¹r∨q>2⁻¹r X Y ((+ 1 / 2) ℚ.* α) ax+ay>α/4)
where
open ℝ-Solver
open ℤ-Solver using ()
renaming
( solve to ℤsolve
; _⊕_ to _:+_
; _⊗_ to _:*_
; ⊝_ to :-_
; _⊜_ to _:=_
; Κ to κ
)
α-generator = fast-density-of-ℚ 0ℝ (x + y) x+y>0
α = proj₁ α-generator
pos4⁻¹α : Positive (((+ 1 / 4) ℚ.* α) ⋆)
pos4⁻¹α = posp⇒posp⋆ ((+ 1 / 4) ℚ.* α) (ℚ.positive (begin-strict
0ℚᵘ ≈⟨ ℚP.≃-sym (ℚP.*-zeroʳ (+ 1 / 4)) ⟩
(+ 1 / 4) ℚ.* 0ℚᵘ <⟨ ℚP.*-monoʳ-<-pos {+ 1 / 4} _ (p⋆<q⋆⇒p<q 0ℚᵘ α (proj₁ (proj₂ α-generator))) ⟩
(+ 1 / 4) ℚ.* α ∎))
where open ℚP.≤-Reasoning
X-generator = fast-corollary-2-15 x (((+ 1 / 4) ℚ.* α) ⋆) pos4⁻¹α
X = proj₁ X-generator
Y-generator = fast-corollary-2-15 y (((+ 1 / 4) ℚ.* α) ⋆) pos4⁻¹α
Y = proj₁ Y-generator
2⁻¹*2⁻¹α≃4⁻¹α : (+ 1 / 2) ℚ.* ((+ 1 / 2) ℚ.* α) ℚ.≃ (+ 1 / 4) ℚ.* α
2⁻¹*2⁻¹α≃4⁻¹α = ℚ.*≡* (ℤsolve 2 (λ p q ->
κ (+ 1) :* (κ (+ 1) :* p) :* (κ (+ 4) :* q) := (κ (+ 1) :* p :* (κ (+ 2) :* (κ (+ 2) :* q))))
refl (↥ α) (↧ α))
ax+ay>α/4 : X ℚ.+ Y ℚ.> (+ 1 / 2) ℚ.* α
ax+ay>α/4 = p⋆<q⋆⇒p<q ((+ 1 / 2) ℚ.* α) (X ℚ.+ Y) (begin-strict
((+ 1 / 2) ℚ.* α) ⋆ ≈⟨ ⋆-cong (ℚ.*≡* (ℤsolve 2 (λ p q ->
(κ (+ 1) :* p) :* ((q :* (κ (+ 4) :* q)) :* (κ (+ 4) :* q)) :=
((p :* (κ (+ 4) :* q) :+ (:- (κ (+ 1) :* p)) :* q) :* (κ (+ 4) :* q) :+ (:- (κ (+ 1) :* p)) :*
(q :* (κ (+ 4) :* q))) :* (κ (+ 2) :* q))
refl (↥ α) (↧ α))) ⟩
(α ℚ.- (+ 1 / 4) ℚ.* α ℚ.- (+ 1 / 4) ℚ.* α) ⋆ ≈⟨ ≃-trans
(⋆-distrib-to-p⋆-q⋆ (α ℚ.- (+ 1 / 4) ℚ.* α) ((+ 1 / 4) ℚ.* α))
(+-congˡ (- ((+ 1 / 4 ℚ.* α) ⋆)) (⋆-distrib-to-p⋆-q⋆ α ((+ 1 / 4) ℚ.* α))) ⟩
α ⋆ - ((+ 1 / 4) ℚ.* α) ⋆ - ((+ 1 / 4) ℚ.* α) ⋆ <⟨ +-mono-<
(+-mono-< (proj₂ (proj₂ α-generator)) (neg-mono-< (proj₂ X-generator)))
(neg-mono-< (proj₂ Y-generator)) ⟩
(x + y) - ∣ x - X ⋆ ∣ - ∣ y - Y ⋆ ∣ ≤⟨ +-mono-≤ (+-monoʳ-≤ (x + y) (neg-mono-≤ x≤∣x∣)) (neg-mono-≤ x≤∣x∣) ⟩
(x + y) - (x - X ⋆) - (y - Y ⋆) ≈⟨ +-cong (+-congʳ (x + y) (neg-distrib-+ x (- (X ⋆)))) (neg-distrib-+ y (- (Y ⋆))) ⟩
(x + y) + (- x - (- (X ⋆))) + (- y - (- (Y ⋆))) ≈⟨ solve 4 (λ x y X Y ->
((x ⊕ y) ⊕ (⊝ x ⊖ (⊝ X)) ⊕ (⊝ y ⊖ (⊝ Y))) ⊜ (X ⊕ Y))
≃-refl x y (X ⋆) (Y ⋆) ⟩
X ⋆ + Y ⋆ ≈⟨ ≃-symm (⋆-distrib-+ X Y) ⟩
(X ℚ.+ Y) ⋆ ∎)
where open ≤-Reasoning
lem : ∀ (z : ℝ) -> (Z : ℚᵘ) -> ∣ z - Z ⋆ ∣ < ((+ 1 / 4) ℚ.* α) ⋆ -> Z ℚ.> (+ 1 / 4) ℚ.* α -> z > 0ℝ
lem z Z ∣z-Z∣<4⁻¹α Z>4⁻¹α = begin-strict
0ℝ ≈⟨ ≃-symm (+-inverseʳ (((+ 1 / 4) ℚ.* α) ⋆)) ⟩
((+ 1 / 4) ℚ.* α) ⋆ - ((+ 1 / 4) ℚ.* α) ⋆ <⟨ +-mono-< (p<q⇒p⋆<q⋆ ((+ 1 / 4) ℚ.* α) Z Z>4⁻¹α) (neg-mono-< ∣z-Z∣<4⁻¹α) ⟩
Z ⋆ - ∣ z - Z ⋆ ∣ ≈⟨ +-congʳ (Z ⋆) (-‿cong (∣x-y∣≃∣y-x∣ z (Z ⋆))) ⟩
Z ⋆ - ∣ Z ⋆ - z ∣ ≤⟨ +-monoʳ-≤ (Z ⋆) (neg-mono-≤ x≤∣x∣) ⟩
Z ⋆ - (Z ⋆ - z) ≈⟨ solve 2 (λ z Z -> (Z ⊖ (Z ⊖ z)) ⊜ z) ≃-refl z (Z ⋆) ⟩
z ∎
where open ≤-Reasoning
proposition-2-16 : ∀ xs -> ∀ n -> {n ≢0} -> ∑₀ xs n > 0ℝ -> ∃ λ j -> j ℕ.< n × xs j > 0ℝ
proposition-2-16 xs 1 ∑xs>0 = 0 , ℕP.0<1+n , <-respʳ-≃ (+-identityˡ (xs 0)) ∑xs>0
proposition-2-16 xs (suc (suc n-2)) ∑xs>0 = let n-1 = suc n-2 in
[ (λ hyp -> let fromhyp = proposition-2-16 xs n-1 hyp in
proj₁ fromhyp , ℕP.<-trans (proj₁ (proj₂ fromhyp)) (ℕP.n<1+n n-1) , proj₂ (proj₂ fromhyp)) ,
(λ hyp -> n-1 , ℕP.n<1+n n-1 , hyp) ]′
(x+y>0⇒x>0∨y>0 (∑₀ xs n-1) (xs n-1) ∑xs>0)
corollary-2-17 : ∀ x y z -> y < z -> x < z ⊎ x > y
corollary-2-17 x y z y<z = [ (λ z-x>0 -> inj₁ (0<y-x⇒x<y x z z-x>0)) , (λ x-y>0 -> inj₂ (0<y-x⇒x<y y x x-y>0)) ]′
(x+y>0⇒x>0∨y>0 (z - x) (x - y) (<-respʳ-≃ lem (x<y⇒0<y-x y z y<z)))
where
open ℝ-Solver
lem : z - y ≃ (z - x) + (x - y)
lem = solve 3 (λ x y z -> (z ⊖ y) ⊜ ((z ⊖ x) ⊕ (x ⊖ y))) ≃-refl x y z
abstract
fast-corollary-2-17 : ∀ x y z -> y < z -> x < z ⊎ x > y
fast-corollary-2-17 = corollary-2-17
_≮_ : Rel ℝ 0ℓ
x ≮ y = ¬ (x < y)
_≰_ : Rel ℝ 0ℓ
x ≰ y = ¬ (x ≤ y)
_≱_ : Rel ℝ 0ℓ
x ≱ y = y ≰ x
{-
Proposition:
If x ≮ y, then y ≤ x.
Proof:
This is the extended version of Bishop's proof. Let n∈ℕ. Either y₂ₙ - x₂ₙ ≤ n⁻¹ or y₂ₙ - x₂ₙ > n⁻¹.
If y₂ₙ - x₂ₙ > n⁻¹, then y - x is positive and x < y, a contradiction. Thus y₂ₙ - x₂ₙ ≤ n⁻¹, and so
x₂ₙ - y₂ₙ ≥ -n⁻¹ for all n∈ℕ. Hence x - y ≥ 0, and y ≤ x. □
x - y = - (y - x)
-}
≮⇒≥ : _≮_ ⇒ _≥_
≮⇒≥ {x} {y} x≮y = nonNeg* (λ {(suc k₁) -> let n = suc k₁ in
ℚP.≤-respʳ-≃ (solve 2 (λ x y -> (⊝ (y ⊖ x)) ⊜ (x ⊖ y)) ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)))
(ℚP.neg-mono-≤ ([ (λ hyp -> hyp) , (λ hyp -> ⊥-elim (x≮y (pos* (k₁ , hyp)))) ]′ (≤∨> (seq (y - x) n) (+ 1 / n))))})
where open ℚ-Solver
m<1+n⇒m≤n : ∀ m n -> m ℕ.< suc n -> m ℕ.≤ n
m<1+n⇒m≤n m n (ℕ.s≤s m≤n) = m≤n
x<y∧x<z⇒x<y⊓z : ∀ x y z -> x < y -> x < z -> x < y ⊓ z
x<y∧x<z⇒x<y⊓z x y z x<y x<z = lemma-2-8-1-onlyif (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
fromx<y = fast-lemma-2-8-1-if x<y
N₁ = suc (proj₁ fromx<y)
fromx<z = fast-lemma-2-8-1-if x<z
N₂ = suc (proj₁ fromx<z)
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (y ⊓ z - x) m ℚ.≥ + 1 / N
lem m m≥N = [ left , right ]′ (ℚP.≤-total (seq y (2 ℕ.* m)) (seq z (2 ℕ.* m)))
where
N₁≤N = ℕP.m≤m⊔n N₁ N₂
N₂≤N = ℕP.m≤n⊔m N₁ N₂
left : seq y (2 ℕ.* m) ℚ.≤ seq z (2 ℕ.* m) ->
seq (y ⊓ z - x) m ℚ.≥ + 1 / N
left y₂ₘ≤z₂ₘ = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 N₁ N N₁≤N ⟩
+ 1 / N₁ ≤⟨ proj₂ fromx<y m (ℕP.≤-trans N₁≤N m≥N) ⟩
seq y (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ≈⟨ ℚP.+-congˡ (ℚ.- seq x (2 ℕ.* m))
(ℚP.≃-sym (ℚP.p≤q⇒p⊓q≃p y₂ₘ≤z₂ₘ)) ⟩
seq (y ⊓ z) (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ∎
where
test : seq (y - x) m ℚ.≃ seq y (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m)
test = ℚP.≃-refl
right : seq z (2 ℕ.* m) ℚ.≤ seq y (2 ℕ.* m) ->
seq (y ⊓ z - x) m ℚ.≥ + 1 / N
right z₂ₘ≤y₂ₘ = begin
+ 1 / N ≤⟨ q≤r⇒+p/r≤+p/q 1 N₂ N N₂≤N ⟩
+ 1 / N₂ ≤⟨ proj₂ fromx<z m (ℕP.≤-trans N₂≤N m≥N) ⟩
seq z (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ≈⟨ ℚP.+-congˡ (ℚ.- seq x (2 ℕ.* m))
(ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q z₂ₘ≤y₂ₘ)) ⟩
seq (y ⊓ z) (2 ℕ.* m) ℚ.- seq x (2 ℕ.* m) ∎
p-q≥j⁻¹⇒p≥q : ∀ {p q : ℚᵘ} ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} -> p ℚ.- q ℚ.≥ (+ 1 / j) {j≢0}) -> p ℚ.≥ q
p-q≥j⁻¹⇒p≥q {p} {q} hyp = ℚP.≮⇒≥ (λ p<q -> let arch = fast-archimedean-ℚ₂ (q ℚ.- p) (+ 1) (ℚ.positive (p<q⇒0<q-p p q p<q))
; j = suc (proj₁ arch) in
ℚP.<-irrefl ℚP.≃-refl (begin-strict
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / j ≤⟨ hyp j ⟩
p ℚ.- q ≈⟨ solve 2 (λ p q -> (p ⊖ q) ⊜ (⊝ (q ⊖ p))) ℚP.≃-refl p q ⟩
ℚ.- (q ℚ.- p) <⟨ ℚP.neg-mono-< (proj₂ arch) ⟩
ℚ.- (+ 1 / j) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ ∎))
where
open ℚP.≤-Reasoning
open ℚ-Solver
p⋆≤q⋆⇒p≤q : ∀ p q -> p ⋆ ≤ q ⋆ -> p ℚ.≤ q
p⋆≤q⋆⇒p≤q p q (nonNeg* hyp) = p-q≤j⁻¹⇒p≤q (λ {(suc j-1) -> let j = suc j-1 in
ℚP.≤-respˡ-≃ (solve 2 (λ p q -> (⊝ (q ⊖ p)) ⊜ (p ⊖ q)) ℚP.≃-refl p q)
(ℚP.≤-respʳ-≃ (ℚP.neg-involutive (+ 1 / j)) (ℚP.neg-mono-≤ (hyp j)))})
where open ℚ-Solver
p≤q⇒p⋆≤q⋆ : ∀ p q -> p ℚ.≤ q -> p ⋆ ≤ q ⋆
p≤q⇒p⋆≤q⋆ p q p≤q = nonNeg* (λ {(suc n-1) -> let n = suc n-1 in begin
ℚ.- (+ 1 / n) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ ≤⟨ ℚP.p≤q⇒0≤q-p p≤q ⟩
q ℚ.- p ∎})
where open ℚP.≤-Reasoning
0<n⇒n≢0 : ∀ n -> 0 ℕ.< n -> n ≢0
0<n⇒n≢0 (suc n-1) 0<n = _
regular-n≤m : (x : ℕ -> ℚᵘ) ->
(∀ (m n : ℕ) -> {m≢0 : m ≢0} -> {n≢0 : n ≢0} -> m ℕ.≥ n -> ℚ.∣ x m ℚ.- x n ∣ ℚ.≤ (+ 1 / m) {m≢0} ℚ.+ (+ 1 / n) {n≢0}) ->
∀ (m n : ℕ) -> {m≢0 : m ≢0} -> {n≢0 : n ≢0} -> ℚ.∣ x m ℚ.- x n ∣ ℚ.≤ (+ 1 / m) {m≢0} ℚ.+ (+ 1 / n) {n≢0}
regular-n≤m x hyp (suc m-1) (suc n-1) = [ left , right ]′ (ℕP.≤-total m n)
where
open ℚP.≤-Reasoning
m = suc m-1
n = suc n-1
left : m ℕ.≤ n -> ℚ.∣ x m ℚ.- x n ∣ ℚ.≤ (+ 1 / m) ℚ.+ (+ 1 / n)
left m≤n = begin
ℚ.∣ x m ℚ.- x n ∣ ≈⟨ ∣p-q∣≃∣q-p∣ (x m) (x n) ⟩
ℚ.∣ x n ℚ.- x m ∣ ≤⟨ hyp n m m≤n ⟩
+ 1 / n ℚ.+ + 1 / m ≈⟨ ℚP.+-comm (+ 1 / n) (+ 1 / m) ⟩
+ 1 / m ℚ.+ + 1 / n ∎
right : n ℕ.≤ m -> ℚ.∣ x m ℚ.- x n ∣ ℚ.≤ (+ 1 / m) ℚ.+ (+ 1 / n)
right n≤m = hyp m n n≤m
uncountability : ∀ (a : ℕ -> ℝ) -> ∀ (x₀ y₀ : ℝ) -> x₀ < y₀ ->
∃ λ (x : ℝ) -> (x₀ ≤ x ≤ y₀) × (∀ (n : ℕ) -> {n≢0 : n ≢0} -> x ≄ a n)
uncountability a x₀ y₀ x₀<y₀ = x , ((≤-trans (x₀≤xₙ 1) (xₙ≤x 1)) , (≤-respˡ-≃ (≃-symm x≃y) (≤-trans (yₙ≥y 1) (yₙ≤y₀ 1)))) , x≄aₙ
where
generator : (n : ℕ) -> {n≢0 : n ≢0} -> (xₙ₋₁ yₙ₋₁ : ℝ) -> xₙ₋₁ < yₙ₋₁ -> x₀ ≤ xₙ₋₁ -> yₙ₋₁ ≤ y₀ ->
∃ λ (xₙ : ℚᵘ) -> ∃ λ (yₙ : ℚᵘ) ->
((x₀ ≤ xₙ₋₁ ≤ (xₙ ⋆)) × (xₙ ℚ.< yₙ) × ((yₙ ⋆) ≤ yₙ₋₁ ≤ y₀)) ×
((xₙ ⋆ > a n) ⊎ yₙ ⋆ < a n) ×
yₙ ℚ.- xₙ ℚ.< (+ 1 / n) {n≢0}
generator (suc n-1) xₙ₋₁ yₙ₋₁ xₙ₋₁<yₙ₋₁ x₀≤xₙ₋₁ yₙ₋₁≤y₀ = func (fast-corollary-2-17 (a n) xₙ₋₁ yₙ₋₁ xₙ₋₁<yₙ₋₁)
where
n = suc n-1
func : a n < yₙ₋₁ ⊎ a n > xₙ₋₁ ->
∃ λ (xₙ : ℚᵘ) -> ∃ λ (yₙ : ℚᵘ) ->
((x₀ ≤ xₙ₋₁ ≤ (xₙ ⋆)) × (xₙ ℚ.< yₙ) × ((yₙ ⋆) ≤ yₙ₋₁ ≤ y₀)) ×
((xₙ ⋆ > a n) ⊎ yₙ ⋆ < a n) ×
yₙ ℚ.- xₙ ℚ.< + 1 / n
func (inj₁ aₙ<yₙ₋₁) = xₙ , yₙ , prop1 , prop2 , prop3
where
open ℚP.≤-Reasoning
open ℚ-Solver
yₙp = fast-density-of-ℚ (a n ⊔ xₙ₋₁) yₙ₋₁ (x<z∧y<z⇒x⊔y<z (a n) xₙ₋₁ yₙ₋₁ aₙ<yₙ₋₁ xₙ₋₁<yₙ₋₁)
yₙ = proj₁ yₙp
xₙp = fast-density-of-ℚ (a n ⊔ xₙ₋₁ ⊔ ((yₙ ℚ.- + 1 / n) ⋆)) (yₙ ⋆)
(x<z∧y<z⇒x⊔y<z (a n ⊔ xₙ₋₁) ((yₙ ℚ.- + 1 / n) ⋆) (yₙ ⋆) (proj₁ (proj₂ yₙp))
(p<q⇒p⋆<q⋆ (yₙ ℚ.- + 1 / n) yₙ (begin-strict
yₙ ℚ.- + 1 / n <⟨ ℚP.+-monoʳ-< yₙ {ℚ.- (+ 1 / n)} {0ℚᵘ} (ℚP.negative⁻¹ _) ⟩
yₙ ℚ.+ 0ℚᵘ ≈⟨ ℚP.+-identityʳ yₙ ⟩
yₙ ∎)))
xₙ = proj₁ xₙp
prop1 : (x₀ ≤ xₙ₋₁ ≤ (xₙ ⋆)) × (xₙ ℚ.< yₙ) × ((yₙ ⋆) ≤ yₙ₋₁ ≤ y₀)
prop1 = (x₀≤xₙ₋₁ , helper) , p⋆<q⋆⇒p<q xₙ yₙ (proj₂ (proj₂ xₙp)) , (<⇒≤ (proj₂ (proj₂ yₙp)) , yₙ₋₁≤y₀)
where
helper : xₙ₋₁ ≤ (xₙ ⋆)
helper = ≤-trans (≤-trans (x≤y⊔x xₙ₋₁ (a n)) (x≤x⊔y (a n ⊔ xₙ₋₁) ((yₙ ℚ.- + 1 / n) ⋆)))
(<⇒≤ (proj₁ (proj₂ xₙp)))
prop2 : (xₙ ⋆ > a n) ⊎ yₙ ⋆ < a n
prop2 = inj₁ (≤-<-trans (≤-trans (x≤x⊔y (a n) xₙ₋₁) (x≤x⊔y (a n ⊔ xₙ₋₁) ((yₙ ℚ.- + 1 / n) ⋆))) (proj₁ (proj₂ xₙp)))
prop3 : yₙ ℚ.- xₙ ℚ.< + 1 / n
prop3 = begin-strict
yₙ ℚ.- xₙ ≈⟨ solve 3 (λ xₙ yₙ n⁻¹ ->
(yₙ ⊖ xₙ) ⊜ ((yₙ ⊖ n⁻¹) ⊕ (n⁻¹ ⊖ xₙ)))
ℚP.≃-refl xₙ yₙ (+ 1 / n) ⟩
yₙ ℚ.- + 1 / n ℚ.+ (+ 1 / n ℚ.- xₙ) <⟨ ℚP.+-monoˡ-< (+ 1 / n ℚ.- xₙ)
(p⋆<q⋆⇒p<q (yₙ ℚ.- + 1 / n) xₙ
(≤-<-trans (x≤y⊔x ((yₙ ℚ.- + 1 / n) ⋆) (a n ⊔ xₙ₋₁)) (proj₁ (proj₂ xₙp)))) ⟩
xₙ ℚ.+ (+ 1 / n ℚ.- xₙ) ≈⟨ solve 2 (λ xₙ n⁻¹ -> (xₙ ⊕ (n⁻¹ ⊖ xₙ)) ⊜ n⁻¹) ℚP.≃-refl xₙ (+ 1 / n) ⟩
+ 1 / n ∎
func (inj₂ aₙ>xₙ₋₁) = xₙ , yₙ , prop1 , prop2 , prop3
where
open ℚP.≤-Reasoning
open ℚ-Solver
xₙp = fast-density-of-ℚ xₙ₋₁ (a n ⊓ yₙ₋₁) (x<y∧x<z⇒x<y⊓z xₙ₋₁ (a n) yₙ₋₁ aₙ>xₙ₋₁ xₙ₋₁<yₙ₋₁)
xₙ = proj₁ xₙp
yₙp = fast-density-of-ℚ (xₙ ⋆) (a n ⊓ yₙ₋₁ ⊓ ((xₙ ℚ.+ + 1 / n) ⋆))
(x<y∧x<z⇒x<y⊓z (xₙ ⋆) (a n ⊓ yₙ₋₁) ((xₙ ℚ.+ + 1 / n) ⋆) (proj₂ (proj₂ xₙp))
(p<q⇒p⋆<q⋆ xₙ (xₙ ℚ.+ + 1 / n) (begin-strict
xₙ ≈⟨ ℚP.≃-sym (ℚP.+-identityʳ xₙ) ⟩
xₙ ℚ.+ 0ℚᵘ <⟨ ℚP.+-monoʳ-< xₙ {0ℚᵘ} {+ 1 / n} (ℚP.positive⁻¹ _) ⟩
xₙ ℚ.+ + 1 / n ∎)))
yₙ = proj₁ yₙp
prop1 : (x₀ ≤ xₙ₋₁ ≤ (xₙ ⋆)) × (xₙ ℚ.< yₙ) × ((yₙ ⋆) ≤ yₙ₋₁ ≤ y₀)
prop1 = (x₀≤xₙ₋₁ , <⇒≤ (proj₁ (proj₂ xₙp))) , p⋆<q⋆⇒p<q xₙ yₙ (proj₁ (proj₂ yₙp)) , helper , yₙ₋₁≤y₀
where
helper : yₙ ⋆ ≤ yₙ₋₁
helper = ≤-trans (<⇒≤ (proj₂ (proj₂ yₙp)))
(≤-trans (x⊓y≤x (a n ⊓ yₙ₋₁) ((xₙ ℚ.+ + 1 / n) ⋆)) (x⊓y≤y (a n) yₙ₋₁))
prop2 : (xₙ ⋆ > a n) ⊎ yₙ ⋆ < a n
prop2 = inj₂ (<-≤-trans (proj₂ (proj₂ yₙp))
(≤-trans (x⊓y≤x (a n ⊓ yₙ₋₁) ((xₙ ℚ.+ + 1 / n) ⋆)) (x⊓y≤x (a n) yₙ₋₁)))
prop3 : yₙ ℚ.- xₙ ℚ.< + 1 / n
prop3 = begin-strict
yₙ ℚ.- xₙ <⟨ ℚP.+-monoˡ-< (ℚ.- xₙ)
(p⋆<q⋆⇒p<q yₙ (xₙ ℚ.+ + 1 / n)
(<-≤-trans (proj₂ (proj₂ yₙp))
(x⊓y≤y (a n ⊓ yₙ₋₁) ((xₙ ℚ.+ + 1 / n) ⋆)))) ⟩
xₙ ℚ.+ + 1 / n ℚ.- xₙ ≈⟨ solve 2 (λ xₙ n⁻¹ -> (xₙ ⊕ n⁻¹ ⊖ xₙ) ⊜ n⁻¹) ℚP.≃-refl xₙ (+ 1 / n) ⟩
+ 1 / n ∎
xs : ℕ -> ℚᵘ
ys : ℕ -> ℚᵘ
xs-increasing : ∀ (n : ℕ) -> {n ≢0} -> xs n ℚ.≤ xs (suc n)
ys-decreasing : ∀ (n : ℕ) -> {n ≢0} -> ys (suc n) ℚ.≤ ys n
xₙ<yₙ : ∀ (n : ℕ) -> {n ≢0} -> xs n ⋆ < ys n ⋆
x₀≤xₙ : ∀ (n : ℕ) -> {n ≢0} -> x₀ ≤ xs n ⋆
yₙ≤y₀ : ∀ (n : ℕ) -> {n ≢0} -> ys n ⋆ ≤ y₀
xs 0 = 0ℚᵘ
xs 1 = proj₁ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl)
xs (suc (suc n-2)) = proj₁ (generator (suc (suc n-2)) (xs (suc n-2) ⋆) (ys (suc n-2) ⋆) (xₙ<yₙ (suc n-2)) (x₀≤xₙ (suc n-2)) (yₙ≤y₀ (suc n-2)))
ys 0 = 0ℚᵘ
ys 1 = proj₁ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl))
ys (suc (suc n-2)) = proj₁ (proj₂ ((generator (suc (suc n-2)) (xs (suc n-2) ⋆) (ys (suc n-2) ⋆) (xₙ<yₙ (suc n-2)) (x₀≤xₙ (suc n-2)) (yₙ≤y₀ (suc n-2)))))
xs-increasing 1 = p⋆≤q⋆⇒p≤q (xs 1) (xs 2)
(proj₂ (proj₁ (proj₁ (proj₂ (proj₂ (generator 2 (xs 1 ⋆) (ys 1 ⋆) (xₙ<yₙ 1) (x₀≤xₙ 1) (yₙ≤y₀ 1)))))))
xs-increasing (suc (suc n-2)) = let n-1 = suc (suc n-2); n = suc n-1 in
p⋆≤q⋆⇒p≤q (xs n-1) (xs n)
(proj₂ (proj₁ (proj₁ (proj₂ (proj₂ (generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1)))))))
ys-decreasing 1 = p⋆≤q⋆⇒p≤q (ys 2) (ys 1)
(proj₁ (proj₂ (proj₂ (proj₁ (proj₂ (proj₂ (generator 2 (xs 1 ⋆) (ys 1 ⋆) (xₙ<yₙ 1) (x₀≤xₙ 1) (yₙ≤y₀ 1))))))))
ys-decreasing (suc (suc n-2)) = let n-1 = suc (suc n-2); n = suc n-1 in
p⋆≤q⋆⇒p≤q (ys n) (ys n-1)
(proj₁ (proj₂ (proj₂ (proj₁ (proj₂ (proj₂ (generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1))))))))
xₙ<yₙ 1 = p<q⇒p⋆<q⋆ (xs 1) (ys 1) (proj₁ (proj₂ (proj₁ (proj₂ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl))))))
xₙ<yₙ (suc (suc n-2)) = let n-1 = suc n-2; n = suc n-1 in
p<q⇒p⋆<q⋆ (xs n) (ys n) (proj₁ (proj₂ (proj₁ (proj₂ (proj₂ (generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1)))))))
x₀≤xₙ 1 = proj₂ (proj₁ (proj₁ (proj₂ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl)))))
x₀≤xₙ (suc (suc n-2)) = let n-1 = suc n-2; n = suc n-1; get = generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1) in
≤-trans {x₀} {xs n-1 ⋆} {xs n ⋆} (x₀≤xₙ n-1) (proj₂ (proj₁ (proj₁ (proj₂ (proj₂ get)))))
yₙ≤y₀ 1 = proj₁ (proj₂ (proj₂ (proj₁ (proj₂ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl))))))
yₙ≤y₀ (suc (suc n-2)) = let n-1 = suc n-2; n = suc n-1; get = generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1) in
≤-trans {ys n ⋆} {ys n-1 ⋆} {y₀} (proj₁ (proj₂ (proj₂ (proj₁ (proj₂ (proj₂ get)))))) (yₙ≤y₀ n-1)
n≤m⇒xₙ≤xₘ : ∀ (m n : ℕ) -> {n ≢0} -> n ℕ.≤ m -> xs n ⋆ ≤ xs m ⋆
n≤m⇒xₙ≤xₘ (suc m-1) (suc n-1) n≤m = let m = suc m-1; n = suc n-1 in
[ (λ {refl -> ≤-refl}) ,
(λ {n<m -> ≤-trans (n≤m⇒xₙ≤xₘ m-1 n (m<1+n⇒m≤n n m-1 n<m))
(p≤q⇒p⋆≤q⋆ (xs m-1) (xs m) (xs-increasing m-1
{0<n⇒n≢0 m-1 (ℕP.<-transˡ ℕP.0<1+n (m<1+n⇒m≤n n m-1 n<m))}))}) ]′
(≤⇒≡∨< n m n≤m)
n≤m⇒yₘ≤yₙ : ∀ (m n : ℕ) -> {n ≢0} -> n ℕ.≤ m -> ys m ⋆ ≤ ys n ⋆
n≤m⇒yₘ≤yₙ (suc m-1) (suc n-1) n≤m = let m = suc m-1; n = suc n-1 in
[ (λ {refl -> ≤-refl}) ,
(λ {n<m -> ≤-trans (p≤q⇒p⋆≤q⋆ (ys m) (ys m-1) (ys-decreasing m-1
{0<n⇒n≢0 m-1 (ℕP.<-transˡ ℕP.0<1+n (m<1+n⇒m≤n n m-1 n<m))}))
(n≤m⇒yₘ≤yₙ m-1 n (m<1+n⇒m≤n n m-1 n<m))}) ]′
(≤⇒≡∨< n m n≤m)
xₙ>aₙ∨yₙ<aₙ : ∀ (n : ℕ) -> {n ≢0} -> xs n ⋆ > a n ⊎ ys n ⋆ < a n
xₙ>aₙ∨yₙ<aₙ 1 = proj₁ (proj₂ (proj₂ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl))))
xₙ>aₙ∨yₙ<aₙ (suc (suc n-2)) = let n-1 = suc n-2; n = suc n-1 in
proj₁ (proj₂ (proj₂ (proj₂ (generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1)))))
yₙ-xₙ<n⁻¹ : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ys n ℚ.- xs n ℚ.< (+ 1 / n) {n≢0}
yₙ-xₙ<n⁻¹ 1 = proj₂ (proj₂ (proj₂ (proj₂ (generator 1 x₀ y₀ x₀<y₀ ≤-refl ≤-refl))))
yₙ-xₙ<n⁻¹ (suc (suc n-2)) = let n-1 = suc n-2; n = suc n-1 in
proj₂ (proj₂ (proj₂ (proj₂ (generator n (xs n-1 ⋆) (ys n-1 ⋆) (xₙ<yₙ n-1) (x₀≤xₙ n-1) (yₙ≤y₀ n-1)))))
x : ℝ
seq x = xs
reg x = regular-n≤m xs (λ {(suc m-1) (suc n-1) m≥n → let m = suc m-1; n = suc n-1 in begin
ℚ.∣ xs m ℚ.- xs n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p⋆≤q⋆⇒p≤q (xs n) (xs m) (n≤m⇒xₙ≤xₘ m n m≥n))) ⟩
xs m ℚ.- xs n <⟨ ℚP.+-monoˡ-< (ℚ.- xs n) (p⋆<q⋆⇒p<q (xs m) (ys n)
(<-≤-trans (xₙ<yₙ m) (n≤m⇒yₘ≤yₙ m n m≥n))) ⟩
ys n ℚ.- xs n <⟨ yₙ-xₙ<n⁻¹ n ⟩
+ 1 / n ≈⟨ ℚP.≃-sym (ℚP.+-identityˡ (+ 1 / n)) ⟩
0ℚᵘ ℚ.+ + 1 / n <⟨ ℚP.+-monoˡ-< (+ 1 / n) {0ℚᵘ} {+ 1 / m} (ℚP.positive⁻¹ _) ⟩
+ 1 / m ℚ.+ + 1 / n ∎})
where open ℚP.≤-Reasoning
y : ℝ
seq y = ys
reg y = regular-n≤m ys (λ {(suc m-1) (suc n-1) m≥n -> let m = suc m-1; n = suc n-1 in begin
ℚ.∣ ys m ℚ.- ys n ∣ ≈⟨ ∣p-q∣≃∣q-p∣ (ys m) (ys n) ⟩
ℚ.∣ ys n ℚ.- ys m ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.p≤q⇒0≤q-p (p⋆≤q⋆⇒p≤q (ys m) (ys n) (n≤m⇒yₘ≤yₙ m n m≥n))) ⟩
ys n ℚ.- ys m <⟨ ℚP.+-monoʳ-< (ys n) (ℚP.neg-mono-< (p⋆<q⋆⇒p<q (xs n) (ys m)
(≤-<-trans (n≤m⇒xₙ≤xₘ m n m≥n) (xₙ<yₙ m)))) ⟩
ys n ℚ.- xs n <⟨ yₙ-xₙ<n⁻¹ n ⟩
+ 1 / n ≈⟨ ℚP.≃-sym (ℚP.+-identityˡ (+ 1 / n)) ⟩
0ℚᵘ ℚ.+ + 1 / n <⟨ ℚP.+-monoˡ-< (+ 1 / n) {0ℚᵘ} {+ 1 / m} (ℚP.positive⁻¹ _) ⟩
+ 1 / m ℚ.+ + 1 / n ∎})
where open ℚP.≤-Reasoning
x≃y : x ≃ y
x≃y = *≃* (λ {(suc n-1) -> let n = suc n-1 in begin
ℚ.∣ xs n ℚ.- ys n ∣ ≈⟨ ∣p-q∣≃∣q-p∣ (xs n) (ys n) ⟩
ℚ.∣ ys n ℚ.- xs n ∣ ≈⟨ ℚP.0≤p⇒∣p∣≃p (ℚP.<⇒≤ (p<q⇒0<q-p (xs n) (ys n)
(p⋆<q⋆⇒p<q (xs n) (ys n) (xₙ<yₙ n)))) ⟩
ys n ℚ.- xs n <⟨ yₙ-xₙ<n⁻¹ n ⟩
+ 1 / n ≤⟨ ℚ.*≤* (ℤP.*-monoʳ-≤-nonNeg n {+ 1} {+ 2} (ℤ.+≤+ (ℕ.s≤s ℕ.z≤n))) ⟩
+ 2 / n ∎})
where open ℚP.≤-Reasoning
xₙ≤x : ∀ (n : ℕ) -> {n ≢0} -> xs n ⋆ ≤ x
xₙ≤x (suc n-1) = let n = suc n-1 in
lemma-2-8-2-onlyif (λ {(suc k-1) -> n , _ , λ {(suc m-1) m≥n -> let k = suc k-1; m = suc m-1 in
begin
ℚ.- (+ 1 / k) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ ≤⟨ ℚP.p≤q⇒0≤q-p (p⋆≤q⋆⇒p≤q (xs n) (xs (2 ℕ.* m))
(n≤m⇒xₙ≤xₘ (2 ℕ.* m) n (ℕP.≤-trans m≥n (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
xs (2 ℕ.* m) ℚ.- xs n ∎}})
where open ℚP.≤-Reasoning
yₙ≥y : ∀ (n : ℕ) -> {n ≢0} -> ys n ⋆ ≥ y
yₙ≥y (suc n-1) = let n = suc n-1 in
lemma-2-8-2-onlyif (λ {(suc k-1) -> n , _ , λ {(suc m-1) m≥n -> let k = suc k-1; m = suc m-1 in
begin
ℚ.- (+ 1 / k) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ ≤⟨ ℚP.p≤q⇒0≤q-p (p⋆≤q⋆⇒p≤q (ys (2 ℕ.* m)) (ys n)
(n≤m⇒yₘ≤yₙ (2 ℕ.* m) n (ℕP.≤-trans m≥n (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
ys n ℚ.- ys (2 ℕ.* m) ∎}})
where open ℚP.≤-Reasoning
x≄aₙ : ∀ (n : ℕ) -> {n ≢0} -> x ≄ (a n)
x≄aₙ (suc n-1) = let n = suc n-1 in
[ (λ xₙ>aₙ -> inj₂ (<-≤-trans xₙ>aₙ (xₙ≤x n))) ,
(λ yₙ<aₙ -> inj₁ (<-respˡ-≃ (≃-symm x≃y) (≤-<-trans (yₙ≥y n) yₙ<aₙ))) ]′
(xₙ>aₙ∨yₙ<aₙ n)
| {
"alphanum_fraction": 0.3408212626,
"avg_line_length": 51.7684299381,
"ext": "agda",
"hexsha": "96abb82e7e0c2c0f0aaa17ac040468315a95a9d5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "z-murray/AnalysisAgda",
"max_forks_repo_path": "RealsRefactored.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "z-murray/AnalysisAgda",
"max_issues_repo_path": "RealsRefactored.agda",
"max_line_length": 183,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6fbaca08b1d63b5765d184f6284fb0e58c9f5e52",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "z-murray/AnalysisAgda",
"max_stars_repo_path": "RealsRefactored.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 92994,
"size": 183985
} |
module Singleton where
open import Level
open import Data.Unit
open import Data.Product
open import Function
open import Relation.Binary
open import Function.Inverse
open import Function.Equality as FE
open import Relation.Binary.PropositionalEquality as P
open import Pi using (⟦_⟧; _⟷_ )
embed₁ : Set → Set
embed₁ b = Σ b (λ _ → ⊤)
B-to-Σ⊤ : {B : Set} → B → embed₁ B
B-to-Σ⊤ v = (v , tt)
Σ⊤-to-B : {B : Set} → embed₁ B → B
Σ⊤-to-B (v , _) = v
BΣ₁ : ∀ {b} → Inverse (P.setoid b) (P.setoid (embed₁ b))
BΣ₁ = record {
to = record { _⟨$⟩_ = B-to-Σ⊤; cong = P.cong B-to-Σ⊤ }
; from = record { _⟨$⟩_ = Σ⊤-to-B; cong = P.cong Σ⊤-to-B }
; inverse-of = record { left-inverse-of = λ _ → refl
; right-inverse-of = λ x → refl } }
data Singleton {c : Level} {A : Set c} : A → Set c where
singleton : (x : A) -> Singleton x
-- That a Singleton type is a setoid is not needed, but here is the proof anyways.
data _∼_ {c : Level} {A : Set c} {v : A} (x : Singleton v) (y : Singleton v) : Set c where
uniq : x ∼ y
∼Equiv : {c : Level} {A : Set c} {v : A} → IsEquivalence {_} {_} {Singleton v} _∼_
∼Equiv {v = v } = record {
refl = uniq
; sym = λ _ → uniq
; trans = λ _ _ → uniq }
SingSetoid : {c c : Level} → (A : Setoid c c) → (Setoid.Carrier A) → Setoid c c
SingSetoid A v = record {
Carrier = Singleton v
; _≈_ = _∼_
; isEquivalence = ∼Equiv }
-- We can map a type to its Σ of Singletons and back.
embed₂ : Set → Set
embed₂ b = Σ b Singleton
B-to-ΣS : {B : Set} → B → embed₂ B
B-to-ΣS v = (v , singleton v)
ΣS-to-B : {B : Set} → embed₂ B → B
ΣS-to-B x = proj₁ x
right-inverse : ∀ {c} {b : Set c} → (x : Σ b (Singleton {A = b})) → (proj₁ x , singleton (proj₁ x)) ≡ x
right-inverse (v , singleton .v) = refl
BΣ₂ : ∀ {b} → Inverse (P.setoid b) (P.setoid (embed₂ b))
BΣ₂ = record {
to = record { _⟨$⟩_ = B-to-ΣS; cong = P.cong B-to-ΣS }
; from = record { _⟨$⟩_ = ΣS-to-B; cong = P.cong ΣS-to-B }
; inverse-of = record { left-inverse-of = λ x → refl
; right-inverse-of = right-inverse } }
-- A generalized idea of a permutation: a bijection between any two types
Permutation : Set → Set -> Set
Permutation a b = Inverse (P.setoid a) (P.setoid b)
-- Now, what we really want is to interpret Pi combinators as
-- permutations. We need a refined version of embed₂ which
-- allows us to use a permutation to transport things.
embed₃ : {l : Level} → (S T : Setoid l l) → Inverse S T → Setoid l l
embed₃ S T f = record {
Carrier = Σ A (λ b → Singleton (to f ⟨$⟩ b))
; _≈_ = _≡_
; isEquivalence = P.isEquivalence }
where open Inverse {From = S} {T}
A = Setoid.Carrier S
| {
"alphanum_fraction": 0.5538194444,
"avg_line_length": 34.2857142857,
"ext": "agda",
"hexsha": "4e98801b39ea5719cac4fe22a97dcc147386add2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "agda/Singleton.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "agda/Singleton.agda",
"max_line_length": 103,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "agda/Singleton.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 1002,
"size": 2880
} |
{-# OPTIONS --copatterns #-}
module HighlightCopattern where
record WrapSet : Set₂ where
field
wrapped : Set₁
open WrapSet
my : WrapSet
wrapped my = Set -- 'wrapped' should be highlighted in projection color
proj : WrapSet → Set₁
proj w = wrapped w -- 'wrapped' should be highlighted in projection color
| {
"alphanum_fraction": 0.7232704403,
"avg_line_length": 21.2,
"ext": "agda",
"hexsha": "a51832cd827892b727845d2f8688abe924855e47",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/HighlightCopattern.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/HighlightCopattern.agda",
"max_line_length": 74,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/HighlightCopattern.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 80,
"size": 318
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.Lattice {l₁ l₂} (L : Lattice l₁ l₂) where
open Lattice L
open import Algebra.Structures
open import Algebra.FunctionProperties _≈_
import Algebra.Properties.Semilattice as SL
open import Relation.Binary
import Relation.Binary.Lattice as R
open import Relation.Binary.Reasoning.Setoid setoid
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; module Equivalence)
open import Data.Product using (_,_; swap)
------------------------------------------------------------------------
-- Every lattice contains two semilattices.
∧-idempotent : Idempotent _∧_
∧-idempotent x = begin
x ∧ x ≈⟨ refl ⟨ ∧-cong ⟩ sym (∨-absorbs-∧ _ _) ⟩
x ∧ (x ∨ x ∧ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩
x ∎
∨-idempotent : Idempotent _∨_
∨-idempotent x = begin
x ∨ x ≈⟨ refl ⟨ ∨-cong ⟩ sym (∧-idempotent _) ⟩
x ∨ x ∧ x ≈⟨ ∨-absorbs-∧ _ _ ⟩
x ∎
∧-isSemilattice : IsSemilattice _≈_ _∧_
∧-isSemilattice = record
{ isBand = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∧-cong
}
; assoc = ∧-assoc
}
; idem = ∧-idempotent
}
; comm = ∧-comm
}
∧-semilattice : Semilattice l₁ l₂
∧-semilattice = record { isSemilattice = ∧-isSemilattice }
∨-isSemilattice : IsSemilattice _≈_ _∨_
∨-isSemilattice = record
{ isBand = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∨-cong
}
; assoc = ∨-assoc
}
; idem = ∨-idempotent
}
; comm = ∨-comm
}
∨-semilattice : Semilattice l₁ l₂
∨-semilattice = record { isSemilattice = ∨-isSemilattice }
open SL ∧-semilattice public using (poset)
open Poset poset using (_≤_; isPartialOrder)
------------------------------------------------------------------------
-- The dual construction is also a lattice.
∧-∨-isLattice : IsLattice _≈_ _∧_ _∨_
∧-∨-isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ∧-comm
; ∨-assoc = ∧-assoc
; ∨-cong = ∧-cong
; ∧-comm = ∨-comm
; ∧-assoc = ∨-assoc
; ∧-cong = ∨-cong
; absorptive = swap absorptive
}
∧-∨-lattice : Lattice _ _
∧-∨-lattice = record { isLattice = ∧-∨-isLattice }
------------------------------------------------------------------------
-- Every algebraic lattice can be turned into an order-theoretic one.
isOrderTheoreticLattice : R.IsLattice _≈_ _≤_ _∨_ _∧_
isOrderTheoreticLattice = record
{ isPartialOrder = isPartialOrder
; supremum = supremum
; infimum = infimum
}
where
∧-meetSemilattice = SL.orderTheoreticMeetSemilattice ∧-semilattice
∨-joinSemilattice = SL.orderTheoreticJoinSemilattice ∨-semilattice
open R.MeetSemilattice ∧-meetSemilattice using (infimum)
open R.JoinSemilattice ∨-joinSemilattice using ()
renaming (supremum to supremum′; _≤_ to _≤′_)
-- An alternative but equivalent interpretation of the order _≤_.
sound : ∀ {x y} → x ≤′ y → x ≤ y
sound {x} {y} y≈y∨x = sym $ begin
x ∧ y ≈⟨ ∧-congˡ y≈y∨x ⟩
x ∧ (y ∨ x) ≈⟨ ∧-congˡ (∨-comm y x) ⟩
x ∧ (x ∨ y) ≈⟨ ∧-absorbs-∨ x y ⟩
x ∎
complete : ∀ {x y} → x ≤ y → x ≤′ y
complete {x} {y} x≈x∧y = sym $ begin
y ∨ x ≈⟨ ∨-congˡ x≈x∧y ⟩
y ∨ (x ∧ y) ≈⟨ ∨-congˡ (∧-comm x y) ⟩
y ∨ (y ∧ x) ≈⟨ ∨-absorbs-∧ y x ⟩
y ∎
supremum : R.Supremum _≤_ _∨_
supremum x y =
let x∨y≥x , x∨y≥y , greatest = supremum′ x y
in sound x∨y≥x , sound x∨y≥y ,
λ z x≤z y≤z → sound (greatest z (complete x≤z) (complete y≤z))
orderTheoreticLattice : R.Lattice _ _ _
orderTheoreticLattice = record { isLattice = isOrderTheoreticLattice }
------------------------------------------------------------------------
-- One can replace the underlying equality with an equivalent one.
replace-equality : {_≈′_ : Rel Carrier l₂} →
(∀ {x y} → x ≈ y ⇔ (x ≈′ y)) → Lattice _ _
replace-equality {_≈′_} ≈⇔≈′ = record
{ _≈_ = _≈′_
; _∧_ = _∧_
; _∨_ = _∨_
; isLattice = record
{ isEquivalence = record
{ refl = to ⟨$⟩ refl
; sym = λ x≈y → to ⟨$⟩ sym (from ⟨$⟩ x≈y)
; trans = λ x≈y y≈z → to ⟨$⟩ trans (from ⟨$⟩ x≈y) (from ⟨$⟩ y≈z)
}
; ∨-comm = λ x y → to ⟨$⟩ ∨-comm x y
; ∨-assoc = λ x y z → to ⟨$⟩ ∨-assoc x y z
; ∨-cong = λ x≈y u≈v → to ⟨$⟩ ∨-cong (from ⟨$⟩ x≈y) (from ⟨$⟩ u≈v)
; ∧-comm = λ x y → to ⟨$⟩ ∧-comm x y
; ∧-assoc = λ x y z → to ⟨$⟩ ∧-assoc x y z
; ∧-cong = λ x≈y u≈v → to ⟨$⟩ ∧-cong (from ⟨$⟩ x≈y) (from ⟨$⟩ u≈v)
; absorptive = (λ x y → to ⟨$⟩ ∨-absorbs-∧ x y)
, (λ x y → to ⟨$⟩ ∧-absorbs-∨ x y)
}
} where open module E {x y} = Equivalence (≈⇔≈′ {x} {y})
| {
"alphanum_fraction": 0.5142355694,
"avg_line_length": 31.4601226994,
"ext": "agda",
"hexsha": "71daa6585a68d7cdbdf6e372b7fd4b3a15d38c5f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/Lattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/Lattice.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Properties/Lattice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1925,
"size": 5128
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Object.Subobject.Properties where
open import Level
open import Data.Product
open import Data.Unit
open import Function using (_$_)
open import Relation.Binary using (_=[_]⇒_)
open import Relation.Binary.Bundles
open import Relation.Binary.OrderMorphism
open import Categories.Category
open import Categories.Functor
open import Categories.Functor.Presheaf
open import Categories.Category.Slice
open import Categories.Object.Subobject
open import Categories.Diagram.Pullback renaming (glue to glue-pullback)
open import Categories.Diagram.Pullback.Properties
open import Categories.Category.Instance.Posets
open import Categories.Category.Instance.Setoids
open import Categories.Adjoint.Instance.PosetCore
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
open import Categories.Morphism.Notation
module _ {o ℓ e} {𝒞 : Category o ℓ e} (has-pullbacks : ∀ {A B X} → (f : 𝒞 [ A , X ]) → (g : 𝒞 [ B , X ]) → Pullback 𝒞 f g) where
private
module 𝒞 = Category 𝒞
open 𝒞.HomReasoning
open 𝒞.Equiv
open Mor 𝒞
open MR 𝒞
open _↣_
-- The Subobject functor, into the category of posets
Subₚ : Presheaf 𝒞 (Posets (o ⊔ ℓ ⊔ e) (ℓ ⊔ e) (ℓ ⊔ e))
Subₚ = record
{ F₀ = Subobjects 𝒞
; F₁ = λ f → record
{ fun = morphism f
; monotone = λ {(α , m) (β , n)} h → monotone f {(α , m)} {β , n} h
}
; identity = λ {A} {(α , m)} →
let pid = has-pullbacks 𝒞.id (mor m)
in record
{ from = record
{ h = Pullback.p₂ pid
; △ = ⟺ (Pullback.commute pid) ○ 𝒞.identityˡ
}
; to = record
{ h = Pullback.universal pid id-comm-sym
; △ = Pullback.p₁∘universal≈h₁ pid
}
; iso = record
{ isoˡ = pullback-identity 𝒞 pid
; isoʳ = Pullback.p₂∘universal≈h₂ pid
}
}
; homomorphism = λ {X} {Y} {Z} {f} {g} {(α , m)} →
let pfg = has-pullbacks (𝒞 [ f ∘ g ]) (mor m)
pf = has-pullbacks f (mor m)
pg = has-pullbacks g (Pullback.p₁ pf)
iso = up-to-iso 𝒞 pfg (glue-pullback 𝒞 pf pg)
module iso = _≅_ iso
in record
{ from = record
{ h = iso.from
; △ = Pullback.p₁∘universal≈h₁ pg
}
; to = record
{ h = iso.to
; △ = Pullback.p₁∘universal≈h₁ pfg
}
; iso = record
{ isoˡ = iso.isoˡ
; isoʳ = iso.isoʳ
}
}
; F-resp-≈ = λ {A B f g} eq {(α , m)} →
let pf = has-pullbacks f (mor m)
pg = has-pullbacks g (mor m)
iso = up-to-iso 𝒞 pf (pullback-resp-≈ 𝒞 pg (sym eq) refl)
module iso = _≅_ iso
in record
{ from = record
{ h = iso.from
; △ = Pullback.p₁∘universal≈h₁ pg
}
; to = record
{ h = iso.to
; △ = Pullback.p₁∘universal≈h₁ pf
}
; iso = record
{ isoˡ = iso.isoˡ
; isoʳ = iso.isoʳ
}
}
}
where
morphism : ∀ {A B} → (f : 𝒞 [ B , A ]) → Σ[ α ∈ 𝒞.Obj ] (α ↣ A) → Σ[ β ∈ 𝒞.Obj ] (β ↣ B)
morphism f (α , m) =
let pb = has-pullbacks f (mor m)
in Pullback.P pb , record
{ mor = Pullback.p₁ pb
; mono = Pullback-resp-Mono 𝒞 pb (mono m)
}
monotone : ∀ {A B} (f : 𝒞 [ B , A ]) → Poset._≤_ (Subobjects 𝒞 A) =[ morphism f ]⇒ Poset._≤_ (Subobjects 𝒞 B)
monotone f {(α , m)} {(β , n)} h =
let pm = has-pullbacks f (mor m)
pn = has-pullbacks f (mor n)
in record
{ h = Pullback.universal pn $ begin
𝒞 [ f ∘ Pullback.p₁ pm ] ≈⟨ Pullback.commute pm ⟩
𝒞 [ mor m ∘ Pullback.p₂ pm ] ≈⟨ pushˡ (⟺ (Slice⇒.△ h)) ⟩
𝒞 [ mor n ∘ 𝒞 [ Slice⇒.h h ∘ Pullback.p₂ pm ] ] ∎
; △ = Pullback.p₁∘universal≈h₁ pn
}
-- The subobject functor as a presheaf on Setoids.
-- This is just Subₚ composed with the 'Core'
Sub : Presheaf 𝒞 (Setoids (o ⊔ ℓ ⊔ e) (ℓ ⊔ e))
Sub = Core ∘F Subₚ
| {
"alphanum_fraction": 0.5394221352,
"avg_line_length": 31.4153846154,
"ext": "agda",
"hexsha": "860dda5c961a512ea594954e703282e209b92370",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Subobject/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Subobject/Properties.agda",
"max_line_length": 128,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Subobject/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1408,
"size": 4084
} |
module Issue2217.M where
| {
"alphanum_fraction": 0.84,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "3863534789cc47fa55b9d7331c07a5687676224d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue2217/M.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue2217/M.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2217/M.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 7,
"size": 25
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via `Relation.Binary`.
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Core where
open import Function.Base using (_on_)
open import Level using (Level; _⊔_; suc)
private
variable
a b c ℓ ℓ₁ ℓ₂ ℓ₃ : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- Definitions
------------------------------------------------------------------------
-- Heterogeneous binary relations
REL : Set a → Set b → (ℓ : Level) → Set (a ⊔ b ⊔ suc ℓ)
REL A B ℓ = A → B → Set ℓ
-- Homogeneous binary relations
Rel : Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)
Rel A ℓ = REL A A ℓ
------------------------------------------------------------------------
-- Relationships between relations
------------------------------------------------------------------------
infixr 4 _⇒_ _=[_]⇒_
-- Implication/containment - could also be written _⊆_.
_⇒_ : REL A B ℓ₁ → REL A B ℓ₂ → Set _
P ⇒ Q = ∀ {x y} → P x y → Q x y
-- Generalised implication - if P ≡ Q it can be read as "f preserves P".
_=[_]⇒_ : Rel A ℓ₁ → (A → B) → Rel B ℓ₂ → Set _
P =[ f ]⇒ Q = P ⇒ (Q on f)
-- A synonym for _=[_]⇒_.
_Preserves_⟶_ : (A → B) → Rel A ℓ₁ → Rel B ℓ₂ → Set _
f Preserves P ⟶ Q = P =[ f ]⇒ Q
-- A binary variant of _Preserves_⟶_.
_Preserves₂_⟶_⟶_ : (A → B → C) → Rel A ℓ₁ → Rel B ℓ₂ → Rel C ℓ₃ → Set _
_∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y u v} → P x y → Q u v → R (x ∙ u) (y ∙ v)
| {
"alphanum_fraction": 0.4387936132,
"avg_line_length": 27.2741935484,
"ext": "agda",
"hexsha": "57ca7f7109b1d2411138d747f8a3ac59971a7fce",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Core.agda",
"max_line_length": 74,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 505,
"size": 1691
} |
module equational where
open import lib
postulate
A : Set
a : A
b : A
c : A
d : A
f : A → A
g : A → A
h : A → A → A
p : a ≡ b
q : b ≡ c
r : f a ≡ a
s : h a a ≡ a
t : ∀ x → f (g x) ≡ g (f x)
u : ∀ {x} → f x ≡ x → g (g x) ≡ x -- {x} means x is implicit, so you do not need to write it when you call u
v : ∀ x → h x d ≡ x
L0 : c ≡ c
L0 = refl
L1 : c ≡ a
L1 rewrite p | q = refl
L2 : h (f a) (f (f a)) ≡ a
L2 rewrite r | r = s
L3 : f b ≡ b
L3 rewrite sym p = r
L4 : h (h d d) d ≡ d
L4 rewrite s | v d = v d
L5 : f (g (g a)) ≡ a
L5 rewrite t ( g a) | t a | r | u r = refl
L6 : f (g (f (g a))) ≡ g (g (f (f a)))
L6 rewrite t a | r | u r | r | u r = refl
L7 : ∀ x → f (f (f x)) ≡ x → f (f (f (f (f x)))) ≡ x → f x ≡ x
L7 x y z rewrite y | z | r = y
| {
"alphanum_fraction": 0.4078947368,
"avg_line_length": 18.5777777778,
"ext": "agda",
"hexsha": "569165cd6da07d52674c4069eb79903278ae41aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "51d54ed9c232f93baad238d328b77dd024344226",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout6",
"max_forks_repo_path": "equational.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "51d54ed9c232f93baad238d328b77dd024344226",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout6",
"max_issues_repo_path": "equational.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "51d54ed9c232f93baad238d328b77dd024344226",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout6",
"max_stars_repo_path": "equational.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 399,
"size": 836
} |
module libbijection where
open import Level renaming ( zero to Zero ; suc to Suc )
open import Data.Nat
open import Data.Maybe
open import Data.List hiding ([_] ; sum )
open import Data.Nat.Properties
open import Relation.Nullary
open import Data.Empty
open import Data.Unit hiding ( _≤_ )
open import Relation.Binary.Core hiding (_⇔_)
open import Relation.Binary.Definitions
open import Relation.Binary.PropositionalEquality
open import Function.Inverse hiding (sym)
open import Function.Bijection renaming (Bijection to Bijection1)
open import Function.Equality hiding (cong)
open import logic
open import nat
-- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
-- field
-- fun← : S → R
-- fun→ : R → S
-- fiso← : (x : R) → fun← ( fun→ x ) ≡ x
-- fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
--
-- injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
-- injection R S f = (x y : R) → f x ≡ f y → x ≡ y
open Bijection
b→injection1 : {n m : Level} (R : Set n) (S : Set m) → (b : Bijection R S) → injection S R (fun← b)
b→injection1 R S b x y eq = trans ( sym ( fiso→ b x ) ) (trans ( cong (λ k → fun→ b k ) eq ) ( fiso→ b y ))
--
-- injection as an uniquneness of bijection
--
b→injection0 : {n m : Level} (R : Set n) (S : Set m) → (b : Bijection R S) → injection R S (fun→ b)
b→injection0 R S b x y eq = begin
x
≡⟨ sym ( fiso← b x ) ⟩
fun← b ( fun→ b x )
≡⟨ cong (λ k → fun← b k ) eq ⟩
fun← b ( fun→ b y )
≡⟨ fiso← b y ⟩
y
∎ where open ≡-Reasoning
open import Relation.Binary using (Rel; Setoid; Symmetric; Total)
open import Function.Surjection
≡-Setoid : {n : Level} (R : Set n) → Setoid n n
≡-Setoid R = record {
Carrier = R
; _≈_ = _≡_
; isEquivalence = record { sym = sym ; refl = refl ; trans = trans }
}
libBijection : {n m : Level} (R : Set n) (S : Set m) → Bijection R S → Bijection1 (≡-Setoid R) (≡-Setoid S)
libBijection R S b = record {
to = record { _⟨$⟩_ = λ x → fun→ b x ; cong = λ i=j → cong (fun→ b) i=j }
; bijective = record {
injective = λ {x} {y} eq → b→injection0 R S b x y eq
; surjective = record { from = record { _⟨$⟩_ = λ x → fun← b x ; cong = λ i=j → cong (fun← b) i=j }
; right-inverse-of = λ x → fiso→ b x }
}
}
fromBijection1 : {n m : Level} (R : Set n) (S : Set m) → Bijection1 (≡-Setoid R) (≡-Setoid S) → Bijection R S
fromBijection1 R S b = record {
fun← = Π._⟨$⟩_ (Surjective.from (Bijective.surjective (Bijection1.bijective b)))
; fun→ = Π._⟨$⟩_ (Bijection1.to b)
; fiso← = λ x → Bijective.injective (Bijection1.bijective b) (fb1 x)
; fiso→ = Surjective.right-inverse-of (Bijective.surjective (Bijection1.bijective b))
} where
-- fun← b x ≡ fun← b y → x ≡ y
-- fun← (fun→ ( fun← x )) ≡ fun← x
-- fun→ ( fun← x ) ≡ x
fb1 : (x : R) → Π._⟨$⟩_ (Bijection1.to b) (Surjective.from (Bijective.surjective (Bijection1.bijective b)) ⟨$⟩ (Bijection1.to b ⟨$⟩ x)) ≡ Π._⟨$⟩_ (Bijection1.to b) x
fb1 x = begin
Π._⟨$⟩_ (Bijection1.to b) (Surjective.from (Bijective.surjective (Bijection1.bijective b)) ⟨$⟩ (Bijection1.to b ⟨$⟩ x))
≡⟨ Surjective.right-inverse-of (Bijective.surjective (Bijection1.bijective b)) _ ⟩
Π._⟨$⟩_ (Bijection1.to b) x ∎ where open ≡-Reasoning
| {
"alphanum_fraction": 0.5736658933,
"avg_line_length": 39.632183908,
"ext": "agda",
"hexsha": "9b109bbf2ca44aeec32d694236f1953e13c06a2b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/libbijection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/libbijection.agda",
"max_line_length": 171,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/libbijection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1284,
"size": 3448
} |
{-
A parameterized family of structures S can be combined into a single structure:
X ↦ (a : A) → S a X
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Parameterized where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Functions.FunExtEquiv
open import Cubical.Foundations.SIP
module _ {ℓ ℓ₁ ℓ₂} (A : Type ℓ) where
ParamStructure : (S : A → Type ℓ₁ → Type ℓ₂)
→ Type ℓ₁ → Type (ℓ-max ℓ ℓ₂)
ParamStructure S X = (a : A) → S a X
ParamEquivStr : {S : A → Type ℓ₁ → Type ℓ₂} {ℓ₃ : Level}
→ (∀ a → StrEquiv (S a) ℓ₃) → StrEquiv (ParamStructure S) (ℓ-max ℓ ℓ₃)
ParamEquivStr ι (X , l) (Y , m) e = ∀ a → ι a (X , l a) (Y , m a) e
ParamUnivalentStr : {S : A → Type ℓ₁ → Type ℓ₂} {ℓ₃ : Level}
(ι : ∀ a → StrEquiv (S a) ℓ₃) (θ : ∀ a → UnivalentStr (S a) (ι a))
→ UnivalentStr (ParamStructure S) (ParamEquivStr ι)
ParamUnivalentStr ι θ e = compEquiv (equivPi λ a → θ a e) funExtEquiv
| {
"alphanum_fraction": 0.6444444444,
"avg_line_length": 34.1379310345,
"ext": "agda",
"hexsha": "7cae20fc840a4d2c20b3b6e1c55e8f4b426807c7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Structures/Parameterized.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Structures/Parameterized.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Structures/Parameterized.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 390,
"size": 990
} |
{-# OPTIONS --allow-unsolved-metas --guardedness #-}
import Tutorials.Monday-Complete as Mon
import Tutorials.Tuesday-Complete as Tue
import Tutorials.Wednesday-Complete as Wed
open Mon using (⊤; tt; ℕ; zero; suc)
open Mon.Simple using (_⊎_; inl; inr)
open Tue.Product using (Σ; _,_; fst; snd; _×_)
module Tutorials.Thursday where
variable
A B C S : Set
-- Things that we skipped so far
--------------------------------
module WithAbstraction where
open Mon using (Bool; true; false; Pred; _≡_; refl; _+_; subst; +-comm)
open Mon.List using (List; []; _∷_)
-- With abstraction
-- You can use "with abstraction" to pattern match on intermediary computations
-- These can be nested, or executed simultaneously
filter : (A → Bool) → List A → List A
filter f [] = []
filter f (x ∷ xs) with f x
filter f (x ∷ xs) | true = x ∷ filter f xs
filter f (x ∷ xs) | false = filter f xs
-- Alternative notation
filter′ : (A → Bool) → List A → List A
filter′ f [] = []
filter′ f (x ∷ xs) with f x
... | true = x ∷ filter′ f xs
... | false = filter′ f xs
-- The goal type and the type of the arguments are generalised over the value of the scrutinee
thm : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
-- 1) Here (p : P (n + m)) and (eq : n + m ≡ m + n)
-- thm n m p with +-comm n m
-- thm n m p | eq = {!!}
-- 2) Here (p : P x) and (eq : x ≡ m + n)
-- thm n m p with n + m | +-comm n m
-- thm n m p | x | eq = {!!}
-- 3) Pattern matching we get (p : P (m + n)), the dot signifies that the argument is uniquely determined
thm n m p with n + m | +-comm n m
thm n m p | .(m + n) | refl = p
-- This is such a common formula that there is special syntax for it
thm′ : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
thm′ n m p rewrite +-comm n m = p
-- We could use subst to be more explicit about *where* the rewrite happens
thm′′ : {P : Pred ℕ} (n m : ℕ) → P (n + m) → P (m + n)
thm′′ {P} n m p = subst {P = P} (+-comm n m) p
-- A little on coinductive types
--------------------------------
-- Stolen from https://github.com/pigworker/CS410-17/blob/master/lectures/Lec6Done.agda
ListT : Set → Set → Set
ListT X B = ⊤ ⊎ (X × B)
module List where
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
mkList : ListT A (List A) → List A
mkList x = {!!}
foldr : (ListT A B → B) → List A → B
foldr alg xs = {!!}
list-id : List A → List A
list-id = {!!}
incr : ListT A ℕ → ℕ
incr x = {!!}
length : List A → ℕ
length = {!!}
module CoList where
record CoList (A : Set) : Set where
coinductive
field
next : ListT A (CoList A)
open CoList
[] : CoList A
[] = {!!}
_∷_ : A → CoList A → CoList A
(x ∷ xs) = {!!}
unfoldr : (S → ListT A S) → S → CoList A
unfoldr coalg s = {!!}
colist-id : CoList A → CoList A
colist-id = {!!}
repeat : A → CoList A
repeat = {!!}
take : ℕ → CoList A → List.List A
take n xs = {!!}
module Stream where
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream
forever : A → Stream A
forever x = {!!}
unfold : (S → A × S) → S → Stream A
unfold coalg s = {!!}
---------------------------------------------
-- If you are interested in more
-- Documentation for Agda: https://agda.readthedocs.io/en/v2.6.0.1/index.html
-- Programming Language Foundations in Agda: https://plfa.github.io/
-- Lots of other nice tutorials online
-- The standard library: https://agda.github.io/agda-stdlib/
| {
"alphanum_fraction": 0.5628323538,
"avg_line_length": 25.7050359712,
"ext": "agda",
"hexsha": "f769fd0cff1011255ff9eaafd6b602660d7e2198",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:50:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-23T08:50:13.000Z",
"max_forks_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "poncev/agda-bcam",
"max_forks_repo_path": "Tutorials/Thursday.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "poncev/agda-bcam",
"max_issues_repo_path": "Tutorials/Thursday.agda",
"max_line_length": 107,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "poncev/agda-bcam",
"max_stars_repo_path": "Tutorials/Thursday.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-03T22:53:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T17:59:21.000Z",
"num_tokens": 1199,
"size": 3573
} |
{- Copyright © 1992–2002 The University of Glasgow
Copyright © 2015 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an ‘AS IS’ BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. -}
module B.Prelude.Functor where
import Category.Monad as Monad
import Category.Functor
import Data.List
import Data.Maybe
open import Function using (_∘_)
open Category.Functor
using (RawFunctor)
public
open Category.Functor.RawFunctor ⦃...⦄
using (_<$>_)
public
instance
Functor-List : ∀ {ℓ} → RawFunctor (Data.List.List {ℓ})
Functor-List = Monad.RawMonad.rawFunctor Data.List.monad
Functor-Maybe : ∀ {ℓ} → RawFunctor (Data.Maybe.Maybe {ℓ})
Functor-Maybe = Monad.RawMonad.rawFunctor Data.Maybe.monad
Functor-Function : ∀ {ℓ} {r : Set ℓ} → RawFunctor {ℓ} (λ s → (r → s))
Functor-Function {r} =
-- I could say _<$>_ = _∘_ here, but that makes type checking much more
-- challenging.
record { _<$>_ = λ f g → f ∘ g }
-- TODO: Do proper instance for dependent pairs
| {
"alphanum_fraction": 0.7269528501,
"avg_line_length": 31.5777777778,
"ext": "agda",
"hexsha": "805aeff41df7464e45f4b13eed62d1adc845ad6f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "bbarenblat/B",
"max_forks_repo_path": "Prelude/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "bbarenblat/B",
"max_issues_repo_path": "Prelude/Functor.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c1fd2daa41aa1b915f74b4c09c6e62c79320e8ec",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "bbarenblat/B",
"max_stars_repo_path": "Prelude/Functor.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-30T15:59:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-30T15:59:38.000Z",
"num_tokens": 395,
"size": 1421
} |
{-# OPTIONS --show-implicit #-}
module BottomUp where
open import Foundation.Primitive
open import Foundation.Bottom
open import Foundation.Equivalence
open import Agda.Builtin.List
open import Agda.Builtin.Equality
open import Agda.Builtin.Unit
module NegEquiv {ℓ'} (⊥ : Set ℓ') ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where
_≉_ : ∀ {a} {A : Set a} {ℓ} ⦃ _ : Equivalence A ℓ ⦄ → A → A → Set (ℓ ⊔ ℓ')
x ≉ y = x ≈ y → ⊥
module Data-⊥ where
data Data⊥ : Set where
instance bottom-rule : ∀ {b} → IsBottom Data⊥ b
IsBottom.⊥-elim (bottom-rule {b}) () {B}
module IsDecisive-Module {ℓ'} (⊥ : Set ℓ') ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where
open NegEquiv ⊥
record IsDecisive a
(Decision : (A : Set a) → Set a)
(yes-c : {A : Set a} → A → Decision A)
(no-c : {A : Set a} → (A → ⊥) → Decision A)
ℓ
⦃ equiv-decision : {A : Set a} → Equivalence (Decision A) ℓ ⦄
: Set (ℓ ⊔ ⟰ a ⊔ ℓ') where
field
yes-correct : {A : Set a} → (dec : Decision A) → (x : A) → yes-c x ≈ dec
no-correct : {A : Set a} → (dec : Decision A) → (x : A → ⊥) → no-c x ≈ dec
yes-no-incompat : {A : Set a} (x : A) (nx : A → ⊥) → yes-c x ≉ no-c nx
open IsDecisive ⦃ … ⦄ public
record ⊤′ {a} : Set a where
instance constructor tt
module Data-Decision {ℓ} (⊥ : Set ℓ) ⦃ _ : ∀ {b} → IsBottom ⊥ b ⦄ where
data Decision {a} (A : Set a) : Set (a ⊔ ℓ) where
yes : A → Decision A
no : (A → ⊥) → Decision A
open IsDecisive-Module ⊥
instance dec-equiv : ∀ {a} {A : Set a} → Equivalence (Decision {a} A) a
(dec-equiv {a} {A} Equivalence.≈ yes x₁) (yes x₂) = ⊤′
(dec-equiv {a} {A} Equivalence.≈ yes x₁) (no x₂) = ⊥-elim (x₂ x₁)
(dec-equiv {a} {A} Equivalence.≈ no x₁) (yes x₂) = ⊥-elim (x₁ x₂)
(dec-equiv {a} {A} Equivalence.≈ no x₁) (no x₂) = ⊤′
IsEquivalence.reflexivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) = tt
IsEquivalence.reflexivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) = tt
IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) x₃ = x₃
IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) x₃ = x₃
IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) x₃ = x₃
IsEquivalence.symmetry (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) x₃ = x₃
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) (yes x₃) x₄ x₅ = tt
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (yes x₂) (no x₃) x₄ x₅ = ⊥-elim (x₃ x₂)
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) (yes x₃) x₄ x₅ = tt
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (yes x₁) (no x₂) (no x₃) x₄ x₅ = ⊥-elim (x₂ x₁)
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) (yes x₃) x₄ x₅ = ⊥-elim (x₁ x₂)
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (yes x₂) (no x₃) x₄ x₅ = tt
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) (yes x₃) x₄ x₅ = ⊥-elim (x₂ x₃)
IsEquivalence.transitivity (Equivalence.isEquivalence (dec-equiv {a} {A})) (no x₁) (no x₂) (no x₃) x₄ x₅ = tt
instance dec-instance : ∀ {a} → IsDecisive (a ⊔ ℓ) (Decision {a ⊔ ℓ}) yes no (a ⊔ ℓ)
IsDecisive-Module.IsDecisive.yes-correct (dec-instance {a}) {A} (yes x₁) x₂ = tt
IsDecisive-Module.IsDecisive.yes-correct (dec-instance {a}) {A} (no x₁) x₂ = ⊥-elim (x₁ x₂)
IsDecisive-Module.IsDecisive.no-correct (dec-instance {a}) {A} (yes x₁) x₂ = ⊥-elim (x₂ x₁)
IsDecisive-Module.IsDecisive.no-correct (dec-instance {a}) {A} (no x₁) x₂ = tt
IsDecisive-Module.IsDecisive.yes-no-incompat (dec-instance {a}) x₁ nx x₂ = nx x₁
open Data-⊥
-- module DecisionModule (⊥ : Set) ⦃ _ : ∀ {a} {b} → IsBottom ⊥ a b ⦄ where
-- record IsDecidableEquivalence {a} {A : Set a} {ℓ} (_≈_ : A → A → Set ℓ) : Set (a ⊔ ℓ) where
-- infix 4 _≈?_
-- field
-- isEquivalence : IsEquivalence _≈_
-- _≈?_ : (x y : A) → Decision (x ≈ y)
-- record DecidableEquivalence {a} (A : Set a) ℓ : Set (lsuc (a ⊔ ℓ)) where
-- field
-- ⦃ equivalence ⦄ : Equivalence A ℓ
-- --open Equivalence equivalence
-- infix 4 _≈?_
-- field
-- _≈?_ : (x y : A) → Decision (x ≈ y)
-- open DecidableEquivalence ⦃ … ⦄ public
-- record DecidableEquivalence' {a} (A : Set a) : Set (lsuc a) where
-- field
-- ⦃ equivalence ⦄ : Equivalence A a
-- infix 4 _≈?_
-- field
-- _≈?_ : (x y : A) → Decision (x ≈ y)
-- data ⊥-fake : Set where
-- faker : ⊥-fake
-- ⊥fake-rule : ∀ {a} {A : Set a} → (A → ⊥-fake) → A → ∀ {b} {B : Set b} → B
-- ⊥fake-rule x x₁ with x x₁
-- ⊥fake-rule x x₁ | faker = {!!}
-- open DecisionModule ⊥
-- data Tree (A : Set) : Set where
-- value : A → Tree A
-- leaf : Tree A
-- branch : Tree A → Tree A → Tree A
-- substitute₁List : ∀ {a} {A : Set a} ⦃ _ : DecidableEquivalence A a ⦄ → A → A → List A → List A
-- substitute₁List x₁ y [] = []
-- substitute₁List x₁ y (x₂ ∷ xs) with x₁ ≈? x₂
-- substitute₁List x₁ y (x₂ ∷ xs) | yes x₃ = y ∷ substitute₁List x₁ y xs
-- substitute₁List x₁ y (x₂ ∷ xs) | no x₃ = x₂ ∷ substitute₁List x₁ y xs
-- open import Agda.Builtin.Nat
-- open import Agda.Builtin.Bool
-- instance EquivalenceNat : Equivalence Nat lzero
-- (EquivalenceNat Equivalence.≈ x) x₁ = (x == x₁) ≡ true
-- IsEquivalence.reflexivity (Equivalence.isEquivalence EquivalenceNat) = isrefl where
-- isrefl : ∀ x → (x == x) ≡ true
-- isrefl zero = refl
-- isrefl (suc x) = isrefl x
-- IsEquivalence.symmetry (Equivalence.isEquivalence EquivalenceNat) = issym where
-- issym : (x y : Nat) →
-- EquivalenceNat .Equivalence._≈_ x y →
-- EquivalenceNat .Equivalence._≈_ y x
-- issym zero zero x₁ = refl
-- issym zero (suc y) x₁ = x₁
-- issym (suc x) zero x₁ = x₁
-- issym (suc x) (suc y) x₁ = issym x y x₁
-- IsEquivalence.transitivity (Equivalence.isEquivalence EquivalenceNat) = {!!}
-- instance DecidableEquivalenceNat : DecidableEquivalence Nat lzero
-- DecisionModule.DecidableEquivalence.equivalence DecidableEquivalenceNat = EquivalenceNat
-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? zero) zero = yes refl
-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? zero) (suc y) = no (λ x → {!!})
-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? suc x) zero = {!!}
-- (DecidableEquivalenceNat DecisionModule.DecidableEquivalence.≈? suc x) (suc y) = {!!}
-- {-
-- $&[{}(=*)+]!#
-- ~%7531902468`
-- ;,.
-- :<>
-- -}
| {
"alphanum_fraction": 0.6093380615,
"avg_line_length": 41.5214723926,
"ext": "agda",
"hexsha": "925148347826ef1c14277e0d7e461605bc878f77",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/BottomUp.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/BottomUp.agda",
"max_line_length": 125,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/BottomUp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2636,
"size": 6768
} |
{- Example by Guillaume Brunerie, 17-11-2015 -}
{-# OPTIONS --rewriting --cubical-compatible #-}
open import Agda.Primitive
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
idr : ∀ {i} {A : Set i} {a : A} → a ↦ a
{-# BUILTIN REWRITE _↦_ #-}
infixr 3 _==_
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
PathOver : ∀ {i j} {A : Set i} (B : A → Set j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set j
PathOver B idp u v = (u == v)
syntax PathOver B p u v =
u == v [ B ↓ p ]
postulate
PathOver-rewr : ∀ {i j} {A : Set i} {B : Set j} {x y : A} (p : x == y) (u v : B) →
(PathOver (λ _ → B) p u v) ↦ (u == v)
{-# REWRITE PathOver-rewr #-}
ap : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → PathOver B p (f x) (f y)
ap f idp = idp
module _ {i j k} {A : Set i} {B : Set j} {C : Set k} (g : B → C) (f : A → B) where
∘ap : {x y : A} (p : x == y) →
ap g (ap f p) ↦ ap (λ x → g (f x)) p
∘ap idp = idr
{-# REWRITE ∘ap #-}
ap∘ : {x y : A} (p : x == y) →
ap (λ x → g (f x)) p ↦ ap g (ap f p)
ap∘ p = idr
| {
"alphanum_fraction": 0.4430264357,
"avg_line_length": 24.9318181818,
"ext": "agda",
"hexsha": "9982f1dcd682707b7b199be317567fdac2e05975",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue1652-3.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue1652-3.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue1652-3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 521,
"size": 1097
} |
-- Andreas, 2014-09-03
-- Test explanation of local shadowed by import.
module _ where
module M where
A = Set1
test : (A : Set) → let open M in {!A!}
test A = Set
-- The A exported by M is in competition with the local A.
-- Ambiguous name should be reported.
| {
"alphanum_fraction": 0.6779026217,
"avg_line_length": 17.8,
"ext": "agda",
"hexsha": "4cbd051f339e6cb506d441ef09d876ac15c55b65",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue1266whyInScope.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue1266whyInScope.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1266whyInScope.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 78,
"size": 267
} |
module Transducer where
open import Data.Unit
open import Data.Product
open import Data.Sum
open import Data.List
_* = List
-- | Finite and infinite sequences (constructively useful variant)
record Seq (A : Set) : Set where
coinductive
field
out : (A ⊎ ⊤) × Seq A
open Seq
-- | Functor that allows us to capture transducer as coalgebras.
F : (A B : Set) → Set → Set
F A B X = A → B * × X
-- | Interpretation of transducers as maps between sequences, i.e., corecursion.
⟦_⟧ : ∀{A B X} → (δ : X → F A B X) → X → (Seq A → Seq B)
out (⟦_⟧ {B = B} {X} δ x s) with out s
... | (inj₁ a , t) =
let (w , y) = δ x a
in cont y w
where
cont : X → B * → (B ⊎ ⊤) × Seq B
cont y [] = (inj₂ tt , ⟦ δ ⟧ y t)
proj₁ (cont y (b ∷ bs)) = inj₁ b
out (proj₂ (cont y (b ∷ bs))) = cont y bs
... | (inj₂ tt , y) = (inj₂ tt , ⟦ δ ⟧ x y)
| {
"alphanum_fraction": 0.5704142012,
"avg_line_length": 25.6060606061,
"ext": "agda",
"hexsha": "5682e8e5994b33ae4de29e634c9e55b7ce876992",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "Streams/Transducer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "Streams/Transducer.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "Streams/Transducer.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 323,
"size": 845
} |
{-# OPTIONS --cubical --safe --no-import-sorts #-}
module Cubical.Algebra.Module where
open import Cubical.Algebra.Module.Base public
| {
"alphanum_fraction": 0.7555555556,
"avg_line_length": 27,
"ext": "agda",
"hexsha": "1662aeb738f29e0c91f345c57f34052ddca093ff",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Algebra/Module.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Algebra/Module.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Algebra/Module.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 32,
"size": 135
} |
------------------------------------------------------------------------------
-- Test the consistency of FOTC.Base
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- In the module FOTC.Base we declare Agda postulates as first-order
-- logic axioms. We test if it is possible to prove an unprovable
-- theorem from these axioms.
module FOTC.Base.Consistency.Axioms where
open import FOTC.Base
------------------------------------------------------------------------------
postulate impossible : ∀ d e → d ≡ e
{-# ATP prove impossible #-}
| {
"alphanum_fraction": 0.4404283802,
"avg_line_length": 33.9545454545,
"ext": "agda",
"hexsha": "3ed3a5364644ec470d22bc0ebfa80cbd16ae88ce",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Base/Consistency/Axioms.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Base/Consistency/Axioms.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Base/Consistency/Axioms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 128,
"size": 747
} |
module Slice where
open import Logic.Relations
open import Logic.Equivalence
open import Logic.Base
open import Category
module SliceCat (ℂ : Cat)(Γ : Category.Obj ℂ) where
open module CC = Category.Category ℂ
record SlObj : Set1 where
field
dom : Obj
arr : dom ─→ Γ
record _Sl→_ (f f' : SlObj) : Set where
field
h : (SlObj.dom f) ─→ (SlObj.dom f')
π : (SlObj.arr f') ∘ h == (SlObj.arr f)
SlId : {f : SlObj} -> f Sl→ f
SlId = record
{ h = id
; π = idRight
}
_o_ : {f f' f'' : SlObj} -> f' Sl→ f'' -> f Sl→ f' -> f Sl→ f''
_o_ {F} {F'} {F''} F₁ F₂ =
let f = SlObj.arr F in
let f' = SlObj.arr F' in
let f'' = SlObj.arr F'' in
let h' = _Sl→_.h F₁ in
let h = _Sl→_.h F₂ in
record
{ h = (_Sl→_.h F₁) ∘ (_Sl→_.h F₂)
-- Proof of f'' ∘ (h' ∘ h) == f
; π = trans (trans (sym assoc)
(congL (_Sl→_.π F₁)))
(_Sl→_.π F₂)
}
SlRel : {A B : SlObj} -> Rel (A Sl→ B)
SlRel f f' = (_Sl→_.h f) == (_Sl→_.h f')
SlRefl : {A B : SlObj} -> Reflexive {A Sl→ B} SlRel
SlRefl = refl
SlSym : {A B : SlObj} -> Symmetric {A Sl→ B} SlRel
SlSym = sym
SlTrans : {A B : SlObj} -> Transitive {A Sl→ B} SlRel
SlTrans = trans
SlEq : {A B : SlObj} -> Equivalence (A Sl→ B)
SlEq {A} {B} = record
{ _==_ = SlRel {A} {B}
; refl = \{f : A Sl→ B} -> SlRefl {A}{B}{f}
; sym = \{f g : A Sl→ B} -> SlSym {A}{B}{f}{g}
; trans = \{f g h : A Sl→ B} -> SlTrans {A}{B}{f}{g}{h}
}
SlCong : {A B C : SlObj}{f f' : B Sl→ C}{g g' : A Sl→ B} ->
SlRel f f' -> SlRel g g' -> SlRel (f o g) (f' o g')
SlCong = cong
SlIdLeft : {A B : SlObj}{f : A Sl→ B} -> SlRel (SlId o f) f
SlIdLeft = idLeft
SlIdRight : {A B : SlObj}{f : A Sl→ B} -> SlRel (f o SlId) f
SlIdRight = idRight
SlAssoc : {A B C D : SlObj}{f : C Sl→ D}{g : B Sl→ C}{h : A Sl→ B} ->
SlRel ((f o g) o h) (f o (g o h))
SlAssoc = assoc
Slice : Cat
Slice = record
{ Obj = SlObj
; _─→_ = _Sl→_
; id = SlId
; _∘_ = _o_
; Eq = SlEq
; cong = \{A B C : SlObj}{f f' : B Sl→ C}{g g' : A Sl→ B} -> SlCong {A}{B}{C}{f}{f'}{g}{g'}
; idLeft = \{A B : SlObj}{f : A Sl→ B} -> SlIdLeft {A} {B} {f}
; idRight = \{A B : SlObj}{f : A Sl→ B} -> SlIdRight {A} {B} {f}
; assoc = \{A B C D : SlObj}{f : C Sl→ D}{g : B Sl→ C}{h : A Sl→ B} ->
SlAssoc {A}{B}{C}{D}{f}{g}{h}
}
| {
"alphanum_fraction": 0.4622453056,
"avg_line_length": 27.2065217391,
"ext": "agda",
"hexsha": "07e2adc2de680e53c9965774016fd3df0abc8bf1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/Slice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/Slice.agda",
"max_line_length": 98,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/Slice.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 1074,
"size": 2503
} |
{-# OPTIONS --without-K --safe #-}
module Algebra.Structures.Bundles.Field where
open import Algebra
open import Level using (suc; _⊔_)
open import Relation.Binary using (Rel)
open import Algebra.Structures.Field
record Field c ℓ : Set (suc (c ⊔ ℓ)) where
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Carrier -> Carrier -> Carrier
_*_ : Carrier -> Carrier -> Carrier
0# : Carrier
1# : Carrier
-_ : Carrier -> Carrier
_⁻¹ : MultiplicativeInverse _≈_ 0#
isField : IsField _≈_ _+_ _*_ 0# 1# -_ _⁻¹
open IsField isField public
| {
"alphanum_fraction": 0.6169154229,
"avg_line_length": 25.125,
"ext": "agda",
"hexsha": "ceda0ac96b70bdd0299f6bf9007aa140ec189057",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Structures/Bundles/Field.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Structures/Bundles/Field.agda",
"max_line_length": 46,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Structures/Bundles/Field.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 188,
"size": 603
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Groups
open import Groups.Homomorphisms.Definition
open import Groups.Definition
open import Numbers.Naturals.Naturals
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Groups.Homomorphisms.Lemmas2 {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+A_ : A → A → A} (G : Group S _+A_) where
imageGroup : {c d : _} {B : Set c} {T : Setoid {c} {d} B} {_+B_ : B → B → B} → (f : A → B) → SetoidSurjection S T f → ({x y : A} → Setoid._∼_ T (f (x +A y)) ((f x) +B (f y))) → ({x y m n : B} → Setoid._∼_ T x m → Setoid._∼_ T y n → Setoid._∼_ T (x +B y) (m +B n)) → Group T _+B_
Group.+WellDefined (imageGroup f surj respects+ wd) {m} {n} {x} {y} = wd
Group.0G (imageGroup f surj respects+ wd) = f (Group.0G G)
Group.inverse (imageGroup f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) b with surjective {b}
Group.inverse (imageGroup f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) b | a , fa=b = f (Group.inverse G a)
Group.+Associative (imageGroup {T = T} f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {a} {b} {c} with surjective {a}
... | x , fx=a with surjective {b}
... | y , fy=b with surjective {c}
... | z , fz=c = transitive (wd (symmetric fx=a) (transitive (wd (symmetric fy=b) (symmetric fz=c)) (symmetric respects+))) (transitive (transitive (symmetric respects+) (transitive (wellDefined (Group.+Associative G)) respects+)) (wd (transitive respects+ (wd fx=a fy=b)) fz=c))
where
open Setoid T
open Equivalence eq
Group.identRight (imageGroup {T = T} f record { wellDefined = wd ; surjective = surjective } respects+ bWd) {b} with surjective {b}
... | a , fa=b = transitive (bWd (symmetric fa=b) reflexive) (transitive (symmetric respects+) (transitive (wd (Group.identRight G)) fa=b))
where
open Setoid T
open Equivalence eq
Group.identLeft (imageGroup {T = T} f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {b} with surjective {b}
... | a , fa=b = transitive (wd reflexive (symmetric fa=b)) (transitive (symmetric respects+) (transitive (wellDefined (Group.identLeft G)) fa=b))
where
open Setoid T
open Equivalence eq
Group.invLeft (imageGroup {T = T} f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {b} with surjective {b}
Group.invLeft (imageGroup {T = T} f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {b} | a , fa=b = transitive (wd reflexive (symmetric fa=b)) (transitive (symmetric respects+) (wellDefined (Group.invLeft G)))
where
open Setoid T
open Equivalence eq
Group.invRight (imageGroup f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {b} with surjective {b}
Group.invRight (imageGroup {T = T} f record { wellDefined = wellDefined ; surjective = surjective } respects+ wd) {b} | a , fa=b = transitive (wd (symmetric fa=b) reflexive) (transitive (symmetric respects+) (wellDefined (Group.invRight G)))
where
open Setoid T
open Equivalence eq
homToImageGroup : {c d : _} {B : Set c} {T : Setoid {c} {d} B} {_+B_ : B → B → B} → (f : A → B) → (surj : SetoidSurjection S T f) → (respects+ : {x y : A} → Setoid._∼_ T (f (x +A y)) ((f x) +B (f y))) → (wd : {x y m n : B} → Setoid._∼_ T x m → Setoid._∼_ T y n → Setoid._∼_ T (x +B y) (m +B n)) → GroupHom G (imageGroup f surj respects+ wd) f
GroupHom.groupHom (homToImageGroup f surj respects+ wd) = respects+
GroupHom.wellDefined (homToImageGroup f surj respects+ wd) = SetoidSurjection.wellDefined surj
| {
"alphanum_fraction": 0.6774279616,
"avg_line_length": 72.0769230769,
"ext": "agda",
"hexsha": "6b7300fdd1e586e092403222cf06f3b549f1c0a1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/Homomorphisms/Lemmas2.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Homomorphisms/Lemmas2.agda",
"max_line_length": 342,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/Homomorphisms/Lemmas2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 1235,
"size": 3748
} |
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong; cong₂; _≢_)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.List using (List; []; _∷_; takeWhile; dropWhile)
open import Data.List.All using (All; []; _∷_)
open import Data.Bool using (Bool; true; false; T)
open import Data.Unit using (⊤; tt)
open import Relation.Nullary using (¬_)
open import Function using (_∘_)
module TakeDropBool (A : Set) (P : A → Bool) where
Head : ∀ {A : Set} → (A → Bool) → List A → Set
Head P [] = ⊥
Head P (c ∷ s) = T (P c)
data Book (x : A) (b : Bool) : Set where
book : P x ≡ b → Book x b
boo : ∀ (x : A) → Book x (P x)
boo x = book refl
dropWhile-lemma : ∀ (s : List A) → ¬ Head P (dropWhile P s)
dropWhile-lemma [] = λ()
dropWhile-lemma (c ∷ s) with P c | boo c
... | true | _ = dropWhile-lemma s
... | false | book eq rewrite eq = λ()
takeWhile-lemma : ∀ (s : List A) → All (T ∘ P) (takeWhile P s)
takeWhile-lemma [] = []
takeWhile-lemma (c ∷ s) with P c | boo c
... | false | _ = []
... | true | book eq rewrite eq = {! tt!} ∷ takeWhile-lemma s
{- Hole 0
Goal: T (P c)
————————————————————————————————————————————————————————————
s : List A
eq : P c ≡ true
c : A
P : A → Bool
A : Set
-}
| {
"alphanum_fraction": 0.4667106131,
"avg_line_length": 33.7111111111,
"ext": "agda",
"hexsha": "54ce883b57bc40906397f687705f5996b2d89e5d",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/TakeDropBool.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/TakeDropBool.agda",
"max_line_length": 91,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/TakeDropBool.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 476,
"size": 1517
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.DisjointlyPointedSet
module groups.DisjointlyPointedSet where
diff-and-separate : ∀ {i j} {X : Ptd i} (G : Group j)
→ (de⊙ X → Group.El G) → Group.El G × (MinusPoint X → Group.El G)
diff-and-separate {X = X} G f =
f (pt X) , λ x- → Group.diff G (f (fst x-)) (f (pt X))
shift-and-unite : ∀ {i j} {X : Ptd i} (G : Group j)
→ is-separable X
→ Group.El G × (MinusPoint X → Group.El G) → (de⊙ X → Group.El G)
shift-and-unite {X = X} G X-sep p x with X-sep x
... | inl _ = fst p
... | inr pt≠x = Group.comp G (snd p (x , pt≠x)) (fst p)
diff-and-separate-hom : ∀ {i j} {X : Ptd i} (G : AbGroup j)
→ Πᴳ (de⊙ X) (λ _ → AbGroup.grp G)
→ᴳ AbGroup.grp G ×ᴳ Πᴳ (MinusPoint X) (λ _ → AbGroup.grp G)
diff-and-separate-hom {X = X} G = group-hom (diff-and-separate grp) lemma where
open AbGroup G
abstract
lemma : preserves-comp
(Group.comp (Πᴳ (de⊙ X) (λ _ → AbGroup.grp G)))
(Group.comp (AbGroup.grp G ×ᴳ Πᴳ (MinusPoint X) (λ _ → AbGroup.grp G)))
(diff-and-separate grp)
lemma f₀ f₁ = pair×= idp
(λ= λ x- → diff-comp (f₀ (fst x-)) (f₁ (fst x-)) (f₀ (pt X)) (f₁ (pt X)))
diff-and-separate-is-equiv : ∀ {i j} {X : Ptd i} (G : Group j)
→ is-separable X → is-equiv (diff-and-separate {X = X} G)
diff-and-separate-is-equiv {X = X} G X-sep = is-eq to from to-from (λ= ∘ from-to)
where
open Group G
to = diff-and-separate {X = X} G
from = shift-and-unite {X = X} G X-sep
abstract
fst-to-from : ∀ p → fst (to (from p)) == fst p
fst-to-from _ with X-sep (pt X)
... | inl _ = idp
... | inr pt≠pt = ⊥-rec (pt≠pt idp)
snd-to-from : ∀ p x → snd (to (from p)) x == snd p x
snd-to-from p x with X-sep (fst x)
... | inl pt=x = ⊥-rec (snd x pt=x)
... | inr pt≠x with X-sep (pt X)
... | inl _ = assoc (snd p (fst x , pt≠x)) (fst p) (inv (fst p))
∙ ap (comp (snd p (fst x , pt≠x))) (inv-r (fst p))
∙ unit-r (snd p (fst x , pt≠x))
∙ ap (λ neq → snd p (fst x , neq)) (prop-has-all-paths _ _)
... | inr pt≠pt = ⊥-rec (pt≠pt idp)
to-from : ∀ p → to (from p) == p
to-from p = pair×= (fst-to-from p) (λ= (snd-to-from p))
from-to : ∀ f x → from (to f) x == f x
from-to f x with X-sep x
... | inl idp = idp
... | inr _ = assoc (f x) (inv (f (pt X))) (f (pt X))
∙ ap (comp (f x)) (inv-l (f (pt X)))
∙ unit-r (f x)
diff-and-separate-iso : ∀ {i j} {X : Ptd i} (G : AbGroup j)
→ is-separable X
→ Πᴳ (de⊙ X) (λ _ → AbGroup.grp G)
≃ᴳ AbGroup.grp G ×ᴳ Πᴳ (MinusPoint X) (λ _ → AbGroup.grp G)
diff-and-separate-iso G X-sep =
diff-and-separate-hom G , diff-and-separate-is-equiv (AbGroup.grp G) X-sep
| {
"alphanum_fraction": 0.500168976,
"avg_line_length": 40.5342465753,
"ext": "agda",
"hexsha": "04e986f7f7e60cc4e19c80117221be8c97c17843",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/groups/DisjointlyPointedSet.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/groups/DisjointlyPointedSet.agda",
"max_line_length": 87,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/groups/DisjointlyPointedSet.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1129,
"size": 2959
} |
-- See also test/Succeed/InlineCompiled.agda
module _ where
id : {A : Set} → A → A
id x = x
{-# INLINE id #-}
-- this is pointless and should generate a warning in the info buffer
{-# COMPILE GHC id = \ _ x -> x #-}
| {
"alphanum_fraction": 0.6301369863,
"avg_line_length": 19.9090909091,
"ext": "agda",
"hexsha": "9672ad99ef790c5c9462fa9a944e272f0baf2a78",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/CompilationWarnings.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/CompilationWarnings.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/CompilationWarnings.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 63,
"size": 219
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NConnected
open import lib.types.TLevel
open import lib.NType2
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Pointed
open import lib.types.LoopSpace
open import lib.types.Truncation
open import lib.types.PathSet
module lib.types.Cover where
{-
The definition of covering spaces.
-}
record Cover {i} (A : Type i) j : Type (lmax i (lsucc j)) where
constructor cover
field
Fiber : A → Type j
Fiber-level : ∀ a → is-set (Fiber a)
Fiber-is-set = Fiber-level
TotalSpace = Σ A Fiber
-- Basic lemmas
module _ {i} {A : Type i} {j} where
open Cover
-- Equality between covers.
private
cover=′ : {c₁ c₂ : Cover A j} → Fiber c₁ == Fiber c₂ → c₁ == c₂
cover=′ {cover f _} {cover .f _} idp = ap (cover f) $
prop-has-all-paths (Π-is-prop λ _ → is-set-is-prop) _ _
cover= : {c₁ c₂ : Cover A j} → (∀ a → Fiber c₁ a ≃ Fiber c₂ a)
→ c₁ == c₂
cover= F≃ = cover=′ (λ= λ a → ua $ F≃ a)
-- The definition of universality in terms of connectedness.
is-universal : Cover A j → Type (lmax i j)
is-universal cov = is-connected 1 $ TotalSpace cov
-- In terms of connectedness
UniversalCover : Type (lmax i (lsucc j))
UniversalCover = Σ (Cover A j) is-universal
-- Theorem: A covering space keeps higher homotopy groups.
module _ {i} (A∙ : Ptd i)
{j} (c : Cover (fst A∙) j)
(a↑ : Cover.Fiber c (snd A∙)) where
open Cover c
private
F = Cover.Fiber c
F-level = Cover.Fiber-level c
A = fst A∙
a = snd A∙
private
-- The projection map with one end free (in order to apply J).
to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ idp == p⇑ → idp == fst= p⇑
to′ idp=p⇑ = ap fst= idp=p⇑
-- The projection map from Ω²(Σ A F) to Ω²(A).
to : Ω^ 2 ⊙[ Σ A F , (a , a↑) ] → Ω^ 2 A∙
to p²⇑ = to′ {p⇑ = idp} p²⇑
-- Auxiliary synthesized path for injection.
idp=p↑ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
idp=p↑ idp = prop-has-all-paths (F-level a _ _) _ _
-- The injection map with some ends free (in order to apply J).
from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ]
→ idp == pair= p p↑
from′ idp=p idp=p↑ = pair== idp=p idp=p↑
-- The injection map from Ω²(A) to Ω²(Σ A F).
from : Ω^ 2 A∙ → Ω^ 2 ⊙[ Σ A F , (a , a↑) ]
from p² = from′ {p = idp} {p↑ = idp} p² (idp=p↑ p²)
-- Injection is left-inverse to projection (with some ends free).
from′-to′ : ∀ {p⇑ : _==_ {A = Σ A F} (a , a↑) (a , a↑)}
→ (idp=p⇑ : idp == p⇑)
→ (idp=snd=p⇑ : idp == snd= p⇑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ to′ idp=p⇑ ])
→ from′ (to′ idp=p⇑) idp=snd=p⇑ == idp=p⇑
[ (λ p⇑ → idp == p⇑) ↓ ! (pair=-η p⇑) ]
from′-to′ idp idp=snd=p⇑ = ap (from′ idp)
$ contr-has-all-paths (F-level a _ _ _ _) _ _
-- Injection is left-inverse to projection.
from-to : ∀ p²⇑ → from (to p²⇑) == p²⇑
from-to p²⇑ = from′-to′ {p⇑ = idp} p²⇑ (idp=p↑ (to′ p²⇑))
-- Injection is right-inverse to projection (with some ends free).
to′-from′ : ∀ {p : a == a} {p↑ : a↑ == a↑ [ F ↓ p ]}
→ (idp=p : idp == p)
→ (idp=p↑ : idp == p↑ -- aux
[ (λ p → a↑ == a↑ [ F ↓ p ]) ↓ idp=p ])
→ to′ (from′ idp=p idp=p↑) == idp=p
[ (λ p → idp == p) ↓ fst=-β p p↑ ]
to′-from′ idp idp = idp
-- Injection is right-inverse to projection.
to-from : ∀ p² → to (from p²) == p²
to-from p² = to′-from′ p² (idp=p↑ p²)
-- The theorem.
Ω²ΣAFiber≃Ω²A : Ω^ 2 (Σ A F , (a , a↑)) ≃ Ω^ 2 A∙
Ω²ΣAFiber≃Ω²A = to , is-eq to from to-from from-to
-- A natural way to construct a G-set from covering spaces.
module _ {i} {A : Type i} where
open Cover
cover-trace : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ Fiber cov a₁ → a₁ =₀ a₂
→ Fiber cov a₂
cover-trace cov a↑ p =
transport₀ (Fiber cov) (Fiber-is-set cov _) p a↑
abstract
cover-trace-idp₀ : ∀ {j} (cov : Cover A j) {a₁}
→ (a↑ : Fiber cov a₁)
→ cover-trace cov a↑ idp₀ == a↑
cover-trace-idp₀ cov a↑ = idp
cover-paste : ∀ {j} (cov : Cover A j) {a₁ a₂}
→ (a↑ : Fiber cov a₁)
→ (loop : a₁ =₀ a₁)
→ (p : a₁ =₀ a₂)
→ cover-trace cov (cover-trace cov a↑ loop) p
== cover-trace cov a↑ (loop ∙₀ p)
cover-paste cov a↑ loop p = ! $ trans₀-∙₀ (Fiber-is-set cov) loop p a↑
-- Path sets form a covering space
module _ {i} (A∙ : Ptd i) where
path-set-cover : Cover (fst A∙) i
path-set-cover = record
{ Fiber = λ a → snd A∙ =₀ a
; Fiber-level = λ a → Trunc-level
}
-- Cover morphisms
CoverHom : ∀ {i} {A : Type i} {j₁ j₂}
→ (cov1 : Cover A j₁)
→ (cov2 : Cover A j₂)
→ Type (lmax i (lmax j₁ j₂))
CoverHom (cover F₁ _) (cover F₂ _) = ∀ a → F₁ a → F₂ a
| {
"alphanum_fraction": 0.5157232704,
"avg_line_length": 31.8,
"ext": "agda",
"hexsha": "c6afb9bd86a907da73ba783a467bda37705697c3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Cover.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Cover.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Cover.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1999,
"size": 5088
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Semilattice where
open import Cubical.Algebra.Semilattice.Base public
| {
"alphanum_fraction": 0.7863247863,
"avg_line_length": 23.4,
"ext": "agda",
"hexsha": "240f18094633f1938113f0368cf8f2e0a9a5cbe0",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Algebra/Semilattice.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Algebra/Semilattice.agda",
"max_line_length": 51,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Algebra/Semilattice.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 29,
"size": 117
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.