Search is not available for this dataset
text
string | meta
dict |
---|---|
module Data.List.Equiv where
open import Logic.Propositional
import Lvl
open import Data.List
open import Structure.Operator
open import Structure.Setoid
open import Type
private variable ℓ ℓₑ ℓₚ : Lvl.Level
private variable T : Type{ℓ}
-- A correct equality relation on lists should state that prepend is a function and have the generalized cancellation properties for lists.
record Extensionality ⦃ equiv : Equiv{ℓₑ}(T) ⦄ (equiv-List : Equiv{ℓₚ}(List(T))) : Type{ℓₑ Lvl.⊔ Lvl.of(T) Lvl.⊔ ℓₚ} where
constructor intro
private instance _ = equiv-List
field
⦃ binaryOperator ⦄ : BinaryOperator(List._⊰_)
generalized-cancellationᵣ : ∀{x y : T}{l₁ l₂ : List(T)} → (x ⊰ l₁ ≡ y ⊰ l₂) → (x ≡ y)
generalized-cancellationₗ : ∀{x y : T}{l₁ l₂ : List(T)} → (x ⊰ l₁ ≡ y ⊰ l₂) → (l₁ ≡ l₂)
case-unequality : ∀{x : T}{l : List(T)} → (∅ ≢ x ⊰ l)
generalized-cancellation : ∀{x y : T}{l₁ l₂ : List(T)} → (x ⊰ l₁ ≡ y ⊰ l₂) → ((x ≡ y) ∧ (l₁ ≡ l₂))
generalized-cancellation p = [∧]-intro (generalized-cancellationᵣ p) (generalized-cancellationₗ p)
open Extensionality ⦃ … ⦄ renaming
( binaryOperator to [⊰]-binaryOperator
; generalized-cancellationₗ to [⊰]-generalized-cancellationₗ
; generalized-cancellationᵣ to [⊰]-generalized-cancellationᵣ
; generalized-cancellation to [⊰]-generalized-cancellation
; case-unequality to [∅][⊰]-unequal
) public
|
{
"alphanum_fraction": 0.6843636364,
"avg_line_length": 42.96875,
"ext": "agda",
"hexsha": "6370e115c015d5907255d8ae0cba4383db66ba8b",
"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/List/Equiv.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/List/Equiv.agda",
"max_line_length": 139,
"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/List/Equiv.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": 494,
"size": 1375
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Lemmas
open import Groups.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Orders.Total.Definition
open import Rings.Orders.Partial.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Orders.Total.Definition
open import Rings.IntegralDomains.Definition
module Rings.Orders.Total.AbsoluteValue {n m p : _} {A : Set n} {S : Setoid {n} {m} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {_<_ : Rel {_} {p} A} {pOrder : SetoidPartialOrder S _<_} {pOrderRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pOrderRing) where
open Ring R
open Group additiveGroup
open Setoid S
open SetoidPartialOrder pOrder
open TotallyOrderedRing order
open SetoidTotalOrder total
open PartiallyOrderedRing pOrderRing
open import Rings.Lemmas R
open import Rings.Orders.Partial.Lemmas pOrderRing
open import Rings.Orders.Total.Lemmas order
abs : A → A
abs a with totality 0R a
abs a | inl (inl 0<a) = a
abs a | inl (inr a<0) = inverse a
abs a | inr 0=a = a
absWellDefined : (a b : A) → a ∼ b → abs a ∼ abs b
absWellDefined a b a=b with totality 0R a
absWellDefined a b a=b | inl (inl 0<a) with totality 0R b
absWellDefined a b a=b | inl (inl 0<a) | inl (inl 0<b) = a=b
absWellDefined a b a=b | inl (inl 0<a) | inl (inr b<0) = exFalso (irreflexive {0G} (<Transitive 0<a (<WellDefined (Equivalence.symmetric eq a=b) (Equivalence.reflexive eq) b<0)))
absWellDefined a b a=b | inl (inl 0<a) | inr 0=b = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq a=b (Equivalence.symmetric eq 0=b)) 0<a))
absWellDefined a b a=b | inl (inr a<0) with totality 0R b
absWellDefined a b a=b | inl (inr a<0) | inl (inl 0<b) = exFalso (irreflexive {0G} (<Transitive 0<b (<WellDefined a=b (Equivalence.reflexive eq) a<0)))
absWellDefined a b a=b | inl (inr a<0) | inl (inr b<0) = inverseWellDefined additiveGroup a=b
absWellDefined a b a=b | inl (inr a<0) | inr 0=b = exFalso (irreflexive {0G} (<WellDefined (Equivalence.transitive eq a=b (Equivalence.symmetric eq 0=b)) (Equivalence.reflexive eq) a<0))
absWellDefined a b a=b | inr 0=a with totality 0R b
absWellDefined a b a=b | inr 0=a | inl (inl 0<b) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (Equivalence.transitive eq 0=a a=b)) 0<b))
absWellDefined a b a=b | inr 0=a | inl (inr b<0) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq 0=a a=b)) (Equivalence.reflexive eq) b<0))
absWellDefined a b a=b | inr 0=a | inr 0=b = a=b
triangleInequality : (a b : A) → ((abs (a + b)) < ((abs a) + (abs b))) || (abs (a + b) ∼ (abs a) + (abs b))
triangleInequality a b with totality 0R (a + b)
triangleInequality a b | inl (inl 0<a+b) with totality 0R a
triangleInequality a b | inl (inl 0<a+b) | inl (inl 0<a) with totality 0R b
triangleInequality a b | inl (inl 0<a+b) | inl (inl 0<a) | inl (inl 0<b) = inr (Equivalence.reflexive eq)
triangleInequality a b | inl (inl 0<a+b) | inl (inl 0<a) | inl (inr b<0) = inl (<WellDefined groupIsAbelian groupIsAbelian (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder b<0 (lemm2 b b<0)) a))
triangleInequality a b | inl (inl 0<a+b) | inl (inl 0<a) | inr 0=b = inr (Equivalence.reflexive eq)
triangleInequality a b | inl (inl 0<a+b) | inl (inr a<0) with totality 0R b
triangleInequality a b | inl (inl 0<a+b) | inl (inr a<0) | inl (inl 0<b) = inl (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder a<0 (lemm2 a a<0)) b)
triangleInequality a b | inl (inl 0<a+b) | inl (inr a<0) | inl (inr b<0) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<a+b (<WellDefined (Equivalence.reflexive eq) identLeft (ringAddInequalities a<0 b<0))))
triangleInequality a b | inl (inl 0<a+b) | inl (inr a<0) | inr 0=b = inl (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder a<0 (lemm2 a a<0)) b)
triangleInequality a b | inl (inl 0<a+b) | inr 0=a with totality 0R b
triangleInequality a b | inl (inl 0<a+b) | inr 0=a | inl (inl 0<b) = inr (Equivalence.reflexive eq)
triangleInequality a b | inl (inl 0<a+b) | inr 0=a | inl (inr b<0) = inl (<WellDefined groupIsAbelian groupIsAbelian (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder b<0 (lemm2 b b<0)) a))
triangleInequality a b | inl (inl 0<a+b) | inr 0=a | inr 0=b = inr (Equivalence.reflexive eq)
triangleInequality a b | inl (inr a+b<0) with totality 0G a
triangleInequality a b | inl (inr a+b<0) | inl (inl 0<a) with totality 0G b
triangleInequality a b | inl (inr a+b<0) | inl (inl 0<a) | inl (inl 0<b) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (<WellDefined identLeft (Equivalence.reflexive eq) (ringAddInequalities 0<a 0<b)) a+b<0))
triangleInequality a b | inl (inr a+b<0) | inl (inl 0<a) | inl (inr b<0) = inl (<WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq (invContravariant additiveGroup)) (inverseWellDefined additiveGroup groupIsAbelian)) (Equivalence.reflexive eq) (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder (lemm2' _ 0<a) 0<a) (inverse b)))
triangleInequality a b | inl (inr a+b<0) | inl (inl 0<a) | inr 0=b = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<a (<WellDefined (Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) identRight) (Equivalence.reflexive eq) a+b<0)))
triangleInequality a b | inl (inr a+b<0) | inl (inr a<0) with totality 0G b
triangleInequality a b | inl (inr a+b<0) | inl (inr a<0) | inl (inl 0<b) = inl (<WellDefined (Equivalence.symmetric eq (invContravariant additiveGroup)) groupIsAbelian (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder (lemm2' _ 0<b) 0<b) (inverse a)))
triangleInequality a b | inl (inr a+b<0) | inl (inr a<0) | inl (inr b<0) = inr (Equivalence.transitive eq (invContravariant additiveGroup) groupIsAbelian)
triangleInequality a b | inl (inr a+b<0) | inl (inr a<0) | inr 0=b = inr (Equivalence.transitive eq (invContravariant additiveGroup) (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (+WellDefined (Equivalence.transitive eq (inverseWellDefined additiveGroup (Equivalence.symmetric eq 0=b)) (invIdent additiveGroup)) (Equivalence.reflexive eq)) identLeft) (Equivalence.symmetric eq identRight)) (+WellDefined (Equivalence.reflexive eq) 0=b)))
triangleInequality a b | inl (inr a+b<0) | inr 0=a with totality 0G b
triangleInequality a b | inl (inr a+b<0) | inr 0=a | inl (inl 0<b) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<b (<WellDefined (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq)) identLeft) (Equivalence.reflexive eq) a+b<0)))
triangleInequality a b | inl (inr a+b<0) | inr 0=a | inl (inr b<0) = inr (Equivalence.transitive eq (invContravariant additiveGroup) (Equivalence.transitive eq groupIsAbelian (+WellDefined (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq (inverseWellDefined additiveGroup 0=a)) (invIdent additiveGroup)) 0=a) (Equivalence.reflexive eq))))
triangleInequality a b | inl (inr a+b<0) | inr 0=a | inr 0=b = exFalso (irreflexive {0G} (<WellDefined (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.symmetric eq 0=b)) identLeft) (Equivalence.reflexive eq) a+b<0))
triangleInequality a b | inr 0=a+b with totality 0G a
triangleInequality a b | inr 0=a+b | inl (inl 0<a) with totality 0G b
triangleInequality a b | inr 0=a+b | inl (inl 0<a) | inl (inl 0<b) = exFalso (irreflexive {0G} (<WellDefined identLeft (Equivalence.symmetric eq 0=a+b) (ringAddInequalities 0<a 0<b)))
triangleInequality a b | inr 0=a+b | inl (inl 0<a) | inl (inr b<0) = inl (<WellDefined groupIsAbelian groupIsAbelian (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder b<0 (lemm2 _ b<0)) a))
triangleInequality a b | inr 0=a+b | inl (inl 0<a) | inr 0=b = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (lemm3 _ _ (Equivalence.transitive eq 0=a+b groupIsAbelian) 0=b)) 0<a))
triangleInequality a b | inr 0=a+b | inl (inr a<0) with totality 0G b
triangleInequality a b | inr 0=a+b | inl (inr a<0) | inl (inl 0<b) = inl (orderRespectsAddition (SetoidPartialOrder.<Transitive pOrder a<0 (lemm2 _ a<0)) b)
triangleInequality a b | inr 0=a+b | inl (inr a<0) | inl (inr b<0) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq 0=a+b) identLeft (ringAddInequalities a<0 b<0)))
triangleInequality a b | inr 0=a+b | inl (inr a<0) | inr 0=b = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq (lemm3 _ _ (Equivalence.transitive eq 0=a+b groupIsAbelian) 0=b)) (Equivalence.reflexive eq) a<0))
triangleInequality a b | inr 0=a+b | inr 0=a with totality 0G b
triangleInequality a b | inr 0=a+b | inr 0=a | inl (inl 0<b) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq (lemm3 a b 0=a+b 0=a)) 0<b))
triangleInequality a b | inr 0=a+b | inr 0=a | inl (inr b<0) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq (lemm3 a b 0=a+b 0=a)) (Equivalence.reflexive eq) b<0))
triangleInequality a b | inr 0=a+b | inr 0=a | inr 0=b = inr (Equivalence.reflexive eq)
absZero : abs (Ring.0R R) ≡ Ring.0R R
absZero with totality (Ring.0R R) (Ring.0R R)
absZero | inl (inl x) = exFalso (irreflexive x)
absZero | inl (inr x) = exFalso (irreflexive x)
absZero | inr x = refl
absNegation : (a : A) → (abs a) ∼ (abs (inverse a))
absNegation a with totality 0R a
absNegation a | inl (inl 0<a) with totality 0G (inverse a)
absNegation a | inl (inl 0<a) | inl (inl 0<-a) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<-a (lemm2' a 0<a)))
absNegation a | inl (inl 0<a) | inl (inr -a<0) = Equivalence.symmetric eq (invTwice additiveGroup a)
absNegation a | inl (inl 0<a) | inr 0=-a = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq (invTwice additiveGroup a)) (inverseWellDefined additiveGroup (Equivalence.symmetric eq 0=-a))) (invIdent additiveGroup)) 0<a))
absNegation a | inl (inr a<0) with totality 0G (inverse a)
absNegation a | inl (inr a<0) | inl (inl 0<-a) = Equivalence.reflexive eq
absNegation a | inl (inr a<0) | inl (inr -a<0) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (<WellDefined (Equivalence.reflexive eq) (invTwice additiveGroup a) (lemm2 (inverse a) -a<0)) a<0))
absNegation a | inl (inr a<0) | inr 0=-a = exFalso (irreflexive {0G} (<WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq (Equivalence.transitive eq (inverseWellDefined additiveGroup 0=-a) (invTwice additiveGroup a))) (invIdent additiveGroup)) (Equivalence.reflexive eq) a<0))
absNegation a | inr 0=a with totality 0G (inverse a)
absNegation a | inr 0=a | inl (inl 0<-a) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (inverseWellDefined additiveGroup (Equivalence.symmetric eq 0=a)) (invIdent additiveGroup)) 0<-a))
absNegation a | inr 0=a | inl (inr -a<0) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.transitive eq (inverseWellDefined additiveGroup (Equivalence.symmetric eq 0=a)) (invIdent additiveGroup)) (Equivalence.reflexive eq) -a<0))
absNegation a | inr 0=a | inr 0=-a = Equivalence.transitive eq (Equivalence.symmetric eq 0=a) 0=-a
absRespectsTimes : (a b : A) → abs (a * b) ∼ (abs a) * (abs b)
absRespectsTimes a b with totality 0R a
absRespectsTimes a b | inl (inl 0<a) with totality 0R b
absRespectsTimes a b | inl (inl 0<a) | inl (inl 0<b) with totality 0R (a * b)
absRespectsTimes a b | inl (inl 0<a) | inl (inl 0<b) | inl (inl 0<ab) = Equivalence.reflexive eq
absRespectsTimes a b | inl (inl 0<a) | inl (inl 0<b) | inl (inr ab<0) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (orderRespectsMultiplication 0<a 0<b) ab<0))
absRespectsTimes a b | inl (inl 0<a) | inl (inl 0<b) | inr 0=ab = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=ab) (orderRespectsMultiplication 0<a 0<b)))
absRespectsTimes a b | inl (inl 0<a) | inl (inr b<0) with totality 0R (a * b)
absRespectsTimes a b | inl (inl 0<a) | inl (inr b<0) | inl (inl 0<ab) with <WellDefined (Equivalence.reflexive eq) ringMinusExtracts (orderRespectsMultiplication 0<a (lemm2 b b<0))
... | bl = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<ab (<WellDefined (invTwice additiveGroup _) (Equivalence.reflexive eq) (lemm2' _ bl))))
absRespectsTimes a b | inl (inl 0<a) | inl (inr b<0) | inl (inr ab<0) = Equivalence.symmetric eq ringMinusExtracts
absRespectsTimes a b | inl (inl 0<a) | inl (inr b<0) | inr 0=ab = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq 0=ab) (Equivalence.reflexive eq) (posTimesNeg a b 0<a b<0)))
absRespectsTimes a b | inl (inl 0<a) | inr 0=b with totality 0R (a * b)
absRespectsTimes a b | inl (inl 0<a) | inr 0=b | inl (inl 0<ab) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) (timesZero {a})) 0<ab))
absRespectsTimes a b | inl (inl 0<a) | inr 0=b | inl (inr ab<0) = exFalso ((irreflexive {0G} (<WellDefined (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) (timesZero {a})) (Equivalence.reflexive eq) ab<0)))
absRespectsTimes a b | inl (inl 0<a) | inr 0=b | inr 0=ab = Equivalence.reflexive eq
absRespectsTimes a b | inl (inr a<0) with totality 0R b
absRespectsTimes a b | inl (inr a<0) | inl (inl 0<b) with totality 0R (a * b)
absRespectsTimes a b | inl (inr a<0) | inl (inl 0<b) | inl (inl 0<ab) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<ab (<WellDefined *Commutative (Equivalence.reflexive eq) (posTimesNeg b a 0<b a<0))))
absRespectsTimes a b | inl (inr a<0) | inl (inl 0<b) | inl (inr ab<0) = Equivalence.symmetric eq ringMinusExtracts'
absRespectsTimes a b | inl (inr a<0) | inl (inl 0<b) | inr 0=ab = exFalso (irreflexive {0G} (<WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq 0=ab *Commutative)) (Equivalence.reflexive eq) (posTimesNeg b a 0<b a<0)))
absRespectsTimes a b | inl (inr a<0) | inl (inr b<0) with totality 0R (a * b)
absRespectsTimes a b | inl (inr a<0) | inl (inr b<0) | inl (inl 0<ab) = Equivalence.symmetric eq twoNegativesTimes
absRespectsTimes a b | inl (inr a<0) | inl (inr b<0) | inl (inr ab<0) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (negTimesPos a b a<0 b<0) ab<0))
absRespectsTimes a b | inl (inr a<0) | inl (inr b<0) | inr 0=ab = exFalso (exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=ab) (negTimesPos a b a<0 b<0))))
absRespectsTimes a b | inl (inr a<0) | inr 0=b with totality 0R (a * b)
absRespectsTimes a b | inl (inr a<0) | inr 0=b | inl (inl 0<ab) = exFalso (irreflexive {0R} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) (timesZero {a})) 0<ab))
absRespectsTimes a b | inl (inr a<0) | inr 0=b | inl (inr ab<0) = exFalso (irreflexive {0R} (<WellDefined (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) timesZero) (Equivalence.reflexive eq) ab<0))
absRespectsTimes a b | inl (inr a<0) | inr 0=b | inr 0=ab = Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) (Equivalence.transitive eq (Equivalence.transitive eq timesZero (Equivalence.symmetric eq timesZero)) (*WellDefined (Equivalence.reflexive eq) 0=b))
absRespectsTimes a b | inr 0=a with totality 0R b
absRespectsTimes a b | inr 0=a | inl (inl 0<b) with totality 0R (a * b)
absRespectsTimes a b | inr 0=a | inl (inl 0<b) | inl (inl 0<ab) = Equivalence.reflexive eq
absRespectsTimes a b | inr 0=a | inl (inl 0<b) | inl (inr ab<0) = Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (inverseWellDefined additiveGroup (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq)) (Equivalence.transitive eq *Commutative timesZero))) (invIdent additiveGroup)) (Equivalence.transitive eq (Equivalence.symmetric eq timesZero) *Commutative)) (*WellDefined 0=a (Equivalence.reflexive eq))
absRespectsTimes a b | inr 0=a | inl (inl 0<b) | inr 0=ab = Equivalence.reflexive eq
absRespectsTimes a b | inr 0=a | inl (inr b<0) with totality 0R (a * b)
absRespectsTimes a b | inr 0=a | inl (inr b<0) | inl (inl 0<ab) = Equivalence.transitive eq (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq)) *Commutative) (Equivalence.transitive eq timesZero (Equivalence.transitive eq (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative timesZero)) (*WellDefined 0=a (Equivalence.reflexive eq))))
absRespectsTimes a b | inr 0=a | inl (inr b<0) | inl (inr ab<0) = Equivalence.symmetric eq ringMinusExtracts
absRespectsTimes a b | inr 0=a | inl (inr b<0) | inr 0=ab = Equivalence.transitive eq (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq)) *Commutative) (Equivalence.transitive eq timesZero (Equivalence.transitive eq (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative timesZero)) (*WellDefined 0=a (Equivalence.reflexive eq))))
absRespectsTimes a b | inr 0=a | inr 0=b with totality 0R (a * b)
absRespectsTimes a b | inr 0=a | inr 0=b | inl (inl 0<ab) = exFalso (irreflexive {0R} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) timesZero) 0<ab))
absRespectsTimes a b | inr 0=a | inr 0=b | inl (inr ab<0) = exFalso (irreflexive {0R} (<WellDefined (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq 0=b)) timesZero) (Equivalence.reflexive eq) ab<0))
absRespectsTimes a b | inr 0=a | inr 0=b | inr 0=ab = Equivalence.reflexive eq
absNonnegative : {a : A} → (abs a < 0R) → False
absNonnegative {a} pr with totality 0R a
absNonnegative {a} pr | inl (inl x) = irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder x pr)
absNonnegative {a} pr | inl (inr x) = irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (<WellDefined (Equivalence.reflexive eq) (invTwice additiveGroup a) (lemm2 (inverse a) pr)) x)
absNonnegative {a} pr | inr x = irreflexive {0G} (<WellDefined (Equivalence.symmetric eq x) (Equivalence.reflexive eq) pr)
absZeroImpliesZero : {a : A} → abs a ∼ 0R → a ∼ 0R
absZeroImpliesZero {a} a=0 with totality 0R a
absZeroImpliesZero {a} a=0 | inl (inl 0<a) = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) a=0 0<a))
absZeroImpliesZero {a} a=0 | inl (inr a<0) = Equivalence.symmetric eq (lemm3 (inverse a) a (Equivalence.symmetric eq invLeft) (Equivalence.symmetric eq a=0))
absZeroImpliesZero {a} a=0 | inr 0=a = a=0
addingAbsCannotShrink : {a b : A} → 0G < b → 0G < ((abs a) + b)
addingAbsCannotShrink {a} {b} 0<b with totality 0G a
addingAbsCannotShrink {a} {b} 0<b | inl (inl x) = <WellDefined identLeft (Equivalence.reflexive eq) (ringAddInequalities x 0<b)
addingAbsCannotShrink {a} {b} 0<b | inl (inr x) = <WellDefined identLeft (Equivalence.reflexive eq) (ringAddInequalities (lemm2 a x) 0<b)
addingAbsCannotShrink {a} {b} 0<b | inr x = <WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.symmetric eq identLeft) (+WellDefined x (Equivalence.reflexive eq))) 0<b
greaterZeroImpliesEqualAbs : {a : A} → 0R < a → a ∼ abs a
greaterZeroImpliesEqualAbs {a} 0<a with totality 0R a
... | inl (inl _) = Equivalence.reflexive eq
... | inl (inr a<0) = exFalso (irreflexive (SetoidPartialOrder.<Transitive pOrder a<0 0<a))
... | inr 0=a = exFalso (irreflexive (<WellDefined 0=a (Equivalence.reflexive eq) 0<a))
lessZeroImpliesEqualNegAbs : {a : A} → a < 0R → abs a ∼ inverse a
lessZeroImpliesEqualNegAbs {a} a<0 with totality 0R a
... | inl (inr _) = Equivalence.reflexive eq
... | inl (inl 0<a) = exFalso (irreflexive (SetoidPartialOrder.<Transitive pOrder a<0 0<a))
... | inr 0=a = exFalso (irreflexive (<WellDefined (Equivalence.reflexive eq) 0=a a<0))
absZeroIsZero : abs 0R ∼ 0R
absZeroIsZero with totality 0R 0R
... | inl (inl bad) = exFalso (irreflexive bad)
... | inl (inr bad) = exFalso (irreflexive bad)
... | inr _ = Equivalence.reflexive eq
greaterThanAbsImpliesGreaterThan0 : {a b : A} → (abs a) < b → 0R < b
greaterThanAbsImpliesGreaterThan0 {a} {b} a<b with totality 0R a
greaterThanAbsImpliesGreaterThan0 {a} {b} a<b | inl (inl 0<a) = SetoidPartialOrder.<Transitive pOrder 0<a a<b
greaterThanAbsImpliesGreaterThan0 {a} {b} a<b | inl (inr a<0) = SetoidPartialOrder.<Transitive pOrder (lemm2 _ a<0) a<b
greaterThanAbsImpliesGreaterThan0 {a} {b} a<b | inr 0=a = <WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq) a<b
abs1Is1 : abs 1R ∼ 1R
abs1Is1 with totality 0R 1R
abs1Is1 | inl (inl 0<1) = Equivalence.reflexive eq
abs1Is1 | inl (inr 1<0) = exFalso (1<0False 1<0)
abs1Is1 | inr 0=1 = Equivalence.reflexive eq
absBoundedImpliesBounded : {a b : A} → abs a < b → a < b
absBoundedImpliesBounded {a} {b} a<b with totality 0G a
absBoundedImpliesBounded {a} {b} a<b | inl (inl x) = a<b
absBoundedImpliesBounded {a} {b} a<b | inl (inr x) = SetoidPartialOrder.<Transitive pOrder x (SetoidPartialOrder.<Transitive pOrder (lemm2 a x) a<b)
absBoundedImpliesBounded {a} {b} a<b | inr x = a<b
a-bPos : {a b : A} → ((a ∼ b) → False) → 0R < abs (a + inverse b)
a-bPos {a} {b} a!=b with totality 0R (a + inverse b)
a-bPos {a} {b} a!=b | inl (inl x) = x
a-bPos {a} {b} a!=b | inl (inr x) = lemm2 _ x
a-bPos {a} {b} a!=b | inr x = exFalso (a!=b (transferToRight additiveGroup (Equivalence.symmetric eq x)))
|
{
"alphanum_fraction": 0.7231485247,
"avg_line_length": 101.5183486239,
"ext": "agda",
"hexsha": "0959157e1828a52c278e412f50afdb3a3cb447da",
"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": "Rings/Orders/Total/AbsoluteValue.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": "Rings/Orders/Total/AbsoluteValue.agda",
"max_line_length": 483,
"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": "Rings/Orders/Total/AbsoluteValue.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": 8236,
"size": 22131
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.AbGroup.TensorProduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function hiding (flip)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Relation.Binary
open import Cubical.Data.Nat as ℕ
open import Cubical.Data.Int using (ℤ)
open import Cubical.Data.List
open import Cubical.Data.Sigma
open import Cubical.Data.Sum hiding (map)
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.AbGroup.Base
private
variable
ℓ ℓ' : Level
module _ (AGr : AbGroup ℓ) (BGr : AbGroup ℓ') where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
data _⨂₁_ : Type (ℓ-max ℓ ℓ') where
_⊗_ : (a : A) → (b : B) → _⨂₁_
_+⊗_ : (w : _⨂₁_) → (u : _⨂₁_) → _⨂₁_
+⊗Comm : (x y : _) → x +⊗ y ≡ y +⊗ x
+⊗Assoc : (x y z : _) → x +⊗ (y +⊗ z) ≡ (x +⊗ y) +⊗ z
+⊗IdL : (x : _) → (0A ⊗ 0B) +⊗ x ≡ x
⊗DistR+⊗ : (x : A) (y z : B) → x ⊗ (y +B z) ≡ ((x ⊗ y) +⊗ (x ⊗ z))
⊗DistL+⊗ : (x y : A) (z : B) → (x +A y) ⊗ z ≡ ((x ⊗ z) +⊗ (y ⊗ z))
⊗squash : isSet _⨂₁_
module _ {AGr : AbGroup ℓ} {BGr : AbGroup ℓ'} where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
A⊗B = AGr ⨂₁ BGr
⊗elimProp : ∀ {ℓ} {C : AGr ⨂₁ BGr → Type ℓ}
→ ((x : _) → isProp (C x))
→ (f : (x : A) (b : B) → C (x ⊗ b))
→ (g : ((x y : _) → C x → C y → C (x +⊗ y)))
→ (x : _) → C x
⊗elimProp p f g (a ⊗ b) = f a b
⊗elimProp p f g (x +⊗ y) = g x y (⊗elimProp p f g x) (⊗elimProp p f g y)
⊗elimProp {C = C} p f g (+⊗Comm x y j) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g x y (⊗elimProp p f g x) (⊗elimProp p f g y))
(g y x (⊗elimProp p f g y) (⊗elimProp p f g x)) (+⊗Comm x y) j
⊗elimProp {C = C} p f g (+⊗Assoc x y z j) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g x (y +⊗ z) (⊗elimProp p f g x)
(g y z (⊗elimProp p f g y) (⊗elimProp p f g z)))
(g (x +⊗ y) z (g x y (⊗elimProp p f g x)
(⊗elimProp p f g y)) (⊗elimProp p f g z)) (+⊗Assoc x y z) j
⊗elimProp {C = C} p f g (+⊗IdL x i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g (0A ⊗ 0B) x (f 0A 0B) (⊗elimProp p f g x))
(⊗elimProp p f g x)
(+⊗IdL x) i
⊗elimProp {C = C} p f g (⊗DistR+⊗ x y z i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(f x (y +B z)) (g (x ⊗ y) (x ⊗ z) (f x y) (f x z)) (⊗DistR+⊗ x y z) i
⊗elimProp {C = C} p f g (⊗DistL+⊗ x y z i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(f (x +A y) z) (g (x ⊗ z) (y ⊗ z) (f x z) (f y z)) (⊗DistL+⊗ x y z) i
⊗elimProp {C = C} p f g (⊗squash x y q r i j) =
isOfHLevel→isOfHLevelDep 2 {B = C} (λ x → isProp→isSet (p x))
_ _ (λ j → ⊗elimProp p f g (q j)) (λ j → ⊗elimProp p f g (r j))
(⊗squash x y q r) i j
-- Group structure
0⊗ : AGr ⨂₁ BGr
0⊗ = 0A ⊗ 0B
-⊗ : AGr ⨂₁ BGr → AGr ⨂₁ BGr
-⊗ (a ⊗ b) = (-A a) ⊗ b
-⊗ (x +⊗ x₁) = -⊗ x +⊗ -⊗ x₁
-⊗ (+⊗Comm x y i) = +⊗Comm (-⊗ x) (-⊗ y) i
-⊗ (+⊗Assoc x y z i) = +⊗Assoc (-⊗ x) (-⊗ y) (-⊗ z) i
-⊗ (+⊗IdL x i) = ((λ i → (GroupTheory.inv1g (AbGroup→Group AGr) i ⊗ 0B) +⊗ -⊗ x)
∙ +⊗IdL (-⊗ x)) i
-⊗ (⊗DistR+⊗ x y z i) = ⊗DistR+⊗ (-A x) y z i
-⊗ (⊗DistL+⊗ x y z i) = ((λ i → (GroupTheory.invDistr (AbGroup→Group AGr) x y
∙ +Comm strA (-A y) (-A x)) i ⊗ z)
∙ ⊗DistL+⊗ (-A x) (-A y) z) i
-⊗ (⊗squash x y p q i j) = ⊗squash _ _ (λ j → -⊗ (p j)) (λ j → -⊗ (q j)) i j
+⊗IdR : (x : A⊗B) → x +⊗ 0⊗ ≡ x
+⊗IdR x = +⊗Comm x 0⊗ ∙ +⊗IdL x
-------------------------------------------------------------------------------
-- Useful induction principle, which lets us view elements of A ⨂ B as lists
-- over (A × B). Used for the right cancellation law
unlist : List (A × B) → AGr ⨂₁ BGr
unlist [] = 0A ⊗ 0B
unlist (x ∷ x₁) = (fst x ⊗ snd x) +⊗ unlist x₁
unlist++ : (x y : List (A × B)) → unlist (x ++ y) ≡ (unlist x +⊗ unlist y)
unlist++ [] y = sym (+⊗IdL (unlist y))
unlist++ (x ∷ x₁) y = (λ i → (fst x ⊗ snd x) +⊗ (unlist++ x₁ y i))
∙ +⊗Assoc (fst x ⊗ snd x) (unlist x₁) (unlist y)
∃List : (x : AGr ⨂₁ BGr) → ∃[ l ∈ List (A × B) ] (unlist l ≡ x)
∃List = ⊗elimProp (λ _ → squash₁)
(λ a b → ∣ [ a , b ] , +⊗IdR (a ⊗ b) ∣₁)
λ x y → rec2 squash₁ λ {(l1 , p) (l2 , q) →
∣ (l1 ++ l2) , unlist++ l1 l2 ∙ cong₂ _+⊗_ p q ∣₁}
⊗elimPropUnlist : ∀ {ℓ} {C : AGr ⨂₁ BGr → Type ℓ}
→ ((x : _) → isProp (C x))
→ ((x : _) → C (unlist x))
→ (x : _) → C x
⊗elimPropUnlist {C = C} p f =
⊗elimProp p (λ x y → subst C (+⊗IdR (x ⊗ y)) (f [ x , y ]))
λ x y → PT.rec (isPropΠ2 λ _ _ → p _)
(PT.rec (isPropΠ3 λ _ _ _ → p _)
(λ {(l1 , p) (l2 , q) ind1 ind2
→ subst C (unlist++ l2 l1 ∙ cong₂ _+⊗_ q p) (f (l2 ++ l1))})
(∃List y))
(∃List x)
-----------------------------------------------------------------------------------
⊗AnnihilL : (x : B) → (0A ⊗ x) ≡ 0⊗
⊗AnnihilL x = sym (+⊗IdR _)
∙∙ cong ((0A ⊗ x) +⊗_) (sym cancelLem)
∙∙ +⊗Assoc (0A ⊗ x) (0A ⊗ x) (0A ⊗ (-B x))
∙∙ cong (_+⊗ (0A ⊗ (-B x))) inner
∙∙ cancelLem
where
cancelLem : (0A ⊗ x) +⊗ (0A ⊗ (-B x)) ≡ 0⊗
cancelLem = sym (⊗DistR+⊗ 0A x (-B x)) ∙ (λ i → 0A ⊗ +InvR strB x i)
inner : (0A ⊗ x) +⊗ (0A ⊗ x) ≡ 0A ⊗ x
inner = sym (⊗DistL+⊗ 0A 0A x) ∙ (λ i → +IdR strA 0A i ⊗ x)
⊗AnnihilR : (x : A) → (x ⊗ 0B) ≡ 0⊗
⊗AnnihilR x = sym (+⊗IdR _)
∙∙ cong ((x ⊗ 0B) +⊗_) (sym cancelLem)
∙∙ +⊗Assoc (x ⊗ 0B) (x ⊗ 0B) ((-A x) ⊗ 0B)
∙∙ cong (_+⊗ ((-A x) ⊗ 0B)) inner
∙∙ cancelLem
where
cancelLem : (x ⊗ 0B) +⊗ ((-A x) ⊗ 0B) ≡ 0⊗
cancelLem = sym (⊗DistL+⊗ x (-A x) 0B) ∙ (λ i → +InvR strA x i ⊗ 0B)
inner : (x ⊗ 0B) +⊗ (x ⊗ 0B) ≡ x ⊗ 0B
inner = sym (⊗DistR+⊗ x 0B 0B) ∙ (λ i → x ⊗ +IdR strB 0B i)
flip : (x : A) (b : B) → x ⊗ (-B b) ≡ ((-A x) ⊗ b)
flip x b = sym (+⊗IdR _)
∙ cong ((x ⊗ (-B b)) +⊗_) (sym cancelLemA)
∙ +⊗Assoc (x ⊗ (-B b)) (x ⊗ b) ((-A x) ⊗ b)
∙ cong (_+⊗ ((-A x) ⊗ b)) cancelLemB
∙ +⊗IdL _
where
cancelLemA : (x ⊗ b) +⊗ ((-A x) ⊗ b) ≡ 0⊗
cancelLemA = sym (⊗DistL+⊗ x (-A x) b) ∙ (λ i → +InvR strA x i ⊗ b) ∙ ⊗AnnihilL b
cancelLemB : (x ⊗ (-B b)) +⊗ (x ⊗ b) ≡ 0⊗
cancelLemB = sym (⊗DistR+⊗ x (-B b) b) ∙ (λ i → x ⊗ +InvL strB b i) ∙ ⊗AnnihilR x
+⊗InvR : (x : AGr ⨂₁ BGr) → (x +⊗ -⊗ x) ≡ 0⊗
+⊗InvR =
⊗elimPropUnlist (λ _ → ⊗squash _ _) h
where
h : (x : List (A × B)) → (unlist x +⊗ -⊗ (unlist x)) ≡ 0⊗
h [] = sym (⊗DistL+⊗ 0A (-A 0A) (0B))
∙ cong (λ x → _⊗_ {AGr = AGr} {BGr = BGr} x 0B) (+InvR strA 0A)
h (x ∷ x₁) = move4 (fst x ⊗ snd x) (unlist x₁) ((-A fst x) ⊗ snd x) (-⊗ (unlist x₁))
_+⊗_ +⊗Assoc +⊗Comm
∙∙ cong₂ _+⊗_ (sym (⊗DistL+⊗ (fst x) (-A (fst x)) (snd x))
∙∙ (λ i → +InvR strA (fst x) i ⊗ (snd x))
∙∙ ⊗AnnihilL (snd x))
(h x₁)
∙∙ +⊗IdR 0⊗
+⊗InvL : (x : AGr ⨂₁ BGr) → (-⊗ x +⊗ x) ≡ 0⊗
+⊗InvL x = +⊗Comm _ _ ∙ +⊗InvR x
module _ where
open AbGroupStr
_⨂_ : AbGroup ℓ → AbGroup ℓ' → AbGroup (ℓ-max ℓ ℓ')
fst (A ⨂ B) = A ⨂₁ B
0g (snd (A ⨂ B)) = 0⊗
AbGroupStr._+_ (snd (A ⨂ B)) = _+⊗_
AbGroupStr.- snd (A ⨂ B) = -⊗
isAbGroup (snd (A ⨂ B)) = makeIsAbGroup ⊗squash +⊗Assoc +⊗IdR +⊗InvR +⊗Comm
-------------- Elimination principle into AbGroups --------------
module _ {ℓ ℓ' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G)
_+A_ = _+G_ (snd A)
_+B_ = _+G_ (snd B)
0A = 0g (snd A)
0B = 0g (snd B)
⨂→AbGroup-elim : ∀ {ℓ} (C : AbGroup ℓ)
→ (f : (fst A × fst B) → fst C)
→ (f (0A , 0B) ≡ 0g (snd C))
→ (linR : (a : fst A) (x y : fst B)
→ f (a , x +B y) ≡ _+G_ (snd C) (f (a , x)) (f (a , y)))
→ (linL : (x y : fst A) (b : fst B)
→ f (x +A y , b) ≡ _+G_ (snd C) (f (x , b)) (f (y , b)))
→ A ⨂₁ B → fst C
⨂→AbGroup-elim C f p linR linL (a ⊗ b) = f (a , b)
⨂→AbGroup-elim C f p linR linL (x +⊗ x₁) =
_+G_ (snd C) (⨂→AbGroup-elim C f p linR linL x)
(⨂→AbGroup-elim C f p linR linL x₁)
⨂→AbGroup-elim C f p linR linL (+⊗Comm x x₁ i) =
+Comm (snd C) (⨂→AbGroup-elim C f p linR linL x)
(⨂→AbGroup-elim C f p linR linL x₁) i
⨂→AbGroup-elim C f p linR linL (+⊗Assoc x x₁ x₂ i) =
+Assoc (snd C) (⨂→AbGroup-elim C f p linR linL x)
(⨂→AbGroup-elim C f p linR linL x₁)
(⨂→AbGroup-elim C f p linR linL x₂) i
⨂→AbGroup-elim C f p linR linL (+⊗IdL x i) =
(cong (λ y → (snd C +G y) (⨂→AbGroup-elim C f p linR linL x)) p
∙ (+IdL (snd C) (⨂→AbGroup-elim C f p linR linL x))) i
⨂→AbGroup-elim C f p linR linL (⊗DistR+⊗ x y z i) = linR x y z i
⨂→AbGroup-elim C f p linR linL (⊗DistL+⊗ x y z i) = linL x y z i
⨂→AbGroup-elim C f p linR linL (⊗squash x x₁ x₂ y i i₁) =
is-set (snd C) _ _
(λ i → ⨂→AbGroup-elim C f p linR linL (x₂ i))
(λ i → ⨂→AbGroup-elim C f p linR linL (y i)) i i₁
⨂→AbGroup-elim-hom : ∀ {ℓ} (C : AbGroup ℓ)
→ (f : (fst A × fst B) → fst C) (linR : _) (linL : _) (p : _)
→ AbGroupHom (A ⨂ B) C
fst (⨂→AbGroup-elim-hom C f linR linL p) = ⨂→AbGroup-elim C f p linR linL
snd (⨂→AbGroup-elim-hom C f linR linL p) = makeIsGroupHom (λ x y → refl)
private
_* = AbGroup→Group
----------- Definition of universal property ------------
tensorFun : (A : Group ℓ) (B : Group ℓ') (T C : AbGroup (ℓ-max ℓ ℓ'))
(f : GroupHom A (HomGroup B T *))
→ GroupHom (T *) (C *)
→ GroupHom A (HomGroup B C *)
fst (fst (tensorFun A B T C (f , p) (g , q)) a) b = g (fst (f a) b)
snd (fst (tensorFun A B T C (f , p) (g , q)) a) =
makeIsGroupHom
λ x y → cong g (IsGroupHom.pres· (snd (f a)) x y)
∙ IsGroupHom.pres· q _ _
snd (tensorFun A B T C (f , p) (g , q)) =
makeIsGroupHom
λ x y → Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt λ b → cong g (funExt⁻ (cong fst (IsGroupHom.pres· p x y)) b)
∙ IsGroupHom.pres· q _ _)
isTensorProductOf_and_ : AbGroup ℓ → AbGroup ℓ' → AbGroup (ℓ-max ℓ ℓ')→ Type _
isTensorProductOf_and_ {ℓ} {ℓ'} A B T =
Σ[ f ∈ GroupHom (A *) ((HomGroup (B *) T) *) ]
((C : AbGroup (ℓ-max ℓ ℓ')) → isEquiv {A = GroupHom (T *) (C *)}
{B = GroupHom (A *) ((HomGroup (B *) C) *)}
(tensorFun (A *) (B *) T C f))
------ _⨂_ satisfies the universal property --------
module UP (AGr : AbGroup ℓ) (BGr : AbGroup ℓ') where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
mainF : GroupHom (AGr *) (HomGroup (BGr *) (AGr ⨂ BGr) *)
fst (fst mainF a) b = a ⊗ b
snd (fst mainF a) = makeIsGroupHom (⊗DistR+⊗ a)
snd mainF = makeIsGroupHom
λ x y → Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt (⊗DistL+⊗ x y))
isTensorProduct⨂ : (isTensorProductOf AGr and BGr) (AGr ⨂ BGr)
fst isTensorProduct⨂ = mainF
snd isTensorProduct⨂ C = isoToIsEquiv mainIso
where
invF : GroupHom (AGr *) (HomGroup (BGr *) C *) → GroupHom ((AGr ⨂ BGr) *) (C *)
fst (invF (f , p)) = F
where
lem : f (0g (snd AGr)) .fst (0g (snd BGr)) ≡ 0g (snd C)
lem = funExt⁻ (cong fst (IsGroupHom.pres1 p)) (0g (snd BGr))
F : ((AGr ⨂ BGr) *) .fst → (C *) .fst
F (a ⊗ b) = f a .fst b
F (x +⊗ x₁) = _+G_ (snd C) (F x) (F x₁)
F (+⊗Comm x x₁ i) = +Comm (snd C) (F x) (F x₁) i
F (+⊗Assoc x y z i) = +Assoc (snd C) (F x) (F y) (F z) i
F (+⊗IdL x i) = (cong (λ y → _+G_ (snd C) y (F x)) lem ∙ +IdL (snd C) (F x)) i
F (⊗DistR+⊗ x y z i) = IsGroupHom.pres· (f x .snd) y z i
F (⊗DistL+⊗ x y z i) = fst (IsGroupHom.pres· p x y i) z
F (⊗squash x x₁ x₂ y i i₁) = is-set (snd C) (F x) (F x₁)
(λ i → F (x₂ i)) (λ i → F (y i)) i i₁
snd (invF (f , p)) = makeIsGroupHom λ x y → refl
mainIso : Iso (GroupHom ((AGr ⨂ BGr) *) (C *))
(GroupHom (AGr *) (HomGroup (BGr *) C *))
Iso.fun mainIso = _
Iso.inv mainIso = invF
Iso.rightInv mainIso (f , p) = Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt λ a → Σ≡Prop (λ _ → isPropIsGroupHom _ _) refl)
Iso.leftInv mainIso (f , p) =
Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt (⊗elimProp (λ _ → is-set (snd C) _ _)
(λ _ _ → refl)
λ x y ind1 ind2 → cong₂ (_+G_ (snd C)) ind1 ind2
∙ sym (IsGroupHom.pres· p x y)))
-------------------- Commutativity ------------------------
commFun : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} → A ⨂₁ B → B ⨂₁ A
commFun (a ⊗ b) = b ⊗ a
commFun (x +⊗ x₁) = commFun x +⊗ commFun x₁
commFun (+⊗Comm x x₁ i) = +⊗Comm (commFun x) (commFun x₁) i
commFun (+⊗Assoc x x₁ x₂ i) = +⊗Assoc (commFun x) (commFun x₁) (commFun x₂) i
commFun (+⊗IdL x i) = +⊗IdL (commFun x) i
commFun (⊗DistR+⊗ x y z i) = ⊗DistL+⊗ y z x i
commFun (⊗DistL+⊗ x y z i) = ⊗DistR+⊗ z x y i
commFun (⊗squash x x₁ x₂ y i i₁) = ⊗squash (commFun x) (commFun x₁)
(λ i → commFun (x₂ i)) (λ i → commFun (y i)) i i₁
commFun²≡id : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} (x : A ⨂₁ B)
→ commFun (commFun x) ≡ x
commFun²≡id = ⊗elimProp (λ _ → ⊗squash _ _)
(λ _ _ → refl)
(λ _ _ p q → cong₂ _+⊗_ p q)
⨂-commIso : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'}
→ GroupIso ((A ⨂ B) *) ((B ⨂ A) *)
Iso.fun (fst ⨂-commIso) = commFun
Iso.inv (fst ⨂-commIso) = commFun
Iso.rightInv (fst ⨂-commIso) = commFun²≡id
Iso.leftInv (fst ⨂-commIso) = commFun²≡id
snd ⨂-commIso = makeIsGroupHom λ x y → refl
⨂-comm : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} → AbGroupEquiv (A ⨂ B) (B ⨂ A)
fst ⨂-comm = isoToEquiv (fst (⨂-commIso))
snd ⨂-comm = snd ⨂-commIso
open AbGroupStr
-------------------- Associativity ------------------------
module _ {ℓ ℓ' ℓ'' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} {C : AbGroup ℓ''} where
private
f : (c : fst C) → AbGroupHom (A ⨂ B) (A ⨂ (B ⨂ C))
f c = ⨂→AbGroup-elim-hom (A ⨂ (B ⨂ C))
(λ ab → (fst ab) ⊗ ((snd ab) ⊗ c))
(λ a b b' → (λ i → a ⊗ (⊗DistL+⊗ b b' c i)) ∙ ⊗DistR+⊗ a (b ⊗ c) (b' ⊗ c))
(λ a a' b → ⊗DistL+⊗ a a' (b ⊗ c))
(⊗AnnihilL _ ∙ sym (⊗AnnihilL _))
assocHom : AbGroupHom ((A ⨂ B) ⨂ C) (A ⨂ (B ⨂ C))
assocHom = ⨂→AbGroup-elim-hom (A ⨂ (B ⨂ C))
(λ x → f (snd x) .fst (fst x))
helper
(λ x y b → IsGroupHom.pres· (snd (f b)) x y)
refl
where
helper : _
helper = ⊗elimProp (λ _ → isPropΠ2 λ _ _ → ⊗squash _ _)
(λ a b x y → (λ i → a ⊗ (⊗DistR+⊗ b x y i))
∙∙ ⊗DistR+⊗ a (b ⊗ x) (b ⊗ y)
∙∙ refl)
λ a b ind1 ind2 x y → cong₂ _+⊗_ (ind1 x y) (ind2 x y)
∙∙ move4 (f x .fst a) (f y .fst a) (f x .fst b) (f y .fst b)
_+⊗_ +⊗Assoc +⊗Comm
∙∙ cong₂ _+⊗_
(sym (IsGroupHom.pres· (snd (f x)) a b))
(IsGroupHom.pres· (snd (f y)) a b)
module _ {ℓ ℓ' ℓ'' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} {C : AbGroup ℓ''} where
private
f' : (a : fst A) → AbGroupHom (B ⨂ C) ((A ⨂ B) ⨂ C)
f' a = ⨂→AbGroup-elim-hom
((A ⨂ B) ⨂ C)
(λ bc → (a ⊗ fst bc) ⊗ snd bc)
(λ x y b → ⊗DistR+⊗ (a ⊗ x) y b)
(λ x y b → (λ i → (⊗DistR+⊗ a x y i) ⊗ b)
∙ ⊗DistL+⊗ (a ⊗ x) (a ⊗ y) b)
λ i → ⊗AnnihilR a i ⊗ (0g (snd C))
assocHom⁻ : AbGroupHom (A ⨂ (B ⨂ C)) ((A ⨂ B) ⨂ C)
assocHom⁻ = ⨂→AbGroup-elim-hom
((A ⨂ B) ⨂ C)
(λ abc → f' (fst abc) .fst (snd abc))
(λ a → IsGroupHom.pres· (snd (f' a)))
helper
refl
where
helper : _
helper = λ x y → ⊗elimProp
(λ _ → ⊗squash _ _)
(λ b c → (λ i → ⊗DistL+⊗ x y b i ⊗ c)
∙ ⊗DistL+⊗ (x ⊗ b) (y ⊗ b) c)
λ a b ind1 ind2 → cong₂ _+⊗_ ind1 ind2
∙∙ move4 _ _ _ _ _+⊗_ +⊗Assoc +⊗Comm
∙∙ cong₂ _+⊗_ (IsGroupHom.pres· (snd (f' x)) a b)
(IsGroupHom.pres· (snd (f' y)) a b)
⨂assocIso : Iso (A ⨂₁ (B ⨂ C)) ((A ⨂ B) ⨂₁ C)
Iso.fun ⨂assocIso = fst assocHom⁻
Iso.inv ⨂assocIso = fst assocHom
Iso.rightInv ⨂assocIso =
⊗elimProp (λ _ → ⊗squash _ _)
(⊗elimProp (λ _ → isPropΠ (λ _ → ⊗squash _ _))
(λ a b c → refl)
λ a b ind1 ind2 c → cong₂ _+⊗_ (ind1 c) (ind2 c)
∙ sym (⊗DistL+⊗ a b c))
λ x y p q → cong (fst assocHom⁻) (IsGroupHom.pres· (snd assocHom) x y)
∙∙ IsGroupHom.pres· (snd assocHom⁻) (fst assocHom x) (fst assocHom y)
∙∙ cong₂ _+⊗_ p q
Iso.leftInv ⨂assocIso =
⊗elimProp (λ _ → ⊗squash _ _)
(λ a → ⊗elimProp (λ _ → ⊗squash _ _)
(λ b c → refl)
λ x y ind1 ind2 →
cong (fst assocHom ∘ fst assocHom⁻) (⊗DistR+⊗ a x y)
∙∙ cong (fst assocHom) (IsGroupHom.pres· (snd assocHom⁻) (a ⊗ x) (a ⊗ y))
∙∙ IsGroupHom.pres· (snd assocHom) (fst assocHom⁻ (a ⊗ x)) (fst assocHom⁻ (a ⊗ y))
∙∙ cong₂ _+⊗_ ind1 ind2
∙∙ sym (⊗DistR+⊗ a x y))
λ x y p q → cong (fst assocHom) (IsGroupHom.pres· (snd assocHom⁻) x y)
∙∙ IsGroupHom.pres· (snd assocHom) (fst assocHom⁻ x) (fst assocHom⁻ y)
∙∙ cong₂ _+⊗_ p q
⨂assoc : AbGroupEquiv (A ⨂ (B ⨂ C)) ((A ⨂ B) ⨂ C)
fst ⨂assoc = isoToEquiv ⨂assocIso
snd ⨂assoc = snd assocHom⁻
|
{
"alphanum_fraction": 0.433604336,
"avg_line_length": 40.6653061224,
"ext": "agda",
"hexsha": "efdfb4f596ba9f7fbc4d78eeabd243d40bf2c341",
"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": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"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": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8789,
"size": 19926
}
|
module int where
open import bool
open import eq
open import nat
open import product
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
data pol : Set where
pos : pol
neg : pol
data sign : Set where
nonzero : pol → sign
zero : sign
data int : sign → Set where
+0 : int zero
unit : ∀ {p : pol} → int (nonzero p)
next_ : ∀ {p : pol} → int (nonzero p) → int (nonzero p)
data nonneg : sign → Set where
pos-nonneg : nonneg (nonzero pos)
zero-nonneg : nonneg zero
data nonpos : sign → Set where
neg-nonpos : nonpos (nonzero neg)
zero-nonpos : nonpos zero
ℤ = Σi sign int
ℤ-≥-0 = Σi sign (λ s → nonneg s × int s)
ℤ-≤-0 = Σi sign (λ s → nonpos s × int s)
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infixl 6 _+ℤ_
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
eq-pol : pol → pol → 𝔹
eq-pol pos pos = tt
eq-pol neg neg = tt
eq-pol pos neg = ff
eq-pol neg pos = ff
{- add a unit with the given polarity to the given int (so if the polarity
is pos we are adding one, if it is neg we are subtracting one).
Return the new int, together with its sign, which could change. -}
add-unit : pol → ∀{s : sign} → int s → ℤ
add-unit p +0 = , unit{p}
add-unit p (unit{p'}) = if eq-pol p p' then , next (unit{p}) else , +0
add-unit p (next_{p'} x) = if eq-pol p p' then , next (next x) else , x
_+ℤ_ : ℤ → ℤ → ℤ
(, +0) +ℤ (, x) = , x
(, x) +ℤ (, +0) = , x
(, x) +ℤ (, unit{p}) = add-unit p x
(, unit{p}) +ℤ (, x) = add-unit p x
(, next_{p} x) +ℤ (, next_{p'} y) with ((, x) +ℤ (, next y))
... | , r = add-unit p r
ℕ-to-ℤ : ℕ → ℤ-≥-0
ℕ-to-ℤ zero = , (zero-nonneg , +0)
ℕ-to-ℤ (suc x) with ℕ-to-ℤ x
... | , (zero-nonneg , y) = , ( pos-nonneg , unit )
... | , (pos-nonneg , y) = , ( pos-nonneg , next y)
|
{
"alphanum_fraction": 0.4587200782,
"avg_line_length": 26.5844155844,
"ext": "agda",
"hexsha": "b02d1aeca500d195e0a104927e1c6f60fb08c0a6",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "cruft/int.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "cruft/int.agda",
"max_line_length": 74,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "cruft/int.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 657,
"size": 2047
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Instances.Int where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Int
renaming (ℤ to ℤType ; _+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_)
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Properties
open GroupStr
ℤ : Group₀
fst ℤ = ℤType
1g (snd ℤ) = 0
_·_ (snd ℤ) = _+ℤ_
inv (snd ℤ) = _-ℤ_ 0
isGroup (snd ℤ) = isGroupℤ
where
abstract
isGroupℤ : IsGroup (pos 0) _+ℤ_ (_-ℤ_ (pos 0))
isGroupℤ = makeIsGroup isSetℤ +Assoc (λ _ → refl) (+Comm 0)
(λ x → +Comm x (pos 0 -ℤ x) ∙ minusPlus x 0)
(λ x → minusPlus x 0)
ℤHom : (n : ℤType) → GroupHom ℤ ℤ
fst (ℤHom n) x = n ·ℤ x
snd (ℤHom n) =
makeIsGroupHom λ x y → ·DistR+ n x y
negEquivℤ : GroupEquiv ℤ ℤ
fst negEquivℤ =
isoToEquiv
(iso (GroupStr.inv (snd ℤ))
(GroupStr.inv (snd ℤ))
(GroupTheory.invInv ℤ)
(GroupTheory.invInv ℤ))
snd negEquivℤ =
makeIsGroupHom λ x y
→ +Comm (pos 0) (-ℤ (x +ℤ y))
∙ -Dist+ x y
∙ cong₂ _+ℤ_ (+Comm (-ℤ x) (pos 0)) (+Comm (-ℤ y) (pos 0))
|
{
"alphanum_fraction": 0.6248037677,
"avg_line_length": 28.3111111111,
"ext": "agda",
"hexsha": "2878504172a660d724dfa793980df10711bc3156",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Instances/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Instances/Int.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MatthiasHu/cubical",
"max_stars_repo_path": "Cubical/Algebra/Group/Instances/Int.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 499,
"size": 1274
}
|
{-# OPTIONS --without-K --rewriting #-}
{-
This file contains a bunch of basic stuff which is needed early.
Maybe it should be organised better.
-}
module lib.Base where
{- Universes and typing
Agda has explicit universe polymorphism, which means that there is an actual
type of universe levels on which you can quantify. This type is called [ULevel]
and comes equipped with the following operations:
- [lzero] : [ULevel] (in order to have at least one universe)
- [lsucc] : [ULevel → ULevel] (the [i]th universe level is a term in the
[lsucc i]th universe)
- [lmax] : [ULevel → ULevel → ULevel] (in order to type dependent products (where
the codomain is in a uniform universe level)
This type is postulated below and linked to Agda’s universe polymorphism
mechanism via the built-in module Agda.Primitive (it’s the new way).
In plain Agda, the [i]th universe is called [Set i], which is not a very good
name from the point of view of HoTT, so we define [Type] as a synonym of [Set]
and [Set] should never be used again.
-}
open import Agda.Primitive public using (lzero)
renaming (Level to ULevel; lsuc to lsucc; _⊔_ to lmax)
Type : (i : ULevel) → Set (lsucc i)
Type i = Set i
Type₀ = Type lzero
Type0 = Type lzero
Type₁ = Type (lsucc lzero)
Type1 = Type (lsucc lzero)
{-
There is no built-in or standard way to coerce an ambiguous term to a given type
(like [u : A] in ML), the symbol [:] is reserved, and the Unicode [∶] is really
a bad idea.
So we’re using the symbol [_:>_], which has the advantage that it can micmic
Coq’s [u = v :> A].
-}
of-type : ∀ {i} (A : Type i) (u : A) → A
of-type A u = u
infix 40 of-type
syntax of-type A u = u :> A
{- Instance search -}
⟨⟩ : ∀ {i} {A : Type i} {{a : A}} → A
⟨⟩ {{a}} = a
{- Identity type
The identity type is called [Path] and [_==_] because the symbol [=] is
reserved in Agda.
The constant path is [idp]. Note that all arguments of [idp] are implicit.
-}
infix 30 _==_
data _==_ {i} {A : Type i} (a : A) : A → Type i where
idp : a == a
Path = _==_
{-# BUILTIN EQUALITY _==_ #-}
{- Paulin-Mohring J rule
At the time I’m writing this (July 2013), the identity type is somehow broken in
Agda dev, it behaves more or less as the Martin-Löf identity type instead of
behaving like the Paulin-Mohring identity type.
So here is the Paulin-Mohring J rule -}
J : ∀ {i j} {A : Type i} {a : A} (B : (a' : A) (p : a == a') → Type j) (d : B a idp)
{a' : A} (p : a == a') → B a' p
J B d idp = d
J' : ∀ {i j} {A : Type i} {a : A} (B : (a' : A) (p : a' == a) → Type j) (d : B a idp)
{a' : A} (p : a' == a) → B a' p
J' B d idp = d
{- Rewriting
This is a new pragma added to Agda to help create higher inductive types.
-}
infix 30 _↦_
postulate -- HIT
_↦_ : ∀ {i} {A : Type i} → A → A → Type i
{-# BUILTIN REWRITE _↦_ #-}
{- Unit type
The unit type is defined as record so that we also get the η-rule definitionally.
-}
record ⊤ : Type₀ where
instance constructor unit
Unit = ⊤
{-# BUILTIN UNIT ⊤ #-}
{- Dependent paths
The notion of dependent path is a very important notion.
If you have a dependent type [B] over [A], a path [p : x == y] in [A] and two
points [u : B x] and [v : B y], there is a type [u == v [ B ↓ p ]] of paths from
[u] to [v] lying over the path [p].
By definition, if [p] is a constant path, then [u == v [ B ↓ p ]] is just an
ordinary path in the fiber.
-}
PathOver : ∀ {i j} {A : Type i} (B : A → Type j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Type j
PathOver B idp u v = (u == v)
infix 30 PathOver
syntax PathOver B p u v =
u == v [ B ↓ p ]
{- Ap, coe and transport
Given two fibrations over a type [A], a fiberwise map between the two fibrations
can be applied to any dependent path in the first fibration ([ap↓]).
As a special case, when [A] is [Unit], we find the familiar [ap] ([ap] is
defined in terms of [ap↓] because it shouldn’t change anything for the user
and this is helpful in some rare cases)
-}
ap : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {x y : A}
→ (x == y → f x == f y)
ap f idp = idp
ap↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(g : {a : A} → B a → C a) {x y : A} {p : x == y}
{u : B x} {v : B y}
→ (u == v [ B ↓ p ] → g u == g v [ C ↓ p ])
ap↓ g {p = idp} p = ap g p
{-
[apd↓] is defined in lib.PathOver. Unlike [ap↓] and [ap], [apd] is not
definitionally a special case of [apd↓]
-}
apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → f x == f y [ B ↓ p ]
apd f idp = idp
{-
An equality between types gives two maps back and forth
-}
coe : ∀ {i} {A B : Type i} (p : A == B) → A → B
coe idp x = x
coe! : ∀ {i} {A B : Type i} (p : A == B) → B → A
coe! idp x = x
{-
The operations of transport forward and backward are defined in terms of [ap]
and [coe], because this is more convenient in practice.
-}
transport : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y)
→ (B x → B y)
transport B p = coe (ap B p)
transport! : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A} (p : x == y)
→ (B y → B x)
transport! B p = coe! (ap B p)
{- Π-types
Shorter notation for Π-types.
-}
Π : ∀ {i j} (A : Type i) (P : A → Type j) → Type (lmax i j)
Π A P = (x : A) → P x
{- Σ-types
Σ-types are defined as a record so that we have definitional η.
-}
infixr 60 _,_
record Σ {i j} (A : Type i) (B : A → Type j) : Type (lmax i j) where
constructor _,_
field
fst : A
snd : B fst
open Σ public
pair= : ∀ {i j} {A : Type i} {B : A → Type j}
{a a' : A} (p : a == a') {b : B a} {b' : B a'}
(q : b == b' [ B ↓ p ])
→ (a , b) == (a' , b')
pair= idp q = ap (_ ,_) q
pair×= : ∀ {i j} {A : Type i} {B : Type j}
{a a' : A} (p : a == a') {b b' : B} (q : b == b')
→ (a , b) == (a' , b')
pair×= idp q = pair= idp q
{- Empty type
We define the eliminator of the empty type using an absurd pattern. Given that
absurd patterns are not consistent with HIT, we will not use empty patterns
anymore after that.
-}
data ⊥ : Type₀ where
Empty = ⊥
⊥-elim : ∀ {i} {P : ⊥ → Type i} → ((x : ⊥) → P x)
⊥-elim ()
Empty-elim = ⊥-elim
{- Negation and disequality -}
¬ : ∀ {i} (A : Type i) → Type i
¬ A = A → ⊥
_≠_ : ∀ {i} {A : Type i} → (A → A → Type i)
x ≠ y = ¬ (x == y)
{- Natural numbers -}
data ℕ : Type₀ where
O : ℕ
S : (n : ℕ) → ℕ
Nat = ℕ
{-# BUILTIN NATURAL ℕ #-}
{- Lifting to a higher universe level
The operation of lifting enjoys both β and η definitionally.
It’s a bit annoying to use, but it’s not used much (for now).
-}
record Lift {i j} (A : Type i) : Type (lmax i j) where
instance constructor lift
field
lower : A
open Lift public
{- Equational reasoning
Equational reasoning is a way to write readable chains of equalities.
The idea is that you can write the following:
t : a == e
t = a =⟨ p ⟩
b =⟨ q ⟩
c =⟨ r ⟩
d =⟨ s ⟩
e ∎
where [p] is a path from [a] to [b], [q] is a path from [b] to [c], and so on.
You often have to apply some equality in some context, for instance [p] could be
[ap ctx thm] where [thm] is the interesting theorem used to prove that [a] is
equal to [b], and [ctx] is the context.
In such cases, you can use instead [thm |in-ctx ctx]. The advantage is that
[ctx] is usually boring whereas the first word of [thm] is the most interesting
part.
_=⟨_⟩ is not definitionally the same thing as concatenation of paths _∙_ because
we haven’t defined concatenation of paths yet, and also you probably shouldn’t
reason on paths constructed with equational reasoning.
If you do want to reason on paths constructed with equational reasoning, check
out lib.types.PathSeq instead.
-}
infixr 10 _=⟨_⟩_
infix 15 _=∎
_=⟨_⟩_ : ∀ {i} {A : Type i} (x : A) {y z : A} → x == y → y == z → x == z
_ =⟨ idp ⟩ idp = idp
_=∎ : ∀ {i} {A : Type i} (x : A) → x == x
_ =∎ = idp
infixl 40 ap
syntax ap f p = p |in-ctx f
{- Various basic functions and function operations
The identity function on a type [A] is [idf A] and the constant function at some
point [b] is [cst b].
Composition of functions ([_∘_]) can handle dependent functions.
-}
idf : ∀ {i} (A : Type i) → (A → A)
idf A = λ x → x
cst : ∀ {i j} {A : Type i} {B : Type j} (b : B) → (A → B)
cst b = λ _ → b
infixr 80 _∘_
_∘_ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → (B a → Type k)}
→ (g : {a : A} → Π (B a) (C a)) → (f : Π A B) → Π A (λ a → C a (f a))
g ∘ f = λ x → g (f x)
-- Application
infixr 0 _$_
_$_ : ∀ {i j} {A : Type i} {B : A → Type j} → (∀ x → B x) → (∀ x → B x)
f $ x = f x
-- (Un)curryfication
curry : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Σ A B → Type k}
→ (∀ s → C s) → (∀ x y → C (x , y))
curry f x y = f (x , y)
uncurry : ∀ {i j k} {A : Type i} {B : A → Type j} {C : ∀ x → B x → Type k}
→ (∀ x y → C x y) → (∀ s → C (fst s) (snd s))
uncurry f (x , y) = f x y
{- Truncation levels
The type of truncation levels is isomorphic to the type of natural numbers but
"starts at -2".
-}
data TLevel : Type₀ where
⟨-2⟩ : TLevel
S : (n : TLevel) → TLevel
ℕ₋₂ = TLevel
⟨_⟩₋₂ : ℕ → ℕ₋₂
⟨ O ⟩₋₂ = ⟨-2⟩
⟨ S n ⟩₋₂ = S ⟨ n ⟩₋₂
{- Coproducts and case analysis -}
data Coprod {i j} (A : Type i) (B : Type j) : Type (lmax i j) where
inl : A → Coprod A B
inr : B → Coprod A B
infixr 80 _⊔_
_⊔_ = Coprod
Dec : ∀ {i} (P : Type i) → Type i
Dec P = P ⊔ ¬ P
{-
Pointed types and pointed maps.
[A ⊙→ B] was pointed, but it was never used as a pointed type.
-}
infix 60 ⊙[_,_]
record Ptd (i : ULevel) : Type (lsucc i) where
constructor ⊙[_,_]
field
de⊙ : Type i
pt : de⊙
open Ptd public
ptd : ∀ {i} (A : Type i) → A → Ptd i
ptd = ⊙[_,_]
ptd= : ∀ {i} {A A' : Type i} (p : A == A')
{a : A} {a' : A'} (q : a == a' [ idf _ ↓ p ])
→ ⊙[ A , a ] == ⊙[ A' , a' ]
ptd= idp q = ap ⊙[ _ ,_] q
Ptd₀ = Ptd lzero
infixr 0 _⊙→_
_⊙→_ : ∀ {i j} → Ptd i → Ptd j → Type (lmax i j)
⊙[ A , a₀ ] ⊙→ ⊙[ B , b₀ ] = Σ (A → B) (λ f → f a₀ == b₀)
⊙idf : ∀ {i} (X : Ptd i) → X ⊙→ X
⊙idf X = (λ x → x) , idp
⊙cst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙→ Y
⊙cst {Y = Y} = (λ x → pt Y) , idp
{-
Used in a hack to make HITs maybe consistent. This is just a parametrized unit
type (positively)
-}
data Phantom {i} {A : Type i} (a : A) : Type₀ where
phantom : Phantom a
{-
Numeric literal overloading
This enables writing numeric literals
-}
record FromNat {i} (A : Type i) : Type (lsucc i) where
field
in-range : ℕ → Type i
read : ∀ n → ⦃ _ : in-range n ⦄ → A
open FromNat ⦃...⦄ public using () renaming (read to from-nat)
{-# BUILTIN FROMNAT from-nat #-}
record FromNeg {i} (A : Type i) : Type (lsucc i) where
field
in-range : ℕ → Type i
read : ∀ n → ⦃ _ : in-range n ⦄ → A
open FromNeg ⦃...⦄ public using () renaming (read to from-neg)
{-# BUILTIN FROMNEG from-neg #-}
instance
ℕ-reader : FromNat ℕ
FromNat.in-range ℕ-reader _ = ⊤
FromNat.read ℕ-reader n = n
TLevel-reader : FromNat TLevel
FromNat.in-range TLevel-reader _ = ⊤
FromNat.read TLevel-reader n = S (S ⟨ n ⟩₋₂)
TLevel-neg-reader : FromNeg TLevel
FromNeg.in-range TLevel-neg-reader O = ⊤
FromNeg.in-range TLevel-neg-reader 1 = ⊤
FromNeg.in-range TLevel-neg-reader 2 = ⊤
FromNeg.in-range TLevel-neg-reader (S (S (S _))) = ⊥
FromNeg.read TLevel-neg-reader O = S (S ⟨-2⟩)
FromNeg.read TLevel-neg-reader 1 = S ⟨-2⟩
FromNeg.read TLevel-neg-reader 2 = ⟨-2⟩
FromNeg.read TLevel-neg-reader (S (S (S _))) ⦃()⦄
|
{
"alphanum_fraction": 0.5824583076,
"avg_line_length": 24.7986870897,
"ext": "agda",
"hexsha": "8af326a8b78cbbbfb4f5d5a5458aebf428df7aa0",
"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/Base.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/Base.agda",
"max_line_length": 85,
"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/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4321,
"size": 11333
}
|
{-# OPTIONS --show-implicit #-}
module AgdaFeatureTerminationViaExplicitness where
data Nat : Set where
zero : Nat
suc : (n : Nat) → Nat
id : {A : Set} → A → A
id = λ x → x
data Pat (n : Nat) : Set where
pzero : Pat n
psuc : Pat n → Pat n
data Cat : Nat → Set where
cat : ∀ {n} → Cat (suc n)
postulate
up : ∀ {n} → (Cat n → Cat n) → Cat (suc n)
down : ∀ {n} → Cat (suc n) → Cat n
rectify-works : ∀ {x y} → Pat x → Pat y
rectify-fails : ∀ {x y} → Pat x → Pat (id y)
test-works1 : ∀ {n} → Pat n → Cat n → Cat n
test-works1 (psuc t) acc = down (up (test-works1 t))
test-works1 t cat = up (test-works1 (rectify-works t))
{-# TERMINATING #-}
test-fails2 : ∀ {n} → Pat n → Cat n → Cat n
test-fails2 (psuc t) acc = down (up (test-fails2 t))
test-fails2 t cat = up (test-fails2 (rectify-fails t))
test-works3 : ∀ {n} → Pat n → Cat n → Cat n
test-works3 (psuc t) cat = down (up (test-works3 t))
test-works3 t@pzero (cat {n = n}) = up (test-works3 {n = n} (rectify-fails t))
|
{
"alphanum_fraction": 0.5850956697,
"avg_line_length": 26.8378378378,
"ext": "agda",
"hexsha": "f15399ce784adc45a8d4c655f7f93cef516a65d7",
"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/AgdaFeatureTerminationViaExplicitness.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/AgdaFeatureTerminationViaExplicitness.agda",
"max_line_length": 78,
"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/AgdaFeatureTerminationViaExplicitness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 389,
"size": 993
}
|
{-# OPTIONS --rewriting --confluence-check #-}
module Issue4333.M where
postulate
A : Set
_==_ : A → A → Set
{-# BUILTIN REWRITE _==_ #-}
postulate
a a₀' a₁' : A
p₀ : a == a₀'
p₁ : a == a₁'
B : A → Set
b : B a
|
{
"alphanum_fraction": 0.5330396476,
"avg_line_length": 14.1875,
"ext": "agda",
"hexsha": "66d0b0e5187d6817c5ebbfd4f0fa4fca7b2ca4b4",
"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/Issue4333/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/Issue4333/M.agda",
"max_line_length": 46,
"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/Issue4333/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": 90,
"size": 227
}
|
{-# OPTIONS --without-K --safe #-}
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 using (Rel)
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ℚᵘ; ↥_; ↧_; ↧ₙ_)
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 Algebra.Solver.Ring as Solver
import Algebra.Solver.Ring.AlmostCommutativeRing as ACR
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 _≃_
_≃_ : Rel ℝ 0ℓ
x ≃ y = ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 2) / n) {n≢0}
≃-refl : Reflexive _≃_
≃-refl {x} (suc k) = begin
ℚ.∣ seq x n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (seq x n)) ⟩
ℚ.∣ 0ℚᵘ ∣ ≈⟨ ℚP.≃-refl ⟩
0ℚᵘ ≤⟨ ℚP.∣p∣≃p⇒0≤p ℚP.≃-refl ⟩
((+ 2) / n) ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k
≃-symm : Symmetric _≃_
≃-symm {x} {y} x≃y (suc k) = begin
(ℚ.∣ seq y n ℚ.- seq x n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-trans (ℚP.≃-sym (ℚP.≃-reflexive (ℚP.∣-p∣≡∣p∣ (seq y n ℚ.- seq x n))))
(ℚP.∣-∣-cong (solve 2 (λ a b -> (:- (a :- b)) := b :- a) (ℚ.*≡* _≡_.refl) (seq y n) (seq x n)))) ⟩
ℚ.∣ seq x n ℚ.- seq y n ∣ ≤⟨ x≃y n ⟩
(+ 2) / n ∎)
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k
lemma1A : ∀ (x y : ℝ) -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 1) / j) {j≢0}
lemma1A x y x≃y (suc j) {j≢0} = 2 ℕ.* (suc j) ,
λ { (suc n) N<n → ℚP.≤-trans (x≃y (suc n)) (*≤* (+≤+ (ℕP.<⇒≤ (subst (ℕ._<_ (2 ℕ.* (suc j))) (cong suc (sym (ℕP.+-identityʳ n))) N<n))))}
abstract
no-0-divisors : ∀ (m n : ℕ) -> m ≢0 -> n ≢0 -> m ℕ.* n ≢0
no-0-divisors (suc m) (suc n) m≢0 n≢0 with (suc m) ℕ.* (suc n) ℕ.≟ 0
... | res = _
m≤∣m∣ : ∀ (m : ℤ) -> m ℤ.≤ + ℤ.∣ m ∣
m≤∣m∣ (+_ n) = ℤP.≤-reflexive _≡_.refl
m≤∣m∣ (-[1+_] n) = ℤ.-≤+
pos⇒≢0 : ∀ p → ℚ.Positive p → ℤ.∣ ↥ p ∣ ≢0
pos⇒≢0 p p>0 = fromWitnessFalse (contraposition ℤP.∣n∣≡0⇒n≡0 (≢-sym (ℤP.<⇒≢ (ℤP.positive⁻¹ p>0))))
0<⇒pos : ∀ p -> 0ℚᵘ ℚ.< p -> ℚ.Positive p
0<⇒pos p p>0 = ℚ.positive p>0
archimedean-ℚ : ∀ (p r : ℚᵘ) -> ℚ.Positive p -> ∃ λ (N : ℕ) -> r ℚ.< ((+ N) ℤ.* (↥ p)) / (↧ₙ p)
archimedean-ℚ (mkℚᵘ (+ p) q-1) (mkℚᵘ u v-1) p/q>0 = ℤ.∣ (+ 1) ℤ.+ 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 2 (λ pv t ->
pv :+ (t :* pv) := (con (+ 1) :+ t) :* pv)
_≡_.refl (+ (p ℕ.* v)) t ⟩
((+ 1) ℤ.+ t) ℤ.* (+ (p ℕ.* v)) ≤⟨ ℤP.*-monoʳ-≤-nonNeg (p ℕ.* v) (m≤∣m∣ ((+ 1) ℤ.+ t)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* (+ (p ℕ.* v)) ≡⟨ cong (λ x -> (+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* x) (sym (ℤP.pos-distrib-* p v)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* ((+ p) ℤ.* (+ v)) ≡⟨ sym (ℤP.*-assoc (+ ℤ.∣ (+ 1) ℤ.+ t ∣) (+ p) (+ v)) ⟩
(+ ℤ.∣ (+ 1) ℤ.+ t ∣) ℤ.* + p ℤ.* + v ∎)
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
v : ℕ
v = suc v-1
p≢0 : p ≢0
p≢0 = pos⇒≢0 ((+ p) / q) p/q>0
pv≢0 : p ℕ.* v ≢0
pv≢0 = no-0-divisors p v p≢0 _
r : ℕ
r = ((u ℤ.* (+ q)) modℕ (p ℕ.* v)) {pv≢0}
t : ℤ
t = ((u ℤ.* (+ q)) divℕ (p ℕ.* v)) {pv≢0}
alternate : ∀ (p : ℚᵘ) -> ∀ (N : ℕ) -> ((+ N) ℤ.* (↥ p)) / (↧ₙ p) ℚ.≃ ((+ N) / 1) ℚ.* p
alternate p N = ℚ.*≡* (cong (λ x -> ((+ N) ℤ.* (↥ p)) ℤ.* x) (ℤP.*-identityˡ (↧ p)))
get0ℚᵘ : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ((+ 0) / n) {n≢0} ℚ.≃ 0ℚᵘ
get0ℚᵘ (suc n) = ℚ.*≡* (trans (ℤP.*-zeroˡ (+ 1)) (sym (ℤP.*-zeroˡ (+ (suc n)))))
lemma1B : ∀ (x y : ℝ) -> (∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) ->
∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq y n ∣ ℚ.≤ ((+ 1) / j) {j≢0}) -> x ≃ y
lemma1B x y hyp (suc k₁) = lemA lemB
where
n : ℕ
n = suc k₁
∣xn-yn∣ : ℚᵘ
∣xn-yn∣ = ℚ.∣ seq x n ℚ.- seq y n ∣
2/n : ℚᵘ
2/n = (+ 2) / n
lemA : (∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / j) {j≢0}) ->
∣xn-yn∣ ℚ.≤ 2/n
lemA hyp with ℚP.<-cmp ∣xn-yn∣ 2/n
... | tri< a ¬b ¬c = ℚP.<⇒≤ a
... | tri≈ ¬a b ¬c = ℚP.≤-reflexive b
... | tri> ¬a ¬b c with archimedean-ℚ (∣xn-yn∣ ℚ.- 2/n) ((+ 3) / 1) isPos
where
0<res : 0ℚᵘ ℚ.< ∣xn-yn∣ ℚ.- 2/n
0<res = ℚP.<-respˡ-≃ (ℚP.+-inverseʳ 2/n) (ℚP.+-monoˡ-< (ℚ.- 2/n) c)
isPos : ℚ.Positive (∣xn-yn∣ ℚ.- 2/n)
isPos = ℚ.positive 0<res
... | 0 , 3<Nres = ⊥-elim (ℚP.<-asym 3<Nres (ℚP.<-respˡ-≃ (ℚP.≃-sym (get0ℚᵘ _)) (ℚP.positive⁻¹ {(+ 3) / 1} _)))
... | suc M , 3<Nres = ⊥-elim (ℚP.<-irrefl ℚP.≃-refl (ℚP.<-≤-trans part4 part5))
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = suc M
part1 : (+ 3) / 1 ℚ.< ((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)
part1 = ℚP.<-respʳ-≃ (alternate (∣xn-yn∣ ℚ.- 2/n) N) 3<Nres
part2a : ((+ 1) / N) ℚ.* (((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)) ℚ.≃ ∣xn-yn∣ ℚ.- 2/n
part2a = begin-equality
((+ 1) / N) ℚ.* (((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n)) ≈⟨ ℚP.≃-sym (ℚP.*-assoc ((+ 1) / N) ((+ N) / 1) (∣xn-yn∣ ℚ.- 2/n)) ⟩
((+ 1) / N) ℚ.* ((+ N) / 1) ℚ.* (∣xn-yn∣ ℚ.- 2/n) ≈⟨ ℚP.*-congʳ {∣xn-yn∣ ℚ.- 2/n} (ℚ.*≡* {((+ 1) / N) ℚ.* ((+ N) / 1)} {ℚ.1ℚᵘ}
(solve 1 (λ N ->
(con (+ 1) :* N) :* con (+ 1) := con (+ 1) :* (N :* con (+ 1)))
_≡_.refl (+ N))) ⟩
ℚ.1ℚᵘ ℚ.* (∣xn-yn∣ ℚ.- 2/n) ≈⟨ ℚP.*-identityˡ (∣xn-yn∣ ℚ.- 2/n) ⟩
∣xn-yn∣ ℚ.- 2/n ∎
part2 : ((+ 1) / N) ℚ.* ((+ 3) / 1) ℚ.< ∣xn-yn∣ ℚ.- 2/n
part2 = ℚP.<-respʳ-≃ part2a (ℚP.*-monoʳ-<-pos {(+ 1) / N} _ part1)
part3a : ((+ 1) / N) ℚ.* ((+ 3) / 1) ℚ.≃ (+ 3) / N
part3a = ℚ.*≡* (trans (cong (λ x -> x ℤ.* (+ N)) (ℤP.*-identityˡ (+ 3))) (cong (λ x -> (+ 3) ℤ.* x) (sym (ℤP.*-identityʳ (+ N)))))
part3 : (+ 3) / N ℚ.< ∣xn-yn∣ ℚ.- 2/n
part3 = ℚP.<-respˡ-≃ part3a part2
part4 : 2/n ℚ.+ ((+ 3) / N) ℚ.< ∣xn-yn∣
part4 = ℚP.<-respˡ-≃ (ℚP.+-comm ((+ 3) / N) 2/n) (ℚP.<-respʳ-≃ (ℚP.≃-trans (ℚP.+-congʳ ∣xn-yn∣ (ℚP.+-inverseʳ 2/n)) (ℚP.+-identityʳ ∣xn-yn∣))
(ℚP.<-respʳ-≃ (ℚP.+-assoc ∣xn-yn∣ (ℚ.- 2/n) 2/n) (ℚP.+-monoˡ-< 2/n part3)))
part5 : ∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / N)
part5 = hyp N
lemB : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∣xn-yn∣ ℚ.≤ 2/n ℚ.+ ((+ 3) / j) {j≢0}
lemB (suc k₂) with hyp (suc k₂)
... | N , proof = begin
∣xn-yn∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xn yn xm ym ->
xn ℚ:- yn ℚ:= (xn ℚ:- xm) ℚ:+ (xm ℚ:- ym) ℚ:+ (ym ℚ:- yn))
(ℚ.*≡* _≡_.refl) (seq x n) (seq y n) (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.≤-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ʳ-≤ (ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ℚ.∣ seq x m ℚ.- seq y m ∣)
(reg y m n) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ℚ.∣ seq x m ℚ.- seq y m ∣ ℚ.+ (((+ 1) / m) ℚ.+ (+ 1) / n) ≤⟨ ℚP.+-monoˡ-≤ (((+ 1) / m) ℚ.+ (+ 1) / n)
(ℚP.+-monoʳ-≤ ℚ.∣ seq x n ℚ.- seq x m ∣ (proof m (ℕP.m≤m⊔n (suc N) j))) ⟩
ℚ.∣ seq x n ℚ.- seq x m ∣ ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoˡ-≤ (((+ 1) / m) ℚ.+ (+ 1) / n)
(ℚP.+-monoˡ-≤ ((+ 1) / j) (reg x n m)) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / m) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoˡ-≤ ((((+ 1) / m) ℚ.+ ((+ 1) / n)))
(ℚP.+-monoˡ-≤ ((+ 1) / j)
(ℚP.+-monoʳ-≤ ((+ 1) / n) 1/m≤1/j)) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / m) ℚ.+ ((+ 1) / n)) ≤⟨ ℚP.+-monoʳ-≤ ((((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j))
(ℚP.+-monoˡ-≤ ((+ 1) / n) 1/m≤1/j) ⟩
(((+ 1) / n) ℚ.+ (+ 1) / j) ℚ.+ ((+ 1) / j) ℚ.+ (((+ 1) / j) ℚ.+ (+ 1) / n) ≈⟨ ℚ.*≡* (solve 2 (λ n j ->
{- Function for the solver -}
(((((con (+ 1) :* j :+ con (+ 1) :* n) :* j) :+ con (+ 1) :* (n :* j)) :* (j :* n)) :+ ((con (+ 1) :* n :+ con (+ 1) :* j) :* ((n :* j) :* j))) :* (n :* j) :=
((con (+ 2) :* j :+ con (+ 3) :* n) :* (((n :* j) :* j) :* (j :* n)))) _≡_.refl (+ n) (+ j)) ⟩
((+ 2) / n) ℚ.+ ((+ 3) / j) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
j : ℕ
j = suc k₂
m : ℕ
m = (suc N) ℕ.⊔ j
1/m≤1/j : ((+ 1) / m) ℚ.≤ (+ 1) / j
1/m≤1/j = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ j)))
(ℤP.≤-trans (+≤+ (ℕP.m≤n⊔m (suc N) j))
(ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ m))))))
≃-trans : Transitive _≃_
≃-trans {x} {y} {z} x≃y y≃z = lemma1B x z lem
where
lem : ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x n ℚ.- seq z n ∣ ℚ.≤ ((+ 1) / j) {j≢0}
lem (suc k₁) with (lemma1A x y x≃y (2 ℕ.* (suc k₁))) | (lemma1A y z y≃z (2 ℕ.* (suc k₁)))
lem (suc k₁) | N₁ , xy | N₂ , yz = N , λ {n N<n -> begin
ℚ.∣ seq x n ℚ.- seq z n ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 3 (λ x y z ->
x ℚ:- z ℚ:= (x ℚ:- y) ℚ:+ (y ℚ:- z)) (ℚ.*≡* _≡_.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.≤-trans (ℚP.+-monoˡ-≤ ℚ.∣ seq y n ℚ.- seq z n ∣ (xy n (ℕP.m⊔n≤o⇒m≤o (suc N₁) (suc N₂) N<n)))
(ℚP.+-monoʳ-≤ ((+ 1) / (2 ℕ.* j)) (yz n (ℕP.m⊔n≤o⇒n≤o (suc N₁) (suc N₂) N<n))) ⟩
((+ 1) / (2 ℕ.* j)) ℚ.+ ((+ 1) / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ (con (+ 1) :* (con (+ 2) :* j))) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j)))) _≡_.refl (+ j)) ⟩
(+ 1) / j ∎}
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:=_ to _ℚ:=_
; _:*_ to _ℚ:*_
; _:-_ to _ℚ:-_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
N : ℕ
N = N₁ ℕ.⊔ N₂
j : ℕ
j = suc k₁
antidensity-ℤ : ¬(∃ λ (n : ℤ) -> + 0 ℤ.< n × n ℤ.< + 1)
antidensity-ℤ (+[1+ n ] , +<+ m<n , +<+ (ℕ.s≤s ()))
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₂) = begin
ℚ.∣ (seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m))
ℚ.- (seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xm ym xn yn ->
(xm ℚ:+ ym) ℚ:- (xn ℚ:+ yn) ℚ:=
(xm ℚ:- xn) ℚ:+ (ym ℚ:- yn))
(ℚ.*≡* _≡_.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.≤-trans (ℚP.+-monoʳ-≤ ℚ.∣ seq x (2 ℕ.* m) ℚ.- seq x (2 ℕ.* n) ∣
(reg y (2 ℕ.* m) (2 ℕ.* n)))
(ℚP.+-monoˡ-≤ (((+ 1) / (2 ℕ.* m)) ℚ.+ ((+ 1) / (2 ℕ.* n)))
(reg x (2 ℕ.* m) (2 ℕ.* n))) ⟩
(((+ 1) / (2 ℕ.* m)) ℚ.+ ((+ 1) / (2 ℕ.* n))) ℚ.+ (((+ 1) / (2 ℕ.* m))
ℚ.+ ((+ 1) / (2 ℕ.* n))) ≈⟨ ℚ.*≡* (solve 2 (λ m n ->
(((con (+ 1) :* (con (+ 2) :* n) :+ con (+ 1) :* (con (+ 2) :* m))
:* ((con (+ 2) :* m) :* (con (+ 2) :* n))) :+
(con (+ 1) :* (con (+ 2) :* n) :+ con (+ 1) :* (con (+ 2) :* m))
:* ((con (+ 2) :* m) :* (con (+ 2) :* n))) :* (m :* n) :=
(con (+ 1) :* n :+ con (+ 1) :* m) :*
(((con (+ 2) :* m) :* (con (+ 2) :* n)) :*
(((con (+ 2) :* m) :* (con (+ 2) :* n)))))
_≡_.refl (+ m) (+ n)) ⟩
((+ 1) / m) ℚ.+ ((+ 1) / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
2ℚᵘ : ℚᵘ
2ℚᵘ = (+ 2) / 1
least-ℤ>ℚ : ℚᵘ -> ℤ
least-ℤ>ℚ p = + 1 ℤ.+ (↥ p divℕ ↧ₙ p)
abstract
least-ℤ>ℚ-greater : ∀ (p : ℚᵘ) -> p ℚ.< least-ℤ>ℚ p / 1
least-ℤ>ℚ-greater (mkℚᵘ p q-1) = ℚ.*<* (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 := (con (+ 1) :+ t) :* q) _≡_.refl (+ q) t ⟩
(+ 1 ℤ.+ t) ℤ.* (+ q) ∎)
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
t : ℤ
t = p divℕ q
r : ℕ
r = p modℕ q
least-ℤ>ℚ-least : ∀ (p : ℚᵘ) -> ∀ (n : ℤ) -> p ℚ.< n / 1 -> least-ℤ>ℚ p ℤ.≤ n
least-ℤ>ℚ-least (mkℚᵘ p q-1) n p/q<n with (least-ℤ>ℚ (mkℚᵘ p q-1)) ℤP.≤? n
... | .Bool.true because ofʸ P = P
... | .Bool.false because ofⁿ ¬P = ⊥-elim (antidensity-ℤ (n ℤ.- t , 0<n-t ,′ n-t<1))
where
open ℤP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
q : ℕ
q = suc q-1
t : ℤ
t = p divℕ q
r : ℕ
r = p modℕ q
n-t<1 : n ℤ.- t ℤ.< + 1
n-t<1 = ℤP.<-≤-trans (ℤP.+-monoˡ-< (ℤ.- t) (ℤP.≰⇒> ¬P))
(ℤP.≤-reflexive (solve 1 (λ t -> con (+ 1) :+ t :- t := con (+ 1)) _≡_.refl t))
part1 : (+ r) ℤ.+ t ℤ.* (+ q) ℤ.< n ℤ.* (+ q)
part1 = begin-strict
(+ r) ℤ.+ t ℤ.* (+ q) ≡⟨ trans (sym (a≡a%ℕn+[a/ℕn]*n p q)) (sym (ℤP.*-identityʳ p)) ⟩
p ℤ.* (+ 1) <⟨ ℚP.drop-*<* p/q<n ⟩
n ℤ.* (+ q) ∎
part2 : (+ r) ℤ.< (n ℤ.- t) ℤ.* (+ q)
part2 = begin-strict
+ r ≡⟨ solve 2 (λ r t -> r := r :+ t :- t) _≡_.refl (+ r) (t ℤ.* (+ q)) ⟩
(+ r) ℤ.+ t ℤ.* (+ q) ℤ.- t ℤ.* (+ q) <⟨ ℤP.+-monoˡ-< (ℤ.- (t ℤ.* + q)) part1 ⟩
n ℤ.* (+ q) ℤ.- t ℤ.* (+ q) ≡⟨ solve 3 (λ n q t -> n :* q :- t :* q := (n :- t) :* q) _≡_.refl n (+ q) t ⟩
(n ℤ.- t) ℤ.* (+ q) ∎
part3 : + 0 ℤ.< (n ℤ.- t) ℤ.* (+ q)
part3 = ℤP.≤-<-trans (+≤+ ℕ.z≤n) part2
0<n-t : + 0 ℤ.< n ℤ.- t
0<n-t = ℤP.*-cancelʳ-<-nonNeg q (ℤP.≤-<-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ q))) part3)
least : ∀ (p : ℚᵘ) -> ∃ λ (K : ℤ) ->
p ℚ.< (K / 1) × (∀ (n : ℤ) -> p ℚ.< (n / 1) -> K ℤ.≤ n)
least p = least-ℤ>ℚ p , least-ℤ>ℚ-greater p ,′ least-ℤ>ℚ-least p
K : ℝ -> ℕ
K x with ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ
... | mkℚᵘ p q-1 = suc ℤ.∣ p divℕ (suc q-1) ∣
private
Kx=1+t : ∀ (x : ℝ) -> + K x ≡ (+ 1) ℤ.+ (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))
Kx=1+t x = sym (trans (cong (λ x -> (+ 1) ℤ.+ x) (sym ∣t∣=t)) _≡_.refl)
where
t : ℤ
t = ↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) divℕ ↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)
0≤∣x₁∣+2 : 0ℚᵘ ℚ.≤ ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ
0≤∣x₁∣+2 = ℚP.≤-trans (ℚP.0≤∣p∣ (seq x 1)) (ℚP.p≤p+q {ℚ.∣ seq x 1 ∣} {2ℚᵘ} _)
∣t∣=t : + ℤ.∣ t ∣ ≡ t
∣t∣=t = ℤP.0≤n⇒+∣n∣≡n (0≤n⇒0≤n/ℕd (↥ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) (↧ₙ (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ)) (ℚP.≥0⇒↥≥0 0≤∣x₁∣+2))
canonical-property : ∀ (x : ℝ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< (+ K x) / 1 ×
(∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n)
canonical-property x = left ,′ right
where
left : ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< (+ K x) / 1
left = ℚP.<-respʳ-≃ (ℚP.≃-reflexive (ℚP./-cong (sym (Kx=1+t x)) _≡_.refl _ _))
(least-ℤ>ℚ-greater (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ))
right : ∀ (n : ℤ) -> ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ ℚ.< n / 1 -> + K x ℤ.≤ n
right n hyp = ℤP.≤-trans (ℤP.≤-reflexive (Kx=1+t x)) (least-ℤ>ℚ-least (ℚ.∣ seq x 1 ∣ ℚ.+ 2ℚᵘ) n hyp)
canonical-greater : ∀ (x : ℝ) -> ∀ (n : ℕ) -> {n ≢0} -> ℚ.∣ seq x n ∣ ℚ.< (+ K x) / 1
canonical-greater x (suc k₁) = begin-strict
ℚ.∣ seq x n ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ xn x1 ->
xn := xn :- x1 :+ x1)
(ℚ.*≡* _≡_.refl) (seq x n) (seq x 1)) ⟩
ℚ.∣ seq x n ℚ.- seq x 1 ℚ.+ seq x 1 ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (seq x n ℚ.- seq x 1) (seq x 1) ⟩
ℚ.∣ seq x n ℚ.- seq x 1 ∣ ℚ.+ ℚ.∣ seq x 1 ∣ ≤⟨ ℚP.+-monoˡ-≤ ℚ.∣ seq x 1 ∣ (reg x n 1) ⟩
(+ 1 / n) ℚ.+ (+ 1 / 1) ℚ.+ ℚ.∣ seq x 1 ∣ ≤⟨ ℚP.+-monoˡ-≤ ℚ.∣ seq x 1 ∣
(ℚP.≤-trans (ℚP.+-monoˡ-≤ (+ 1 / 1) 1/n≤1) ℚP.≤-refl) ⟩
2ℚᵘ ℚ.+ ℚ.∣ seq x 1 ∣ <⟨ ℚP.<-respˡ-≃ (ℚP.+-comm ℚ.∣ seq x 1 ∣ 2ℚᵘ) (proj₁ (canonical-property x)) ⟩
(+ K x) / 1 ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
1/n≤1 : + 1 / n ℚ.≤ + 1 / 1
1/n≤1 = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ 1)))
(ℤP.≤-trans (+≤+ (ℕ.s≤s ℕ.z≤n)) (ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ n))))))
∣∣p∣-∣q∣∣≤∣p-q∣ : ∀ p q -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
∣∣p∣-∣q∣∣≤∣p-q∣ p q = [ lemA p q , lemB p q ]′ (ℚP.≤-total ℚ.∣ q ∣ ℚ.∣ p ∣)
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
lemA : ∀ p q -> ℚ.∣ q ∣ ℚ.≤ ℚ.∣ p ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
lemA 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 ∣ ∎
lemB : ∀ p q -> ℚ.∣ p ∣ ℚ.≤ ℚ.∣ q ∣ -> ℚ.∣ ℚ.∣ p ∣ ℚ.- ℚ.∣ q ∣ ∣ ℚ.≤ ℚ.∣ p ℚ.- q ∣
lemB 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 ∣ ∣ ≤⟨ lemA 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 ∣ ∎
{-
Reminder: Make the proof of reg (x * y) abstract to avoid performance issues. Maybe do the same
with the other long proofs too.
-}
_*_ : ℝ -> ℝ -> ℝ
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₂) = begin
ℚ.∣ x₂ₖₘ ℚ.* y₂ₖₘ ℚ.- x₂ₖₙ ℚ.* y₂ₖₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ xm ym xn yn ->
xm ℚ:* ym ℚ:- xn ℚ:* yn ℚ:=
xm ℚ:* (ym ℚ:- yn) ℚ:+ yn ℚ:* (xm ℚ:- xn))
(ℚ.*≡* _≡_.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.≃-trans (ℚP.+-congˡ ℚ.∣ y₂ₖₙ ℚ.* (x₂ₖₘ ℚ.- x₂ₖₙ) ∣
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₖₘ (y₂ₖₘ ℚ.- y₂ₖₙ)))
(ℚP.+-congʳ (ℚ.∣ x₂ₖₘ ∣ ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣)
(ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ₖₙ (x₂ₖₘ ℚ.- x₂ₖₙ))) ⟩
ℚ.∣ x₂ₖₘ ∣ ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ (ℚ.∣ y₂ₖₙ ∣ ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ )
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣} _ ∣x₂ₖₘ∣≤k))
(ℚP.+-monoʳ-≤ ((+ k / 1) ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣)
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣} _ ∣y₂ₖₙ∣≤k)) ⟩
(+ k / 1) ℚ.* ℚ.∣ y₂ₖₘ ℚ.- y₂ₖₙ ∣ ℚ.+
(+ k / 1) ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣ ≤⟨ ℚP.≤-trans (ℚP.+-monoˡ-≤ ((+ k / 1) ℚ.* ℚ.∣ x₂ₖₘ ℚ.- x₂ₖₙ ∣)
(ℚP.*-monoʳ-≤-nonNeg {+ k / 1} _ (reg y 2km 2kn)))
(ℚP.+-monoʳ-≤ ((+ k / 1) ℚ.* ((+ 1 / 2km) ℚ.+ (+ 1 / 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 :* ((((con (+ 1) :* (con (+ 2) :* k :* n)) :+ (con (+ 1) :* (con (+ 2) :* k :* m))) :* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n))) :+
(((con (+ 1) :* (con (+ 2) :* k :* n)) :+ (con (+ 1) :* (con (+ 2) :* k :* m))) :* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)))))
:* (m :* n) :=
(con (+ 1) :* n :+ con (+ 1) :* m) :*
(con (+ 1) :* (((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)):* ((con (+ 2) :* k :* m) :* (con (+ 2) :* k :* n)))))
-- Other solver inputs
_≡_.refl (+ k) (+ m) (+ n)) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
k : ℕ
k = K x ℕ.⊔ K y
2km : ℕ
2km = 2 ℕ.* k ℕ.* m
2kn : ℕ
2kn = 2 ℕ.* k ℕ.* n
x₂ₖₘ : ℚᵘ
x₂ₖₘ = seq x (2 ℕ.* k ℕ.* m)
x₂ₖₙ : ℚᵘ
x₂ₖₙ = seq x (2 ℕ.* k ℕ.* n)
y₂ₖₘ : ℚᵘ
y₂ₖₘ = seq y (2 ℕ.* k ℕ.* m)
y₂ₖₙ : ℚᵘ
y₂ₖₙ = seq y (2 ℕ.* k ℕ.* n)
∣x₂ₖₘ∣≤k : ℚ.∣ x₂ₖₘ ∣ ℚ.≤ (+ k) / 1
∣x₂ₖₘ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-greater x 2km))
(*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityʳ (+ K x)))
(ℤP.≤-trans (+≤+ (ℕP.m≤m⊔n (K x) (K y))) (ℤP.≤-reflexive (sym (ℤP.*-identityʳ (+ k)))))))
∣y₂ₖₙ∣≤k : ℚ.∣ y₂ₖₙ ∣ ℚ.≤ (+ k) / 1
∣y₂ₖₙ∣≤k = ℚP.≤-trans (ℚP.<⇒≤ (canonical-greater y 2kn))
(*≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityʳ (+ K y)))
(ℤP.≤-trans (+≤+ (ℕP.m≤n⊔m (K x) (K y))) (ℤP.≤-reflexive (sym (ℤP.*-identityʳ (+ k)))))))
p≃q⇒-p≃-q : ∀ (p q : ℚᵘ) -> p ℚ.≃ q -> ℚ.- p ℚ.≃ ℚ.- q
p≃q⇒-p≃-q p q p≃q = ℚP.p-q≃0⇒p≃q (ℚ.- p) (ℚ.- q) (ℚP.≃-trans (ℚP.+-comm (ℚ.- p) (ℚ.- (ℚ.- q)))
(ℚP.≃-trans (ℚP.+-congˡ (ℚ.- p) (ℚP.neg-involutive q))
(ℚP.p≃q⇒p-q≃0 q p (ℚP.≃-sym p≃q))))
p≤∣p∣ : ∀ (p : ℚᵘ) -> p ℚ.≤ ℚ.∣ p ∣
p≤∣p∣ (mkℚᵘ (+_ n) q-1) = ℚP.≤-refl
p≤∣p∣ (mkℚᵘ (-[1+_] n) q-1) = *≤* ℤ.-≤+
{-
The book uses an extra assumption to simplify this proof. It seems, for a proper proof, a 4-way
case split is required, as done below.
-}
_⊔_ : ℝ -> ℝ -> ℝ
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 import Data.Rational.Unnormalised.Solver
open +-*-Solver
m : ℕ
m = suc k₁
n : ℕ
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)
(ℚ.*≡* _≡_.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)
(ℚ.*≡* _≡_.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≃q⇒-p≃-q (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≃q⇒-p≃-q (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) ∎
-_ : ℝ -> ℝ
seq (- x) n = ℚ.- seq x n
reg (- x) m n {m≢0} {n≢0} = 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 {m≢0} {n≢0}) ⟩
((+ 1) / m) ℚ.+ ((+ 1) / n) ∎
where
open ℚP.≤-Reasoning
_-_ : ℝ -> ℝ -> ℝ
x - y = x + (- y)
-- Gets a real representation of a rational number.
-- For a rational α, one real representation is the sequence
-- α* = (α, α, α, α, α, ...).
_⋆ : ℚᵘ -> ℝ
seq (p ⋆) n = p
reg (p ⋆) (suc m) (suc n) = begin
ℚ.∣ p ℚ.- p ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.p≃q⇒p-q≃0 p p ℚP.≃-refl) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
((+ 1) / (suc m)) ℚ.+ ((+ 1) / (suc n)) ∎
where
open ℚP.≤-Reasoning
{-
Proofs that the above operations are well-defined functions
(for setoid equality).
-}
{-
∣ x₂ₙ + y₂ₙ - z₂ₙ - w₂ₙ ∣
≤ ∣ x₂ₙ - z₂ₙ ∣ + ∣ y₂ₙ - w₂ₙ ∣
≤ 2/2n + 2/2n
= 2/n
-}
+-cong : Congruent₂ _≃_ _+_
+-cong {x} {z} {y} {w} x≃z y≃w (suc k₁) = begin
ℚ.∣ seq x (2 ℕ.* n) ℚ.+ seq y (2 ℕ.* n) ℚ.-
(seq z (2 ℕ.* n) ℚ.+ seq w (2 ℕ.* n)) ∣ ≤⟨ ℚP.≤-respˡ-≃ (ℚP.∣-∣-cong (ℚsolve 4 (λ x y z w ->
(x ℚ:- z) ℚ:+ (y ℚ:- w) ℚ:= x ℚ:+ y ℚ:- (z ℚ:+ w))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n)) (seq z (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.≤-trans (ℚP.+-monoˡ-≤ ℚ.∣ seq y (2 ℕ.* n) ℚ.- seq w (2 ℕ.* n) ∣ (x≃z (2 ℕ.* n)))
(ℚP.+-monoʳ-≤ (+ 2 / (2 ℕ.* n)) (y≃w (2 ℕ.* n))) ⟩
(+ 2 / (2 ℕ.* n)) ℚ.+ (+ 2 / (2 ℕ.* n)) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(con (+ 2) :* (con (+ 2) :* n) :+ con (+ 2) :* (con (+ 2) :* n)) :* n :=
(con (+ 2) :* ((con (+ 2) :* n) :* (con (+ 2) :* n)))) _≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
n : ℕ
n = suc k₁
+-congʳ : ∀ x {y z} -> y ≃ z -> x + y ≃ x + z
+-congʳ x {y} {z} y≃z = +-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
+-congˡ : ∀ x {y z} -> y ≃ z -> y + x ≃ z + x
+-congˡ x {y} {z} y≃z = +-cong {y} {z} {x} {x} y≃z (≃-refl {x})
+-comm : Commutative _≃_ _+_
+-comm x y (suc k₁) = 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) := con (0ℚᵘ))
ℚP.≃-refl (seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ *≤* (+≤+ ℕ.z≤n) ⟩
(+ 2) / n ∎
where
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
+-assoc : Associative _≃_ _+_
+-assoc x y z (suc k₁) = 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.≤-trans (ℚP.+-monoʳ-≤ ℚ.∣ seq x 4n ℚ.- seq x 2n ∣ (reg z 2n 4n))
(ℚP.+-monoˡ-≤ ((+ 1 / 2n) ℚ.+ (+ 1 / 4n)) (reg x 4n 2n)) ⟩
((+ 1 / 4n) ℚ.+ (+ 1 / 2n)) ℚ.+ ((+ 1 / 2n) ℚ.+ (+ 1 / 4n)) ≈⟨ ℚ.*≡* (solve 1 ((λ 2n ->
((con (+ 1) :* 2n :+ con (+ 1) :* (con (+ 2) :* 2n)) :*
(2n :* (con (+ 2) :* 2n)) :+
(con (+ 1) :* (con (+ 2) :* 2n) :+ con (+ 1) :* 2n) :*
((con (+ 2) :* 2n) :* 2n)) :* 2n :=
con (+ 3) :* (((con (+ 2) :* 2n) :* 2n) :*
(2n :* (con (+ 2) :* 2n)))))
_≡_.refl (+ 2n)) ⟩
+ 3 / 2n ≤⟨ *≤* (ℤP.*-monoʳ-≤-nonNeg 2n (+≤+ (ℕ.s≤s (ℕ.s≤s (ℕ.s≤s (ℕ.z≤n {1})))))) ⟩
+ 4 / 2n ≈⟨ ℚ.*≡* (solve 1 (λ n ->
con (+ 4) :* n := con (+ 2) :* (con (+ 2) :* n))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
2n : ℕ
2n = 2 ℕ.* n
4n : ℕ
4n = 2 ℕ.* 2n
0ℝ : ℝ
0ℝ = 0ℚᵘ ⋆
1ℝ : ℝ
1ℝ = ℚ.1ℚᵘ ⋆
+-identityˡ : LeftIdentity _≃_ 0ℝ _+_
+-identityˡ x (suc k₁) = 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 ->
(con (+ 1) :* n :+ con (+ 1) :* (con (+ 2) :* n)) :* (con (+ 2) :* n) :=
con (+ 3) :* ((con (+ 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 ->
con (+ 4) :* n := con (+ 2) :* (con (+ 2) :* n))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
n : ℕ
n = suc k₁
+-identityʳ : RightIdentity _≃_ 0ℝ _+_
+-identityʳ x = ≃-trans {x + 0ℝ} {0ℝ + x} {x} (+-comm x 0ℝ) (+-identityˡ x)
+-identity : Identity _≃_ 0ℝ _+_
+-identity = +-identityˡ , +-identityʳ
+-inverseʳ : RightInverse _≃_ 0ℝ -_ _+_
+-inverseʳ x (suc k₁) = begin
ℚ.∣ (seq x (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n)) ℚ.+ 0ℚᵘ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ 0ℚᵘ (ℚP.+-inverseʳ (seq x (2 ℕ.* n)))) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
+-inverseˡ : LeftInverse _≃_ 0ℝ -_ _+_
+-inverseˡ x = ≃-trans {(- x) + x} {x - x} {0ℝ} (+-comm (- x) x) (+-inverseʳ x)
+-inverse : Inverse _≃_ 0ℝ -_ _+_
+-inverse = +-inverseˡ , +-inverseʳ
⋆-distrib-+ : ∀ (p r : ℚᵘ) -> (p ℚ.+ r) ⋆ ≃ p ⋆ + r ⋆
⋆-distrib-+ (mkℚᵘ p q-1) (mkℚᵘ u v-1) (suc k₁) = begin
ℚ.∣ ((p / q) ℚ.+ (u / v)) ℚ.- ((p / q) ℚ.+ (u / v)) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ ((p / q) ℚ.+ (u / v))) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
(+ 2) / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
q : ℕ
q = suc q-1
v : ℕ
v = suc v-1
⋆-distrib-neg : ∀ (p : ℚᵘ) -> (ℚ.- p) ⋆ ≃ - (p ⋆)
⋆-distrib-neg p (suc k₁) = begin
ℚ.∣ ℚ.- p ℚ.- (ℚ.- p) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseʳ (ℚ.- p)) ⟩
0ℚᵘ ≤⟨ *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-zeroˡ (+ n))) (+≤+ ℕ.z≤n)) ⟩
(+ 2) / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
abstract
regular⇒cauchy : ∀ (x : ℝ) -> ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (m n : ℕ) ->
N ℕ.≤ m -> N ℕ.≤ n -> ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
regular⇒cauchy x (suc k₁) = 2 ℕ.* j , right
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
j : ℕ
j = suc k₁
N≤m⇒m≢0 : ∀ (m : ℕ) -> 2 ℕ.* j ℕ.≤ m -> m ≢0
N≤m⇒m≢0 (suc m) N≤m = _
N≤m⇒1/m≤1/N : ∀ (m : ℕ) -> (N≤m : 2 ℕ.* j ℕ.≤ m) -> (+ 1 / m) {N≤m⇒m≢0 m N≤m} ℚ.≤ (+ 1 / (2 ℕ.* j))
N≤m⇒1/m≤1/N (suc m) N≤m = *≤* (ℤP.≤-trans (ℤP.≤-reflexive (ℤP.*-identityˡ (+ (2 ℕ.* j))))
(ℤP.≤-trans (ℤ.+≤+ N≤m) (ℤP.≤-reflexive (sym (ℤP.*-identityˡ (+ (suc m)))))))
right : ∀ (m n : ℕ) -> 2 ℕ.* j ℕ.≤ m -> 2 ℕ.* j ℕ.≤ n ->
ℚ.∣ seq x m ℚ.- seq x n ∣ ℚ.≤ + 1 / j
right m n N≤m N≤n = begin
ℚ.∣ seq x m ℚ.- seq x n ∣ ≤⟨ reg x m n {N≤m⇒m≢0 m N≤m} {N≤m⇒m≢0 n N≤n} ⟩
(+ 1 / m) {N≤m⇒m≢0 m N≤m} ℚ.+ (+ 1 / n) {N≤m⇒m≢0 n N≤n} ≤⟨ ℚP.≤-trans
(ℚP.+-monoˡ-≤ ((+ 1 / n) {N≤m⇒m≢0 n N≤n}) (N≤m⇒1/m≤1/N m N≤m))
(ℚP.+-monoʳ-≤ (+ 1 / (2 ℕ.* j)) (N≤m⇒1/m≤1/N n N≤n)) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j)))) _≡_.refl (+ j)) ⟩
+ 1 / j ∎
equals-to-cauchy : ∀ (x y : ℝ) -> x ≃ y -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
∃ λ (N : ℕ) -> ∀ (m n : ℕ) -> N ℕ.< m -> N ℕ.< n ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ (+ 1 / j) {j≢0}
equals-to-cauchy x y x≃y (suc k₁) = N , lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
N₁ : ℕ
N₁ = proj₁ (lemma1A x y x≃y (2 ℕ.* j))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy x (2 ℕ.* j))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemA : ∀ (m n : ℕ) -> N ℕ.< m -> N ℕ.< n ->
ℚ.∣ seq x m ℚ.- seq y n ∣ ℚ.≤ + 1 / j
lemA (suc k₂) (suc k₃) N<m N<n = 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₂) (ℕP.<⇒≤ N<m))
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.<⇒≤ N<n)))
(proj₂ (lemma1A x y x≃y (2 ℕ.* j)) n
(ℕP.<-transʳ (ℕP.m≤m⊔n N₁ N₂) N<n)) ⟩
(+ 1 / (2 ℕ.* j)) ℚ.+
(+ 1 / (2 ℕ.* j)) ≈⟨ ℚ.*≡* (solve 1 (λ j ->
(con (+ 1) :* (con (+ 2) :* j) :+ (con (+ 1) :* (con (+ 2) :* j))) :* j :=
(con (+ 1) :* ((con (+ 2) :* j) :* (con (+ 2) :* j))))
_≡_.refl (+ j)) ⟩
+ 1 / j ∎
where
m : ℕ
m = suc k₂
n : ℕ
n = suc k₃
*-cong : Congruent₂ _≃_ _*_
*-cong {x} {z} {y} {w} x≃z y≃w = lemma1B (x * y) (z * w) lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K y
t : ℕ
t = K z ℕ.⊔ K w
N₁ : ℕ
N₁ = proj₁ (equals-to-cauchy x z x≃z (K y ℕ.* (2 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (equals-to-cauchy y w y≃w (K z ℕ.* (2 ℕ.* j)))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (x * y) n ℚ.- seq (z * w) n ∣ ℚ.≤ (+ 1 / j)
lemB (suc k₂) N<n = 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-greater y (2 ℕ.* r ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (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-greater z (2 ℕ.* t ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (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 :* con (+ 1)) :* (con (+ 1) :* (Kz :* (con (+ 2) :* j))) :+ (Kz :* con (+ 1) :* (con (+ 1) :* (Ky :* (con (+ 2) :* j))))) :* j :=
con (+ 1) :* ((con (+ 1) :* (Ky :* (con (+ 2) :* j))) :* (con (+ 1) :* (Kz :* (con (+ 2) :* j)))))
_≡_.refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
y₂ᵣₙ : ℚᵘ
y₂ᵣₙ = seq y (2 ℕ.* r ℕ.* n)
z₂ₜₙ : ℚᵘ
z₂ₜₙ = seq z (2 ℕ.* t ℕ.* n)
w₂ₜₙ : ℚᵘ
w₂ₜₙ = seq w (2 ℕ.* t ℕ.* n)
N<2kn : ∀ (k : ℕ) -> {k ≢0} -> N ℕ.< 2 ℕ.* k ℕ.* n
N<2kn (suc k) = ℕP.<-transˡ N<n (ℕP.m≤n*m n {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₂) N<k
N₂< : ∀ (k : ℕ) -> N ℕ.< k -> N₂ ℕ.< k
N₂< k N<k = ℕP.<-transʳ (ℕP.m≤n⊔m N₁ N₂) N<k
*-congˡ : LeftCongruent _≃_ _*_
*-congˡ {x} {y} {z} y≃z = *-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
*-congʳ : RightCongruent _≃_ _*_
*-congʳ {x} {y} {z} y≃z = *-cong {y} {z} {x} {x} y≃z (≃-refl {x})
*-comm : Commutative _≃_ _*_
*-comm x y (suc k₁) = begin
ℚ.∣ seq (x * y) n ℚ.- seq (y * x) n ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.≃-trans (ℚP.+-congʳ (seq (x * y) n)
(p≃q⇒-p≃-q _ _ (ℚP.≃-sym xyℚ=yxℚ)))
(ℚP.+-inverseʳ (seq (x * y) n))) ⟩
0ℚᵘ ≤⟨ *≤* (+≤+ ℕ.z≤n) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
xyℚ=yxℚ : seq (x * y) n ℚ.≃ seq (y * x) n
xyℚ=yxℚ = 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) ∎
{-
Proposition:
Multiplication on ℝ is associative.
Proof:
Let x,y,z∈ℝ. We must show that (xy)z = x(yz). Define
r = max{Kx, Ky} s = max{Kxy, Kz}
u = max{Kx, Kyz} t = max{Ky, Kz},
noting that Kxy is the canonical bound for x * y (similarly for Kyz).
Let j∈ℤ⁺. Since (xₙ), (yₙ), and (zₙ) are Cauchy sequences, there is
N₁,N₂,N₃∈ℤ⁺ such that:
∣xₘ - xₙ∣ ≤ 1 / (Ky * Kz * 3j) (m, n ≥ N₁),
∣yₘ - yₙ∣ ≤ 1 / (Kx * Kz * 3j) (m, n ≥ N₂), and
∣zₘ - zₙ∣ ≤ 1 / (Kx * Ky * 3j) (m, n ≥ N₃).
x = z and y = w
then
x * y = z * w
∣xₘ - zₙ∣ ≤ ε
Define N = max{N₁, N₂, N₃}. If we show that
∣x₄ᵣₛₙ * y₄ᵣₛₙ * z₂ₛₙ - x₂ᵤₙ * y₄ₜᵤₙ * z₄ₜᵤₙ∣ ≤ 1 / j
for all n ≥ N, then (xy)z = x(yz) by Lemma 1.
Note that, for all a, b, c, d in ℚ, we have
ab - cd = b(a - c) + c(b - d).
We will use this trick in our proof. We have:
∀ ε > 0 ∃ N ∈ ℕ ∀ m, n ≥ N -> ∣xₘ - xₙ∣ ≤ ε
∀ j ∈ ℤ⁺ ∃ N ∈ ℕ ∀ m, n ≥ N ∣ xn - yn ∣ ≤ 1/j
∀ n ∈ ℕ (∣ xn - yn ∣ ≤ 2/n)
∣x₄ᵣₛₙ * y₄ᵣₛₙ * z₂ₛₙ - x₂ᵤₙ * y₄ₜᵤₙ * z₄ₜᵤₙ∣
= ∣y₄ᵣₛₙ * z₂ₛₙ(x₄ᵣₛₙ - x₂ᵤₙ) + x₂ᵤₙ(y₄ᵣₛₙ * z₂ₛₙ - y₄ₜᵤₙ * z₄ₜᵤₙ)∣
= ∣y₄ᵣₛₙ * z₂ₛₙ(x₄ᵣₛₙ - x₂ᵤₙ) + x₂ᵤₙ(z₂ₛₙ(y₄ᵣₛₙ - y₄ₜᵤₙ) + y₄ₜᵤₙ(z₂ₛₙ - z₄ₜᵤₙ)∣
≤ ∣y₄ᵣₛₙ∣*∣z₂ₛₙ∣*∣x₄ᵣₛₙ - x₂ᵤₙ∣ + ∣x₂ᵤₙ∣*∣z₂ₛₙ∣*∣y₄ᵣₛₙ - y₄ₜᵤₙ∣ + ∣x₂ᵤₙ∣*∣y₄ₜᵤₙ∣*∣z₂ₛₙ - z₄ₜᵤₙ∣
≤ Ky * Kz * (1 / (Ky * Kz * 3j)) + Kx * Kz * (1 / (Kx * Kz * 3j)) + Kx * Ky * (1 / (Kx * Ky * 3j))
= 1 / 3j + 1 / 3j + 1 / 3j
= 1 / j.
Thus ∣x₄ᵣₛₙ*y₄ᵣₛₙ*z₂ₛₙ - x₂ᵤₙ*y₄ₜᵤₙ*z₄ₜᵤₙ∣ ≤ 1/j, as desired. □
-}
*-assoc : Associative _≃_ _*_
*-assoc x y z = lemma1B ((x * y) * z) (x * (y * z)) lemA
where
open ℚP.≤-Reasoning
r : ℕ
r = K x ℕ.⊔ K y
s : ℕ
s = K (x * y) ℕ.⊔ K z
u : ℕ
u = K x ℕ.⊔ K (y * z)
t : ℕ
t = K y ℕ.⊔ K z
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq z (2 ℕ.* s ℕ.* n) ℚ.-
seq x (2 ℕ.* u ℕ.* n) ℚ.* (seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)) ℚ.* seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x ((K y ℕ.* K z) ℕ.* (3 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
N₃ : ℕ
N₃ = proj₁ (regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
N : ℕ
N = (N₁ ℕ.⊔ N₂) ℕ.⊔ N₃
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) ℚ.* seq z (2 ℕ.* s ℕ.* n) ℚ.-
seq x (2 ℕ.* u ℕ.* n) ℚ.* (seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)) ℚ.* seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* 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 ->
(con (+ 1) :* ((con (+ 3) :* j) :* (con (+ 3) :* j)) :+ ((con (+ 1) :* (con (+ 3) :* j)) :+ (con (+ 1) :* (con (+ 3) :* j))) :* (con (+ 3) :* j)) :* j :=
(con (+ 1) :* ((con (+ 3) :* j) :* ((con (+ 3) :* j) :* (con (+ 3) :* j)))))
_≡_.refl (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₄ᵣₛₙ : ℚᵘ
x₄ᵣₛₙ = seq x (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
y₄ᵣₛₙ : ℚᵘ
y₄ᵣₛₙ = seq y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n))
z₂ₛₙ : ℚᵘ
z₂ₛₙ = seq z (2 ℕ.* s ℕ.* n)
x₂ᵤₙ : ℚᵘ
x₂ᵤₙ = seq x (2 ℕ.* u ℕ.* n)
y₄ₜᵤₙ : ℚᵘ
y₄ₜᵤₙ = seq y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
z₄ₜᵤₙ : ℚᵘ
z₄ₜᵤₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N≤4rsn : N ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N≤4rsn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans
(ℕP.m≤n*m n {4 ℕ.* r ℕ.* s} ℕP.0<1+n) (ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 3 (λ r s n ->
con (+ 4) :* r :* s :* n := con (+ 2) :* r :* (con (+ 2) :* s :* n))
_≡_.refl (+ r) (+ s) (+ n)))))
N₁≤4rsn : N₁ ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N₁≤4rsn = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4rsn)
N₁≤2un : N₁ ℕ.≤ 2 ℕ.* u ℕ.* n
N₁≤2un = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃))
(ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* u} ℕP.0<1+n))
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-greater y (2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {(+ K y) / 1} _ (ℚP.<⇒≤
(canonical-greater z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* ℚ.∣ x₄ᵣₛₙ ℚ.- x₂ᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K y ℕ.* K z) / 1} _
(proj₂ (regular⇒cauchy x (K y ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* u ℕ.* n) N₁≤4rsn N₁≤2un) ⟩
(+ (K y ℕ.* K z) / 1) ℚ.* (+ 1 / (K y ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Ky Kz j ->
((Ky :* Kz) :* con (+ 1)) :* (con (+ 3) :* j) :=
(con (+ 1) :* (con (+ 1) :* (Ky :* Kz :* (con (+ 3) :* j)))))
_≡_.refl (+ K y) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
N₂≤4rsn : N₂ ℕ.≤ 2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)
N₂≤4rsn = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4rsn)
N≤4tun : N ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N≤4tun = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {4 ℕ.* t ℕ.* u} ℕP.0<1+n)
(ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 3 (λ t u n ->
con (+ 4) :* t :* u :* n := con (+ 2) :* t :* (con (+ 2) :* u :* n))
_≡_.refl (+ t) (+ u) (+ n)))))
N₂≤4tun : N₂ ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N₂≤4tun = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂) N₃) N≤4tun)
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-greater x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-greater z (2 ℕ.* s ℕ.* n))))) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.* ℚ.∣ y₄ᵣₛₙ ℚ.- y₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K z) / 1} _
(proj₂ (regular⇒cauchy y (K x ℕ.* K z ℕ.* (3 ℕ.* j)))
(2 ℕ.* r ℕ.* (2 ℕ.* s ℕ.* n)) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N₂≤4rsn N₂≤4tun) ⟩
(+ (K x ℕ.* K z) / 1) ℚ.*
(+ 1 / (K x ℕ.* K z ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Kz j ->
(Kx :* Kz :* con (+ 1)) :* (con (+ 3) :* j) :=
(con (+ 1) :* (con (+ 1) :* (Kx :* Kz :* (con (+ 3) :* j)))))
_≡_.refl (+ K x) (+ K z) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
N₃≤2sn : N₃ ℕ.≤ 2 ℕ.* s ℕ.* n
N₃≤2sn = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃)
(ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* s} ℕP.0<1+n))
N₃≤4tun : N₃ ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)
N₃≤4tun = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) N≤4tun
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-greater x (2 ℕ.* u ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(ℚP.<⇒≤ (canonical-greater y (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n)))))) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.* ℚ.∣ z₂ₛₙ ℚ.- z₄ₜᵤₙ ∣ ≤⟨ ℚP.*-monoʳ-≤-nonNeg {+ (K x ℕ.* K y) / 1} _
(proj₂ (regular⇒cauchy z (K x ℕ.* K y ℕ.* (3 ℕ.* j)))
(2 ℕ.* s ℕ.* n) (2 ℕ.* t ℕ.* (2 ℕ.* u ℕ.* n))
N₃≤2sn N₃≤4tun) ⟩
(+ (K x ℕ.* K y) / 1) ℚ.*
(+ 1 / (K x ℕ.* K y ℕ.* (3 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Ky j ->
(((Kx :* Ky) :* con (+ 1)) :* (con (+ 3) :* j)) :=
(con (+ 1) :* (con (+ 1) :* (Kx :* Ky :* (con (+ 3) :* j)))))
_≡_.refl (+ K x) (+ K y) (+ j)) ⟩
+ 1 / (3 ℕ.* j) ∎
*-distribˡ-+ : _DistributesOverˡ_ _≃_ _*_ _+_
*-distribˡ-+ x y z = lemma1B (x * (y + z)) ((x * y) + (x * z)) lemA
where
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
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K (y + z)
s : ℕ
s = K x ℕ.⊔ K y
t : ℕ
t = K x ℕ.⊔ K z
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x (K y ℕ.* (4 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* (4 ℕ.* j)))
N₃ : ℕ
N₃ = proj₁ (regular⇒cauchy x (K z ℕ.* (4 ℕ.* j)))
N₄ : ℕ
N₄ = proj₁ (regular⇒cauchy z (K x ℕ.* (4 ℕ.* j)))
N : ℕ
N = 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 = 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-greater y
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (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-greater x
(2 ℕ.* s ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (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-greater z
(2 ℕ.* (2 ℕ.* r ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K z / 1} _
(proj₂ (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-greater x
(2 ℕ.* t ℕ.* (2 ℕ.* n)))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (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 :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Ky :* (con (+ 4) :* j))))) :*
((con (+ 1) :* (Kz :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :+
(((Kz :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Kz :* (con (+ 4) :* j))))) :*
((con (+ 1) :* (Ky :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))))) :* j :=
con (+ 1) :* (((con (+ 1) :* (Ky :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j)))) :*
((con (+ 1) :* (Kz :* (con (+ 4) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 4) :* j))))))
_≡_.refl (+ K x) (+ K y) (+ K z) (+ j)) ⟩
+ 1 / j ∎
where
n : ℕ
n = suc k₂
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
x₄ₛₙ : ℚᵘ
x₄ₛₙ = seq x (2 ℕ.* s ℕ.* (2 ℕ.* n))
x₄ₜₙ : ℚᵘ
x₄ₜₙ = seq x (2 ℕ.* t ℕ.* (2 ℕ.* n))
y₄ᵣₙ : ℚᵘ
y₄ᵣₙ = seq y (2 ℕ.* (2 ℕ.* r ℕ.* n))
y₄ₛₙ : ℚᵘ
y₄ₛₙ = seq y (2 ℕ.* s ℕ.* (2 ℕ.* n))
z₄ᵣₙ : ℚᵘ
z₄ᵣₙ = seq z (2 ℕ.* (2 ℕ.* r ℕ.* n))
z₄ₜₙ : ℚᵘ
z₄ₜₙ = seq z (2 ℕ.* t ℕ.* (2 ℕ.* n))
N≤2rn : N ℕ.≤ 2 ℕ.* r ℕ.* n
N≤2rn = ℕP.≤-trans (ℕP.<⇒≤ 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.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* s ℕ.* 2} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc (2 ℕ.* s) 2 n)))
N≤4rn : N ℕ.≤ 2 ℕ.* (2 ℕ.* r ℕ.* n)
N≤4rn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* (2 ℕ.* r)} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc 2 (2 ℕ.* r) n)))
N≤4tn : N ℕ.≤ 2 ℕ.* t ℕ.* (2 ℕ.* n)
N≤4tn = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.≤-trans (ℕP.m≤n*m n {2 ℕ.* t ℕ.* 2} ℕP.0<1+n)
(ℕP.≤-reflexive (ℕP.*-assoc (2 ℕ.* t) 2 n)))
N₁≤_ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕ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₄) N≤m)
N₂≤_ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤ N≤m = ℕ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₄) N≤m)
N₃≤_ : {m : ℕ} -> N ℕ.≤ m -> N₃ ℕ.≤ m
N₃≤ N≤m = ℕP.≤-trans (ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂) N₃) (ℕP.m≤m⊔n (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄)) N≤m
N₄≤_ : {m : ℕ} -> N ℕ.≤ m -> N₄ ℕ.≤ m
N₄≤ N≤m = ℕP.≤-trans (ℕP.m≤n⊔m (N₁ ℕ.⊔ N₂ ℕ.⊔ N₃) N₄) N≤m
*-distribʳ-+ : _DistributesOverʳ_ _≃_ _*_ _+_
*-distribʳ-+ x y z = ≃-trans {(y + z) * x} {x * (y + z)} {y * x + z * x} (*-comm (y + z) x)
(≃-trans {x * (y + z)} {x * y + x * z} {y * x + z * x} (*-distribˡ-+ x y z)
(+-cong {x * y} {y * x} {x * z} {z * x} (*-comm x y) (*-comm x z)))
*-distrib-+ : _DistributesOver_ _≃_ _*_ _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
*-identityˡ : LeftIdentity _≃_ 1ℝ _*_
*-identityˡ x (suc k₁) = 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) lem ⟩
(+ 1 / n) ℚ.+ (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(con (+ 1) :* n :+ con (+ 1) :* n) :* n := (con (+ 2) :* (n :* n)))
_≡_.refl (+ n)) ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
k : ℕ
k = K 1ℝ ℕ.⊔ K x
n : ℕ
n = suc k₁
lem : (+ 1 / (2 ℕ.* k ℕ.* n)) ℚ.≤ + 1 / n
lem = *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n*m n {2 ℕ.* k} ℕP.0<1+n)))
*-identityʳ : RightIdentity _≃_ 1ℝ _*_
*-identityʳ x = ≃-trans {x * 1ℝ} {1ℝ * x} {x} (*-comm x 1ℝ) (*-identityˡ x)
*-identity : Identity _≃_ 1ℝ _*_
*-identity = *-identityˡ , *-identityʳ
*-zeroˡ : LeftZero _≃_ 0ℝ _*_
*-zeroˡ x (suc k₁) = 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
n : ℕ
n = suc k₁
k : ℕ
k = K 0ℝ ℕ.⊔ K x
*-zeroʳ : RightZero _≃_ 0ℝ _*_
*-zeroʳ x = ≃-trans {x * 0ℝ} {0ℝ * x} {0ℝ} (*-comm x 0ℝ) (*-zeroˡ x)
*-zero : Zero _≃_ 0ℝ _*_
*-zero = *-zeroˡ , *-zeroʳ
-‿cong : Congruent₁ _≃_ (-_)
-‿cong {x} {y} x≃y n {n≢0} = begin
ℚ.∣ ℚ.- seq x n ℚ.- (ℚ.- seq y n) ∣ ≈⟨ ℚP.∣-∣-cong (solve 2 (λ x y -> :- x :- (:- y) := y :- x) ℚP.≃-refl (seq x n) (seq y n)) ⟩
ℚ.∣ seq y n ℚ.- seq x n ∣ ≤⟨ (≃-symm {x} {y} x≃y) n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
neg-involutive : Involutive _≃_ (-_)
neg-involutive x (suc k₁) = begin
ℚ.∣ ℚ.- (ℚ.- seq x (suc k₁)) ℚ.- seq x (suc k₁) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-inverseˡ (ℚ.- seq x (suc k₁))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / (suc k₁) ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
neg-distrib-+ : ∀ x y -> - (x + y) ≃ (- x) + (- y)
neg-distrib-+ x y (suc k₁) = 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) := con (0ℚᵘ)) ℚP.≃-refl
(seq x (2 ℕ.* n)) (seq y (2 ℕ.* n))) ⟩
0ℚᵘ ≤⟨ ℚP.nonNegative⁻¹ _ ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
⊔-cong : Congruent₂ _≃_ _⊔_
⊔-cong {x} {z} {y} {w} x≃z y≃w (suc k₁) = [ left , right ]′ (ℚP.≤-total (seq x n ℚ.⊔ seq y n) (seq z n ℚ.⊔ seq w n))
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
n = suc k₁
lem : ∀ a b c d -> a ℚ.≤ b -> ℚ.∣ b ℚ.- d ∣ ℚ.≤ + 2 / n ->
(a ℚ.⊔ b) ℚ.- (c ℚ.⊔ d) ℚ.≤ + 2 / n
lem 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) ≤⟨ lem (seq z n) (seq w n) (seq x n) (seq y n) hyp2 (≃-symm {y} {w} 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) ≤⟨ lem (seq w n) (seq z n) (seq y n) (seq x n) hyp2 (≃-symm {x} {z} 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) ≤⟨ lem (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) ≤⟨ lem (seq y n) (seq x n) (seq w n) (seq z n) hyp2 (x≃z n) ⟩
+ 2 / n ∎
⊔-congˡ : LeftCongruent _≃_ _⊔_
⊔-congˡ {x} {y} {z} y≃z = ⊔-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
⊔-congʳ : RightCongruent _≃_ _⊔_
⊔-congʳ {x} {y} {z} y≃z = ⊔-cong {y} {z} {x} {x} y≃z (≃-refl {x})
⊔-comm : Commutative _≃_ _⊔_
⊔-comm x y n {n≢0} = 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) ∣ ≤⟨ ≃-refl {x ⊔ y} n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
⊔-assoc : Associative _≃_ _⊔_
⊔-assoc x y z n {n≢0} = 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) ∣ ≤⟨ ≃-refl {x ⊔ y ⊔ z} n {n≢0} ⟩
+ 2 / n ∎
where
open ℚP.≤-Reasoning
_⊓_ : (x y : ℝ) -> ℝ
x ⊓ y = - ((- x) ⊔ (- y))
⊓-cong : Congruent₂ _≃_ _⊓_
⊓-cong {x} {z} {y} {w} x≃z y≃w = -‿cong {(- x ⊔ - y)} {(- z ⊔ - w)} (⊔-cong {(- x)} {(- z)} {(- y)} {(- w)}
(-‿cong {x} {z} x≃z) (-‿cong {y} {w} y≃w))
⊓-congˡ : LeftCongruent _≃_ _⊓_
⊓-congˡ {x} {y} {z} y≃z = ⊓-cong {x} {x} {y} {z} (≃-refl {x}) y≃z
⊓-congʳ : RightCongruent _≃_ _⊓_
⊓-congʳ {x} {y} {z} y≃z = ⊓-cong {y} {z} {x} {x} y≃z (≃-refl {x})
⊓-comm : Commutative _≃_ _⊓_
⊓-comm x y = -‿cong { - x ⊔ - y} { - y ⊔ - x} (⊔-comm (- x) (- y))
⊓-assoc : Associative _≃_ _⊓_
⊓-assoc x y z = -‿cong {(- (- ((- x) ⊔ (- y)))) ⊔ (- z)} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(≃-trans {(- (- ((- x) ⊔ (- y))) ⊔ (- z))} {((- x) ⊔ (- y)) ⊔ (- z)} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(⊔-congʳ {(- z)} {(- (- ((- x) ⊔ (- y))))} {(- x) ⊔ (- y)} (neg-involutive ((- x) ⊔ (- y))))
(≃-trans {((- x) ⊔ (- y)) ⊔ (- z)} {(- x) ⊔ ((- y) ⊔ (- z))} {(- x) ⊔ (- (- ((- y) ⊔ (- z))))}
(⊔-assoc (- x) (- y) (- z)) (⊔-congˡ { - x} { - y ⊔ - z} { - (- (- y ⊔ - z))}
(≃-symm { - (- (- y ⊔ - z))} { - y ⊔ - z} (neg-involutive ((- y) ⊔ (- z)))))))
∣_∣ : ℝ -> ℝ
∣ x ∣ = x ⊔ (- x)
∣-∣-cong : Congruent₁ _≃_ ∣_∣
∣-∣-cong {x} {y} x≃y = ⊔-cong {x} {y} {(- x)} {(- y)} x≃y (-‿cong {x} {y} x≃y)
∣p∣≃p⊔-p : ∀ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
∣p∣≃p⊔-p p = [ left , right ]′ (ℚP.∣p∣≡p∨∣p∣≡-p p)
where
open ℚP.≤-Reasoning
left : ℚ.∣ p ∣ ≡ p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
left hyp = begin-equality
ℚ.∣ p ∣ ≈⟨ ℚP.≃-reflexive hyp ⟩
p ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊔q≃p (ℚP.≤-trans (p≤∣p∣ (ℚ.- p)) (ℚP.≤-reflexive (ℚP.≃-trans (ℚP.∣-p∣≃∣p∣ p) (ℚP.≃-reflexive hyp))))) ⟩
p ℚ.⊔ (ℚ.- p) ∎
right : ℚ.∣ p ∣ ≡ ℚ.- p -> ℚ.∣ p ∣ ℚ.≃ p ℚ.⊔ (ℚ.- p)
right hyp = begin-equality
ℚ.∣ p ∣ ≈⟨ ℚP.≃-reflexive hyp ⟩
ℚ.- p ≈⟨ ℚP.≃-sym (ℚP.p≤q⇒p⊔q≃q (ℚP.≤-trans (p≤∣p∣ p) (ℚP.≤-reflexive (ℚP.≃-reflexive hyp)))) ⟩
p ℚ.⊔ (ℚ.- p) ∎
-- Alternate definition of absolute value defined pointwise in the real number's regular sequence
∣_∣₂ : ℝ -> ℝ
seq ∣ x ∣₂ n = ℚ.∣ seq x n ∣
reg ∣ x ∣₂ m n {m≢0} {n≢0} = 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 {m≢0} {n≢0} ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
∣x∣≃∣x∣₂ : ∀ x -> ∣ x ∣ ≃ ∣ x ∣₂
∣x∣≃∣x∣₂ x (suc k₁) = begin
ℚ.∣ (seq x n ℚ.⊔ (ℚ.- seq x n)) ℚ.- ℚ.∣ seq x n ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- ℚ.∣ seq x n ∣) (ℚ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
n : ℕ
n = suc k₁
-- K(x*y)
--K∣x∣ K∣y∣
-- ∣x₁∣ + 2
∣x*y∣≃∣x∣*∣y∣ : ∀ x y -> ∣ x * y ∣ ≃ ∣ x ∣ * ∣ y ∣
∣x*y∣≃∣x∣*∣y∣ x y = ≃-trans {∣ x * y ∣} {∣ x * y ∣₂} {∣ x ∣ * ∣ y ∣}
(∣x∣≃∣x∣₂ (x * y))
(≃-trans {∣ x * y ∣₂} {∣ x ∣₂ * ∣ y ∣₂} {∣ x ∣ * ∣ y ∣}
(lemma1B ∣ x * y ∣₂ (∣ x ∣₂ * ∣ y ∣₂) lemA)
(*-cong {∣ x ∣₂} {∣ x ∣} {∣ y ∣₂} {∣ y ∣}
(≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x)) (≃-symm {∣ y ∣} {∣ y ∣₂} (∣x∣≃∣x∣₂ y))))
where
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (∣ x * y ∣₂) n ℚ.- seq (∣ x ∣₂ * ∣ y ∣₂) n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
r : ℕ
r = K x ℕ.⊔ K y
t : ℕ
t = K ∣ x ∣₂ ℕ.⊔ K ∣ y ∣₂
N₁ : ℕ
N₁ = proj₁ (regular⇒cauchy x (K y ℕ.* (2 ℕ.* j)))
N₂ : ℕ
N₂ = proj₁ (regular⇒cauchy y (K x ℕ.* (2 ℕ.* j)))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemB : ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq (∣ x * y ∣₂) n ℚ.- seq (∣ x ∣₂ * ∣ y ∣₂) n ∣ ℚ.≤ (+ 1 / j)
lemB (suc k₁) N<n = begin
ℚ.∣ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣ ℚ.- ℚ.∣ x₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ₜₙ ∣ ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congʳ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣
(ℚP.-‿cong (ℚP.≃-sym (ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₜₙ y₂ₜₙ)))) ⟩
ℚ.∣ ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ∣ ℚ.- ℚ.∣ x₂ₜₙ ℚ.* y₂ₜₙ ∣ ∣ ≤⟨ ∣∣p∣-∣q∣∣≤∣p-q∣ (x₂ᵣₙ ℚ.* y₂ᵣₙ) (x₂ₜₙ ℚ.* y₂ₜₙ) ⟩
ℚ.∣ x₂ᵣₙ ℚ.* y₂ᵣₙ ℚ.- x₂ₜₙ ℚ.* y₂ₜₙ ∣ ≈⟨ ℚP.∣-∣-cong (ℚsolve 4 (λ x y z w ->
x ℚ:* y ℚ:- z ℚ:* w ℚ:=
(y ℚ:* (x ℚ:- z) ℚ:+ z ℚ:* (y ℚ:- w)))
ℚP.≃-refl x₂ᵣₙ y₂ᵣₙ x₂ₜₙ y₂ₜₙ) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ) ℚ.+
x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ) ∣ ≤⟨ ℚP.∣p+q∣≤∣p∣+∣q∣ (y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ))
(x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ℚ.* (x₂ᵣₙ ℚ.- x₂ₜₙ) ∣ ℚ.+
ℚ.∣ x₂ₜₙ ℚ.* (y₂ᵣₙ ℚ.- y₂ₜₙ) ∣ ≈⟨ ℚP.+-cong
(ℚP.∣p*q∣≃∣p∣*∣q∣ y₂ᵣₙ (x₂ᵣₙ ℚ.- x₂ₜₙ))
(ℚP.∣p*q∣≃∣p∣*∣q∣ x₂ₜₙ (y₂ᵣₙ ℚ.- y₂ₜₙ)) ⟩
ℚ.∣ y₂ᵣₙ ∣ ℚ.* ℚ.∣ x₂ᵣₙ ℚ.- x₂ₜₙ ∣ ℚ.+
ℚ.∣ x₂ₜₙ ∣ ℚ.* ℚ.∣ y₂ᵣₙ ℚ.- y₂ₜₙ ∣ ≤⟨ ℚP.+-mono-≤
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ x₂ᵣₙ ℚ.- x₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater y
(2 ℕ.* r ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K y / 1} _
(proj₂ (regular⇒cauchy x (K y ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₁≤ (N≤2kn r)) (N₁≤ (N≤2kn t)))))
(ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ y₂ᵣₙ ℚ.- y₂ₜₙ ∣} _
(ℚP.<⇒≤ (canonical-greater x
(2 ℕ.* t ℕ.* n))))
(ℚP.*-monoʳ-≤-nonNeg {+ K x / 1} _
(proj₂ (regular⇒cauchy y (K x ℕ.* (2 ℕ.* j)))
(2 ℕ.* r ℕ.* n) (2 ℕ.* t ℕ.* n)
(N₂≤ (N≤2kn r)) (N₂≤ (N≤2kn t))))) ⟩
(+ K y / 1) ℚ.* (+ 1 / (K y ℕ.* (2 ℕ.* j))) ℚ.+
(+ K x / 1) ℚ.* (+ 1 / (K x ℕ.* (2 ℕ.* j))) ≈⟨ ℚ.*≡* (solve 3 (λ Kx Ky j ->
-- Function for solver
((Ky :* con (+ 1)) :* (con (+ 1) :* (Kx :* (con (+ 2) :* j))) :+ ((Kx :* con (+ 1)) :* (con (+ 1) :* (Ky :* (con (+ 2) :* j))))) :* j :=
con (+ 1) :* ((con (+ 1) :* (Ky :* (con (+ 2) :* j))) :* (con (+ 1) :* (Kx :* (con (+ 2) :* j)))))
_≡_.refl (+ K x) (+ K y) (+ j)) ⟩
+ 1 / j ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
n : ℕ
n = suc k₁
x₂ᵣₙ : ℚᵘ
x₂ᵣₙ = seq x (2 ℕ.* r ℕ.* n)
x₂ₜₙ : ℚᵘ
x₂ₜₙ = seq x (2 ℕ.* t ℕ.* n)
y₂ᵣₙ : ℚᵘ
y₂ᵣₙ = seq y (2 ℕ.* r ℕ.* n)
y₂ₜₙ : ℚᵘ
y₂ₜₙ = seq y (2 ℕ.* t ℕ.* n)
N≤2kn : ∀ (k : ℕ) -> {k ≢0} -> N ℕ.≤ 2 ℕ.* k ℕ.* n
N≤2kn (suc k₂) = ℕP.≤-trans (ℕP.<⇒≤ N<n) (ℕP.m≤n*m n {2 ℕ.* (suc k₂)} ℕP.0<1+n)
N₁≤ : {m : ℕ} -> N ℕ.≤ m -> N₁ ℕ.≤ m
N₁≤ N≤m = ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤m
N₂≤ : {m : ℕ} -> N ℕ.≤ m -> N₂ ℕ.≤ m
N₂≤ N≤m = ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N≤m
{-
A bunch of algebraic bundles from the standard library. I've followed the conventions used
in the standard library's properties file for unnormalised rationals.
Sometimes we use copatterns so we can use implicit arguments (e.g. in ≃-isEquivalence's
definition).
It's inconvenient, but some properties of ℝ might not work without implicit arguments.
For instance, if we use ≃-trans without its implicit arguments in ≃-isEquivalence below (so
just ≃-trans instead of ≃-trans {x} {y} {z}), Agda will give a constraint error.
-}
≃-isEquivalence : IsEquivalence _≃_
IsEquivalence.refl ≃-isEquivalence {x} = ≃-refl {x}
IsEquivalence.sym ≃-isEquivalence {x} {y} = ≃-symm {x} {y}
IsEquivalence.trans ≃-isEquivalence {x} {y} {z} = ≃-trans {x} {y} {z}
≃-setoid : Setoid 0ℓ 0ℓ
≃-setoid = record
{ isEquivalence = ≃-isEquivalence
}
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≃_
; _∙_ = _+_
}
+-rawMonoid : RawMonoid 0ℓ 0ℓ
+-rawMonoid = record
{ _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
}
+-0-rawGroup : RawGroup 0ℓ 0ℓ
+-0-rawGroup = record
{ Carrier = ℝ
; _≈_ = _≃_
; _∙_ = _+_
; ε = 0ℝ
; _⁻¹ = -_
}
+-*-rawRing : RawRing 0ℓ 0ℓ
+-*-rawRing = record
{ Carrier = ℝ
; _≈_ = _≃_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0ℝ
; 1# = 1ℝ
}
+-isMagma : IsMagma _≃_ _+_
IsMagma.isEquivalence +-isMagma = ≃-isEquivalence
IsMagma.∙-cong +-isMagma {x} {y} {z} {w} = +-cong {x} {y} {z} {w}
+-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ℝ (-_)
IsGroup.isMonoid +-0-isGroup = +-0-isMonoid
IsGroup.inverse +-0-isGroup = +-inverse
IsGroup.⁻¹-cong +-0-isGroup {x} {y} = -‿cong {x} {y}
+-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ℝ
}
*-isMagma : IsMagma _≃_ _*_
IsMagma.isEquivalence *-isMagma = ≃-isEquivalence
IsMagma.∙-cong *-isMagma {x} {y} {z} {w} = *-cong {x} {y} {z} {w}
*-isSemigroup : IsSemigroup _≃_ _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-1-isMonoid : IsMonoid _≃_ _*_ 1ℝ
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≃_ _*_ 1ℝ
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; 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
}
*-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
}
+-*-ring : Ring 0ℓ 0ℓ
+-*-ring = record
{ isRing = +-*-isRing
}
+-*-commutativeRing : CommutativeRing 0ℓ 0ℓ
+-*-commutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
}
{- Predicates about sign of real number and some properties -}
Positive : Pred ℝ 0ℓ
Positive x = ∃ λ (n : ℕ) -> seq x (suc n) ℚ.> + 1 / (suc n)
-- ∀n∈ℕ( xₙ ≥ -n⁻¹)
NonNegative : Pred ℝ 0ℓ
NonNegative x = (n : ℕ) -> {n≢0 : n ≢0} -> seq x n ℚ.≥ ℚ.- ((+ 1 / n) {n≢0})
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
-- r < Np
-- r < (Np)/1 Original version
-- r < (N/1) * p
-- r/N < p
archimedean-ℚ₂ : ∀ (p r : ℚᵘ) -> ℚ.Positive p -> ∃ λ (N : ℕ) ->
r ℚ.< (+ N / 1) ℚ.* p
archimedean-ℚ₂ p r p>0 = N , (begin-strict
r <⟨ proj₂ (archimedean-ℚ p r p>0) ⟩
((+ N) ℤ.* (↥ p)) / (↧ₙ p) ≈⟨ ℚ.*≡* (cong (λ x -> (+ N) ℤ.* (↥ p) ℤ.* x) (ℤP.*-identityˡ (↧ p))) ⟩
(+ N / 1) ℚ.* p ∎)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = proj₁ (archimedean-ℚ p r p>0)
lemma2-8-1a : ∀ x -> Positive x -> ∃ λ (N : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N ->
seq x m ℚ.≥ + 1 / (suc N)
lemma2-8-1a x (n-1 , xₙ>1/n) = N-1 , lem
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
n : ℕ
n = suc n-1
pos : ℚ.Positive (seq x n ℚ.- (+ 1 / n))
pos = 0<⇒pos (seq x n ℚ.- (+ 1 / n)) (p<q⇒0<q-p xₙ>1/n)
N-1 : ℕ
N-1 = proj₁ (archimedean-ℚ₂ (seq x n ℚ.- (+ 1 / n)) (+ 2 / 1) pos)
N : ℕ
N = suc N-1
part1 : + 2 / 1 ℚ.≤ (+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n))
part1 = begin
+ 2 / 1 <⟨ proj₂ (archimedean-ℚ₂ (seq x n ℚ.- (+ 1 / n)) (+ 2 / 1) pos) ⟩
(+ N-1) / 1 ℚ.* (seq x n ℚ.- (+ 1 / n)) ≤⟨ ℚP.*-monoˡ-≤-nonNeg {seq x n ℚ.- + 1 / n}
(ℚP.positive⇒nonNegative {seq x n ℚ.- + 1 / n} pos) {+ N-1 / 1} {+ N / 1}
(*≤* (ℤP.*-monoʳ-≤-nonNeg 1 (+≤+ (ℕP.n≤1+n N-1)))) ⟩
(+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n)) ∎
part2 : + 2 / N ℚ.≤ seq x n ℚ.- (+ 1 / n)
part2 = begin
+ 2 / N ≈⟨ ℚ.*≡* (sym (ℤP.*-assoc (+ 2) (+ 1) (+ N))) ⟩
(+ 2 / 1) ℚ.* (+ 1 / N) ≤⟨ ℚP.*-monoˡ-≤-nonNeg _ part1 ⟩
(+ N / 1) ℚ.* (seq x n ℚ.- (+ 1 / n)) ℚ.* (+ 1 / N) ≈⟨ ℚ.*≡* (solve 3 (λ N p q ->
((N :* p) :* con (+ 1)) :* q := (p :* ((con (+ 1) :* q) :* N)))
_≡_.refl (+ N) (↥ (seq x n ℚ.- (+ 1 / n))) (↧ (seq x n ℚ.- (+ 1 / n)))) ⟩
seq x n ℚ.- (+ 1 / n) ∎
part3 : + 1 / N ℚ.≤ seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N)
part3 = begin
+ 1 / N ≈⟨ ℚ.*≡* (solve 1 (λ N ->
con (+ 1) :* (N :* N) := (((con (+ 2) :* N) :+ (:- con (+ 1) :* N)) :* N)) _≡_.refl (+ N)) ⟩
(+ 2 / N) ℚ.- (+ 1 / N) ≤⟨ ℚP.+-monoˡ-≤ (ℚ.- (+ 1 / N)) part2 ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N) ∎
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq x m ℚ.≥ + 1 / N
lem (suc k₂) N≤m = begin
+ 1 / N ≤⟨ part3 ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / N) ≤⟨ ℚP.+-monoʳ-≤ (seq x n ℚ.- (+ 1 / n)) {ℚ.- (+ 1 / N)} {ℚ.- (+ 1 / m)}
(ℚP.neg-mono-≤ (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ N≤m)))) ⟩
seq x n ℚ.- (+ 1 / n) ℚ.- (+ 1 / m) ≤⟨ ℚP.≤-respˡ-≃ (ℚsolve 3 (λ a b c -> a ℚ:- (b ℚ:+ c) ℚ:= a ℚ:- b ℚ:- c) ℚP.≃-refl (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 (λ a b -> a ℚ:- (a ℚ:- b) ℚ:= b) ℚP.≃-refl (seq x n) (seq x m) ⟩
seq x m ∎
where
m : ℕ
m = suc k₂
lemma2-8-1b : ∀ (x : ℝ) ->
(∃ λ (N-1 : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N-1 -> seq x m ℚ.≥ + 1 / (suc N-1)) ->
Positive x
lemma2-8-1b x (N-1 , proof) = N , (begin-strict
+ 1 / (suc N) <⟨ ℚ.*<* (ℤP.*-monoˡ-<-pos 0 (+<+ (ℕP.n<1+n N))) ⟩
+ 1 / N ≤⟨ proof (suc N) (ℕ.s≤s (ℕP.n≤1+n N-1)) ⟩
seq x (suc N) ∎)
where
open ℚP.≤-Reasoning
N : ℕ
N = suc N-1
-- xₙ ≥ -n⁻¹
-- Nonnegative x ⇒ ∀ n ∃ Nₙ ∀ m≥Nₙ (xₘ ≥ -n⁻¹)
lemma2-8-2a : ∀ (x : ℝ) -> NonNegative x -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lemma2-8-2a x x≥0 (suc k₁) = n , _ , λ {(suc m) m≥n → ℚP.≤-trans (ℚP.neg-mono-≤ (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ m≥n)))) (x≥0 (suc m))}
where
n : ℕ
n = suc k₁
archimedean-ℚ₃ : ∀ (p : ℚᵘ) -> ∀ (r : ℤ) -> ℚ.Positive p -> ∃ λ (N-1 : ℕ) -> r / (suc N-1) ℚ.< p
archimedean-ℚ₃ p r 0<p = ℕ.pred N , (begin-strict
r / N ≈⟨ ℚP.≃-reflexive (ℚP./-cong (sym (ℤP.*-identityʳ r)) (sym (ℕP.*-identityˡ N)) _ _) ⟩
(r / 1) ℚ.* (+ 1 / N) <⟨ ℚP.*-monoˡ-<-pos {+ 1 / N} _ {r / 1} {(+ N / 1) ℚ.* p} (ℚP.<-trans (proj₂ (archimedean-ℚ₂ p (r / 1) 0<p))
(ℚP.*-monoˡ-<-pos {p} 0<p {+ (ℕ.pred N) / 1} {+ N / 1} (ℚ.*<* (ℤP.*-monoʳ-<-pos 0 (+<+ (ℕP.n<1+n (ℕ.pred N))))))) ⟩
(+ N / 1) ℚ.* p ℚ.* (+ 1 / N) ≈⟨ ℚ.*≡* (solve 3 (λ N n d ->
((N :* n) :* con (+ 1)) :* d := (n :* (con (+ 1) :* d :* N)))
_≡_.refl (+ N) (↥ p) (↧ p)) ⟩
p ∎)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N : ℕ
N = suc (proj₁ (archimedean-ℚ₂ p (r / 1) 0<p))
-- y - ε ≤ x
-- y ≤ x
ℚ-≤-lemma : ∀ (x y : ℚᵘ) ->
(∀ (j : ℕ) -> {j≢0 : j ≢0} -> y ℚ.- (+ 1 / j) {j≢0} ℚ.≤ x) ->
y ℚ.≤ x
ℚ-≤-lemma x y hyp with ℚP.<-cmp y x
... | tri< a ¬b ¬c = ℚP.<⇒≤ a
... | tri≈ ¬a b ¬c = ℚP.≤-reflexive b
... | tri> ¬a ¬b c = ⊥-elim (ℚP.<⇒≱ lem (hyp N))
where
open ℚP.≤-Reasoning
open import Data.Rational.Unnormalised.Solver
open +-*-Solver
N : ℕ
N = suc (proj₁ (archimedean-ℚ₃ (y ℚ.- x) (+ 1) (0<⇒pos (y ℚ.- x) (p<q⇒0<q-p c))))
lem : x ℚ.< y ℚ.- (+ 1 / N)
lem = begin-strict
x ≈⟨ solve 2 (λ a b -> a := a :+ b :- b) ℚP.≃-refl x (+ 1 / N) ⟩
x ℚ.+ (+ 1 / N) ℚ.- (+ 1 / N) <⟨ ℚP.+-monoˡ-< (ℚ.- (+ 1 / N))
(ℚP.+-monoʳ-< x (proj₂ (archimedean-ℚ₃ (y ℚ.- x) (+ 1) (0<⇒pos (y ℚ.- x) (p<q⇒0<q-p c))))) ⟩
x ℚ.+ (y ℚ.- x) ℚ.- (+ 1 / N) ≈⟨ solve 3 (λ a b c -> a :+ (b :- a) :- c := b :- c) ℚP.≃-refl x y (+ 1 / N) ⟩
y ℚ.- (+ 1 / N) ∎
{-
Proof of ̄if direction of Lemma 2.8.2:
Let j∈ℤ⁺, let n = 2j, and let m = max{Nₙ, 2j}. Let k∈ℕ. We must show
that xₖ ≥ -k⁻¹. We have:
xₖ = xₘ - (xₘ - xₖ)
≥ xₘ - ∣xₘ - xₖ∣
≥ -n⁻¹ - ∣xₘ - xₖ∣ by assumption since m ≥ Nₙ
≥ -n⁻¹ - (m⁻¹ + k⁻¹) by regularity of x
= -k⁻¹ - (m⁻¹ + n⁻¹)
≥ -k⁻¹ - ((2j)⁻¹ + (2j)⁻¹) since m ≥ 2j and n = 2j
= -k⁻¹ - 1/j.
Thus, for all j∈ℤ⁺, we have
xₖ ≥ -k⁻¹ - 1/j.
Hence xₖ ≥ -k⁻¹, and we are done. □
-}
lemma2-8-2b : ∀ (x : ℝ) -> (∀ (n : ℕ) -> {n≢0 : n ≢0} ->
∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})) ->
NonNegative x
lemma2-8-2b x hyp K {K≢0} = lemB K {K≢0} (lemA K {K≢0})
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; :-_ to ℚ:-_
; _:=_ to _ℚ:=_
)
lemA : ∀ (k : ℕ) -> {k≢0 : k ≢0} -> ∀ (j : ℕ) -> {j≢0 : j ≢0} ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0} ℚ.- (+ 1 / j) {j≢0}
lemA (suc k₁) (suc k₂) = begin
ℚ.- (+ 1 / k) ℚ.- (+ 1 / j) ≈⟨ ℚP.+-congʳ (ℚ.- (+ 1 / k)) {ℚ.- (+ 1 / j)} {ℚ.- ((+ 1 / (2 ℕ.* j)) ℚ.+ (+ 1 / (2 ℕ.* j)))}
(ℚP.-‿cong (ℚ.*≡* (solve 1 (λ j ->
con (+ 1) :* (con (+ 2) :* j :* (con (+ 2) :* j)) :=
((con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j))
_≡_.refl (+ j)))) ⟩
ℚ.- (+ 1 / k) ℚ.- ((+ 1 / n) ℚ.+ (+ 1 / n)) ≤⟨ ℚP.+-monoʳ-≤ (ℚ.- (+ 1 / k)) {ℚ.- ((+ 1 / n) ℚ.+ (+ 1 / n))} {ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / n))}
(ℚP.neg-mono-≤ {(+ 1 / m) ℚ.+ (+ 1 / n)} {(+ 1 / n) ℚ.+ (+ 1 / n)}
(ℚP.+-monoˡ-≤ (+ 1 / n) {+ 1 / m} {+ 1 / n} (*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m (suc Nₙ) n)))))) ⟩
ℚ.- (+ 1 / k) ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / n)) ≈⟨ ℚsolve 3 (λ x y z ->
ℚ:- x ℚ:- (y ℚ:+ z) ℚ:= ℚ:- z ℚ:- (y ℚ:+ x))
ℚP.≃-refl (+ 1 / k) (+ 1 / m) (+ 1 / n) ⟩
ℚ.- (+ 1 / n) ℚ.- ((+ 1 / m) ℚ.+ (+ 1 / k)) ≤⟨ ℚP.+-mono-≤ (proj₂ (proj₂ (hyp n)) m (ℕP.≤-trans (ℕP.n≤1+n Nₙ) (ℕP.m≤m⊔n (suc Nₙ) n)))
(ℚP.neg-mono-≤ (reg x m k)) ⟩
seq x m ℚ.- ℚ.∣ seq x m ℚ.- seq x k ∣ ≤⟨ ℚP.+-monoʳ-≤ (seq x m) (ℚP.neg-mono-≤ (p≤∣p∣ (seq x m ℚ.- seq x k))) ⟩
seq x m ℚ.- (seq x m ℚ.- seq x k) ≈⟨ ℚsolve 2 (λ x y -> x ℚ:- (x ℚ:- y) ℚ:= y) ℚP.≃-refl (seq x m) (seq x k) ⟩
seq x k ∎
where
k : ℕ
k = suc k₁
j : ℕ
j = suc k₂
n : ℕ
n = 2 ℕ.* j
Nₙ : ℕ
Nₙ = proj₁ (hyp n)
m : ℕ
m = (suc Nₙ) ℕ.⊔ 2 ℕ.* j
lemB : ∀ (k : ℕ) -> {k≢0 : k ≢0} -> (∀ (j : ℕ) -> {j≢0 : j ≢0} ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0} ℚ.- (+ 1 / j) {j≢0}) ->
seq x k ℚ.≥ ℚ.- (+ 1 / k) {k≢0}
lemB (suc k₁) = ℚ-≤-lemma (seq x (suc k₁)) (ℚ.- (+ 1 / (suc k₁)))
{-
Proposition:
If x is positive and x ≃ y, then y is positive.
Proof
Since x is positive, there is N₁∈ℕ such that xₘ ≥ N₁⁻¹ for all m ≥ N.
Since x ≃ y, there is N₂∈ℕ such that, for all m > N₂, we have
∣ xₘ - yₘ ∣ ≤ (2N₁)⁻¹. Let N = max{N₁, N₂} and let m ≥ 2N. Then N₁ ≤ N, so
N⁻¹ ≤ N₁⁻¹. We have:
yₘ ≥ xₘ - ∣ xₘ - yₘ ∣
≥ N₁⁻¹ - (2N₁)⁻¹
= (2N₁)⁻¹
≥ (2N)⁻¹.
Thus yₘ ≥ (2N)⁻¹ for all m ≥ 2N. Hence y is positive. □
-}
pos-cong : ∀ x y -> x ≃ y -> Positive x -> Positive y
pos-cong x y x≃y posx = lemma2-8-1b y (ℕ.pred (2 ℕ.* N) , lemA)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = proj₁ (lemma1A x y x≃y (2 ℕ.* N₁))
N : ℕ
N = N₁ ℕ.⊔ N₂
lemA : ∀ (m : ℕ) -> m ℕ.≥ 2 ℕ.* N -> seq y m ℚ.≥ + 1 / (2 ℕ.* N)
lemA m m≥2N = begin
+ 1 / (2 ℕ.* N) ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (ℤP.*-monoˡ-≤-nonNeg 2 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (solve 1 (λ N₁ ->
con (+ 1) :* (N₁ :* (con (+ 2) :* N₁)) :=
(con (+ 1) :* (con (+ 2) :* N₁) :+ (:- con (+ 1)) :* N₁) :* (con (+ 2) :* N₁))
_≡_.refl (+ N₁)) ⟩
(+ 1 / N₁) ℚ.- (+ 1 / (2 ℕ.* N₁)) ≤⟨ ℚP.+-mono-≤
(proj₂ (lemma2-8-1a x posx) m (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.<⇒≤ N<m)))
(ℚP.neg-mono-≤ (proj₂ (lemma1A x y x≃y (2 ℕ.* N₁)) m
(ℕP.<-transʳ (ℕP.m≤n⊔m N₁ N₂) N<m))) ⟩
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
N<m : N ℕ.< m
N<m = ℕP.<-transˡ (ℕP.<-transˡ (ℕP.m<n+m N {N} ℕP.0<1+n)
(ℤP.drop‿+≤+ (ℤP.≤-reflexive (solve 1 (λ N -> N :+ N := con (+ 2) :* N) _≡_.refl (+ N))))) m≥2N
{-
Let x be a positive real number. By Lemma 2.8.1, there is N∈ℕ such that
xₘ ≥ N⁻¹ (m ≥ N).
Let n∈ℕ and let Nₙ = N. Then:
-n⁻¹ < 0
< N⁻¹
≤ xₘ
for all m ≥ Nₙ. Hence x is nonnegative by Lemma 2.8.2. □
-}
pos⇒nonNeg : ∀ x -> Positive x -> NonNegative x
pos⇒nonNeg x posx = lemma2-8-2b x lemA
where
open ℚP.≤-Reasoning
N : ℕ
N = suc (proj₁ (lemma2-8-1a x posx))
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) ->
Nₙ ≢0 × ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq x m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
test : ℚ.Negative (ℚ.- (+ 1 / n))
test = _
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq x m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) <⟨ ℚP.negative⁻¹ _ ⟩
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ (lemma2-8-1a x posx) m m≥N ⟩
seq x m ∎
{-
Proposition:
If x and y are positive, then so is x + y.
Proof:
By Lemma 2.8.1, there is N₁∈ℕ such that m ≥ N₁ implies xₘ ≥ N₂⁻¹. Similarly,
there is N₂∈ℕ such that m ≥ N₂ implies yₘ ≥ N₂⁻¹. Define N = max{N₁, N₂}, and
let m ≥ N. We have:
(x + y)ₘ = x₂ₘ + y₂ₘ
≥ N₁⁻¹ + N₂⁻¹
≥ N⁻¹ + N⁻¹
≥ N⁻¹.
Thus (x + y)ₘ ≥ N⁻¹ for all m ≥ N. By Lemma 2.8.1, x + y is positive. □
-}
posx,y⇒posx+y : ∀ x y -> Positive x -> Positive y -> Positive (x + y)
posx,y⇒posx+y x y posx posy = lemma2-8-1b (x + y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ ℚP.p≤p+q {+ 1 / N} {+ 1 / N} _ ⟩
(+ 1 / N) ℚ.+ (+ 1 / N) ≤⟨ ℚP.+-mono-≤ {+ 1 / N} {+ 1 / N₁} {+ 1 / N} {+ 1 / N₂}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n N₁ N₂))))
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m N₁ N₂)))) ⟩
(+ 1 / N₁) ℚ.+ (+ 1 / N₂) ≤⟨ ℚP.+-mono-≤ {+ 1 / N₁} {seq x (2 ℕ.* m)} {+ 1 / N₂} {seq y (2 ℕ.* m)}
(proj₂ (lemma2-8-1a x posx) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))
(proj₂ (lemma2-8-1a y posy) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
nonNegx,y⇒nonNegx+y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x + y)
nonNegx,y⇒nonNegx+y x y nonx nony = lemma2-8-2b (x + y) lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 × ∀ (m : ℕ) -> m ℕ.≥ Nₙ ->
seq (x + y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
Nx : ℕ
Nx = proj₁ (lemma2-8-2a x nonx (2 ℕ.* n))
Ny : ℕ
Ny = proj₁ (lemma2-8-2a y nony (2 ℕ.* n))
N : ℕ
N = Nx ℕ.⊔ Ny
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(:- con (+ 1)) :* (con (+ 2) :* n :* (con (+ 2) :* n)) :=
(((:- con (+ 1)) :* (con (+ 2) :* n) :+ ((:- con (+ 1)) :* (con (+ 2) :* n))) :* n))
_≡_.refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* n))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))
(proj₂ (proj₂ (lemma2-8-2a y nony (2 ℕ.* n))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) (ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
{-
Suppose x≃y and x is nonnegative. WTS y is nonnegative. Then, for each n∈ℕ, there is
Nₙ∈ℕ such that m≥Nₙ implies xₘ ≥ -n⁻¹. Thus there is N₁∈ℕ such that m ≥ N₁ implies
xₘ ≥ -(2n)⁻¹. Since x ≃ y, there is N₂∈ℕ such that m ≥ N₂ implies ∣xₘ - yₘ∣ ≤ (2n)⁻¹.
Let N = max{N₁, N₂} and let m ≥ N. We have:
yₘ ≥ xₘ - ∣xₘ - yₘ∣
≥ -(2n)⁻¹ - (2n)⁻¹
= -n⁻¹,
so yₘ ≥ -n⁻¹ for all m ≥ N. Thus y is nonnegative. □
-}
nonNeg-cong : ∀ x y -> x ≃ y -> NonNegative x -> NonNegative y
nonNeg-cong x y x≃y nonx = lemma2-8-2b y lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:+_ to _ℚ:+_
; _:-_ to _ℚ:-_
; _:=_ to _ℚ:=_
)
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq y m ℚ.≥ ℚ.- (+ 1 / n)
lemA (suc k₁) = N , _ , lemB
where
n : ℕ
n = suc k₁
N₁ : ℕ
N₁ = proj₁ (lemma2-8-2a x nonx (2 ℕ.* n))
N₂ : ℕ
N₂ = proj₁ (lemma1A x y x≃y (2 ℕ.* n))
N : ℕ
N = suc (N₁ ℕ.⊔ N₂)
lemB : ∀ (m : ℕ) -> m ℕ.≥ N -> seq y m ℚ.≥ ℚ.- (+ 1 / n)
lemB m m≥N = begin
ℚ.- (+ 1 / n) ≈⟨ ℚ.*≡* (solve 1 (λ n ->
(:- con (+ 1)) :* (con (+ 2) :* n :* (con (+ 2) :* n)) :=
(((:- con (+ 1)) :* (con (+ 2) :* n) :+ ((:- con (+ 1)) :* (con (+ 2) :* n))) :* n))
_≡_.refl (+ n)) ⟩
ℚ.- (+ 1 / (2 ℕ.* n)) ℚ.- (+ 1 / (2 ℕ.* n)) ≤⟨ ℚP.+-mono-≤
(proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* n))) m
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.n≤1+n (N₁ ℕ.⊔ N₂)) m≥N)))
(ℚP.neg-mono-≤ (proj₂ (lemma1A x y x≃y (2 ℕ.* n)) m (ℕP.<-transʳ (ℕP.m≤n⊔m 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 ∎
{-
Proposition:
If x is positive and y is nonnegative, then x + y is positive.
Proof:
Since x is positive, there is an N₁∈ℕ such that xₘ ≥ N₁⁻¹ for all m ≥ N₁. Since y is
nonnegative, there is N₂∈ℕ such that, for all m ≥ N₂, we have yₘ ≥ -(2N₁)⁻¹. Let N = 2max{N₁, N₂}.
Let m ≥ N ≥ N₁, N₂. We have:
(x + y)ₘ = x₂ₘ + y₂ₘ
≥ N₁⁻¹ - (2N₁)⁻¹
= (2N₁)⁻¹.
≥ N⁻¹.
Thus (x + y)ₘ ≥ N⁻¹ for all m ≥ N. By Lemma 2.8.1, x + y is positive. □
-}
posx∧nonNegy⇒posx+y : ∀ x y -> Positive x -> NonNegative y -> Positive (x + y)
posx∧nonNegy⇒posx+y x y posx nony = lemma2-8-1b (x + y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = proj₁ (lemma2-8-2a y nony (2 ℕ.* N₁))
N : ℕ
N = 2 ℕ.* (N₁ ℕ.⊔ N₂)
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x + y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (ℤP.*-monoˡ-≤-nonNeg 2 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))) ⟩
+ 1 / (2 ℕ.* N₁) ≈⟨ ℚ.*≡* (solve 1 (λ N₁ ->
con (+ 1) :* (N₁ :* (con (+ 2) :* N₁)) :=
(con (+ 1) :* (con (+ 2) :* N₁) :+ (:- con (+ 1)) :* N₁) :* (con (+ 2) :* N₁))
_≡_.refl (+ N₁)) ⟩
(+ 1 / N₁) ℚ.- (+ 1 / (2 ℕ.* N₁)) ≤⟨ ℚP.+-mono-≤ (proj₂ (lemma2-8-1a x posx) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n)
(ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n)))))
(proj₂ (proj₂ (lemma2-8-2a y nony (2 ℕ.* N₁))) (2 ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) (ℕP.≤-trans (ℕP.m≤n*m (N₁ ℕ.⊔ N₂) {2} ℕP.0<1+n)
(ℕP.≤-trans m≥N (ℕP.m≤n*m m {2} ℕP.0<1+n))))) ⟩
seq x (2 ℕ.* m) ℚ.+ seq y (2 ℕ.* m) ∎
∣x∣nonNeg : ∀ x -> NonNegative ∣ x ∣
∣x∣nonNeg x = nonNeg-cong ∣ x ∣₂ ∣ x ∣ (≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x)) λ {(suc k₁) -> ℚP.≤-trans (ℚP.nonPositive⁻¹ _) (ℚP.0≤∣p∣ (seq x (suc k₁)))}
{-
Module for chain of equality reasoning on ℝ
-}
module ≃-Reasoning where
open import Relation.Binary.Reasoning.Setoid ≃-setoid
public
{-
Proposition:
If x is nonnegative, then ∣x∣ = x.
Proof:
Let j∈ℕ. Since x is nonnegative, there is N∈ℕ such that
xₘ ≥ -(2j)⁻¹ (m ≥ N).
Let m ≥ N. Then -2xₘ ≤ j⁻¹. Either xₘ ≥ 0 or xₘ < 0.
Case 1: Suppose xₘ ≥ 0. Then:
∣∣xₘ∣ - xₘ∣ = ∣xₘ∣ - xₘ
= xₘ - xₘ
= 0
≤ j⁻¹
Case 2: Suppose xₘ < 0. Then:
∣∣xₘ∣ - xₘ∣ = ∣xₘ∣ - xₘ
= -xₘ - xₘ
= -2xₘ
≤ j⁻¹.
Thus ∣∣xₘ∣ - xₘ∣ ≤ j⁻¹ for all m ≥ N. By Lemma 1, ∣x∣ = x. □
-}
nonNegx⇒∣x∣₂≃x : ∀ x -> NonNegative x -> ∣ x ∣₂ ≃ x
nonNegx⇒∣x∣₂≃x x nonx = lemma1B ∣ x ∣₂ x lemA
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver
open +-*-Solver
lemA : ∀ (j : ℕ) -> {j≢0 : j ≢0} -> ∃ λ (N : ℕ) -> ∀ (n : ℕ) -> N ℕ.< n ->
ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ (+ 1 / j) {j≢0}
lemA (suc k₁) = N , lemB
where
j : ℕ
j = suc k₁
N : ℕ
N = proj₁ (lemma2-8-2a x nonx (2 ℕ.* j))
lemB : ∀ (n : ℕ) -> N ℕ.< n -> ℚ.∣ seq ∣ x ∣₂ n ℚ.- seq x n ∣ ℚ.≤ + 1 / j
lemB (suc k₂) N<n = [ left , right ]′ (ℚP.≤-total (seq x n) 0ℚᵘ)
where
n : ℕ
n = suc k₂
-xₙ≤1/2j : ℚ.- seq x n ℚ.≤ + 1 / (2 ℕ.* j)
-xₙ≤1/2j = begin
ℚ.- seq x n ≤⟨ ℚP.neg-mono-≤ (proj₂ (proj₂ (lemma2-8-2a x nonx (2 ℕ.* j))) n (ℕP.<⇒≤ 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 ->
(con (+ 1) :* (con (+ 2) :* j) :+ con (+ 1) :* (con (+ 2) :* j)) :* j :=
(con (+ 1) :* (con (+ 2) :* j :* (con (+ 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⇒∣x∣≃x : ∀ x -> NonNegative x -> ∣ x ∣ ≃ x
nonNegx⇒∣x∣≃x x nonx = ≃-trans {∣ x ∣} {∣ x ∣₂} {x} (∣x∣≃∣x∣₂ x) (nonNegx⇒∣x∣₂≃x x nonx)
{-
Proposition:
If x and y are nonnegative, then so is x * y.
Proof:
Since x and y are nonnegative, we have x = ∣x∣ and y = ∣y∣. Then x*y = ∣x∣*∣y∣ = ∣x*y∣, which is nonnegative. □
-}
nonNegx,y⇒nonNegx*y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x * y)
nonNegx,y⇒nonNegx*y x y nonx nony = nonNeg-cong ∣ x * y ∣ (x * y) lem (∣x∣nonNeg (x * y))
where
open ≃-Reasoning
lem : ∣ x * y ∣ ≃ x * y
lem = begin
∣ x * y ∣ ≈⟨ ∣x*y∣≃∣x∣*∣y∣ x y ⟩
∣ x ∣ * ∣ y ∣ ≈⟨ *-cong {∣ x ∣} {x} {∣ y ∣} {y} (nonNegx⇒∣x∣≃x x nonx) (nonNegx⇒∣x∣≃x y nony) ⟩
x * y ∎
{-
Proposition:
If x and y are positive, then so is x * y.
Proof:
By Lemma 2.8.1, there exists N₁,N₂∈ℕ such that
xₘ ≥ N₁⁻¹ (m ≥ N₁), and
yₘ ≥ N₂⁻¹ (m ≥ N₂).
Let N = max{N₁, N₂} and let m ≥ N². We have:
x₂ₖₘy₂ₖₘ ≥ N₁⁻¹N₂⁻¹
≥ N⁻¹ * N⁻¹
= (N²)⁻¹,
so x₂ₖₘy₂ₖₘ ≥ (N²)⁻¹ for all m ≥ N². By Lemma 2.8.1, x * y is
positive. □
-}
posx,y⇒posx*y : ∀ x y -> Positive x -> Positive y -> Positive (x * y)
posx,y⇒posx*y x y posx posy = lemma2-8-1b (x * y) (ℕ.pred (N ℕ.* N) , lem)
where
open ℚP.≤-Reasoning
k : ℕ
k = K x ℕ.⊔ K y
N₁ : ℕ
N₁ = suc (proj₁ (lemma2-8-1a x posx))
N₂ : ℕ
N₂ = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = N₁ ℕ.⊔ N₂
lem : ∀ (m : ℕ) -> m ℕ.≥ N ℕ.* N -> seq (x * y) m ℚ.≥ + 1 / (N ℕ.* N)
lem m m≥N² = begin
+ 1 / (N ℕ.* N) ≡⟨ _≡_.refl ⟩
(+ 1 / N) ℚ.* (+ 1 / N) ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / N} _ {+ 1 / N} {+ 1 / N₁}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n N₁ N₂)))))
(ℚP.*-monoʳ-≤-nonNeg {+ 1 / N₁} _ {+ 1 / N} {+ 1 / N₂}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m N₁ N₂))))) ⟩
(+ 1 / N₁) ℚ.* (+ 1 / N₂) ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {+ 1 / N₂} _ {+ 1 / N₁} {seq x (2 ℕ.* k ℕ.* m)}
(proj₂ (lemma2-8-1a x posx) (2 ℕ.* k ℕ.* m)
(ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤2km)))
(ℚP.*-monoʳ-≤-pos {seq x (2 ℕ.* k ℕ.* m)} posx₂ₖₘ {+ 1 / N₂}
{seq y (2 ℕ.* k ℕ.* m)}
(proj₂ (lemma2-8-1a y posy) (2 ℕ.* k ℕ.* m)
(ℕP.≤-trans (ℕP.m≤n⊔m N₁ N₂) N≤2km))) ⟩
seq x (2 ℕ.* k ℕ.* m) ℚ.* seq y (2 ℕ.* k ℕ.* m) ∎
where
N≤2km : N ℕ.≤ 2 ℕ.* k ℕ.* m
N≤2km = ℕP.≤-trans (ℕP.m≤n*m N {N} ℕP.0<1+n) (ℕP.≤-trans m≥N² (ℕP.m≤n*m m {2 ℕ.* k} ℕP.0<1+n))
posx₂ₖₘ : ℚ.Positive (seq x (2 ℕ.* k ℕ.* m))
posx₂ₖₘ = 0<⇒pos (seq x (2 ℕ.* k ℕ.* m)) (ℚP.<-≤-trans {0ℚᵘ} {+ 1 / N₁} {seq x (2 ℕ.* k ℕ.* m)}
(ℚP.positive⁻¹ _) (proj₂ (lemma2-8-1a x posx) (2 ℕ.* k ℕ.* m) (ℕP.≤-trans (ℕP.m≤m⊔n N₁ N₂) N≤2km)))
{-
Proposition:
If x is positive and y is any real number, then max{x, y} is positive.
Proof:
Since x is positive, there is N∈ℕ such that m ≥ N implies xₘ ≥ N⁻¹. Let
m ≥ N. We have:
(x ⊔ y)ₘ = xₘ ⊔ yₘ
≥ xₘ
≥ N⁻¹.
-}
posx⇒posx⊔y : ∀ x y -> Positive x -> Positive (x ⊔ y)
posx⇒posx⊔y x y posx = lemma2-8-1b (x ⊔ y) (ℕ.pred N , lem)
where
open ℚP.≤-Reasoning
N : ℕ
N = suc (proj₁ (lemma2-8-1a x posx))
lem : ∀ (m : ℕ) -> m ℕ.≥ N -> seq (x ⊔ y) m ℚ.≥ + 1 / N
lem m m≥N = begin
+ 1 / N ≤⟨ proj₂ (lemma2-8-1a x posx) m m≥N ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎
{-
Proposition:
If x is nonnegative and y is any real number, then max{x, y} is nonnegative.
Proof:
Since x is nonnegative, for each n∈ℕ there is Nₙ∈ℕ such that xₘ ≥ -n⁻¹ for all
m ≥ Nₙ. Let m ≥ Nₙ. Then:
(x ⊔ y)ₘ = xₘ ⊔ yₘ
≥ xₘ
≥ -n⁻¹.
-}
nonNegx⇒nonNegx⊔y : ∀ x y -> NonNegative x -> NonNegative (x ⊔ y)
nonNegx⇒nonNegx⊔y x y nonx = lemma2-8-2b (x ⊔ y) lemA
where
open ℚP.≤-Reasoning
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊔ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemA n {n≢0} = Nₙ , proj₁ (proj₂ (lemma2-8-2a x nonx n {n≢0})) , lemB
where
Nₙ : ℕ
Nₙ = proj₁ (lemma2-8-2a x nonx n {n≢0})
lemB : ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊔ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0}
lemB m m≥Nₙ = begin
ℚ.- (+ 1 / n) {n≢0} ≤⟨ proj₂ (proj₂ (lemma2-8-2a x nonx n {n≢0})) m m≥Nₙ ⟩
seq x m ≤⟨ ℚP.p≤p⊔q (seq x m) (seq y m) ⟩
seq x m ℚ.⊔ seq y m ∎
_⊓₂_ : (x y : ℝ) -> ℝ
seq (x ⊓₂ y) m = seq x m ℚ.⊓ seq y m
reg (x ⊓₂ y) (suc k₁) (suc k₂) = 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ₙ))) ∣ ≤⟨ reg (x ⊓ y) m n ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
xₘ : ℚᵘ
xₘ = seq x m
xₙ : ℚᵘ
xₙ = seq x n
yₘ : ℚᵘ
yₘ = seq y m
yₙ : ℚᵘ
yₙ = seq y n
x⊓y≃x⊓₂y : ∀ x y -> x ⊓ y ≃ x ⊓₂ y
x⊓y≃x⊓₂y x y (suc k₁) = begin
ℚ.∣ (ℚ.- ((ℚ.- xₙ) ℚ.⊔ (ℚ.- yₙ))) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- (xₙ ℚ.⊓ yₙ))
(ℚP.neg-distrib-⊔-⊓ (ℚ.- xₙ) (ℚ.- yₙ))) ⟩
ℚ.∣ ((ℚ.- (ℚ.- xₙ)) ℚ.⊓ (ℚ.- (ℚ.- yₙ))) ℚ.- (xₙ ℚ.⊓ yₙ) ∣ ≈⟨ ℚP.∣-∣-cong (ℚP.+-congˡ (ℚ.- (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
n : ℕ
n = suc k₁
xₙ : ℚᵘ
xₙ = seq x n
yₙ : ℚᵘ
yₙ = seq y n
{-
Proposition:
If x and y are nonnegative, then so is min{x, y}.
Proof:
Since x and y are nonnegative, for each n∈ℕ there is Nₙx, Nₙy∈ℕ such that
xₘ ≥ -n⁻¹ (m ≥ Nₙx), and
yₘ ≥ -n⁻¹ (m ≥ Nₙy).
Let Nₙ = max{Nₙx, Nₙy}, and let m ≥ Nₙ. Suppose, without loss of generality, that
xₘ ⊓ yₘ = xₘ. Then we have:
(x ⊓ y)ₘ = xₘ ⊓ yₘ
= xₘ
≥ -n⁻¹.
-}
nonNegx,y⇒nonNegx⊓y : ∀ x y -> NonNegative x -> NonNegative y -> NonNegative (x ⊓ y)
nonNegx,y⇒nonNegx⊓y x y nonx nony = nonNeg-cong (x ⊓₂ y) (x ⊓ y) (≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y))
(lemma2-8-2b (x ⊓₂ y) lemA)
where
open ℚP.≤-Reasoning
lemA : ∀ (n : ℕ) -> {n≢0 : n ≢0} -> ∃ λ (Nₙ : ℕ) -> Nₙ ≢0 ×
(∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n) {n≢0})
lemA (suc k₁) = Nₙ , _ , lemB
where
n : ℕ
n = suc k₁
Nₙx : ℕ
Nₙx = proj₁ (lemma2-8-2a x nonx n)
Nₙy : ℕ
Nₙy = proj₁ (lemma2-8-2a y nony n)
Nₙ : ℕ
Nₙ = Nₙx ℕ.⊔ Nₙy
lemB : ∀ (m : ℕ) -> m ℕ.≥ Nₙ -> seq (x ⊓₂ y) m ℚ.≥ ℚ.- (+ 1 / n)
lemB 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₂ (lemma2-8-2a x nonx n)) m
(ℕP.≤-trans (ℕP.m≤m⊔n Nₙx Nₙy) 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₂ (lemma2-8-2a y nony n)) m
(ℕP.≤-trans (ℕP.m≤n⊔m Nₙx Nₙy) m≥Nₙ) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
{-
Proposition:
If x and y are positive, then so is min{x, y}.
Proof:
Since x and y are positive, there are Nx, Ny∈ℕ such that
xₘ ≥ Nx⁻¹ (m ≥ Nx), and
yₘ ≥ Ny⁻¹ (m ≥ Ny).
Let N = max{Nx, Ny}, and let m ≥ N. Suppose, without loss of generality, that
xₘ ⊓ yₘ = xₘ. We have:
(x ⊓ y)ₘ = xₘ ⊓ yₘ
= xₘ
≥ Nx⁻¹
≥ N⁻¹.
-}
posx,y⇒posx⊓y : ∀ x y -> Positive x -> Positive y -> Positive (x ⊓ y)
posx,y⇒posx⊓y x y posx posy = pos-cong (x ⊓₂ y) (x ⊓ y) (≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y))
(lemma2-8-1b (x ⊓₂ y) (ℕ.pred N , lem))
where
open ℚP.≤-Reasoning
Nx : ℕ
Nx = suc (proj₁ (lemma2-8-1a x posx))
Ny : ℕ
Ny = suc (proj₁ (lemma2-8-1a y posy))
N : ℕ
N = 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 ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m⊔n Nx Ny))) ⟩
+ 1 / Nx ≤⟨ proj₂ (lemma2-8-1a x posx) m (ℕP.≤-trans (ℕP.m≤m⊔n Nx Ny) 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 ≤⟨ *≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤n⊔m Nx Ny))) ⟩
+ 1 / Ny ≤⟨ proj₂ (lemma2-8-1a y posy) m (ℕP.≤-trans (ℕP.m≤n⊔m Nx Ny) m≥N) ⟩
seq y m ≈⟨ ℚP.≃-sym (ℚP.p≥q⇒p⊓q≃q hyp) ⟩
seq x m ℚ.⊓ seq y m ∎
infix 4 _<_ _>_ _≤_ _≥_
_<_ : Rel ℝ 0ℓ
x < y = Positive (y - x)
_>_ : Rel ℝ 0ℓ
x > y = y < x
_≤_ : Rel ℝ 0ℓ
x ≤ y = NonNegative (y - x)
--data _≤_ : Rel ℝ 0ℓ where
-- ⋆≤⋆ : ∀ x y -> NonNegative (y - x) -> x ≤ y
_≥_ : Rel ℝ 0ℓ
x ≥ y = y ≤ x
Negative : Pred ℝ 0ℓ
Negative x = Positive (- x)
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ {x} {y} x<y = pos⇒nonNeg (y - x) x<y
<-≤-trans : Trans _<_ _≤_ _<_
<-≤-trans {x} {y} {z} x<y y≤z = pos-cong (y - x + (z - y)) (z - x) lem (posx∧nonNegy⇒posx+y (y - x) (z - y) x<y y≤z)
where
open ≃-Reasoning
lem : (y - x) + (z - y) ≃ z - x
lem = begin
(y - x) + (z - y) ≈⟨ +-comm (y - x) (z - y) ⟩
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + ((- y) + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
≤-<-trans : Trans _≤_ _<_ _<_
≤-<-trans {x} {y} {z} x≤y y<z = pos-cong ((z - y) + (y - x)) (z - x) lem (posx∧nonNegy⇒posx+y (z - y) (y - x) y<z x≤y)
where
open ≃-Reasoning
lem : (z - y) + (y - x) ≃ z - x
lem = begin
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + (- y + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
<-trans : Transitive _<_
<-trans {x} {y} {z} = ≤-<-trans {x} {y} {z} ∘ <⇒≤ {x} {y}
≤-trans : Transitive _≤_
≤-trans {x} {y} {z} x≤y y≤z = nonNeg-cong (z - y + (y - x)) (z - x) lem (nonNegx,y⇒nonNegx+y (z - y) (y - x) y≤z x≤y)
where
open ≃-Reasoning
lem : (z - y) + (y - x) ≃ z - x
lem = begin
(z - y) + (y - x) ≈⟨ +-assoc z (- y) (y - x) ⟩
z + (- y + (y - x)) ≈⟨ +-congʳ z {(- y) + (y - x)} {(- y + y) - x} (≃-symm {(- y + y) - x} {(- y) + (y - x)} (+-assoc (- y) y (- x))) ⟩
z + ((- y + y) - x) ≈⟨ +-congʳ z {(- y + y) - x} {0ℝ - x} (+-congˡ (- x) {(- y + y)} {0ℝ} (+-inverseˡ y)) ⟩
z + (0ℝ - x) ≈⟨ +-congʳ z {0ℝ - x} {(- x)} (+-identityˡ (- x)) ⟩
z - x ∎
nonNeg0 : NonNegative 0ℝ
nonNeg0 (suc k₁) = ℚP.<⇒≤ (ℚP.negative⁻¹ _)
nonNeg-refl : ∀ x -> NonNegative (x - x)
nonNeg-refl x = nonNeg-cong 0ℝ (x - x) (≃-symm {x - x} {0ℝ} (+-inverseʳ x)) nonNeg0
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {x} {z} {y} {t} x≤z y≤t = nonNeg-cong ((z - x) + (t - y)) ((z + t) - (x + y)) lem (nonNegx,y⇒nonNegx+y (z - x) (t - y) x≤z y≤t)
where
open ≃-Reasoning
lem : (z - x) + (t - y) ≃ (z + t) - (x + y)
lem = begin
(z - x) + (t - y) ≈⟨ +-congʳ (z - x) {t - y} { - y + t} (+-comm t (- y)) ⟩
(z - x) + (- y + t) ≈⟨ +-assoc z (- x) (- y + t) ⟩
z + (- x + (- y + t)) ≈⟨ ≃-symm {z + ((- x + - y) + t)} {z + (- x + (- y + t))}
(+-congʳ z { - x + - y + t} { - x + (- y + t)} (+-assoc (- x) (- y) t)) ⟩
z + ((- x + - y) + t) ≈⟨ +-congʳ z { - x + - y + t} {t + (- x + - y)} (+-comm (- x + - y) t) ⟩
z + (t + (- x + - y)) ≈⟨ ≃-symm {(z + t) + (- x + - y)} {z + (t + (- x + - y))} (+-assoc z t (- x + - y)) ⟩
(z + t) + (- x + - y) ≈⟨ +-congʳ (z + t) { - x + - y} { - (x + y)} (≃-symm { - (x + y)} { - x + - y} (neg-distrib-+ x y)) ⟩
(z + t) - (x + y) ∎
+-monoʳ-≤ : ∀ (x : ℝ) -> (_+_ x) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ x {y} {z} y≤z = +-mono-≤ {x} {x} {y} {z} (nonNeg-refl x) y≤z
+-monoˡ-≤ : ∀ (x : ℝ) -> (_+ x) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ x {y} {z} y≤z = +-mono-≤ {y} {z} {x} {x} y≤z (nonNeg-refl x)
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< {x} {z} {y} {t} x<z y<t = pos-cong ((z - x) + (t - y)) ((z + t) - (x + y)) lem (posx,y⇒posx+y (z - x) (t - y) x<z y<t)
where
open ≃-Reasoning
lem : (z - x) + (t - y) ≃ (z + t) - (x + y)
lem = begin
(z - x) + (t - y) ≈⟨ +-congʳ (z - x) {t - y} { - y + t} (+-comm t (- y)) ⟩
(z - x) + (- y + t) ≈⟨ +-assoc z (- x) (- y + t) ⟩
z + (- x + (- y + t)) ≈⟨ ≃-symm {z + ((- x + - y) + t)} {z + (- x + (- y + t))}
(+-congʳ z { - x + - y + t} { - x + (- y + t)} (+-assoc (- x) (- y) t)) ⟩
z + ((- x + - y) + t) ≈⟨ +-congʳ z { - x + - y + t} {t + (- x + - y)} (+-comm (- x + - y) t) ⟩
z + (t + (- x + - y)) ≈⟨ ≃-symm {(z + t) + (- x + - y)} {z + (t + (- x + - y))} (+-assoc z t (- x + - y)) ⟩
(z + t) + (- x + - y) ≈⟨ +-congʳ (z + t) { - x + - y} { - (x + y)} (≃-symm { - (x + y)} { - x + - y} (neg-distrib-+ x y)) ⟩
(z + t) - (x + y) ∎
neg-distribˡ-* : ∀ x y -> - (x * y) ≃ - x * y
neg-distribˡ-* x y = begin
- (x * y) ≈⟨ ≃-trans { - (x * y)} { - (x * y) + 0ℝ} { - (x * y) + 0ℝ * y}
(≃-symm { - (x * y) + 0ℝ} { - (x * y)} (+-identityʳ (- (x * y))))
(+-congʳ (- (x * y)) {0ℝ} {0ℝ * y} (≃-symm {0ℝ * y} {0ℝ} (*-zeroˡ y))) ⟩
- (x * y) + 0ℝ * y ≈⟨ +-congʳ (- (x * y)) {0ℝ * y} {(x - x) * y} (*-congʳ {y} {0ℝ} {x - x} (≃-symm {x - x} {0ℝ} (+-inverseʳ x))) ⟩
- (x * y) + (x - x) * y ≈⟨ +-congʳ (- (x * y)) {(x - x) * y} {x * y + (- x) * y} (*-distribʳ-+ y x (- x)) ⟩
- (x * y) + (x * y + (- x) * y) ≈⟨ ≃-symm { - (x * y) + x * y + - x * y} { - (x * y) + (x * y + - x * y)}
(+-assoc (- (x * y)) (x * y) ((- x) * y)) ⟩
- (x * y) + x * y + (- x) * y ≈⟨ +-congˡ (- x * y) { - (x * y) + x * y} {0ℝ} (+-inverseˡ (x * y)) ⟩
0ℝ + (- x) * y ≈⟨ +-identityˡ ((- x) * y) ⟩
(- x) * y ∎
where
open ≃-Reasoning
neg-distribʳ-* : ∀ x y -> - (x * y) ≃ x * (- y)
neg-distribʳ-* x y = begin
- (x * y) ≈⟨ -‿cong {x * y} {y * x} (*-comm x y) ⟩
- (y * x) ≈⟨ neg-distribˡ-* y x ⟩
- y * x ≈⟨ *-comm (- y) x ⟩
x * (- y) ∎
where
open ≃-Reasoning
≤-reflexive : _≃_ ⇒ _≤_
≤-reflexive {x} {y} x≃y = nonNeg-cong (x - x) (y - x) (+-congˡ (- x) {x} {y} x≃y) (nonNeg-refl x)
≤-refl : Reflexive _≤_
≤-refl {x} = ≤-reflexive {x} {x} (≃-refl {x})
≤-isPreorder : IsPreorder _≃_ _≤_
IsPreorder.isEquivalence ≤-isPreorder = ≃-isEquivalence
IsPreorder.reflexive ≤-isPreorder {x} {y} x≃y = ≤-reflexive {x} {y} x≃y
IsPreorder.trans ≤-isPreorder {x} {y} {z} = ≤-trans {x} {y} {z}
<-respʳ-≃ : _<_ Respectsʳ _≃_
<-respʳ-≃ {x} {y} {z} y≃z x<y = <-≤-trans {x} {y} {z} x<y (≤-reflexive {y} {z} y≃z)
<-respˡ-≃ : _<_ Respectsˡ _≃_
<-respˡ-≃ {x} {y} {z} y≃z y<x = ≤-<-trans {z} {y} {x} (≤-reflexive {z} {y} (≃-symm {y} {z} y≃z)) y<x
<-resp-≃ : _<_ Respects₂ _≃_
<-resp-≃ = (λ {x} {y} {z} -> <-respʳ-≃ {x} {y} {z}) , λ {x} {y} {z} -> <-respˡ-≃ {x} {y} {z}
{-
Same issue as with ≃-refl. I need to specify the arguments in order to avoid the constraint error,
hence the lambdas.
-}
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder
(λ {x} {y} {z} -> <-trans {x} {y} {z})
<-resp-≃
(λ {x} {y} -> <⇒≤ {x} {y})
(λ {x} {y} {z} -> <-≤-trans {x} {y} {z})
(λ {x} {y} {z} -> ≤-<-trans {x} {y} {z})
public
*-monoʳ-≤-nonNeg : ∀ x y z -> x ≤ z -> NonNegative y -> x * y ≤ z * y
*-monoʳ-≤-nonNeg x y z x≤z nony = nonNeg-cong ((z - x) * y) (z * y - x * y) lem (nonNegx,y⇒nonNegx*y (z - x) y x≤z nony)
where
open ≃-Reasoning
lem : (z - x) * y ≃ z * y - x * y
lem = begin
(z - x) * y ≈⟨ *-distribʳ-+ y z (- x) ⟩
z * y + (- x) * y ≈⟨ +-congʳ (z * y) { - x * y} { - (x * y)} (≃-symm { - (x * y)} { - x * y} (neg-distribˡ-* x y)) ⟩
z * y - x * y ∎
*-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 y z 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 (y * (z - x)) (y * z - y * x) lem (posx,y⇒posx*y y (z - x) posy x<z)
where
open ≃-Reasoning
lem : y * (z - x) ≃ y * z - y * x
lem = begin
y * (z - x) ≈⟨ *-distribˡ-+ y z (- x) ⟩
y * z + y * (- x) ≈⟨ +-congʳ (y * z) {y * (- x)} { - (y * x)} (≃-symm { - (y * x)} {y * (- x)} (neg-distribʳ-* y x)) ⟩
y * z - y * x ∎
*-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 {y} posy {x} {z} x<z ⟩
y * z ≈⟨ *-comm y z ⟩
z * y ∎
where
open ≤-Reasoning
neg-mono-< : -_ Preserves _<_ ⟶ _>_
neg-mono-< {x} {y} x<y = pos-cong (y - x) (- x - (- y)) lem x<y
where
open ≃-Reasoning
lem : y - x ≃ - x - (- y)
lem = begin
y - x ≈⟨ +-congˡ (- x) {y} { - (- y)} (≃-symm { - (- y)} {y} (neg-involutive y)) ⟩
- (- y) - x ≈⟨ +-comm (- (- y)) (- x) ⟩
- x - (- y) ∎
neg-mono-≤ : -_ Preserves _≤_ ⟶ _≥_
neg-mono-≤ {x} {y} x≤y = nonNeg-cong (y - x) (- x - (- y)) lem x≤y
where
open ≃-Reasoning
lem : y - x ≃ - x - (- y)
lem = begin
y - x ≈⟨ +-congˡ (- x) {y} { - (- y)} (≃-symm { - (- y)} {y} (neg-involutive y)) ⟩
- (- y) - x ≈⟨ +-comm (- (- y)) (- x) ⟩
- x - (- y) ∎
x≤x⊔y : ∀ x y -> x ≤ x ⊔ y
x≤x⊔y x y (suc k₁) = 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
n : ℕ
n = suc k₁
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-cong (x - (x ⊓₂ y)) (x - (x ⊓ y)) lemA lemB
where
open ℚP.≤-Reasoning
lemA : x - (x ⊓₂ y) ≃ x - (x ⊓ y)
lemA = +-congʳ x { - (x ⊓₂ y)} { - (x ⊓ y)} (-‿cong {x ⊓₂ y} {x ⊓ y}
(≃-symm {x ⊓ y} {x ⊓₂ y} (x⊓y≃x⊓₂y x y)))
lemB : x ⊓₂ y ≤ x
lemB (suc k₁) = 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
n : ℕ
n = suc k₁
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
{-
Proposition:
≤ is antisymmetric.
Proof:
Since y - x and x - y are nonnegative, for all n∈ℕ, we have
y₂ₙ - x₂ₙ ≥ -n⁻¹ (1), and
x₂ₙ - y₂ₙ ≥ -n⁻¹ (2)
Let n∈ℕ. Either ∣x₂ₙ - y₂ₙ∣ = x₂ₙ - y₂ₙ or ∣x₂ₙ - y₂ₙ∣ = y₂ₙ - x₂ₙ.
Case 1: We have:
∣x₂ₙ - y₂ₙ∣ = x₂ₙ - y₂ₙ
≤ n⁻¹ by (1)
≤ 2n⁻¹.
Case 2: Similar.
Thus x - y ≃ 0. Hence x ≃ y. □
-}
≤-antisym : Antisymmetric _≃_ _≤_
≤-antisym {x} {y} x≤y y≤x = ≃-symm {y} {x} lemB
where
lemA : x - y ≃ 0ℝ
lemA (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 import Data.Rational.Unnormalised.Solver
open +-*-Solver
n : ℕ
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.*-monoʳ-≤-nonNeg n {+ 1} {+ 2} (+≤+ (ℕ.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.*-monoʳ-≤-nonNeg n {+ 1} {+ 2} (+≤+ (ℕ.s≤s ℕ.z≤n))) ⟩
+ 2 / n ∎
lemB : y ≃ x
lemB = begin
y ≈⟨ ≃-symm {y + 0ℝ} {y} (+-identityʳ y) ⟩
y + 0ℝ ≈⟨ +-congʳ y {0ℝ} {x - y} (≃-symm {x - y} {0ℝ} lemA) ⟩
y + (x - y) ≈⟨ +-congʳ y {x - y} { - y + x} (+-comm x (- y)) ⟩
y + (- y + x) ≈⟨ ≃-symm {y - y + x} {y + (- y + x)} (+-assoc y (- y) x) ⟩
y - y + x ≈⟨ +-congˡ x {y - y} {0ℝ} (+-inverseʳ y) ⟩
0ℝ + x ≈⟨ +-identityˡ x ⟩
x ∎
where
open ≃-Reasoning
0≤∣x∣ : ∀ x -> 0ℝ ≤ ∣ x ∣
0≤∣x∣ x = nonNeg-cong ∣ x ∣ (∣ x ∣ - 0ℝ) (≃-symm {∣ x ∣ - 0ℝ} {∣ x ∣} (+-identityʳ ∣ x ∣)) (∣x∣nonNeg x)
∣x+y∣₂≤∣x∣₂+∣y∣₂ : ∀ x y -> ∣ x + y ∣₂ ≤ ∣ x ∣₂ + ∣ y ∣₂
∣x+y∣₂≤∣x∣₂+∣y∣₂ x y (suc k₁) = 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
n : ℕ
n = suc k₁
∣x₄ₙ∣ : ℚᵘ
∣x₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ∣
∣y₄ₙ∣ : ℚᵘ
∣y₄ₙ∣ = ℚ.∣ seq y (2 ℕ.* (2 ℕ.* n)) ∣
∣x₄ₙ+y₄ₙ∣ : ℚᵘ
∣x₄ₙ+y₄ₙ∣ = ℚ.∣ seq x (2 ℕ.* (2 ℕ.* n)) ℚ.+ seq y (2 ℕ.* (2 ℕ.* n)) ∣
∣x+y∣≤∣x∣+∣y∣ : ∀ x y -> ∣ x + y ∣ ≤ ∣ x ∣ + ∣ y ∣
∣x+y∣≤∣x∣+∣y∣ x y = begin
∣ x + y ∣ ≈⟨ ∣x∣≃∣x∣₂ (x + y) ⟩
∣ x + y ∣₂ ≤⟨ ∣x+y∣₂≤∣x∣₂+∣y∣₂ x y ⟩
∣ x ∣₂ + ∣ y ∣₂ ≈⟨ +-cong {∣ x ∣₂} {∣ x ∣} {∣ y ∣₂} {∣ y ∣}
(≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x))
(≃-symm {∣ y ∣} {∣ y ∣₂} (∣x∣≃∣x∣₂ y)) ⟩
∣ x ∣ + ∣ y ∣ ∎
where
open ≤-Reasoning
_≄_ : Rel ℝ 0ℓ
x ≄ y = x < y ⊎ y < x
x≤∣x∣ : ∀ x -> x ≤ ∣ x ∣
x≤∣x∣ x (suc k₁) = 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 x (2 ℕ.* n))) ⟩
seq ∣ x ∣ (2 ℕ.* n) ℚ.- seq x (2 ℕ.* n) ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
∣-x∣₂≃∣x∣₂ : ∀ x -> ∣ - x ∣₂ ≃ ∣ x ∣₂
∣-x∣₂≃∣x∣₂ x (suc k₁) = 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
n : ℕ
n = suc k₁
test : seq ∣ - x ∣₂ n ℚ.≃ ℚ.∣ ℚ.- seq x n ∣
test = ℚP.≃-refl
∣-x∣≃∣x∣ : ∀ x -> ∣ - x ∣ ≃ ∣ x ∣
∣-x∣≃∣x∣ x = begin
∣ - x ∣ ≈⟨ ∣x∣≃∣x∣₂ (- x) ⟩
∣ - x ∣₂ ≈⟨ ∣-x∣₂≃∣x∣₂ x ⟩
∣ x ∣₂ ≈⟨ ≃-symm {∣ x ∣} {∣ x ∣₂} (∣x∣≃∣x∣₂ x) ⟩
∣ x ∣ ∎
where
open ≃-Reasoning
0<x⇒posx : ∀ x -> 0ℝ < x -> Positive x
0<x⇒posx x 0<x = pos-cong (x - 0ℝ) x (+-identityʳ x) 0<x
posx⇒0<x : ∀ x -> Positive x -> 0ℝ < x
posx⇒0<x x posx = pos-cong x (x - 0ℝ) (≃-symm {x - 0ℝ} {x} (+-identityʳ x)) posx
x≄0⇒0<∣x∣ : ∀ x -> x ≄ 0ℝ -> 0ℝ < ∣ x ∣
x≄0⇒0<∣x∣ x x≄0 = [ left , right ]′ x≄0
where
open ≤-Reasoning
left : x < 0ℝ -> 0ℝ < ∣ x ∣
left hyp = begin-strict
0ℝ <⟨ neg-mono-< {x} {0ℝ} hyp ⟩
- x ≤⟨ x≤∣x∣ (- x) ⟩
∣ - x ∣ ≈⟨ ∣-x∣≃∣x∣ x ⟩
∣ x ∣ ∎
right : 0ℝ < x -> 0ℝ < ∣ x ∣
right hyp = begin-strict
0ℝ <⟨ hyp ⟩
x ≤⟨ x≤∣x∣ x ⟩
∣ x ∣ ∎
x≄0⇒pos∣x∣ : ∀ x -> x ≄ 0ℝ -> Positive ∣ x ∣
x≄0⇒pos∣x∣ x x≄0 = 0<x⇒posx ∣ x ∣ (x≄0⇒0<∣x∣ x x≄0)
x≄0⇒pos∣x∣₂ : ∀ x -> x ≄ 0ℝ -> Positive ∣ x ∣₂
x≄0⇒pos∣x∣₂ x x≄0 = pos-cong ∣ x ∣ ∣ x ∣₂ (∣x∣≃∣x∣₂ x) (x≄0⇒pos∣x∣ x x≄0)
{-
Using abstract versions of previous results for better performance.
For instance, using lemma2-8-1a directly can be very slow.
-}
abstract
fastℕ<?ℕ : Decidable ℕ._<_
fastℕ<?ℕ = ℕP._<?_
fast2-8-1a : ∀ x -> Positive x -> ∃ λ (N : ℕ) -> ∀ (m : ℕ) -> m ℕ.≥ suc N ->
seq x m ℚ.≥ + 1 / (suc N)
fast2-8-1a = lemma2-8-1a
ℚ≠-helper : ∀ p -> p ℚ.> 0ℚᵘ ⊎ p ℚ.< 0ℚᵘ -> p ℚ.≠ 0ℚᵘ
ℚ≠-helper p hyp1 hyp2 = [ left , right ]′ hyp1
where
left : ¬ (p ℚ.> 0ℚᵘ)
left hyp = ℚP.<-irrefl (ℚP.≃-sym hyp2) hyp
right : ¬ (p ℚ.< 0ℚᵘ)
right hyp = ℚP.<-irrefl hyp2 hyp
{-
For the sake of performance, we define an alternative version of the inverse given
by Bishop.
-}
Nₐ : (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ℕ
Nₐ x {x≄0} = suc (proj₁ (fast2-8-1a ∣ x ∣₂ (x≄0⇒pos∣x∣₂ x x≄0)))
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 = Nₐ x {x≄0}
xₛ : ℚᵘ
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
0<∣xₛ∣ : 0ℚᵘ ℚ.< ℚ.∣ xₛ ∣
0<∣xₛ∣ = begin-strict
0ℚᵘ <⟨ ℚP.positive⁻¹ _ ⟩
+ 1 / N ≤⟨ proj₂ (fast2-8-1a ∣ 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ℚᵘ ∎)
{-
Strangely enough, this function is EXTREMELY slow. It pretty much does not compute. But proving an instance of it in
the definition of multiplicative inverse is very fast. Not sure why.
-}
-- ∣xₘ∣ ≥ N⁻¹
{-
abstract
inverse-helper : ∀ (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ∀ (n : ℕ) -> {n≢0 : n ≢0} ->
ℚ.∣ (ℚ.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} (suc k₁) = begin
ℚ.∣ xₛ⁻¹ ∣ ≈⟨ {!N!} {-{!ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ ℚ.∣ xₛ⁻¹ ∣))
(ℚP.*-congˡ {ℚ.∣ xₛ⁻¹ ∣} (ℚP.≃-sym (ℚP.*-inverseʳ (+ 1 / N))))!}-} ⟩
ℚ.∣ xₛ⁻¹ ∣ ℚ.* ((+ 1 / N) ℚ.* (+ N / 1)) ≤⟨ {!!} ⟩
+ N / 1 ∎
where
open ℚP.≤-Reasoning
n : ℕ
n = suc k₁
N : ℕ
N = Nₐ x {x≄0}
xₛ : ℚᵘ
xₛ = seq x ((n ℕ.+ N) ℕ.* (N ℕ.* N))
xₛ≢0 : ℤ.∣ ↥ xₛ ∣ ≢0
xₛ≢0 = not0-helper x {x≄0} n
xₛ⁻¹ : ℚᵘ
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ℚᵘ ∎-}
{-
∣x∣ > 0
∣xₘ∣ ≥ N⁻¹ (m ≥ N)
x ≄ 0
x⁻¹ = (x (N³))⁻¹ if n < N
(x (n * N²))⁻¹ else
x⁻¹ = (x ((n + N) * N²))⁻¹
x⁻¹ n with n <? N
-}
_⁻¹ : (x : ℝ) -> {x≄0 : x ≄ 0ℝ} -> ℝ
seq ((x ⁻¹) {x≄0}) n = (ℚ.1/ xₛ) {not0-helper x {x≄0} n}
where
open ℚP.≤-Reasoning
N : ℕ
N = Nₐ x {x≄0}
xₛ : ℚᵘ
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 ->
-- Function and details for solver
((N :* N) :* ((con (+ 1) :* ((m :+ N) :* (N :* N))) :+ (con (+ 1) :* ((n :+ N) :* (N :* N))))) :* ((m :+ N) :* (n :+ N)) :=
(con (+ 1) :* (n :+ N) :+ con (+ 1) :* (m :+ N)) :* (con (+ 1) :* con (+ 1) :* (((n :+ N) :* (N :* N)) :* ((m :+ N) :* (N :* N)))))
_≡_.refl (+ m) (+ n) (+ N)) ⟩
(+ 1 / (m ℕ.+ N)) ℚ.+ (+ 1 / (n ℕ.+ N)) ≤⟨ ℚP.+-mono-≤ {+ 1 / (m ℕ.+ N)} {+ 1 / m} {+ 1 / (n ℕ.+ N)} {+ 1 / n}
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m+n m N))))
(*≤* (ℤP.*-monoˡ-≤-nonNeg 1 (+≤+ (ℕP.m≤m+n n N)))) ⟩
(+ 1 / m) ℚ.+ (+ 1 / n) ∎
where
open ℚP.≤-Reasoning
open import Data.Integer.Solver as ℤ-Solver
open ℤ-Solver.+-*-Solver
open import Data.Rational.Unnormalised.Solver as ℚ-Solver
open ℚ-Solver.+-*-Solver using ()
renaming
( solve to ℚsolve
; _:-_ to _ℚ:-_
; _:*_ to _ℚ:*_
; _:=_ to _ℚ:=_
)
N : ℕ
N = Nₐ x {x≄0}
m : ℕ
m = suc k₁
n : ℕ
n = suc k₂
xₘ : ℚᵘ
xₘ = seq x ((m ℕ.+ N) ℕ.* (N ℕ.* N))
xₙ : ℚᵘ
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ₘ : ℚᵘ
yₘ = (ℚ.1/ xₘ) {xₖ≢0 m}
yₙ : ℚᵘ
yₙ = (ℚ.1/ xₙ) {xₖ≢0 n}
∣yₖ∣≤N : ∀ (k : ℕ) -> ℚ.∣ (ℚ.1/ (seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N)))) {not0-helper x {x≄0} k} ∣ ℚ.≤ + N / 1
∣yₖ∣≤N k = begin
ℚ.∣ yₖ ∣ ≈⟨ ℚP.≃-trans (ℚP.≃-sym (ℚP.*-identityʳ ℚ.∣ yₖ ∣)) (ℚP.*-congˡ {ℚ.∣ yₖ ∣} (ℚP.≃-sym (ℚP.*-inverseʳ (+ 1 / N)))) ⟩
ℚ.∣ yₖ ∣ ℚ.* ((+ 1 / N) ℚ.* (+ N / 1)) ≤⟨ ℚP.*-monoʳ-≤-nonNeg {ℚ.∣ yₖ ∣} _ (ℚP.*-monoˡ-≤-nonNeg {+ N / 1} _
(proj₂ (fast2-8-1a ∣ x ∣₂ (x≄0⇒pos∣x∣₂ x x≄0)) ((k ℕ.+ N) ℕ.* (N ℕ.* N))
(ℕP.≤-trans (ℕP.m≤m*n N {N} ℕP.0<1+n)
(ℕP.m≤n*m (N ℕ.* N) {k ℕ.+ N} (subst (0 ℕ.<_) (ℕP.+-comm N k) ℕP.0<1+n))))) ⟩
ℚ.∣ yₖ ∣ ℚ.* (ℚ.∣ xₖ ∣ ℚ.* (+ N / 1)) ≈⟨ ℚP.≃-trans
(ℚP.≃-sym (ℚP.*-assoc ℚ.∣ yₖ ∣ ℚ.∣ xₖ ∣ (+ N / 1)))
(ℚP.≃-sym (ℚP.*-congʳ {+ N / 1} (ℚP.∣p*q∣≃∣p∣*∣q∣ yₖ xₖ))) ⟩
ℚ.∣ yₖ ℚ.* xₖ ∣ ℚ.* (+ N / 1) ≈⟨ ℚP.≃-trans
(ℚP.*-congʳ {+ N / 1} (ℚP.∣-∣-cong (ℚP.*-inverseˡ xₖ {xₖ≢0 k})))
(ℚP.*-identityˡ (+ N / 1)) ⟩
+ N / 1 ∎
where
xₖ : ℚᵘ
xₖ = seq x ((k ℕ.+ N) ℕ.* (N ℕ.* N))
yₖ : ℚᵘ
yₖ = (ℚ.1/ xₖ) {not0-helper x {x≄0} k}
∣yₘ*yₙ∣≤N² : ℚ.∣ yₘ ℚ.* yₙ ∣ ℚ.≤ (+ N / 1) ℚ.* (+ N / 1)
∣yₘ*yₙ∣≤N² = begin
ℚ.∣ yₘ ℚ.* yₙ ∣ ≈⟨ ℚP.∣p*q∣≃∣p∣*∣q∣ yₘ yₙ ⟩
ℚ.∣ yₘ ∣ ℚ.* ℚ.∣ yₙ ∣ ≤⟨ ℚP.≤-trans
(ℚP.*-monoˡ-≤-nonNeg {ℚ.∣ yₙ ∣} _ (∣yₖ∣≤N m))
(ℚP.*-monoʳ-≤-nonNeg {+ N / 1} _ (∣yₖ∣≤N n)) ⟩
(+ N / 1) ℚ.* (+ N / 1) ∎
{-
DISCUSSION POINTS ON THE POSSIBILITY OF THE ℝ SOLVER
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Obviously, we want the ring solver to work on ℝ. It would be extremely tedious to prove any interesting result later on without the ring
solver. But there are some problems, at least right now, preventing it from working.
First, note that the ring solvers generally use rings with decidable equality. But it actually CAN work without decidable equality. The
equality can be so weak that it's not even slightly weakly decidable. As proof of concept, see the example below.
-}
{-
sadDec : ∀ (x y : ℚᵘ) -> Maybe (x ℚ.≃ y)
sadDec x y = nothing
module ℚ-Sad-+-*-Solver =
Solver ℚP.+-*-rawRing (ACR.fromCommutativeRing ℚP.+-*-commutativeRing) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing ℚP.+-*-commutativeRing)) sadDec
testing₁ : ∀ (x y z : ℚᵘ) -> ℚ.1ℚᵘ ℚ.* (x ℚ.+ y ℚ.- z ℚ.+ 0ℚᵘ) ℚ.≃ y ℚ.- (ℚ.- x ℚ.+ z)
testing₁ x y z = solve 3 (λ x y z -> con ℚ.1ℚᵘ :* (x :+ y :- z :+ con 0ℚᵘ) := y :- (:- x :+ z)) ℚP.≃-refl x y z
where
open ℚ-Sad-+-*-Solver
-}
{- However, the same solution will NOT work on ℝ, at least for now, as shown below.-}
{-
≃-weaklyDec : ∀ x y -> Maybe (x ≃ y)
≃-weaklyDec x y = nothing
module ℝ-+-*-Solver =
Solver +-*-rawRing (ACR.fromCommutativeRing +-*-commutativeRing) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing +-*-commutativeRing)) ≃-weaklyDec
testing₂ : ∀ x y z -> 1ℝ * (x + y - z + 0ℝ) ≃ y - (- x + z)
testing₂ x y z = ?
where
open ℝ-+-*-Solver
-}
{-
The problem is ≃-refl. For some reason, it's incapable of determining implicit arguments, even in trivial cases. For instance, 0ℝ ≃ 0ℝ must be proved using
≃-refl {0ℝ}. Excluding the implicit argument results in a constraint error, as shown below.-}
{-sad0ℝ₁ : 0ℝ ≃ 0ℝ
sad0ℝ₁ = ≃-refl
sad0ℝ₂ : 0ℝ ≃ 0ℝ
sad0ℝ₂ = ≃-refl {0ℝ}
-}
{- From the constraint error, I thought it was a problem with the definition of regularity in the definition of ℝ. In particular, the issue could be
the implicit m ≢0 and n ≢0 arguments. But modifying the definition so that there are NO implicit arguments still doesn't work. I am unsure what the cause is.
So, how do we let ℝ's solver work with reflexivity proofs? Here are some proposed attempts:
(1) Prove the ring equality at the sequence level instead. This means, to prove that (x + y) - z ≃ y - (z - x), for instance, we prove it by definition of ≃
instead of by using the various ring properties of ℝ. So our proof would need to be of the form
∣ (x₄ₘ + y₄ₘ - z₂ₘ) - (y₂ₘ - (z₄ₘ - x₄ₘ)) ∣ ≤ 2m⁻¹ (m∈ℤ⁺)
and we would use the ℚ ring solver to assist with it. This could be shorter, in some instances, than applying a bunch of ring properties of ℝ. But it most likely
becomes intractable when we get more difficult equalities and, for instance, when the ring equality includes multiplication (since the canonical bounds would
interfere).
(2) Prove the ring equality for ALL rings and then apply it to ℝ. It seems to work, as shown below in testing₃, but it's very tedious and seems prone to fail.
(3) The final option I've come up with is to wait for the next Agda release, which looks to be right around the corner. I've had this "constraints that seem
trivial but Agda won't solve" issue a few times now, and it was solved by an update twice (the other time there was an easy function I could make to fix it.
That doesn't seem to be the case here).
-}
{-
testing₃ : ∀ x y z -> x + y + z ≃ y + (z + x)
testing₃ = lem (+-*-commutativeRing)
where
open CommutativeRing using (Carrier; 0#; 1#; _≈_)
renaming
( _+_ to _R+_
; _-_ to _R-_
; _*_ to _R*_
; -_ to R-_
)
{-
The notation is a bit ugly, but this says
x + y - z + 0 = 1 * (y - (z - x)).
-}
lem : ∀ (R : CommutativeRing 0ℓ 0ℓ) -> ∀ (x y z : Carrier R) ->
(_≈_ R) ((_R+_ R) ((_R+_ R) x y) z)
((_R+_ R) y ((_R+_ R) z x))
lem R x y z = solve 3 (λ x y z ->
x :+ y :+ z := y :+ (z :+ x))
R-refl x y z
where
R-weaklyDec : ∀ x y -> Maybe ((R ≈ x) y)
R-weaklyDec x y = nothing
rawRing : RawRing 0ℓ 0ℓ
rawRing = {!!}
R-refl : Reflexive (_≈_ R)
R-refl = {!!}
module R-Solver =
Solver rawRing (ACR.fromCommutativeRing R) (ACR.-raw-almostCommutative⟶ (ACR.fromCommutativeRing R)) R-weaklyDec
open R-Solver
UPDATE
It seems (3) won't fix the problem. I tried the newest developmental release as of June 7th, 2021, and it didn't work.
Solution (2) might be promising if I can make some sort of function that says something for general rings R like
"If ϕᴿ(x₁,...,xₙ) = ψᴿ(x₁,...,xₙ) for all xᵢ∈R and for all rings R, then ϕ̂(x₁,...,xₙ) = ψ(x₁,...,xₙ) for all xᵢ∈ℝ.
That might save me the trouble of declaring a general ring solver and whatnot over and over again. Not sure if this
is possible, though.
-}
{-
If ϕ(x) = ψ(x) for all x∈R for all rings R, then ϕ(x) = ψ(x) for all x∈ℝ."
-}
{-
open CommutativeRing {{...}} using (Carrier; 0#; 1#; _≈_)
renaming
( _+_ to _R+_
; _-_ to _R-_
; _*_ to _R*_
; -_ to R-_
)
-}
-- This function and its counterparts are probably useless since we'd have to prove the
-- middle section anyway, which we could then directly apply in our proof instead of wasting our
-- time with this function.
{-solveMe : (ϕ ψ : (R : CommutativeRing 0ℓ 0ℓ) -> (x y z : Carrier) -> Carrier R) ->
(∀ (R : CommutativeRing 0ℓ 0ℓ) -> ∀ (x y z : Carrier R) -> (_≈_ R) (ϕ R x y z) (ψ R x y z)) ->
∀ (x y z : ℝ) -> ϕ +-*-commutativeRing x y z ≃ ψ +-*-commutativeRing x y z
solveMe ϕ ψ hyp x y z = hyp +-*-commutativeRing x y z-}
{-
R-Solver : CommutativeRing 0ℓ 0ℓ -> {!!}
R-Solver R = {!+-*-Solver!}
where
module +-*-Solver = Solver {!!} {!!} {!!} {!!}
open +-*-Solver
test : ∀ {{R : CommutativeRing 0ℓ 0ℓ}} -> ∀ (x y : Carrier) -> x R+ y ≈ (y R+ x)
test x y = {!!}
where
module +-*-Solver = Solver {!!} {!!} {!!} {!!}
-}
0test : 0ℝ ≃ - 0ℝ
0test = ≃-refl {0ℝ}
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.∣p∣≃p⇒0≤p ℚP.≃-refl ⟩
+ 2 / n ∎}
where open ℚP.≤-Reasoning
test0 : ∀ p -> - (p ⋆) ≃ (ℚ.- p) ⋆
test0 p = ≃-refl { - (p ⋆)}
test3 : 0ℝ ≃ - 0ℝ
test3 = ≃-refl {0ℝ}
test2 : seq 0ℝ ≡ seq (- 0ℝ)
test2 = _≡_.refl
test4 : reg 0ℝ ≡ reg (- 0ℝ)
test4 = {!refl!}
alpha : ¬ (0ℝ ≡ - 0ℝ)
alpha hyp = {!!}
gamma : 0ℝ ≃ - 0ℝ -> 0ℝ ≡ - 0ℝ
gamma 0≃-0 = {!!}
test1 : ∀ p -> (- (p ⋆)) ≃' ((ℚ.- p) ⋆)
test1 p = {!≃'-refl {(ℚ.- p) ⋆}!}
{-
(tⁿ) diverges iff
∃ε>0 ∀k∈ℕ ∃m,n≥k (∣tᵐ - tⁿ∣ ≥ ε)
t > 1
ε = 1/10
Let k∈ℕ.
-}
|
{
"alphanum_fraction": 0.3358288405,
"avg_line_length": 47.1035130062,
"ext": "agda",
"hexsha": "100eedacc5c506b03d1c982f5b0177e173dbf582",
"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": "Reals.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": "Reals.agda",
"max_line_length": 174,
"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": "Reals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 83794,
"size": 175649
}
|
-- 2010-09-29 Andreas, mail to Ulf
module ExistentialsProjections where
postulate
.irrelevant : {A : Set} -> .A -> A
record Exists (A : Set) (P : A -> Set) : Set where
constructor exists
field
.fwitness : A
fcontent : P fwitness
.witness : forall {A P} -> (x : Exists A P) -> A
witness (exists a p) = irrelevant a
-- second projection out of existential is breaking abstraction, so should be forbidden
content : forall {A P} -> (x : Exists A P) -> P (witness x)
content (exists a p) = p -- should not typecheck!!
{- We have p : P a != P (witness (exists a p)) = P (irrelevant a)
because a != irrelevant a.
-}
|
{
"alphanum_fraction": 0.6444444444,
"avg_line_length": 25.2,
"ext": "agda",
"hexsha": "d48d3ccd84a465164a834b13c40778a9438e5d27",
"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/ExistentialsProjections.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/ExistentialsProjections.agda",
"max_line_length": 87,
"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/ExistentialsProjections.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": 194,
"size": 630
}
|
------------------------------------------------------------------------
-- Some definitions related to and properties of finite sets
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Fin
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (id)
open import Bijection eq as Bijection using (_↔_; module _↔_)
open Derived-definitions-and-properties eq
open import Equality.Decision-procedures eq
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq as F hiding (_∘_; Distinct↔≢)
open import H-level eq hiding (⌞_⌟)
open import H-level.Closure eq
open import List eq
open import Nat eq as Nat using (_≤_; ≤-refl; ≤-step; _<_; pred)
open import Univalence-axiom eq
------------------------------------------------------------------------
-- Some bijections relating Fin and ∃
∃-Fin-zero : ∀ {p ℓ} (P : Fin zero → Type p) → ∃ P ↔ ⊥ {ℓ = ℓ}
∃-Fin-zero P = Σ-left-zero
∃-Fin-suc : ∀ {p n} (P : Fin (suc n) → Type p) →
∃ P ↔ P fzero ⊎ ∃ (P ∘ fsuc)
∃-Fin-suc P =
∃ P ↔⟨ ∃-⊎-distrib-right ⟩
∃ (P ∘ inj₁) ⊎ ∃ (P ∘ inj₂) ↔⟨ Σ-left-identity ⊎-cong id ⟩□
P (inj₁ tt) ⊎ ∃ (P ∘ inj₂) □
------------------------------------------------------------------------
-- Fin n is a set
abstract
Fin-set : ∀ n → Is-set (Fin n)
Fin-set zero = mono₁ 1 ⊥-propositional
Fin-set (suc n) = ⊎-closure 0 (mono 0≤2 ⊤-contractible) (Fin-set n)
where
0≤2 : 0 ≤ 2
0≤2 = ≤-step (≤-step ≤-refl)
------------------------------------------------------------------------
-- If two nonempty finite sets are isomorphic, then we can remove one
-- element from each and get new isomorphic finite sets
private
well-behaved : ∀ {m n} (f : Fin (1 + m) ↔ Fin (1 + n)) →
Well-behaved (_↔_.to f)
well-behaved f {b = i} eq₁ eq₂ = ⊎.inj₁≢inj₂ (
fzero ≡⟨ sym $ to-from f eq₂ ⟩
from f fzero ≡⟨ to-from f eq₁ ⟩∎
fsuc i ∎)
where open _↔_
cancel-suc : ∀ {m n} → Fin (1 + m) ↔ Fin (1 + n) → Fin m ↔ Fin n
cancel-suc f =
⊎-left-cancellative f (well-behaved f) (well-behaved $ inverse f)
-- In fact, we can do it in such a way that, if the input bijection
-- relates elements of two lists with equal heads, then the output
-- bijection relates elements of the tails of the lists.
--
-- xs And ys Are-related-by f is inhabited if the indices of xs and ys
-- which are related by f point to equal elements.
infix 4 _And_Are-related-by_
_And_Are-related-by_ :
∀ {a} {A : Type a}
(xs ys : List A) → Fin (length xs) ↔ Fin (length ys) → Type a
xs And ys Are-related-by f =
∀ i → index xs i ≡ index ys (_↔_.to f i)
abstract
-- The tails are related.
cancel-suc-preserves-relatedness :
∀ {a} {A : Type a} (x : A) xs ys
(f : Fin (length (x ∷ xs)) ↔ Fin (length (x ∷ ys))) →
x ∷ xs And x ∷ ys Are-related-by f →
xs And ys Are-related-by cancel-suc f
cancel-suc-preserves-relatedness x xs ys f related = helper
where
open _↔_ f
helper : xs And ys Are-related-by cancel-suc f
helper i with inspect (to (fsuc i)) | related (fsuc i)
helper i | fsuc k , eq₁ | hyp₁ =
index xs i ≡⟨ hyp₁ ⟩
index (x ∷ ys) (to (fsuc i)) ≡⟨ cong (index (x ∷ ys)) eq₁ ⟩
index (x ∷ ys) (fsuc k) ≡⟨ refl _ ⟩∎
index ys k ∎
helper i | fzero , eq₁ | hyp₁
with inspect (to (fzero)) | related (fzero)
helper i | fzero , eq₁ | hyp₁ | fsuc j , eq₂ | hyp₂ =
index xs i ≡⟨ hyp₁ ⟩
index (x ∷ ys) (to (fsuc i)) ≡⟨ cong (index (x ∷ ys)) eq₁ ⟩
index (x ∷ ys) (fzero) ≡⟨ refl _ ⟩
x ≡⟨ hyp₂ ⟩
index (x ∷ ys) (to (fzero)) ≡⟨ cong (index (x ∷ ys)) eq₂ ⟩
index (x ∷ ys) (fsuc j) ≡⟨ refl _ ⟩∎
index ys j ∎
helper i | fzero , eq₁ | hyp₁ | fzero , eq₂ | hyp₂ =
⊥-elim $ well-behaved f eq₁ eq₂
-- By using cancel-suc we can show that finite sets are isomorphic iff
-- they have equal size.
isomorphic-same-size : ∀ {m n} → (Fin m ↔ Fin n) ⇔ m ≡ n
isomorphic-same-size {m} {n} = record
{ to = to m n
; from = λ m≡n → subst (λ n → Fin m ↔ Fin n) m≡n id
}
where
abstract
to : ∀ m n → (Fin m ↔ Fin n) → m ≡ n
to zero zero _ = refl _
to (suc m) (suc n) 1+m↔1+n = cong suc $ to m n $ cancel-suc 1+m↔1+n
to zero (suc n) 0↔1+n = ⊥-elim $ _↔_.from 0↔1+n fzero
to (suc m) zero 1+m↔0 = ⊥-elim $ _↔_.to 1+m↔0 fzero
------------------------------------------------------------------------
-- The natural number corresponding to a value in Fin n
-- The underlying natural number.
⌞_⌟ : ∀ {n} → Fin n → ℕ
⌞_⌟ {n = zero} ()
⌞_⌟ {n = suc _} fzero = zero
⌞_⌟ {n = suc _} (fsuc i) = suc ⌞ i ⌟
-- Use of subst Fin does not change the underlying natural number.
⌞subst⌟ : ∀ {m n} (p : m ≡ n) (i : Fin m) → ⌞ subst Fin p i ⌟ ≡ ⌞ i ⌟
⌞subst⌟ {m} p i =
⌞ subst Fin p i ⌟ ≡⟨ cong (uncurry λ n p → ⌞ subst Fin p i ⌟) (Σ-≡,≡→≡ (sym p) (
subst (m ≡_) (sym p) p ≡⟨ sym trans-subst ⟩
trans p (sym p) ≡⟨ trans-symʳ p ⟩∎
refl m ∎)) ⟩
⌞ subst Fin (refl m) i ⌟ ≡⟨ cong ⌞_⌟ (subst-refl _ _) ⟩∎
⌞ i ⌟ ∎
-- If the underlying natural numbers are equal, then the values in
-- Fin n are equal.
cancel-⌞⌟ : ∀ {n} {i j : Fin n} → ⌞ i ⌟ ≡ ⌞ j ⌟ → i ≡ j
cancel-⌞⌟ {zero} {}
cancel-⌞⌟ {suc _} {fzero} {fzero} _ = refl _
cancel-⌞⌟ {suc _} {fzero} {fsuc _} 0≡+ = ⊥-elim (Nat.0≢+ 0≡+)
cancel-⌞⌟ {suc _} {fsuc _} {fzero} +≡0 = ⊥-elim (Nat.0≢+ (sym +≡0))
cancel-⌞⌟ {suc _} {fsuc _} {fsuc _} +≡+ =
cong fsuc (cancel-⌞⌟ (Nat.cancel-suc +≡+))
-- Tries to convert from natural numbers.
from-ℕ′ : ∀ {m} (n : ℕ) → m ≤ n ⊎ ∃ λ (i : Fin m) → ⌞ i ⌟ ≡ n
from-ℕ′ {zero} _ = inj₁ (Nat.zero≤ _)
from-ℕ′ {suc m} zero = inj₂ (fzero , refl _)
from-ℕ′ {suc m} (suc n) =
⊎-map Nat.suc≤suc (Σ-map fsuc (cong suc)) (from-ℕ′ {m} n)
from-ℕ : ∀ {m} (n : ℕ) → m ≤ n ⊎ Fin m
from-ℕ = ⊎-map id proj₁ ∘ from-ℕ′
-- Values of type Fin n can be seen as natural numbers smaller than n.
Fin↔< : ∀ n → Fin n ↔ ∃ λ m → m < n
Fin↔< zero =
⊥ ↝⟨ inverse ×-right-zero ⟩
ℕ × ⊥ ↔⟨ ∃-cong (λ _ → inverse <zero↔) ⟩□
(∃ λ m → m < zero) □
Fin↔< (suc n) =
⊤ ⊎ Fin n ↝⟨ inverse (_⇔_.to contractible⇔↔⊤ (singleton-contractible 0)) ⊎-cong Fin↔< n ⟩
(∃ λ m → m ≡ 0) ⊎ (∃ λ m → m < n) ↝⟨ id ⊎-cong ∃<↔∃0<×≤ ⟩
(∃ λ m → m ≡ 0) ⊎ (∃ λ m → 0 < m × m ≤ n) ↝⟨ inverse ∃-⊎-distrib-left ⟩
(∃ λ m → m ≡ 0 ⊎ 0 < m × m ≤ n) ↝⟨ ∃-cong (λ _ → inverse ≤↔≡0⊎0<×≤) ⟩
(∃ λ m → m ≤ n) ↝⟨ ∃-cong (λ _ → inverse suc≤suc↔) ⟩
(∃ λ m → suc m ≤ suc n) ↔⟨⟩
(∃ λ m → m < suc n) □
-- The forward direction of Fin↔< gives the underlying natural number.
Fin↔<≡⌞⌟ :
∀ {n} (i : Fin n) → proj₁ (_↔_.to (Fin↔< n) i) ≡ ⌞ i ⌟
Fin↔<≡⌞⌟ {n = zero} ()
Fin↔<≡⌞⌟ {n = suc _} fzero = refl _
Fin↔<≡⌞⌟ {n = suc _} (fsuc i) = cong suc (Fin↔<≡⌞⌟ i)
-- The largest possible number.
largest : ∀ n → Fin (suc n)
largest zero = fzero
largest (suc n) = fsuc (largest n)
largest-correct : ∀ n → ⌞ largest n ⌟ ≡ n
largest-correct zero = refl _
largest-correct (suc n) = cong suc (largest-correct n)
-- The largest possible number can be expressed using Fin↔<.
largest≡Fin↔< :
∀ {n} → largest n ≡ _↔_.from (Fin↔< (suc n)) (n , ≤-refl)
largest≡Fin↔< {n} =
largest n ≡⟨ sym (_↔_.left-inverse-of (Fin↔< (suc n)) _) ⟩
_↔_.from (Fin↔< (suc n)) (_↔_.to (Fin↔< (suc n)) (largest n)) ≡⟨ cong (_↔_.from (Fin↔< (suc n))) (Σ-≡,≡→≡ (Fin↔<≡⌞⌟ (largest n)) (refl _)) ⟩
_↔_.from (Fin↔< (suc n)) (⌞ largest n ⌟ , p₁) ≡⟨ cong (_↔_.from (Fin↔< (suc n)))
(Σ-≡,≡→≡ (largest-correct n) (≤-propositional p₂ ≤-refl)) ⟩∎
_↔_.from (Fin↔< (suc n)) (n , ≤-refl) ∎
where
p₁ = subst (_< suc n) (Fin↔<≡⌞⌟ (largest n))
(proj₂ (_↔_.to (Fin↔< (suc n)) (largest n)))
p₂ = subst (_< suc n) (largest-correct n) p₁
------------------------------------------------------------------------
-- Weakening
-- Single-step weakening.
weaken₁ : ∀ {n} → Fin n → Fin (suc n)
weaken₁ {zero} ()
weaken₁ {suc _} fzero = fzero
weaken₁ {suc _} (fsuc i) = fsuc (weaken₁ i)
weaken₁-correct : ∀ {n} (i : Fin n) → ⌞ weaken₁ i ⌟ ≡ ⌞ i ⌟
weaken₁-correct {zero} ()
weaken₁-correct {suc _} fzero = refl _
weaken₁-correct {suc _} (fsuc i) = cong suc (weaken₁-correct i)
-- Multiple-step weakening.
weaken : ∀ {m n} → m ≤ n → Fin m → Fin n
weaken (Nat.≤-refl′ m≡n) = subst Fin m≡n
weaken (Nat.≤-step′ m≤k 1+k≡n) = subst Fin 1+k≡n ∘ weaken₁ ∘ weaken m≤k
weaken-correct : ∀ {m n} (m≤n : m ≤ n) (i : Fin m) →
⌞ weaken m≤n i ⌟ ≡ ⌞ i ⌟
weaken-correct (Nat.≤-refl′ m≡n) i =
⌞ subst Fin m≡n i ⌟ ≡⟨ ⌞subst⌟ _ _ ⟩∎
⌞ i ⌟ ∎
weaken-correct (Nat.≤-step′ m≤k 1+k≡n) i =
⌞ subst Fin 1+k≡n (weaken₁ (weaken m≤k i)) ⌟ ≡⟨ ⌞subst⌟ _ _ ⟩
⌞ weaken₁ (weaken m≤k i) ⌟ ≡⟨ weaken₁-correct _ ⟩
⌞ weaken m≤k i ⌟ ≡⟨ weaken-correct m≤k _ ⟩∎
⌞ i ⌟ ∎
------------------------------------------------------------------------
-- Predecessor and successor
-- Predecessor.
predᶠ : ∀ {n} → Fin n → Fin n
predᶠ {n = zero} ()
predᶠ {n = suc _} fzero = fzero
predᶠ {n = suc _} (fsuc i) = weaken₁ i
predᶠ-correct : ∀ {n} (i : Fin n) → ⌞ predᶠ i ⌟ ≡ Nat.pred ⌞ i ⌟
predᶠ-correct {n = zero} ()
predᶠ-correct {n = suc _} fzero = refl _
predᶠ-correct {n = suc _} (fsuc i) = weaken₁-correct i
-- Successor.
sucᶠ : ∀ {n} (i : Fin (suc n)) →
i ≡ largest n ⊎
i ≢ largest n × ∃ λ (j : Fin (suc n)) → ⌞ j ⌟ ≡ suc ⌞ i ⌟
sucᶠ {zero} fzero = inj₁ (refl _)
sucᶠ {zero} (fsuc ())
sucᶠ {suc _} fzero = inj₂ (⊎.inj₁≢inj₂ , fsuc fzero , refl _)
sucᶠ {suc _} (fsuc i) =
⊎-map (cong fsuc)
(Σ-map (_∘ ⊎.cancel-inj₂) (Σ-map fsuc (cong suc)))
(sucᶠ i)
------------------------------------------------------------------------
-- Arithmetic
-- Addition.
_+ᶠ_ : ∀ {m n} → Fin m → Fin n → Fin (m + n)
_+ᶠ_ {m = zero} ()
_+ᶠ_ {m = suc m} fzero j = weaken (Nat.m≤n+m _ (suc m)) j
_+ᶠ_ {m = suc _} (fsuc i) j = fsuc (i +ᶠ j)
+ᶠ-correct :
∀ {m n} (i : Fin m) (j : Fin n) → ⌞ i +ᶠ j ⌟ ≡ ⌞ i ⌟ + ⌞ j ⌟
+ᶠ-correct {m = zero} ()
+ᶠ-correct {m = suc m} fzero j = weaken-correct
(Nat.m≤n+m _ (suc m)) _
+ᶠ-correct {m = suc _} (fsuc i) j = cong suc (+ᶠ-correct i j)
------------------------------------------------------------------------
-- "Type arithmetic" using Fin
-- Taking the disjoint union of two finite sets amounts to the same
-- thing as adding the sizes.
Fin⊎Fin↔Fin+ : ∀ m n → Fin m ⊎ Fin n ↔ Fin (m + n)
Fin⊎Fin↔Fin+ zero n =
Fin 0 ⊎ Fin n ↝⟨ id ⟩
⊥ ⊎ Fin n ↝⟨ ⊎-left-identity ⟩
Fin n ↝⟨ id ⟩□
Fin (0 + n) □
Fin⊎Fin↔Fin+ (suc m) n =
Fin (suc m) ⊎ Fin n ↝⟨ id ⟩
(⊤ ⊎ Fin m) ⊎ Fin n ↝⟨ inverse ⊎-assoc ⟩
⊤ ⊎ (Fin m ⊎ Fin n) ↝⟨ id ⊎-cong Fin⊎Fin↔Fin+ m n ⟩
⊤ ⊎ Fin (m + n) ↝⟨ id ⟩
Fin (suc (m + n)) ↝⟨ id ⟩□
Fin (suc m + n) □
-- Taking the product of two finite sets amounts to the same thing as
-- multiplying the sizes.
Fin×Fin↔Fin* : ∀ m n → Fin m × Fin n ↔ Fin (m * n)
Fin×Fin↔Fin* zero n =
Fin 0 × Fin n ↝⟨ id ⟩
⊥ × Fin n ↝⟨ ×-left-zero ⟩
⊥ ↝⟨ id ⟩□
Fin 0 □
Fin×Fin↔Fin* (suc m) n =
Fin (suc m) × Fin n ↝⟨ id ⟩
(⊤ ⊎ Fin m) × Fin n ↝⟨ ∃-⊎-distrib-right ⟩
⊤ × Fin n ⊎ Fin m × Fin n ↝⟨ ×-left-identity ⊎-cong Fin×Fin↔Fin* m n ⟩
Fin n ⊎ Fin (m * n) ↝⟨ Fin⊎Fin↔Fin+ _ _ ⟩
Fin (n + m * n) ↝⟨ id ⟩□
Fin (suc m * n) □
-- Forming the function space between two finite sets amounts to the
-- same thing as raising one size to the power of the other (assuming
-- extensionality).
[Fin→Fin]↔Fin^ :
Extensionality (# 0) (# 0) →
∀ m n → (Fin m → Fin n) ↔ Fin (n ^ m)
[Fin→Fin]↔Fin^ ext zero n =
(Fin 0 → Fin n) ↝⟨ id ⟩
(⊥ → Fin n) ↝⟨ Π⊥↔⊤ ext ⟩
⊤ ↝⟨ inverse ⊎-right-identity ⟩□
Fin 1 □
[Fin→Fin]↔Fin^ ext (suc m) n =
(Fin (suc m) → Fin n) ↝⟨ id ⟩
(⊤ ⊎ Fin m → Fin n) ↝⟨ Π⊎↔Π×Π ext ⟩
(⊤ → Fin n) × (Fin m → Fin n) ↝⟨ Π-left-identity ×-cong [Fin→Fin]↔Fin^ ext m n ⟩
Fin n × Fin (n ^ m) ↝⟨ Fin×Fin↔Fin* _ _ ⟩
Fin (n * n ^ m) ↝⟨ id ⟩□
Fin (n ^ suc m) □
-- Automorphisms on Fin n are isomorphic to Fin (n !) (assuming
-- extensionality).
[Fin↔Fin]↔Fin! :
Extensionality (# 0) (# 0) →
∀ n → (Fin n ↔ Fin n) ↔ Fin (n !)
[Fin↔Fin]↔Fin! ext zero =
Fin 0 ↔ Fin 0 ↝⟨ Eq.↔↔≃ ext (Fin-set 0) ⟩
Fin 0 ≃ Fin 0 ↝⟨ id ⟩
⊥ ≃ ⊥ ↔⟨ ≃⊥≃¬ ext ⟩
¬ ⊥ ↝⟨ ¬⊥↔⊤ ext ⟩
⊤ ↝⟨ inverse ⊎-right-identity ⟩
⊤ ⊎ ⊥ ↝⟨ id ⟩□
Fin 1 □
[Fin↔Fin]↔Fin! ext (suc n) =
Fin (suc n) ↔ Fin (suc n) ↝⟨ [⊤⊎↔⊤⊎]↔[⊤⊎×↔] Fin._≟_ ext ⟩
Fin (suc n) × (Fin n ↔ Fin n) ↝⟨ id ×-cong [Fin↔Fin]↔Fin! ext n ⟩
Fin (suc n) × Fin (n !) ↝⟨ Fin×Fin↔Fin* _ _ ⟩□
Fin (suc n !) □
-- A variant of the previous property.
[Fin≡Fin]↔Fin! :
Extensionality (# 0) (# 0) →
Univalence (# 0) →
∀ n → (Fin n ≡ Fin n) ↔ Fin (n !)
[Fin≡Fin]↔Fin! ext univ n =
Fin n ≡ Fin n ↔⟨ ≡≃≃ univ ⟩
Fin n ≃ Fin n ↝⟨ inverse $ Eq.↔↔≃ ext (Fin-set n) ⟩
Fin n ↔ Fin n ↝⟨ [Fin↔Fin]↔Fin! ext n ⟩□
Fin (n !) □
------------------------------------------------------------------------
-- Inequality and a related isomorphism
-- Inequality.
Distinct : ∀ {n} → Fin n → Fin n → Type
Distinct i j = Nat.Distinct ⌞ i ⌟ ⌞ j ⌟
-- This definition of inequality is pointwise logically equivalent to
-- _≢_, and in the presence of extensionality the two definitions are
-- pointwise isomorphic.
Distinct↔≢ :
∀ {k n} {i j : Fin n} →
Extensionality? ⌊ k ⌋-sym lzero lzero →
Distinct i j ↝[ ⌊ k ⌋-sym ] i ≢ j
Distinct↔≢ {i = i} {j} ext =
Distinct i j ↔⟨⟩
Nat.Distinct ⌞ i ⌟ ⌞ j ⌟ ↝⟨ F.Distinct↔≢ ext ⟩
⌞ i ⌟ ≢ ⌞ j ⌟ ↝⟨ generalise-ext?-prop ≢⇔≢ ¬-propositional ¬-propositional ext ⟩□
i ≢ j □
where
≢⇔≢ : ⌞ i ⌟ ≢ ⌞ j ⌟ ⇔ i ≢ j
≢⇔≢ = record { to = _∘ cong ⌞_⌟; from = _∘ cancel-⌞⌟ }
-- For every i : Fin n there is a bijection between Fin (pred n) and
-- numbers in Fin n distinct from i.
--
-- When n is positive the forward direction of this bijection
-- corresponds to the function "thin" from McBride's "First-order
-- unification by structural recursion", with an added inequality
-- proof, and the other direction is a total variant of "thick".
Fin↔Fin+≢ :
∀ {n} (i : Fin n) →
Fin (pred n) ↔ ∃ λ (j : Fin n) → Distinct j i
Fin↔Fin+≢ {suc n} fzero =
Fin n ↝⟨ inverse ⊎-left-identity ⟩
⊥ ⊎ Fin n ↝⟨ inverse $ id ⊎-cong ×-right-identity ⟩
⊥ ⊎ Fin n × ⊤ ↝⟨ inverse $ ∃-Fin-suc _ ⟩□
(∃ λ (j : Fin (suc n)) → Distinct j fzero) □
Fin↔Fin+≢ {suc (suc n)} (fsuc i) =
Fin (1 + n) ↔⟨⟩
⊤ ⊎ Fin n ↝⟨ id ⊎-cong Fin↔Fin+≢ i ⟩
⊤ ⊎ (∃ λ (j : Fin (1 + n)) → Distinct j i) ↔⟨ inverse $ ∃-Fin-suc _ ⟩□
(∃ λ (j : Fin (2 + n)) → Distinct j (fsuc i)) □
Fin↔Fin+≢ {zero} ()
Fin↔Fin+≢ {suc zero} (fsuc ())
|
{
"alphanum_fraction": 0.4743744061,
"avg_line_length": 35.6320541761,
"ext": "agda",
"hexsha": "7522df8ccb5a708b1c1aaecd41cd0d69f4483e58",
"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": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"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/equality",
"max_issues_repo_path": "src/Fin.agda",
"max_line_length": 143,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Fin.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 6727,
"size": 15785
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by total orders
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.TotalOrder
{t₁ t₂ t₃} (T : TotalOrder t₁ t₂ t₃) where
open Relation.Binary.TotalOrder T
open import Relation.Binary.Consequences
decTotalOrder : Decidable _≈_ → DecTotalOrder _ _ _
decTotalOrder ≟ = record
{ isDecTotalOrder = record
{ isTotalOrder = isTotalOrder
; _≟_ = ≟
; _≤?_ = total+dec⟶dec reflexive antisym total ≟
}
}
|
{
"alphanum_fraction": 0.5285714286,
"avg_line_length": 28,
"ext": "agda",
"hexsha": "9e7bfe7647a4e743975929d548f800a7287e2e71",
"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/Binary/Properties/TotalOrder.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/Binary/Properties/TotalOrder.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/Binary/Properties/TotalOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 160,
"size": 700
}
|
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.HLevel
open import HoTT.HLevel.Truncate
open import HoTT.Logic
open import HoTT.Identity
open import HoTT.Identity.Identity
open import HoTT.Identity.Coproduct
open import HoTT.Identity.Sigma
open import HoTT.Identity.Pi
open import HoTT.Identity.Universe
open import HoTT.Equivalence
open import HoTT.Equivalence.Lift
open import HoTT.Sigma.Transport
module HoTT.Exercises.Chapter3 where
module Exercise1 {i} {A B : 𝒰 i} (e : A ≃ B) (A-set : isSet A)
where
□ : isSet B
□ {x} {y} p q = ap⁻¹ (ap≃ (e ⁻¹ₑ) x y) (A-set (ap g p) (ap g q))
where open Iso (eqv→iso e)
module Exercise2 {i} {A B : 𝒰 i} (A-set : isSet A) (B-set : isSet B)
where
□ : isSet (A + B)
□ {inl x} {inl y} p q = ap⁻¹ =+-equiv
(ap lift (A-set (lower (=+-elim p)) (lower (=+-elim q))))
□ {inl x} {inr y} p q = 𝟎-rec (=+-elim p)
□ {inr x} {inl y} p q = 𝟎-rec (=+-elim p)
□ {inr x} {inr y} p q = ap⁻¹ =+-equiv
(ap lift (B-set (lower (=+-elim p)) (lower (=+-elim q))))
module Exercise3
{i} {A : 𝒰 i} (A-set : isSet A)
{j} {B : A → 𝒰 j} (B-set : {x : A} → isSet (B x))
where
□ : isSet (Σ A B)
□ {x = x@(x₁ , x₂)} {y = y@(y₁ , y₂)} p q =
ap⁻¹ =Σ-equiv (lemma (pr₁ =Σ-equiv p) (pr₁ =Σ-equiv q))
where
lemma : (p q : Σ (x₁ == y₁) λ p₁ → (transport B p₁ x₂ == y₂)) → p == q
lemma (p₁ , p₂) (q₁ , q₂) = pair⁼ (r₁ , r₂)
where
r₁ = A-set p₁ q₁
r₂ = B-set (transport _ r₁ p₂) q₂
module Exercise4 {i} {A : 𝒰 i} where
_ : isProp A → isContr (A → A)
_ = λ A-prop → id , λ f → funext λ x → A-prop x (f x)
_ : isContr (A → A) → isProp A
_ = λ where
(f , contr) x y → happly (contr (const x) ⁻¹ ∙ contr (const y)) x
module Exercise5 {i} {A : 𝒰 i} where
open import HoTT.Pi.Transport
open import HoTT.Sigma.Transport
_ : isProp A ≃ (A → isContr A)
_ = f , qinv→isequiv (g , η , ε)
where
f : isProp A → (A → isContr A)
f A-prop x = x , A-prop x
g : (A → isContr A) → isProp A
g h x y = let contr = pr₂ (h x) in contr x ⁻¹ ∙ contr y
η : g ∘ f ~ id
η _ = isProp-prop _ _
ε : f ∘ g ~ id
ε h = funext λ _ → isContr-prop _ _
module Exercise6 {i} {A : 𝒰 i} where
instance
LEM-prop : ⦃ hlevel 1 A ⦄ → hlevel 1 (A + ¬ A)
LEM-prop = isProp→hlevel1 λ where
(inl a) (inl a') → ap inl center
(inl a) (inr f) → 𝟎-rec (f a)
(inr f) (inl b') → 𝟎-rec (f b')
(inr f) (inr f') → ap inr center
module Exercise7
{i} {A : 𝒰 i} {A-prop : isProp A}
{j} {B : 𝒰 j} {B-prop : isProp B}
where
□ : ¬ (A × B) → isProp (A + B)
□ f = λ where
(inl x) (inl y) → ap inl (A-prop _ _)
(inl x) (inr y) → 𝟎-rec (f (x , y))
(inr x) (inl y) → 𝟎-rec (f (y , x))
(inr x) (inr y) → ap inr (B-prop _ _)
module Exercise8 {i j} {A : 𝒰 i} {B : 𝒰 j} {f : A → B} where
open import HoTT.Equivalence.Proposition
prop₁ : qinv f → ∥ qinv f ∥
prop₁ e = ∣ e ∣
prop₂ : ∥ qinv f ∥ → qinv f
prop₂ e = isequiv→qinv (∥-rec ⦃ isProp→hlevel1 isequiv-prop ⦄ qinv→isequiv e)
prop₃ : isProp ∥ qinv f ∥
prop₃ = hlevel1→isProp
module Exercise9 {i} (lem : LEM {i}) where
open import HoTT.Logic
open import HoTT.Equivalence.Lift
_ : Prop𝒰 i ≃ 𝟐
_ = f , qinv→isequiv (g , η , ε)
where
f : Prop𝒰 i → 𝟐
f P with lem P
... | inl _ = 0₂
... | inr _ = 1₂
g : 𝟐 → Prop𝒰 i
g 0₂ = ⊤
g 1₂ = ⊥
η : g ∘ f ~ id
η P with lem P
... | inl t = hlevel⁼ (ua (prop-equiv (const t) (const ★)))
... | inr f = hlevel⁼ (ua (prop-equiv 𝟎-rec (𝟎-rec ∘ f)))
ε : f ∘ g ~ id
ε 0₂ with lem (g 0₂)
... | inl _ = refl
... | inr f = 𝟎-rec (f ★)
ε 1₂ with lem (g 1₂)
... | inl ()
... | inr _ = refl
import HoTT.Exercises.Chapter3.Exercise10
module Exercise11 where
open variables
open import HoTT.Pi.Transport
open import HoTT.Identity.Boolean
prop : ¬ ((A : 𝒰₀) → ∥ A ∥ → A)
prop f = 𝟎-rec (g (f 𝟐 ∣ 0₂ ∣) p)
where
not = 𝟐-rec 1₂ 0₂
e : 𝟐 ≃ 𝟐
e = not , qinv→isequiv (not , 𝟐-ind _ refl refl , 𝟐-ind _ refl refl)
g : (x : 𝟐) → ¬ (not x == x)
g 0₂ = 𝟎-rec ∘ pr₁ =𝟐-equiv
g 1₂ = 𝟎-rec ∘ pr₁ =𝟐-equiv
p : not (f 𝟐 ∣ 0₂ ∣) == f 𝟐 ∣ 0₂ ∣
p =
not (f 𝟐 ∣ 0₂ ∣)
=⟨ ap (λ e → pr₁ e (f 𝟐 ∣ 0₂ ∣)) (=𝒰-β e) ⁻¹ ⟩
transport id (ua e) (f 𝟐 ∣ 0₂ ∣)
=⟨ ap (λ x → transport id (ua e) (f 𝟐 x)) center ⟩
transport id (ua e) (f 𝟐 (transport ∥_∥ (ua e ⁻¹) ∣ 0₂ ∣))
=⟨ happly (transport-→ ∥_∥ id (ua e) (f 𝟐) ⁻¹) ∣ 0₂ ∣ ⟩
transport (λ A → ∥ A ∥ → A) (ua e) (f 𝟐) ∣ 0₂ ∣
=⟨ happly (apd f (ua e)) ∣ 0₂ ∣ ⟩
f 𝟐 ∣ 0₂ ∣
∎
where open =-Reasoning
module Exercise12 {i} {A : 𝒰 i} (lem : LEM {i}) where
open variables using (B ; j)
□ : ∥ (∥ A ∥ → A) ∥
□ with lem (type ∥ A ∥)
... | inl x = swap ∥-rec x λ x → ∣ const x ∣
... | inr f = ∣ 𝟎-rec ∘ f ∣
module Exercise13 {i} (lem : LEM∞ {i}) where
□ : AC {i} {i} {i}
□ {X = X} {A = A} {P = P} f = ∣ pr₁ ∘ g , pr₂ ∘ g ∣
where
g : (x : X) → Σ (A x) (P x)
g x with lem (Σ (A x) (P x))
... | inl t = t
... | inr b = ∥-rec ⦃ hlevel-in (λ {x} → 𝟎-rec (b x)) ⦄ id (f x)
module Exercise14 (lem : ∀ {i} → LEM {i}) where
open import HoTT.Sigma.Universal
open variables
∥_∥' : 𝒰 i → 𝒰 i
∥ A ∥' = ¬ ¬ A
∣_∣' : A → ∥ A ∥'
∣ a ∣' f = f a
∥'-hlevel : hlevel 1 ∥ A ∥'
∥'-hlevel = ⟨⟩
∥'-rec : ⦃ hlevel 1 B ⦄ → (f : A → B) →
Σ[ g ∶ (∥ A ∥' → B) ] Π[ a ∶ A ] g ∣ a ∣' == f a
∥'-rec f = λ where
.pr₁ a → +-rec id (λ b → 𝟎-rec (a (𝟎-rec ∘ b ∘ f))) (lem (type _))
.pr₂ _ → center
_ : ∥ A ∥' ≃ ∥ A ∥
_ = let open Iso in iso→eqv λ where
.f → pr₁ (∥'-rec ∣_∣)
.g → ∥-rec ∣_∣'
.η _ → center
.ε _ → center
module Exercise15
(LiftProp-isequiv : ∀ {i j} → isequiv (LiftProp {i} {j}))
where
open import HoTT.Equivalence.Transport
open variables
open module LiftProp-qinv {i} {j} = qinv (isequiv→qinv (LiftProp-isequiv {i} {j}))
renaming (g to LowerProp ; η to LiftProp-η ; ε to LiftProp-ε)
∥_∥' : 𝒰 (lsuc i) → 𝒰 (lsuc i)
∥_∥' {i} A = (P : Prop𝒰 i) → (A → P ty) → P ty
∣_∣' : A → ∥ A ∥'
∣ a ∣' _ f = f a
∥'-hlevel : hlevel 1 ∥ A ∥'
∥'-hlevel = ⟨⟩
∥'-rec : {A : 𝒰 (lsuc i)} {(type B) : Prop𝒰 (lsuc i)} → (f : A → B) →
Σ (∥ A ∥' → B) λ g → (a : A) → g ∣ a ∣' == f a
∥'-rec {_} {_} {B} f = let p = ap _ty (LiftProp-ε B) in λ where
.pr₁ a → transport id p (lift (a (LowerProp B) (lower ∘ transport id (p ⁻¹) ∘ f)))
-- We do not get a definitional equality since our propositional
-- resizing equivalence does not give us definitionally equal
-- types, i.e. LowerProp B ≢ B. If it did, then we could write
--
-- ∥'-rec f a :≡ a (LowerProp B) f
--
-- and then we'd have ∥'-rec f ∣a∣' ≡ f a.
.pr₂ a → Eqv.ε (transport-equiv p) (f a)
module Exercise16
{i} {(type X) : Set𝒰 i}
{j} {Y : X → Prop𝒰 j}
(lem : ∀ {i} → LEM {i})
where
_ : Π[ x ∶ X ] ¬ ¬ Y x ty ≃ ¬ ¬ (Π[ x ∶ X ] Y x ty)
_ = let open Iso in iso→eqv λ where
.f s t → t λ x → +-rec id (𝟎-rec ∘ s x) (lem (Y x))
.g s x y → 𝟎-rec (s λ f → 𝟎-rec (y (f x)))
.η _ → center
.ε _ → center
module Exercise17
{i} {A : 𝒰 i}
{j} {B : ∥ A ∥ → Prop𝒰 j}
where
∥-ind : ((a : A) → B ∣ a ∣ ty) → (x : ∥ A ∥) → B x ty
∥-ind f x = ∥-rec (transport (_ty ∘ B) center ∘ f) x
where instance _ = λ {x} → hlevel𝒰.h (B x)
module Exercise18 {i} where
open Exercise6
_ : LEM {i} → LDN {i}
_ = λ lem P f → +-rec id (𝟎-rec ∘ f) (lem P)
_ : LDN {i} → LEM {i}
_ = λ ldn P → ldn (type (P ty + ¬ P ty)) λ f → f (inr (f ∘ inl))
module Exercise19
{i} {P : ℕ → 𝒰 i}
(P-lem : (n : ℕ) → P n + ¬ P n)
-- Do not assume that all P n are mere propositions so we can
-- reuse this solution for exercise 23.
where
open import HoTT.NaturalNumber renaming (_+_ to _+ₙ_ ; +-comm to +ₙ-comm)
open import HoTT.Identity.NaturalNumber
open import HoTT.Transport.Identity
open import HoTT.Base.Inspect
open import HoTT.Identity.Product
open import HoTT.Equivalence.Sigma
open import HoTT.Equivalence.Coproduct
open import HoTT.Equivalence.Empty
-- P n does not hold for any m < n
ℕ* : ℕ → 𝒰 i
ℕ* zero = 𝟏
ℕ* (succ n) = ¬ P n × ℕ* n
P* : {n : ℕ} → P n → 𝒰 i
P* {n} p = inl p == P-lem n
-- ℕ* is the product of 𝟏 and some ¬ P n, all of which are
-- propositions, so it is a proposition as well.
instance ℕ*-hlevel : {n : ℕ} → hlevel 1 (ℕ* n)
ℕ*-hlevel {zero} = 𝟏-hlevel
ℕ*-hlevel {succ n} = ×-hlevel
P*-hlevel : {n : ℕ} → hlevel 1 (Σ (P n) P*)
hlevel-out (P*-hlevel {n}) {p , _} = ⟨⟩
where
e : P n ≃ P n + ¬ P n
e = +-empty₂ ⁻¹ₑ ∙ₑ +-equiv reflₑ (𝟎-equiv (_$ p))
instance
_ = =-contrᵣ (P-lem n)
_ = raise ⦃ equiv-hlevel (Σ-equiv₁ e ⁻¹ₑ) ⦄
instance _ = P*-hlevel
-- Extract evidence that ¬ P m for some m < n
extract : {m n : ℕ} → m < n → ℕ* n → ¬ P m
extract {m} (k , p) = pr₁ ∘ weaken ∘ transport ℕ* p'
where
p' = p ⁻¹ ∙ +ₙ-comm (succ m) k
weaken : {k : ℕ} → ℕ* (k +ₙ succ m) → ℕ* (succ m)
weaken {zero} = id
weaken {succ k} = weaken ∘ pr₂
-- The smallest n such that P n holds
Pₒ = Σ (Σ ℕ λ n → Σ (P n) P*) (ℕ* ∘ pr₁)
Pₒ-prop : isProp Pₒ
Pₒ-prop ((n , p , _) , n*) ((m , q , _) , m*) =
pair⁼ (pair⁼ (n=m , center) , center)
where
n=m : n == m
n=m with n <=> m
-- If n = m, then there is nothing to do.
... | inl n=m = n=m
-- If n < m, we have P n and we know ℕ* m contains ¬ P n
-- somewhere inside, so we can just extract it to find a
-- contradiction.
... | inr (inl n<m) = 𝟎-rec (extract n<m m* p)
-- The m < n case is symmetrical.
... | inr (inr m<n) = 𝟎-rec (extract m<n n* q)
instance _ = isProp→hlevel1 Pₒ-prop
-- Use the decidability of P to search for an instance of P in
-- some finite range of natural numbers, keeping track of evidence
-- that P does not hold for lower n.
find-P : (n : ℕ) → Pₒ + ℕ* n
find-P zero = inr ★
find-P (succ n) with find-P n | P-lem n | inspect P-lem n
... | inl x | _ | _ = inl x
... | inr n* | inl p | [ p* ] = inl ((n , p , p*) , n*)
... | inr n* | inr ¬p | _ = inr (¬p , n*)
-- If we know P holds for some n, then we have an upper bound for
-- which to search for the smallest n. If we do not find any other
-- n' ≤ n such that P n', then we have a contradiction.
to-Pₒ : Σ ℕ P → Pₒ
to-Pₒ (n , p) with find-P (succ n)
... | inl x = x
... | inr (¬p , _) = 𝟎-rec (¬p p)
from-Pₒ : Pₒ → Σ ℕ P
from-Pₒ ((n , p , p*) , n*) = n , p
_ : ∥ Σ ℕ P ∥ → Σ ℕ P
_ = from-Pₒ ∘ ∥-rec to-Pₒ
module Exercise20 where
open variables
-- See HoTT.HLevel
_ : ⦃ _ : hlevel 0 A ⦄ → Σ A P ≃ P center
_ = Σ-contr₁
module Exercise21 {i} {P : 𝒰 i} where
open import HoTT.Equivalence.Proposition
_ : isProp P ≃ (P ≃ ∥ P ∥)
_ = prop-equiv ⦃ isProp-hlevel1 ⦄ f g
where
f : isProp P → P ≃ ∥ P ∥
f p = prop-equiv ∣_∣ (∥-rec id)
where instance _ = isProp→hlevel1 p
g : P ≃ ∥ P ∥ → isProp P
g e = hlevel1→isProp ⦃ equiv-hlevel (e ⁻¹ₑ) ⦄
instance
_ = Σ-hlevel ⦃ Π-hlevel ⦄ ⦃ isProp→hlevel1 isequiv-prop ⦄
module Exercise22 where
Fin : ℕ → 𝒰₀
Fin zero = 𝟎
Fin (succ n) = Fin n + 𝟏
□ : ∀ {i} (n : ℕ) {A : Fin n → 𝒰 i} {P : (x : Fin n) → A x → 𝒰 i} →
((x : Fin n) → ∥ Σ (A x) (P x) ∥) →
∥ Σ ((x : Fin n) → A x) (λ g → ((x : Fin n) → P x (g x))) ∥
□ zero _ = ∣ 𝟎-ind , 𝟎-ind ∣
□ (succ n) {A} {P} f =
swap ∥-rec (f (inr ★)) λ zₛ →
swap ∥-rec (□ n (f ∘ inl)) λ zₙ →
let f = f' zₛ zₙ in ∣ pr₁ ∘ f , pr₂ ∘ f ∣
where
f' : _ → _ → (x : Fin (succ n)) → Σ (A x) (P x)
f' (_ , _) (g , h) (inl m) = g m , h m
f' (x , y) (_ , _) (inr ★) = x , y
module Exercise23 where
-- The solution for Exercise19 covers the case where P is not
-- necessarily a mere proposition.
open Exercise19
|
{
"alphanum_fraction": 0.5127774042,
"avg_line_length": 30.192893401,
"ext": "agda",
"hexsha": "0715f345be8081b38e70b079c4d2b588cd32951e",
"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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Exercises/Chapter3.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Exercises/Chapter3.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Exercises/Chapter3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5412,
"size": 11896
}
|
{-# OPTIONS --without-K #-}
module sets.vec.core where
open import function.core
open import sets.nat.core using (ℕ; zero; suc)
open import sets.fin
data Vec {i}(A : Set i) : ℕ → Set i where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
infixr 5 _∷_
head : ∀ {i}{A : Set i}{n : ℕ} → Vec A (suc n) → A
head (x ∷ _) = x
tail : ∀ {i}{A : Set i}{n : ℕ} → Vec A (suc n) → Vec A n
tail (_ ∷ xs) = xs
tabulate : ∀ {i}{A : Set i}{n : ℕ}
→ (Fin n → A) → Vec A n
tabulate {n = zero} _ = []
tabulate {n = suc m} f = f zero ∷ tabulate (f ∘ suc)
lookup : ∀ {i}{A : Set i}{n : ℕ}
→ Vec A n → Fin n → A
lookup [] ()
lookup (x ∷ xs) zero = x
lookup (x ∷ xs) (suc i) = lookup xs i
_!_ : ∀ {i}{A : Set i}{n : ℕ}
→ Vec A n → Fin n → A
_!_ = lookup
|
{
"alphanum_fraction": 0.5084525358,
"avg_line_length": 23.303030303,
"ext": "agda",
"hexsha": "ea5f530d9db8264359d3fcd43a00bfbac223a038",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "sets/vec/core.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/vec/core.agda",
"max_line_length": 56,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "sets/vec/core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 319,
"size": 769
}
|
-- Andreas, 2020-05-08, issue #4637
-- Print record pattern (in with-function) in termination error.
-- {-# OPTIONS -v reify:60 #-}
record R : Set where
pattern; inductive
field foo : R
postulate
bar : R → R
test : R → R
test r with bar r
test r | record { foo = x } with bar x
test r | record { foo = x } | _ = test x
-- WAS:
-- Termination checking failed for the following functions:
-- test
-- Problematic calls:
-- test r | bar r
-- Issue4637.with-14 r (recCon-NOT-PRINTED x)
-- | bar x
-- test x
-- EXPECTED:
-- Termination checking failed for the following functions:
-- test
-- Problematic calls:
-- test r | bar r
-- Issue4637.with-14 r (record { foo = x })
-- | bar x
-- test x
|
{
"alphanum_fraction": 0.625,
"avg_line_length": 20.5714285714,
"ext": "agda",
"hexsha": "2e6a28a38cffcf7181ab89e205ea66509b6cd46c",
"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/Issue4637.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/Issue4637.agda",
"max_line_length": 64,
"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/Issue4637.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": 226,
"size": 720
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Lists.Definition
open import Lists.Fold.Fold
open import Lists.Concat
open import Lists.Length
open import Numbers.Naturals.Semiring
module Lists.Monad where
open import Lists.Map.Map public
flatten : {a : _} {A : Set a} → (l : List (List A)) → List A
flatten [] = []
flatten (l :: ls) = l ++ flatten ls
flatten' : {a : _} {A : Set a} → (l : List (List A)) → List A
flatten' = fold _++_ []
flatten=flatten' : {a : _} {A : Set a} (l : List (List A)) → flatten l ≡ flatten' l
flatten=flatten' [] = refl
flatten=flatten' (l :: ls) = applyEquality (l ++_) (flatten=flatten' ls)
lengthFlatten : {a : _} {A : Set a} (l : List (List A)) → length (flatten l) ≡ (fold _+N_ zero (map length l))
lengthFlatten [] = refl
lengthFlatten (l :: ls) rewrite lengthConcat l (flatten ls) | lengthFlatten ls = refl
flattenConcat : {a : _} {A : Set a} (l1 l2 : List (List A)) → flatten (l1 ++ l2) ≡ (flatten l1) ++ (flatten l2)
flattenConcat [] l2 = refl
flattenConcat (l1 :: ls) l2 rewrite flattenConcat ls l2 | concatAssoc l1 (flatten ls) (flatten l2) = refl
pure : {a : _} {A : Set a} → A → List A
pure a = [ a ]
bind : {a b : _} {A : Set a} {B : Set b} → (f : A → List B) → List A → List B
bind f l = flatten (map f l)
private
leftIdentLemma : {a : _} {A : Set a} (xs : List A) → flatten (map pure xs) ≡ xs
leftIdentLemma [] = refl
leftIdentLemma (x :: xs) rewrite leftIdentLemma xs = refl
leftIdent : {a b : _} {A : Set a} {B : Set b} → (f : A → List B) → {x : A} → bind pure (f x) ≡ f x
leftIdent f {x} with f x
leftIdent f {x} | [] = refl
leftIdent f {x} | y :: ys rewrite leftIdentLemma ys = refl
rightIdent : {a b : _} {A : Set a} {B : Set b} → (f : A → List B) → {x : A} → bind f (pure x) ≡ f x
rightIdent f {x} with f x
rightIdent f {x} | [] = refl
rightIdent f {x} | y :: ys rewrite appendEmptyList ys = refl
associative : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → (f : A → List B) (g : B → List C) → {x : List A} → bind g (bind f x) ≡ bind (λ a → bind g (f a)) x
associative f g {[]} = refl
associative f g {x :: xs} rewrite mapConcat (f x) (flatten (map f xs)) g | flattenConcat (map g (f x)) (map g (flatten (map f xs))) = applyEquality (flatten (map g (f x)) ++_) (associative f g {xs})
|
{
"alphanum_fraction": 0.603215993,
"avg_line_length": 40.3684210526,
"ext": "agda",
"hexsha": "ddeb258d84f00dade5bceaa75aec56c6f23a0813",
"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": "Lists/Monad.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": "Lists/Monad.agda",
"max_line_length": 198,
"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": "Lists/Monad.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": 822,
"size": 2301
}
|
-- Andreas, 2013-06-22, bug reported by evancavallo
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.conv:20 -v impossible:100 #-}
module Issue874 where
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
module _ {A : Set} where
postulate
P : A → Set
foo : A → Set
foo _ = Σ (A → A) (λ _ → (∀ _ → A))
-- the unsolved meta here is essential to trigger the bug
bar : (x : A) → foo x → Set
bar x (g , _) = P (g x)
postulate
pos : {x : A} → Σ (foo x) (bar x)
test : {x : A} → Σ (foo x) (bar x)
test = pos
-- this raised an internal error in Conversion.compareElims
-- when projecting at unsolved record type
|
{
"alphanum_fraction": 0.5836909871,
"avg_line_length": 21.84375,
"ext": "agda",
"hexsha": "c0fca3b512908ebde6591d56be94f0273ce882d8",
"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/Issue874.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/Issue874.agda",
"max_line_length": 61,
"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/Issue874.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": 244,
"size": 699
}
|
{-# OPTIONS --without-K --safe #-}
-- adding eta/epsilon to PiPointed
-- separate file for presentation in paper
module PiPointedFrac where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Singleton
infixr 90 _#_
infixr 70 _×ᵤ_
infixr 60 _+ᵤ_
infixr 50 _⊚_
infix 100 !_
infixr 70 _∙×ᵤ_
infixr 60 _∙+ᵤl_
infixr 60 _∙+ᵤr_
infixr 70 _∙⊗_
infixr 60 _∙⊕ₗ_
infixr 60 _∙⊕ᵣ_
infixr 50 _∙⊚_
infix 100 !∙_
------------------------------------------------------------------------------
-- Pi
data 𝕌 : Set
⟦_⟧ : (A : 𝕌) → Set
data _⟷_ : 𝕌 → 𝕌 → Set
eval : {A B : 𝕌} → (A ⟷ B) → ⟦ A ⟧ → ⟦ B ⟧
data 𝕌 where
𝟘 : 𝕌
𝟙 : 𝕌
_+ᵤ_ : 𝕌 → 𝕌 → 𝕌
_×ᵤ_ : 𝕌 → 𝕌 → 𝕌
⟦ 𝟘 ⟧ = ⊥
⟦ 𝟙 ⟧ = ⊤
⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
data _⟷_ where
unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ⟷ t
uniti₊l : {t : 𝕌} → t ⟷ 𝟘 +ᵤ t
unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ⟷ t
uniti₊r : {t : 𝕌} → t ⟷ t +ᵤ 𝟘
swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ⟷ t₂ +ᵤ t₁
assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ +ᵤ t₂) +ᵤ t₃
assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ⟷ t₁ +ᵤ (t₂ +ᵤ t₃)
unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ⟷ t
uniti⋆l : {t : 𝕌} → t ⟷ 𝟙 ×ᵤ t
unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ⟷ t
uniti⋆r : {t : 𝕌} → t ⟷ t ×ᵤ 𝟙
swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ⟷ t₂ ×ᵤ t₁
assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) ×ᵤ t₃
assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ⟷ t₁ ×ᵤ (t₂ ×ᵤ t₃)
absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ⟷ 𝟘
absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ⟷ 𝟘
factorzr : {t : 𝕌} → 𝟘 ⟷ t ×ᵤ 𝟘
factorzl : {t : 𝕌} → 𝟘 ⟷ 𝟘 ×ᵤ t
dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ⟷ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃)
factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ +ᵤ t₂) ×ᵤ t₃
distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)
factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ⟷ t₁ ×ᵤ (t₂ +ᵤ t₃)
id⟷ : {t : 𝕌} → t ⟷ t
_⊚_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ +ᵤ t₂ ⟷ t₃ +ᵤ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ ×ᵤ t₂ ⟷ t₃ ×ᵤ t₄)
!_ : {A B : 𝕌} → A ⟷ B → B ⟷ A
! unite₊l = uniti₊l
! uniti₊l = unite₊l
! unite₊r = uniti₊r
! uniti₊r = unite₊r
! swap₊ = swap₊
! assocl₊ = assocr₊
! assocr₊ = assocl₊
! unite⋆l = uniti⋆l
! uniti⋆l = unite⋆l
! unite⋆r = uniti⋆r
! uniti⋆r = unite⋆r
! swap⋆ = swap⋆
! assocl⋆ = assocr⋆
! assocr⋆ = assocl⋆
! absorbr = factorzl
! absorbl = factorzr
! factorzr = absorbl
! factorzl = absorbr
! dist = factor
! factor = dist
! distl = factorl
! factorl = distl
! id⟷ = id⟷
! (c₁ ⊚ c₂) = (! c₂) ⊚ (! c₁)
! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂)
! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
eval unite₊l (inj₂ v) = v
eval uniti₊l v = inj₂ v
eval unite₊r (inj₁ v) = v
eval uniti₊r v = inj₁ v
eval swap₊ (inj₁ v) = inj₂ v
eval swap₊ (inj₂ v) = inj₁ v
eval assocl₊ (inj₁ v) = inj₁ (inj₁ v)
eval assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
eval assocl₊ (inj₂ (inj₂ v)) = inj₂ v
eval assocr₊ (inj₁ (inj₁ v)) = inj₁ v
eval assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
eval assocr₊ (inj₂ v) = inj₂ (inj₂ v)
eval unite⋆l (tt , v) = v
eval uniti⋆l v = (tt , v)
eval unite⋆r (v , tt) = v
eval uniti⋆r v = (v , tt)
eval swap⋆ (v₁ , v₂) = (v₂ , v₁)
eval assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
eval assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
eval absorbl ()
eval absorbr ()
eval factorzl ()
eval factorzr ()
eval dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
eval dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
eval factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
eval factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
eval distl (v , inj₁ v₁) = inj₁ (v , v₁)
eval distl (v , inj₂ v₂) = inj₂ (v , v₂)
eval factorl (inj₁ (v , v₁)) = (v , inj₁ v₁)
eval factorl (inj₂ (v , v₂)) = (v , inj₂ v₂)
eval id⟷ v = v
eval (c₁ ⊚ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₁ v) = inj₁ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₂ v) = inj₂ (eval c₂ v)
eval (c₁ ⊗ c₂) (v₁ , v₂) = (eval c₁ v₁ , eval c₂ v₂)
ΠisRev : ∀ {A B} → (c : A ⟷ B) (a : ⟦ A ⟧) → eval (c ⊚ ! c) a ≡ a
ΠisRev unite₊l (inj₂ y) = refl
ΠisRev uniti₊l a = refl
ΠisRev unite₊r (inj₁ x) = refl
ΠisRev uniti₊r a = refl
ΠisRev swap₊ (inj₁ x) = refl
ΠisRev swap₊ (inj₂ y) = refl
ΠisRev assocl₊ (inj₁ x) = refl
ΠisRev assocl₊ (inj₂ (inj₁ x)) = refl
ΠisRev assocl₊ (inj₂ (inj₂ y)) = refl
ΠisRev assocr₊ (inj₁ (inj₁ x)) = refl
ΠisRev assocr₊ (inj₁ (inj₂ y)) = refl
ΠisRev assocr₊ (inj₂ y) = refl
ΠisRev unite⋆l (tt , y) = refl
ΠisRev uniti⋆l a = refl
ΠisRev unite⋆r (x , tt) = refl
ΠisRev uniti⋆r a = refl
ΠisRev swap⋆ (x , y) = refl
ΠisRev assocl⋆ (x , (y , z)) = refl
ΠisRev assocr⋆ ((x , y) , z) = refl
ΠisRev dist (inj₁ x , z) = refl
ΠisRev dist (inj₂ y , z) = refl
ΠisRev factor (inj₁ (x , z)) = refl
ΠisRev factor (inj₂ (y , z)) = refl
ΠisRev distl (x , inj₁ y) = refl
ΠisRev distl (x , inj₂ z) = refl
ΠisRev factorl (inj₁ (x , y)) = refl
ΠisRev factorl (inj₂ (x , z)) = refl
ΠisRev id⟷ a = refl
ΠisRev (c₁ ⊚ c₂) a rewrite ΠisRev c₂ (eval c₁ a) = ΠisRev c₁ a
ΠisRev (c₁ ⊕ c₂) (inj₁ x) rewrite ΠisRev c₁ x = refl
ΠisRev (c₁ ⊕ c₂) (inj₂ y) rewrite ΠisRev c₂ y = refl
ΠisRev (c₁ ⊗ c₂) (x , y) rewrite ΠisRev c₁ x | ΠisRev c₂ y = refl
------------------------------------------------------------------------------
-- Pointed types and singleton types
data ∙𝕌 : Set where
_#_ : (t : 𝕌) → (v : ⟦ t ⟧) → ∙𝕌
_∙×ᵤ_ : ∙𝕌 → ∙𝕌 → ∙𝕌
_∙+ᵤl_ : ∙𝕌 → ∙𝕌 → ∙𝕌
_∙+ᵤr_ : ∙𝕌 → ∙𝕌 → ∙𝕌
Singᵤ : ∙𝕌 → ∙𝕌
Recipᵤ : ∙𝕌 → ∙𝕌
∙⟦_⟧ : ∙𝕌 → Σ[ A ∈ Set ] A
∙⟦ t # v ⟧ = ⟦ t ⟧ , v
∙⟦ T₁ ∙×ᵤ T₂ ⟧ = zip _×_ _,_ ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ T₁ ∙+ᵤl T₂ ⟧ = zip _⊎_ (λ x _ → inj₁ x) ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ T₁ ∙+ᵤr T₂ ⟧ = zip _⊎_ (λ _ y → inj₂ y) ∙⟦ T₁ ⟧ ∙⟦ T₂ ⟧
∙⟦ Singᵤ T ⟧ = < uncurry Singleton , (λ y → proj₂ y , refl) > ∙⟦ T ⟧
∙⟦ Recipᵤ T ⟧ = < uncurry Recip , (λ _ _ → tt) > ∙⟦ T ⟧
∙𝟙 : ∙𝕌
∙𝟙 = 𝟙 # tt
data _∙⟶_ : ∙𝕌 → ∙𝕌 → Set where
-- when we know the base type
∙c : {t₁ t₂ : 𝕌} {v : ⟦ t₁ ⟧} →
(c : t₁ ⟷ t₂) → t₁ # v ∙⟶ t₂ # (eval c v)
∙times# : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
((t₁ ×ᵤ t₂) # (v₁ , v₂)) ∙⟶ ((t₁ # v₁) ∙×ᵤ (t₂ # v₂))
∙#times : {t₁ t₂ : 𝕌} {v₁ : ⟦ t₁ ⟧} {v₂ : ⟦ t₂ ⟧} →
((t₁ # v₁) ∙×ᵤ (t₂ # v₂)) ∙⟶ ((t₁ ×ᵤ t₂) # (v₁ , v₂))
-- some things need to be explicitly lifted
∙id⟷ : {T : ∙𝕌} → T ∙⟶ T
_∙⊚_ : {T₁ T₂ T₃ : ∙𝕌} → (T₁ ∙⟶ T₂) → (T₂ ∙⟶ T₃) → (T₁ ∙⟶ T₃)
∙unite⋆l : {t : ∙𝕌} → ∙𝟙 ∙×ᵤ t ∙⟶ t
∙uniti⋆l : {t : ∙𝕌} → t ∙⟶ ∙𝟙 ∙×ᵤ t
∙unite⋆r : {t : ∙𝕌} → t ∙×ᵤ ∙𝟙 ∙⟶ t
∙uniti⋆r : {t : ∙𝕌} → t ∙⟶ t ∙×ᵤ ∙𝟙
∙swap⋆ : {T₁ T₂ : ∙𝕌} → T₁ ∙×ᵤ T₂ ∙⟶ T₂ ∙×ᵤ T₁
∙assocl⋆ : {T₁ T₂ T₃ : ∙𝕌} → T₁ ∙×ᵤ (T₂ ∙×ᵤ T₃) ∙⟶ (T₁ ∙×ᵤ T₂) ∙×ᵤ T₃
∙assocr⋆ : {T₁ T₂ T₃ : ∙𝕌} → (T₁ ∙×ᵤ T₂) ∙×ᵤ T₃ ∙⟶ T₁ ∙×ᵤ (T₂ ∙×ᵤ T₃)
_∙⊗_ : {T₁ T₂ T₃ T₄ : ∙𝕌} → (T₁ ∙⟶ T₃) → (T₂ ∙⟶ T₄)
→ (T₁ ∙×ᵤ T₂ ∙⟶ T₃ ∙×ᵤ T₄)
_∙⊕ₗ_ : {T₁ T₂ T₃ T₄ : ∙𝕌} → (T₁ ∙⟶ T₃) → (T₂ ∙⟶ T₄)
→ (T₁ ∙+ᵤl T₂ ∙⟶ T₃ ∙+ᵤl T₄)
_∙⊕ᵣ_ : {T₁ T₂ T₃ T₄ : ∙𝕌} → (T₁ ∙⟶ T₃) → (T₂ ∙⟶ T₄)
→ (T₁ ∙+ᵤr T₂ ∙⟶ T₃ ∙+ᵤr T₄)
-- monad
return : (T : ∙𝕌) → T ∙⟶ Singᵤ T
-- comonad
extract : (T : ∙𝕌) → Singᵤ T ∙⟶ T
-- eta/epsilon
η : (T : ∙𝕌) → ∙𝟙 ∙⟶ (Singᵤ T ∙×ᵤ Recipᵤ T)
ε : (T : ∙𝕌) → (Singᵤ T ∙×ᵤ Recipᵤ T) ∙⟶ ∙𝟙
tensor : {T₁ T₂ : ∙𝕌} → (Singᵤ T₁ ∙×ᵤ Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
tensor {T₁} {T₂} = (extract T₁ ∙⊗ extract T₂) ∙⊚ return (T₁ ∙×ᵤ T₂)
untensor : {T₁ T₂ : ∙𝕌} → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (Singᵤ T₁ ∙×ᵤ Singᵤ T₂)
untensor {T₁} {T₂} = extract (T₁ ∙×ᵤ T₂) ∙⊚ (return T₁ ∙⊗ return T₂)
tensorl : {T₁ T₂ : ∙𝕌} → (Singᵤ T₁ ∙×ᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
tensorl {T₁} {T₂} = (extract T₁ ∙⊗ ∙id⟷) ∙⊚ return (T₁ ∙×ᵤ T₂)
tensorr : {T₁ T₂ : ∙𝕌} → (T₁ ∙×ᵤ Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙×ᵤ T₂)
tensorr {T₁} {T₂} = (∙id⟷ ∙⊗ extract T₂) ∙⊚ return (T₁ ∙×ᵤ T₂)
cotensorl : {T₁ T₂ : ∙𝕌} → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (Singᵤ T₁ ∙×ᵤ T₂)
cotensorl {T₁} {T₂} = extract (T₁ ∙×ᵤ T₂) ∙⊚ (return T₁ ∙⊗ ∙id⟷)
cotensorr : {T₁ T₂ : ∙𝕌} → Singᵤ (T₁ ∙×ᵤ T₂) ∙⟶ (T₁ ∙×ᵤ Singᵤ T₂)
cotensorr {T₁} {T₂} = extract (T₁ ∙×ᵤ T₂) ∙⊚ (∙id⟷ ∙⊗ return T₂)
plusl : {T₁ T₂ : ∙𝕌} → (Singᵤ T₁ ∙+ᵤl T₂) ∙⟶ Singᵤ (T₁ ∙+ᵤl T₂)
plusl {T₁} {T₂} = (extract T₁ ∙⊕ₗ ∙id⟷) ∙⊚ return (T₁ ∙+ᵤl T₂)
plusr : {T₁ T₂ : ∙𝕌} → (T₁ ∙+ᵤr Singᵤ T₂) ∙⟶ Singᵤ (T₁ ∙+ᵤr T₂)
plusr {T₁} {T₂} = (∙id⟷ ∙⊕ᵣ extract T₂) ∙⊚ return (T₁ ∙+ᵤr T₂)
coplusl : {T₁ T₂ : ∙𝕌} → Singᵤ (T₁ ∙+ᵤl T₂) ∙⟶ (Singᵤ T₁ ∙+ᵤl T₂)
coplusl {T₁} {T₂} = extract (T₁ ∙+ᵤl T₂) ∙⊚ (return T₁ ∙⊕ₗ ∙id⟷)
coplusr : {T₁ T₂ : ∙𝕌} → Singᵤ (T₁ ∙+ᵤr T₂) ∙⟶ (T₁ ∙+ᵤr Singᵤ T₂)
coplusr {T₁} {T₂} = extract (T₁ ∙+ᵤr T₂) ∙⊚ (∙id⟷ ∙⊕ᵣ return T₂)
-- functor
∙Singᵤ : {T₁ T₂ : ∙𝕌} → (T₁ ∙⟶ T₂) → (Singᵤ T₁ ∙⟶ Singᵤ T₂)
∙Singᵤ {T₁} {T₂} c = extract T₁ ∙⊚ c ∙⊚ return T₂
join : {T₁ : ∙𝕌} → Singᵤ (Singᵤ T₁) ∙⟶ Singᵤ T₁
join {T₁} = extract (Singᵤ T₁)
duplicate : {T₁ : ∙𝕌} → Singᵤ T₁ ∙⟶ Singᵤ (Singᵤ T₁)
duplicate {T₁} = return (Singᵤ T₁)
!∙_ : {A B : ∙𝕌} → A ∙⟶ B → B ∙⟶ A
!∙ (∙c {t₁} {t₂} {v} c) = subst (λ x → t₂ # eval c v ∙⟶ t₁ # x) (ΠisRev c v) (∙c (! c))
!∙ ∙times# = ∙#times
!∙ ∙#times = ∙times#
!∙ ∙id⟷ = ∙id⟷
!∙ (c₁ ∙⊚ c₂) = (!∙ c₂) ∙⊚ (!∙ c₁)
!∙ ∙unite⋆l = ∙uniti⋆l
!∙ ∙uniti⋆l = ∙unite⋆l
!∙ ∙unite⋆r = ∙uniti⋆r
!∙ ∙uniti⋆r = ∙unite⋆r
!∙ ∙swap⋆ = ∙swap⋆
!∙ ∙assocl⋆ = ∙assocr⋆
!∙ ∙assocr⋆ = ∙assocl⋆
!∙ (c₁ ∙⊗ c₂) = (!∙ c₁) ∙⊗ (!∙ c₂)
!∙ (c₁ ∙⊕ₗ c₂) = (!∙ c₁) ∙⊕ₗ (!∙ c₂)
!∙ (c₁ ∙⊕ᵣ c₂) = (!∙ c₁) ∙⊕ᵣ (!∙ c₂)
!∙ return T = extract T
!∙ extract T = return T
!∙ η T = ε T
!∙ ε T = η T
∙eval : {T₁ T₂ : ∙𝕌} → (C : T₁ ∙⟶ T₂) →
let (t₁ , v₁) = ∙⟦ T₁ ⟧
(t₂ , v₂) = ∙⟦ T₂ ⟧
in Σ (t₁ → t₂) (λ f → f v₁ ≡ v₂)
∙eval ∙id⟷ = (λ x → x) , refl
∙eval (∙c c) = eval c , refl
∙eval (C₁ ∙⊚ C₂) with ∙eval C₁ | ∙eval C₂
... | (f , p) | (g , q) = (λ x → g (f x)) , trans (cong g p) q
∙eval ∙unite⋆l = (λ {(tt , x) → x}) , refl
∙eval ∙uniti⋆l = (λ {x → (tt , x)}) , refl
∙eval ∙unite⋆r = (λ {(x , tt) → x}) , refl
∙eval ∙uniti⋆r = (λ {x → (x , tt)}) , refl
∙eval ∙swap⋆ = (λ {(x , y) → y , x}) , refl
∙eval ∙assocl⋆ = (λ {(x , (y , z)) → ((x , y) , z)}) , refl
∙eval ∙assocr⋆ = (λ {((x , y) , z) → (x , (y , z))}) , refl
∙eval (C₀ ∙⊗ C₁) with ∙eval C₀ | ∙eval C₁
... | (f , p) | (g , q) = (λ {(t₁ , t₂) → f t₁ , g t₂}) , cong₂ _,_ p q
∙eval (C₀ ∙⊕ₗ C₁) with ∙eval C₀ | ∙eval C₁
... | (f , p) | (g , q) = (λ { (inj₁ x) → inj₁ (f x)
; (inj₂ y) → inj₂ (g y) })
, cong inj₁ p
∙eval (C₀ ∙⊕ᵣ C₁) with ∙eval C₀ | ∙eval C₁
... | (f , p) | (g , q) = (λ { (inj₁ x) → inj₁ (f x)
; (inj₂ y) → inj₂ (g y) })
, cong inj₂ q
∙eval ∙times# = (λ x → x) , refl
∙eval ∙#times = (λ x → x) , refl
∙eval (return T) = (λ _ → proj₂ ∙⟦ T ⟧ , refl) , refl
∙eval (extract T) = (λ {(w , refl) → w}) , refl
∙eval (η T) = (λ tt → (proj₂ ∙⟦ T ⟧ , refl) , λ _ → tt) , refl
∙eval (ε T) = (λ { ((_ , refl) , f) → f (proj₂ ∙⟦ T ⟧ , refl)}) , refl
-- you don't need to prove this
∙ΠisRev : ∀ {T₁ T₂} → (c : T₁ ∙⟶ T₂) →
let (t₁ , v₁) = ∙⟦ T₁ ⟧
(t₂ , v₂) = ∙⟦ T₂ ⟧
(f , pf) = ∙eval (c ∙⊚ !∙ c) in
f v₁ ≡ v₁
∙ΠisRev c = proj₂ (∙eval (c ∙⊚ !∙ c))
-----------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4701566887,
"avg_line_length": 33.1561561562,
"ext": "agda",
"hexsha": "bdd3a1ba677b4506722c7094b0cb37c92e980a5d",
"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": "fracGC/PiPointedFrac.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": "fracGC/PiPointedFrac.agda",
"max_line_length": 87,
"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": "fracGC/PiPointedFrac.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": 7112,
"size": 11041
}
|
module Formalization.LambdaCalculus.SyntaxTransformation where
open import Formalization.LambdaCalculus
open import Lang.Instance
open import Numeral.Natural
open import Numeral.Finite
open import Numeral.Finite.Bound
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
private variable d d₁ d₂ : ℕ
private variable x y : Term(d)
-- Increase the depth level of the given term by something.
-- Example: `depth-[≤](Var(2) : Term(5)) = Var(2) : Term(50)`
depth-[≤] : ⦃ _ : (d₁ ≤ d₂) ⦄ → Term(d₁) → Term(d₂)
depth-[≤] (Apply t1 t2) = Apply(depth-[≤] t1) (depth-[≤] t2)
depth-[≤] (Abstract t) = Abstract(depth-[≤] t)
depth-[≤] (Var x) = Var(bound-[≤] infer x)
-- Increment the depth level of the given term by 1.
-- Example: `depth-𝐒(Var(2) : Term(5)) = Var(2) : Term(6)`
depth-𝐒 : Term(d) → Term(𝐒(d))
depth-𝐒 = depth-[≤]
-- depth-𝐒 (Apply(f)(x)) = Apply (depth-𝐒(f)) (depth-𝐒(x))
-- depth-𝐒 (Abstract(body)) = Abstract(depth-𝐒(body))
-- depth-𝐒 (Var(n)) = Var(bound-𝐒 (n))
Apply₊ : ⦃ _ : (d₁ ≤ d₂) ⦄ → Term(d₂) → Term(d₁) → Term(d₂)
Apply₊ {d₁}{d₂} f(x) = Apply f(depth-[≤] {d₁}{d₂} (x))
{-
-- Increase all variables of the given term
var-[≤] : ∀{d₁ d₂} → ⦃ _ : (d₁ ≤ d₂) ⦄ → Term(d₁) → Term(d₂)
var-[≤] (Apply t1 t2) = Apply(depth-[≤] t1) (depth-[≤] t2)
var-[≤] (Abstract t) = Abstract(depth-[≤] t)
var-[≤] (Var x) = Var({!x + (d₂ − d₁)!}) where
open import Numeral.Natural.TotalOper
-}
-- Increment all variables of the given term.
-- Example: `var-𝐒(Var(2) : Term(5)) = Var(3) : Term(6)`
-- Examples:
-- term : Term(1)
-- term = (1 ↦ (2 ↦ 2 ← 2) ← 0 ← 1 ← 0)
--
-- Then:
-- term = 1 ↦ (2 ↦ 2 ← 2) ← 0 ← 1 ← 0
-- var-𝐒(term) = 2 ↦ (3 ↦ 3 ← 3) ← 1 ← 2 ← 1
-- var-𝐒(var-𝐒(term)) = 3 ↦ (4 ↦ 4 ← 4) ← 2 ← 3 ← 2
var-𝐒 : Term(d) → Term(𝐒(d))
var-𝐒 (Apply(f)(x)) = Apply (var-𝐒(f)) (var-𝐒(x))
var-𝐒 (Abstract{d}(body)) = Abstract{𝐒(d)} (var-𝐒(body))
var-𝐒 (Var{𝐒(d)}(n)) = Var{𝐒(𝐒(d))} (𝐒(n))
-- Substitutes the most recent free variable with a term in a term, while also decrementing them.
-- `substitute val term` is the term where all occurences in `term` of the outer-most variable is replaced with the term `val`.
-- Examples:
-- substituteOuterVar x (Var(0) : Term(1)) = x
-- substituteOuterVar x ((Apply (Var(1)) (Var(0))) : Term(2)) = Apply (Var(0)) x
-- substituteOuterVar (𝜆 0 0) ((𝜆 1 1) ← 0) = ((𝜆 0 0) ← (𝜆 0 0))
-- substituteOuterVar (𝜆 0 0) ((𝜆 1 1 ← 0) ← 0) = (((𝜆 0 0) ← (𝜆 0 0)) ← (𝜆 0 0))
substituteVar0 : Term(d) → Term(𝐒(d)) → Term(d)
substituteVar0 val (Apply(f)(x)) = Apply (substituteVar0 val f) (substituteVar0 val x)
substituteVar0 val (Abstract(body)) = Abstract (substituteVar0 (var-𝐒 val) body)
substituteVar0 val (Var(𝟎)) = val
substituteVar0 val (Var(𝐒(v))) = Var v
{-
substituteMap : (𝕟(d₁) → Term(d₂)) → Term(d₁) → Term(d₂)
substituteMap F (Apply(f)(x)) = Apply (substituteMap F (f)) (substituteMap F (x))
substituteMap F (Var(v)) = F(v)
substituteMap F (Abstract(body)) = Abstract (substituteMap F (body)) -- TODO: Probably incorrect
-}
-- Substituting the outer variable of `var-𝐒 x` yields `x`.
-- This is useful because `substituteVar0` uses `var-𝐒` in its definition.
substituteVar0-var-𝐒 : (substituteVar0 y (var-𝐒 x) ≡ x)
substituteVar0-var-𝐒 {d}{y}{Apply f x} rewrite substituteVar0-var-𝐒 {d}{y}{f} rewrite substituteVar0-var-𝐒 {d}{y}{x} = [≡]-intro
substituteVar0-var-𝐒 {d}{y}{Abstract x} rewrite substituteVar0-var-𝐒 {𝐒 d}{var-𝐒 y}{x} = [≡]-intro
substituteVar0-var-𝐒 {_}{_}{Var 𝟎} = [≡]-intro
substituteVar0-var-𝐒 {_}{_}{Var(𝐒 _)} = [≡]-intro
{-# REWRITE substituteVar0-var-𝐒 #-}
|
{
"alphanum_fraction": 0.6073834546,
"avg_line_length": 43.6588235294,
"ext": "agda",
"hexsha": "9be3757f226692a7e7b3aa5fc3ef9be6c69799ae",
"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": "Formalization/LambdaCalculus/SyntaxTransformation.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": "Formalization/LambdaCalculus/SyntaxTransformation.agda",
"max_line_length": 129,
"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": "Formalization/LambdaCalculus/SyntaxTransformation.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": 1542,
"size": 3711
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.HITs.InfNat.Properties where
open import Cubical.Core.Everything
open import Cubical.Data.Maybe
open import Cubical.Data.Nat
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.InfNat.Base
import Cubical.Data.InfNat as Coprod
ℕ+∞→Cℕ+∞ : ℕ+∞ → Coprod.ℕ+∞
ℕ+∞→Cℕ+∞ zero = Coprod.zero
ℕ+∞→Cℕ+∞ (suc n) = Coprod.suc (ℕ+∞→Cℕ+∞ n)
ℕ+∞→Cℕ+∞ ∞ = Coprod.∞
ℕ+∞→Cℕ+∞ (suc-inf i) = Coprod.∞
ℕ→ℕ+∞ : ℕ → ℕ+∞
ℕ→ℕ+∞ zero = zero
ℕ→ℕ+∞ (suc n) = suc (ℕ→ℕ+∞ n)
Cℕ+∞→ℕ+∞ : Coprod.ℕ+∞ → ℕ+∞
Cℕ+∞→ℕ+∞ Coprod.∞ = ∞
Cℕ+∞→ℕ+∞ (Coprod.fin n) = ℕ→ℕ+∞ n
ℕ→ℕ+∞→Cℕ+∞ : ∀ n → ℕ+∞→Cℕ+∞ (ℕ→ℕ+∞ n) ≡ Coprod.fin n
ℕ→ℕ+∞→Cℕ+∞ zero = refl
ℕ→ℕ+∞→Cℕ+∞ (suc n) = cong Coprod.suc (ℕ→ℕ+∞→Cℕ+∞ n)
Cℕ+∞→ℕ+∞→Cℕ+∞ : ∀ n → ℕ+∞→Cℕ+∞ (Cℕ+∞→ℕ+∞ n) ≡ n
Cℕ+∞→ℕ+∞→Cℕ+∞ Coprod.∞ = refl
Cℕ+∞→ℕ+∞→Cℕ+∞ (Coprod.fin n) = ℕ→ℕ+∞→Cℕ+∞ n
suc-hom : ∀ n → Cℕ+∞→ℕ+∞ (Coprod.suc n) ≡ suc (Cℕ+∞→ℕ+∞ n)
suc-hom Coprod.∞ = suc-inf
suc-hom (Coprod.fin x) = refl
ℕ+∞→Cℕ+∞→ℕ+∞ : ∀ n → Cℕ+∞→ℕ+∞ (ℕ+∞→Cℕ+∞ n) ≡ n
ℕ+∞→Cℕ+∞→ℕ+∞ zero = refl
ℕ+∞→Cℕ+∞→ℕ+∞ ∞ = refl
ℕ+∞→Cℕ+∞→ℕ+∞ (suc n) = suc-hom (ℕ+∞→Cℕ+∞ n) ∙ cong suc (ℕ+∞→Cℕ+∞→ℕ+∞ n)
ℕ+∞→Cℕ+∞→ℕ+∞ (suc-inf i) = lemma i
where
lemma : (λ i → ∞ ≡ suc-inf i) [ refl ≡ suc-inf ∙ refl ]
lemma i j = hcomp (λ k → λ
{ (i = i0) → ∞
; (i = i1) → compPath-filler suc-inf refl k j
; (j = i0) → ∞
; (j = i1) → suc-inf i
}) (suc-inf (i ∧ j))
open Iso
ℕ+∞⇔Cℕ+∞ : Iso ℕ+∞ Coprod.ℕ+∞
ℕ+∞⇔Cℕ+∞ .fun = ℕ+∞→Cℕ+∞
ℕ+∞⇔Cℕ+∞ .inv = Cℕ+∞→ℕ+∞
ℕ+∞⇔Cℕ+∞ .leftInv = ℕ+∞→Cℕ+∞→ℕ+∞
ℕ+∞⇔Cℕ+∞ .rightInv = Cℕ+∞→ℕ+∞→Cℕ+∞
|
{
"alphanum_fraction": 0.5222696766,
"avg_line_length": 26.435483871,
"ext": "agda",
"hexsha": "c50e2ba4ebea4f418d4b4c7c0d5932f613bf672a",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/InfNat/Properties.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/HITs/InfNat/Properties.agda",
"max_line_length": 71,
"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/HITs/InfNat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1124,
"size": 1639
}
|
{-# OPTIONS --cubical --safe #-}
module Function.Surjective where
open import Function.Surjective.Base public
|
{
"alphanum_fraction": 0.7589285714,
"avg_line_length": 18.6666666667,
"ext": "agda",
"hexsha": "babc71b6096b3cd33a73a0647232cb20a781f266",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Function/Surjective.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Function/Surjective.agda",
"max_line_length": 43,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Function/Surjective.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 25,
"size": 112
}
|
module Issue3295 where
open import Issue3295.Incomplete
open import Issue3295.Incomplete2
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
_ : f 0 ≡ 0
_ = {!!}
_ : g 0 ≡ 0
_ = {!!}
_ : f 1 ≡ 1 -- the evaluation of `f` should be blocked here
_ = {!!} -- so looking at the normalised type should not cause any issue
_ : g 1 ≡ 1 -- the evaluation of `g` should be blocked here
_ = {!!} -- so looking at the normalised type should not cause any issue
|
{
"alphanum_fraction": 0.6822033898,
"avg_line_length": 24.8421052632,
"ext": "agda",
"hexsha": "ee7299b4f84000811de5e972ec4610903b06c4fc",
"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/Issue3295.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/Issue3295.agda",
"max_line_length": 75,
"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/Issue3295.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": 149,
"size": 472
}
|
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Poset)
-- A thin (or posetal) category is a category with at most one
-- morphism between any pair of objects.
--
-- As explained on nLab:
--
-- "Up to isomorphism, a thin category is the same thing as a
-- proset. Up to equivalence, a thin category is the same thing as a
-- poset. (...) (It is really a question of whether you're working
-- with strict categories, which are classified up to isomorphism,
-- or categories as such, which are classified up to equivalence.)"
--
-- -- https://ncatlab.org/nlab/show/thin+category
--
-- Since
--
-- 1. posets in the standard library are defined up to an underlying
-- equivalence/setoid, but
--
-- 2. categories in this library do not have a notion of equality on
-- objects (i.e. objects are considered up to isomorphism),
--
-- it makes sense to work with the weaker notion of thin categories
-- here, i.e. those generated by posets rather than prosets. This
-- means that the core of a thin category (the groupoid consisting of
-- all its isomorphism) is just the setoid underlying the
-- corresponding poset.
--
-- (See Categories.Adjoint.Instance.PosetCore for more details.)
module Categories.Category.Construction.Thin {o ℓ₁ ℓ₂} e (P : Poset o ℓ₁ ℓ₂) where
open import Level
open import Data.Unit using (⊤)
open import Function using (flip)
open import Categories.Category
import Categories.Morphism as Morphism
open Poset P
Thin : Category o ℓ₂ e
Thin = record
{ Obj = Carrier
; _⇒_ = _≤_
; _≈_ = λ _ _ → Lift e ⊤
; id = refl
; _∘_ = flip trans
; assoc = _
; identityˡ = _
; identityʳ = _
; equiv = _
; ∘-resp-≈ = _
}
module EqIsIso where
open Category Thin hiding (_≈_)
open Morphism Thin using (_≅_)
open _≅_
-- Equivalent elements of |P| are isomorphic objects of |Thin P|.
≈⇒≅ : ∀ {x y : Obj} → x ≈ y → x ≅ y
≈⇒≅ x≈y = record
{ from = reflexive x≈y
; to = reflexive (Eq.sym x≈y)
}
≅⇒≈ : ∀ {x y : Obj} → x ≅ y → x ≈ y
≅⇒≈ x≅y = antisym (from x≅y) (to x≅y)
|
{
"alphanum_fraction": 0.6448730009,
"avg_line_length": 28.3466666667,
"ext": "agda",
"hexsha": "0ff3916792d3be0985eec8b616cd024df0ad42d7",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Thin.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Thin.agda",
"max_line_length": 82,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Thin.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 661,
"size": 2126
}
|
{-# OPTIONS --safe --without-K #-}
open import Data.Char.Base using (Char)
open import Data.List.Base using (List; []; _∷_)
module PiCalculus.Syntax where
Name : Set
Name = List Char
module Raw where
infixr 20 _∥_
infixr 15 ⦅ν_⦆_
infixr 10 _⦅_⦆_ _⟨_⟩_
data Raw : Set where
𝟘 : Raw
⦅ν_⦆_ : Name → Raw → Raw
_∥_ : Raw → Raw → Raw
_⦅_⦆_ : Name → Name → Raw → Raw
_⟨_⟩_ : Name → Name → Raw → Raw
module Scoped where
open import Data.Fin.Base
open import Data.Nat.Base
infixr 20 _∥_
infixr 15 ν
infixr 10 _⦅⦆_ _⟨_⟩_
private
variable
n : ℕ
data Scoped : ℕ → Set where
𝟘 : Scoped n
ν : Scoped (suc n) → ⦃ name : Name ⦄ → Scoped n
_∥_ : Scoped n → Scoped n → Scoped n
_⦅⦆_ : Fin n → Scoped (suc n) → ⦃ name : Name ⦄ → Scoped n
_⟨_⟩_ : Fin n → Fin n → Scoped n → Scoped n
module Conversion where
private
open Raw
open Scoped
open import Level using (Lift; _⊔_)
open import Function using (_∘_)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Nullary.Decidable using (isYes; True; toWitness)
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Nullary.Negation using (¬?)
import Data.Vec.Base as Vec
import Data.Char.Base as Char
import Data.Char.Properties as Charₚ
import Data.List.Base as List
import Data.List.Properties as Listₚ
import Data.String.Base as String
import Data.String.Properties as Stringₚ
import Data.Nat.Show as ℕₛ
import Data.Vec.Membership.DecPropositional as DecPropositional
open import Data.Empty using (⊥)
open import Data.Bool.Base using (true; false; if_then_else_)
open import Data.Product using (_,_; _×_)
open import Data.Unit using (⊤; tt)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Fin.Base using (Fin; zero; suc)
open import Data.String.Base using (_++_)
open import Data.Vec.Membership.Propositional using (_∈_; _∉_)
open import Data.Vec.Relation.Unary.Any using (here; there)
open Vec using (Vec; []; _∷_)
_∈?_ = DecPropositional._∈?_ (Listₚ.≡-dec Charₚ._≟_)
variable
n m : ℕ
Ctx : ℕ → Set
Ctx = Vec Name
count : Name → Ctx n → ℕ
count name = Vec.count (Listₚ.≡-dec Charₚ._≟_ name)
toChars : Name × ℕ → List Char.Char
toChars (x , i) = x List.++ ('^' ∷ ℕₛ.charsInBase 10 i)
repr : ∀ x (xs : Vec Name n) → Name
repr x xs = toChars (x , (count x xs))
apply : Ctx n → Ctx n
apply [] = []
apply (x ∷ xs) = repr x xs ∷ apply xs
WellScoped : Ctx n → Raw → Set
WellScoped ctx 𝟘 = ⊤
WellScoped ctx (⦅ν x ⦆ P) = WellScoped (x ∷ ctx) P
WellScoped ctx (P ∥ Q) = WellScoped ctx P × WellScoped ctx Q
WellScoped ctx (x ⦅ y ⦆ P) = (x ∈ ctx) × WellScoped (y ∷ ctx) P
WellScoped ctx (x ⟨ y ⟩ P) = (x ∈ ctx) × (y ∈ ctx) × WellScoped ctx P
WellScoped? : (ctx : Ctx n) (P : Raw) → Dec (WellScoped ctx P)
WellScoped? ctx 𝟘 = yes tt
WellScoped? ctx (⦅ν x ⦆ P) = WellScoped? (x ∷ ctx) P
WellScoped? ctx (P ∥ Q) = WellScoped? ctx P ×-dec WellScoped? ctx Q
WellScoped? ctx (x ⦅ y ⦆ P) = x ∈? ctx ×-dec WellScoped? (y ∷ ctx) P
WellScoped? ctx (x ⟨ y ⟩ P) = x ∈? ctx ×-dec y ∈? ctx ×-dec WellScoped? ctx P
NotShadowed : Ctx n → Raw → Set
NotShadowed ctx 𝟘 = ⊤
NotShadowed ctx (⦅ν name ⦆ P) = name ∉ ctx × NotShadowed (name ∷ ctx) P
NotShadowed ctx (P ∥ Q) = NotShadowed ctx P × NotShadowed ctx Q
NotShadowed ctx (x ⦅ y ⦆ P) = y ∉ ctx × NotShadowed (y ∷ ctx) P
NotShadowed ctx (x ⟨ y ⟩ P) = NotShadowed ctx P
NotShadowed? : (ctx : Ctx n) (P : Raw) → Dec (NotShadowed ctx P)
NotShadowed? ctx 𝟘 = yes tt
NotShadowed? ctx (⦅ν name ⦆ P) = ¬? (name ∈? ctx) ×-dec NotShadowed? (name ∷ ctx) P
NotShadowed? ctx (P ∥ Q) = NotShadowed? ctx P ×-dec NotShadowed? ctx Q
NotShadowed? ctx (x ⦅ y ⦆ P) = ¬? (y ∈? ctx) ×-dec NotShadowed? (y ∷ ctx) P
NotShadowed? ctx (x ⟨ y ⟩ P) = NotShadowed? ctx P
∈toFin : ∀ {a} {A : Set a} {x} {xs : Vec A n} → x ∈ xs → Fin n
∈toFin (here px) = zero
∈toFin (there x∈xs) = suc (∈toFin x∈xs)
fromRaw' : (ctx : Ctx n) (P : Raw) → WellScoped ctx P → Scoped n
fromRaw' ctx 𝟘 tt = 𝟘
fromRaw' ctx (⦅ν x ⦆ P) wsP =
ν (fromRaw' (x ∷ ctx) P wsP) ⦃ x ⦄
fromRaw' ctx (P ∥ Q) (wsP , wsQ) =
fromRaw' ctx P wsP ∥ fromRaw' ctx Q wsQ
fromRaw' ctx (x ⦅ y ⦆ P) (x∈ctx , wsP) =
(∈toFin x∈ctx ⦅⦆ fromRaw' (y ∷ ctx) P wsP) ⦃ y ⦄
fromRaw' ctx (x ⟨ y ⟩ P) (x∈ctx , y∈ctx , wsP) =
∈toFin x∈ctx ⟨ ∈toFin y∈ctx ⟩ fromRaw' ctx P wsP
fromRaw : (ctx : Ctx n) (P : Raw) → ⦃ _ : True (WellScoped? ctx P) ⦄ → Scoped n
fromRaw ctx P ⦃ p ⦄ = fromRaw' ctx P (toWitness p)
toRaw : Ctx n → Scoped n → Raw
toRaw ctx 𝟘 = 𝟘
toRaw ctx (ν P ⦃ name ⦄) =
⦅ν repr name ctx ⦆ toRaw (name ∷ ctx) P
toRaw ctx (P ∥ Q) =
toRaw ctx P ∥ toRaw ctx Q
toRaw ctx ((x ⦅⦆ P) ⦃ name ⦄) =
let ctx' = apply ctx
in Vec.lookup ctx' x ⦅ repr name ctx ⦆ toRaw (name ∷ ctx) P
toRaw ctx (x ⟨ y ⟩ P) =
let ctx' = apply ctx
in Vec.lookup ctx' x ⟨ Vec.lookup ctx' y ⟩ toRaw ctx P
map : ∀ {a} (B : Scoped n → Set a) (ctx : Vec Name n) (P : Raw) → Set a
map B ctx P with WellScoped? ctx P
map B ctx P | yes wsP = B (fromRaw' ctx P wsP)
map B ctx P | no _ = Lift _ ⊥
map₂ : ∀ {a} (B : Scoped n → Scoped n → Set a) (ctx : Vec Name n) (P Q : Raw) → Set a
map₂ B ctx P Q with WellScoped? ctx P | WellScoped? ctx Q
map₂ B ctx P Q | yes wsP | yes wsQ = B (fromRaw' ctx P wsP) (fromRaw' ctx Q wsQ)
map₂ B ctx P Q | _ | _ = Lift _ ⊥
|
{
"alphanum_fraction": 0.5972247252,
"avg_line_length": 33.4277108434,
"ext": "agda",
"hexsha": "c71e83444a2e8f6324a33fd76d3d17f0d0612ed9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/Syntax.agda",
"max_line_length": 87,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 2220,
"size": 5549
}
|
{-
Day 3, 1st part
-}
module a3 where
open import Agda.Builtin.IO using (IO)
open import Agda.Builtin.Unit using (⊤)
open import Agda.Builtin.String using (String; primShowNat)
open import Agda.Builtin.Equality
open import Data.Nat
open import Data.Bool
open import Data.List hiding (lookup;allFin)
renaming (map to mapList)
open import Data.Vec
open import Data.Fin hiding (_+_)
open import Data.Maybe renaming (map to maybeMap)
open import a3-input
postulate putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
-- helper
showMaybeNat : Maybe ℕ → String
showMaybeNat (just n) = primShowNat n
showMaybeNat nothing = "nothing"
data Bit : Set where
one : Bit
zero : Bit
BitVec = Vec Bit
Vecℕ→BitVec : {n : ℕ} → Vec ℕ n → Maybe (BitVec n)
Vecℕ→BitVec [] = just []
Vecℕ→BitVec (x ∷ v) with Vecℕ→BitVec v
... | just v' with x
... | 0 = just (zero ∷ v')
... | 1 = just (one ∷ v')
... | suc (suc _) = nothing
Vecℕ→BitVec (x ∷ v) | nothing = nothing
findMostCommonBit : {n : ℕ} (index : Fin n) → List (BitVec n) → Bit
findMostCommonBit {n = n} index input = iterate 0 0 input
where
iterate : (zeros : ℕ) (ones : ℕ) → List (BitVec n) → Bit
iterate zeros ones [] =
if zeros <ᵇ ones then one else zero
iterate zeros ones (bitVec ∷ list) with lookup bitVec index
... | zero = iterate (1 + zeros) ones list
... | one = iterate zeros (1 + ones) list
bitVecToℕ : {n : ℕ} → BitVec n → ℕ
bitVecToℕ [] = 0
bitVecToℕ (zero ∷ v) = bitVecToℕ v
bitVecToℕ {n = suc n} (one ∷ v) = 2 ^ n + (bitVecToℕ v)
invertBitVec : {n : ℕ} → BitVec n → BitVec n
invertBitVec [] = []
invertBitVec (zero ∷ v) = one ∷ invertBitVec v
invertBitVec (one ∷ v) = zero ∷ invertBitVec v
listMaybe : {A : Set} → List (Maybe A) → Maybe (List A)
listMaybe [] = just []
listMaybe (just x ∷ list) with listMaybe list
... | just proccessedList = just (x ∷ proccessedList)
... | nothing = nothing
listMaybe (nothing ∷ list) = nothing
doTask : List (BitVec 12) → ℕ
doTask input = gamma * epsilon
where
bitVecGamma = map (λ index → findMostCommonBit index input) (allFin 12)
gamma : ℕ
gamma = bitVecToℕ bitVecGamma
epsilon = bitVecToℕ (invertBitVec bitVecGamma)
main : IO ⊤
main = putStrLn (showMaybeNat ((maybeMap doTask) (listMaybe (mapList Vecℕ→BitVec input))))
private
-- checks from the exercise text
testInput : Maybe (List (BitVec 5))
testInput = listMaybe (mapList Vecℕ→BitVec
((0 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 1 ∷ 1 ∷ 1 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(1 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ []) ∷
(0 ∷ 1 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(0 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ []) ∷
(1 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ []) ∷
(1 ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ []) ∷
(0 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ []) ∷
(0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ []) ∷
[]))
_ : maybeMap (findMostCommonBit Fin.zero) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc Fin.zero)) testInput ≡ just zero
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc (Fin.suc Fin.zero))) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (Fin.suc (Fin.suc (Fin.suc Fin.zero)))) testInput ≡ just one
_ = refl
_ : maybeMap (findMostCommonBit (fromℕ 4)) testInput ≡ just zero
_ = refl
-- test bitVecToℕ
_ : bitVecToℕ (one ∷ zero ∷ one ∷ one ∷ zero ∷ []) ≡ 22
_ = refl
_ : Vecℕ→BitVec (1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ []) ≡ just (one ∷ zero ∷ one ∷ one ∷ zero ∷ [])
_ = refl
_ : Vecℕ→BitVec (1 ∷ 0 ∷ 1 ∷ 5 ∷ 0 ∷ []) ≡ nothing
_ = refl
|
{
"alphanum_fraction": 0.5384615385,
"avg_line_length": 31.5714285714,
"ext": "agda",
"hexsha": "3881a435e75d21e014eee77d5cef2addfd4d3fdc",
"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": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felixwellen/adventOfCode",
"max_forks_repo_path": "a3.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"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": "felixwellen/adventOfCode",
"max_issues_repo_path": "a3.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felixwellen/adventOfCode",
"max_stars_repo_path": "a3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1494,
"size": 3978
}
|
{-# OPTIONS --prop --without-K #-}
module Data.Nat.Square where
open import Data.Nat
open import Data.Nat.Properties
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl)
_² : ℕ → ℕ
n ² = n * n
n^2≡n² : ∀ n → n ^ 2 ≡ n ²
n^2≡n² n = Eq.cong (n *_) (*-identityʳ n)
²-mono : _² Preserves _≤_ ⟶ _≤_
²-mono m≤n = *-mono-≤ m≤n m≤n
|
{
"alphanum_fraction": 0.6642156863,
"avg_line_length": 20.4,
"ext": "agda",
"hexsha": "f0e82fca790ed677fafb7fdb7a7fd439e09d2aed",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Data/Nat/Square.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"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": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Data/Nat/Square.agda",
"max_line_length": 73,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Data/Nat/Square.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 157,
"size": 408
}
|
module Structure.Type.Quotient where
import Lvl
open import Logic
open import Logic.Propositional
open import Structure.Function hiding (intro)
open import Structure.Function.Domain hiding (intro)
open import Structure.Relator.Equivalence hiding (intro)
open import Structure.Setoid hiding (intro)
import Type
open import Type.Properties.Empty hiding (intro)
record Quotient {ℓ₁ ℓ₂} {T : TYPE(ℓ₁)} (_≅_ : T → T → Stmt{ℓ₂}) ⦃ equivalence : Equivalence(_≅_) ⦄ : Stmtω where
field
{ℓ} : Lvl.Level
Type : TYPE(ℓ)
{ℓₑ} : Lvl.Level
⦃ equiv ⦄ : Equiv{ℓₑ}(Type) -- TODO: Consider using Id instead of this because otherwise every type has a quotient by just using itself
class : T → Type
⦃ intro-function ⦄ : Function ⦃ Structure.Setoid.intro(_≅_) ⦃ equivalence ⦄ ⦄ (class)
⦃ intro-bijective ⦄ : Bijective ⦃ Structure.Setoid.intro(_≅_) ⦃ equivalence ⦄ ⦄ (class)
-- elim : Type → T -- TODO: Choice?
-- inverseᵣ : ∀{q : Type} → (class(elim(q)) ≡ q)
-- extensionality : ∀{a b : T} → (class(a) ≡ class(b)) ↔ (a ≅ b)
_/_ : ∀{ℓ₁ ℓ₂} → (T : TYPE(ℓ₁)) → (_≅_ : T → T → Stmt{ℓ₂}) → ⦃ e : Equivalence(_≅_) ⦄ → ⦃ q : Quotient(_≅_) ⦃ e ⦄ ⦄ → TYPE(Quotient.ℓ q)
(T / (_≅_)) ⦃ _ ⦄ ⦃ q ⦄ = Quotient.Type(q)
[_of_] : ∀{ℓ₁ ℓ₂}{T : TYPE(ℓ₁)} → T → (_≅_ : T → T → Stmt{ℓ₂}) → ⦃ e : Equivalence(_≅_) ⦄ → ⦃ q : Quotient(_≅_) ⦃ e ⦄ ⦄ → (T / (_≅_))
[ x of (_≅_) ] ⦃ _ ⦄ ⦃ q ⦄ = Quotient.class(q)(x)
{-
record Filterer (Filter : ∀{T : Type} → (T → Stmt) → Type) : Stmt where
field
intro : ∀{P} → (x : T) → ⦃ _ : P(x) ⦄ → Filter(P)
obj : ∀{P} → Filter(P) → T
proof : ∀{P} → (X : Filter(P)) → P(obj(X))
inverseₗ : ∀{P}{X : Filter(P)} → (intro(obj(X)) ⦃ proof(X) ⦄ ≡ X)
inverseᵣ : ∀{P}{x}{px} → (obj(intro(x) ⦃ px ⦄) ≡ x)
extensionality : ∀{T} → ⦃ _ : Equiv(T) ⦄ → ∀{Q : (T / (_≡_))}{a b : Q} → (intro(a) ≡ intro(b)) ↔ (a ≡ b)
-}
|
{
"alphanum_fraction": 0.5657264502,
"avg_line_length": 44.7380952381,
"ext": "agda",
"hexsha": "a35b68d56e4148ee5d9c48adba98a740001952bc",
"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/Type/Quotient.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/Type/Quotient.agda",
"max_line_length": 139,
"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/Type/Quotient.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": 798,
"size": 1879
}
|
module GUIgeneric.Prelude where
open import Data.Sum public hiding (map)
open import Data.List public
open import Data.Bool public
open import Data.String hiding (decSetoid) renaming (_++_ to _++Str_; _==_ to _==Str_; _≟_ to _≟Str_) public
open import Data.Unit hiding (_≟_; decSetoid; setoid) public
open import Data.Empty public
open import Data.Product hiding (map; zip) public
open import Data.Sum hiding (map) public
open import Data.Nat hiding (_≟_; _≤_; _≤?_) public
open import Data.Maybe.Base hiding (map) public
open import Function public
open import Relation.Binary.PropositionalEquality.Core public
open import Relation.Binary.PropositionalEquality hiding (setoid ; preorder ; decSetoid; [_]) public
open import Size public
open import Level renaming (_⊔_ to _⊔Level_; suc to sucLevel; zero to zeroLevel) public
open import Relation.Binary.Core using (Decidable) public
open import Relation.Nullary using (Dec) public
open import Relation.Nullary.Decidable using (⌊_⌋) public
--
-- ooAgda Imports
--
open import NativeIO public
open import StateSizedIO.Base hiding (IOInterfaceˢ; IOˢ; IOˢ'; IOˢ+; delayˢ; doˢ; fmapˢ; fmapˢ'; returnˢ) public
open import StateSizedIO.GUI.WxGraphicsLibLevel3 public renaming (createFrame to createWxFrame)
open import StateSizedIO.GUI.WxBindingsFFI renaming (Frame to FFIFrame; Button to FFIButton; TextCtrl to FFITextCtrl) public
open import SizedIO.Base public
open import StateSizedIO.GUI.BaseStateDependent public
open import StateSizedIO.GUI.VariableList renaming (addVar to addVar'; addVar' to addVar) public
|
{
"alphanum_fraction": 0.7937619351,
"avg_line_length": 38.3170731707,
"ext": "agda",
"hexsha": "8d015a1ee88b15d44eddcb7d8b165e24b3ee0580",
"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": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "examples/GUIgeneric/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"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": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "examples/GUIgeneric/Prelude.agda",
"max_line_length": 125,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "examples/GUIgeneric/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 429,
"size": 1571
}
|
module Dave.Extensionality where
open import Dave.Equality
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
→ f ≡ g
postulate
∀-extensionality : ∀ {A : Set} {B : A → Set} {f g : ∀(x : A) → B x}
→ (∀ (x : A) → f x ≡ g x)
→ f ≡ g
|
{
"alphanum_fraction": 0.4041297935,
"avg_line_length": 28.25,
"ext": "agda",
"hexsha": "f49d2e58d976d3719d3c1f86db178469a748717c",
"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": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Extensionality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"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": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Extensionality.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Extensionality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 122,
"size": 339
}
|
module Cats.Category.Preorder where
open import Data.Unit using (⊤ ; tt)
open import Level
open import Relation.Binary as Rel
using (Rel ; IsEquivalence ; _Preserves₂_⟶_⟶_ ; Setoid)
open import Cats.Category
open import Cats.Category.Setoids using (Setoids ; ≈-intro)
open import Cats.Util.Conv
open import Cats.Util.Function as Fun using (_on_)
module _ (lc l≈ l≤ : Level) where
infixr 9 _∘_
infixr 4 _≈_
private
module Setoids = Category (Setoids lc l≈)
Obj : Set (suc (lc ⊔ l≈ ⊔ l≤))
Obj = Rel.Preorder lc l≈ l≤
Universe : Obj → Setoid lc l≈
Universe A = record
{ Carrier = Rel.Preorder.Carrier A
; _≈_ = Rel.Preorder._≈_ A
; isEquivalence = Rel.Preorder.isEquivalence A
}
record _⇒_ (A B : Obj) : Set (lc ⊔ l≈ ⊔ l≤) where
private
module A = Rel.Preorder A
module B = Rel.Preorder B
field
arr : Universe A Setoids.⇒ Universe B
monotone : ∀ {x y} → x A.∼ y → (arr ⃗) x B.∼ (arr ⃗) y
open Cats.Category.Setoids._⇒_ arr public using (resp)
open _⇒_ using (monotone ; resp)
instance
HasArrow-⇒ : ∀ A B → HasArrow (A ⇒ B) _ _ _
HasArrow-⇒ A B = record { Cat = Setoids lc l≈ ; _⃗ = _⇒_.arr }
id : ∀ {A} → A ⇒ A
id = record { arr = Setoids.id ; monotone = Fun.id }
_∘_ : ∀ {A B C} → B ⇒ C → A ⇒ B → A ⇒ C
g ∘ f = record
{ arr = g ⃗ Setoids.∘ f ⃗
; monotone = monotone g Fun.∘ monotone f
}
_≈_ : {A B : Obj} → Rel (A ⇒ B) (lc ⊔ l≈)
_≈_ = Setoids._≈_ on _⃗
instance Preorder : Category (suc (lc ⊔ l≈ ⊔ l≤)) (lc ⊔ l≈ ⊔ l≤) (lc ⊔ l≈)
Preorder = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = Fun.on-isEquivalence _⃗ Setoids.equiv
; ∘-resp = Setoids.∘-resp
; id-r = Setoids.id-r
; id-l = Setoids.id-l
; assoc = λ { {f = f} {g} {h} → Setoids.assoc {f = f ⃗} {g ⃗} {h ⃗} }
}
preorderAsCategory : ∀ {lc l≈ l≤} → Rel.Preorder lc l≈ l≤ → Category lc l≤ zero
preorderAsCategory P = record
{ Obj = P.Carrier
; _⇒_ = P._∼_
; _≈_ = λ _ _ → ⊤
; id = P.refl
; _∘_ = λ B≤C A≤B → P.trans A≤B B≤C
; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt }
; ∘-resp = λ _ _ → tt
; id-r = tt
; id-l = tt
; assoc = tt
}
where
module P = Rel.Preorder P
|
{
"alphanum_fraction": 0.5398116438,
"avg_line_length": 23.36,
"ext": "agda",
"hexsha": "e4965ca15c39a2dc7db524b3b0fbd60b14b1524d",
"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": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Preorder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"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": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Preorder.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Preorder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 955,
"size": 2336
}
|
module plfa.part1.Isomorphism where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; cong-app)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm)
|
{
"alphanum_fraction": 0.7663934426,
"avg_line_length": 30.5,
"ext": "agda",
"hexsha": "c62153f1d56f36b094a9f5eb67ba887890127a4e",
"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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/plfa-exercises/part1/Isomorphism.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/plfa-exercises/part1/Isomorphism.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/plfa-exercises/part1/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 71,
"size": 244
}
|
module Issue2447.Internal-error where
import Issue2447.M
{-# IMPOSSIBLE #-}
|
{
"alphanum_fraction": 0.7564102564,
"avg_line_length": 13,
"ext": "agda",
"hexsha": "d364d41d23503ce6d57ee44eaed9b0b2ddddbfe7",
"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/Issue2447/Internal-error.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/Issue2447/Internal-error.agda",
"max_line_length": 37,
"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/Issue2447/Internal-error.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": 20,
"size": 78
}
|
{-# OPTIONS --without-K #-}
module sets.nat.ordering.lt where
open import sets.nat.ordering.lt.core public
open import sets.nat.ordering.lt.level public
|
{
"alphanum_fraction": 0.7662337662,
"avg_line_length": 25.6666666667,
"ext": "agda",
"hexsha": "2e73b18f34c7f4da0f5e1ffc8217e8faa71b7a31",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/nat/ordering/lt.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/nat/ordering/lt.agda",
"max_line_length": 45,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/nat/ordering/lt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 37,
"size": 154
}
|
module Thesis.SIRelBigStep.DLangDerive where
open import Thesis.SIRelBigStep.DSyntax public
derive-const : ∀ {Δ σ} → (c : Const σ) → DSVal Δ σ
derive-const (lit n) = dconst (lit 0)
derive-dterm : ∀ {Δ σ} → (t : Term Δ σ) → DTerm Δ σ
derive-dsval : ∀ {Δ σ} → (t : SVal Δ σ) → DSVal Δ σ
derive-dsval (var x) = dvar x
derive-dsval (abs t) = dabs (derive-dterm t)
derive-dsval (cons sv1 sv2) = dcons (derive-dsval sv1) (derive-dsval sv2)
derive-dsval (const c) = derive-const c
derive-dterm (val x) = dval (derive-dsval x)
derive-dterm (primapp p sv) = dprimapp p sv (derive-dsval sv)
derive-dterm (app vs vt) = dapp (derive-dsval vs) vt (derive-dsval vt)
derive-dterm (lett s t) = dlett s (derive-dterm s) (derive-dterm t)
-- Nontrivial because of unification problems in pattern matching. I wanted to
-- use it to define ⊕ on closures purely on terms of the closure change.
-- Instead, I decided to use decidable equality on contexts: that's a lot of
-- tedious boilerplate, but not too hard, but the proof that validity and ⊕
-- agree becomes easier.
-- -- Define a DVar and be done?
-- underive-dvar : ∀ {Δ σ} → Var (ΔΔ Δ) (Δτ σ) → Var Δ σ
-- underive-dvar {∅} ()
-- underive-dvar {τ • Δ} x = {!!}
--underive-dvar {σ • Δ} (that x) = that (underive-dvar x)
|
{
"alphanum_fraction": 0.6766798419,
"avg_line_length": 38.3333333333,
"ext": "agda",
"hexsha": "ce464465fbc27579fbfeb753320d46f769a48b63",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Thesis/SIRelBigStep/DLangDerive.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Thesis/SIRelBigStep/DLangDerive.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Thesis/SIRelBigStep/DLangDerive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 443,
"size": 1265
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.elims.CofPushoutSection as CofPushoutSection
module homotopy.SmashIsCofiber {i j} (X : Ptd i) (Y : Ptd j) where
{- the proof that our smash matches the more classical definition as a cofiber -}
Smash-equiv-Cof : Smash X Y ≃ Cofiber (∨-to-× {X = X} {Y = Y})
Smash-equiv-Cof = equiv to from to-from from-to where
module To = SmashRec {C = Cofiber (∨-to-× {X = X} {Y = Y})}
(curry cfcod) cfbase cfbase
(λ x → ! (cfglue (winl x)))
(λ y → ! (cfglue (winr y)))
to : Smash X Y → Cofiber (∨-to-× {X = X} {Y = Y})
to = To.f
module FromGlue = WedgeElim
{P = λ x∨y → smin (pt X) (pt Y) == uncurry smin (∨-to-× {X = X} {Y = Y} x∨y)}
(λ x → smgluel (pt X) ∙' ! (smgluel x))
(λ y → smgluer (pt Y) ∙' ! (smgluer y))
(↓-cst=app-in $
ap2 _∙'_ (!-inv'-r (smgluel (pt X)))
( ap-∘ (uncurry smin) (∨-to-× {X = X} {Y = Y}) wglue
∙ ap (ap (uncurry smin)) (∨-to-×-glue-β {X = X} {Y = Y}))
∙ ! (!-inv'-r (smgluer (pt Y))))
module From = CofiberRec {C = Smash X Y}
(smin (pt X) (pt Y)) (uncurry smin)
FromGlue.f
from : Cofiber (∨-to-× {X = X} {Y = Y}) → Smash X Y
from = From.f
abstract
from-to : ∀ x → from (to x) == x
from-to = Smash-elim
(λ _ _ → idp) (smgluel (pt X)) (smgluer (pt Y))
(λ x → ↓-∘=idf-in' from to $
ap from (ap to (smgluel x)) ∙' smgluel (pt X)
=⟨ ap (_∙' smgluel (pt X)) $
ap from (ap to (smgluel x))
=⟨ ap (ap from) (To.smgluel-β x) ⟩
ap from (! (cfglue (winl x)))
=⟨ ap-! from (cfglue (winl x)) ⟩
! (ap from (cfglue (winl x)))
=⟨ ap ! $ From.glue-β (winl x) ⟩
! (smgluel (pt X) ∙' ! (smgluel x))
=⟨ !-∙' (smgluel (pt X)) (! (smgluel x)) ⟩
! (! (smgluel x)) ∙' ! (smgluel (pt X))
=∎ ⟩
(! (! (smgluel x)) ∙' ! (smgluel (pt X))) ∙' smgluel (pt X)
=⟨ ∙'-assoc (! (! (smgluel x))) (! (smgluel (pt X))) (smgluel (pt X)) ⟩
! (! (smgluel x)) ∙' ! (smgluel (pt X)) ∙' smgluel (pt X)
=⟨ ap2 _∙'_ (!-! (smgluel x)) (!-inv'-l (smgluel (pt X))) ⟩
smgluel x
=∎)
(λ y → ↓-∘=idf-in' from to $
ap from (ap to (smgluer y)) ∙' smgluer (pt Y)
=⟨ ap (_∙' smgluer (pt Y)) $
ap from (ap to (smgluer y))
=⟨ ap (ap from) (To.smgluer-β y) ⟩
ap from (! (cfglue (winr y)))
=⟨ ap-! from (cfglue (winr y)) ⟩
! (ap from (cfglue (winr y)))
=⟨ ap ! $ From.glue-β (winr y) ⟩
! (smgluer (pt Y) ∙' ! (smgluer y))
=⟨ !-∙' (smgluer (pt Y)) (! (smgluer y)) ⟩
! (! (smgluer y)) ∙' ! (smgluer (pt Y))
=∎ ⟩
(! (! (smgluer y)) ∙' ! (smgluer (pt Y))) ∙' smgluer (pt Y)
=⟨ ∙'-assoc (! (! (smgluer y))) (! (smgluer (pt Y))) (smgluer (pt Y)) ⟩
! (! (smgluer y)) ∙' ! (smgluer (pt Y)) ∙' smgluer (pt Y)
=⟨ ap2 _∙'_ (!-! (smgluer y)) (!-inv'-l (smgluer (pt Y))) ⟩
smgluer y
=∎)
to-from : ∀ x → to (from x) == x
to-from = CofPushoutSection.elim
(λ _ → unit) (λ _ → idp)
(! (cfglue (winr (pt Y)))) (λ _ → idp)
(λ x → ↓-∘=idf-in' to from $
ap to (ap from (cfglue (winl x)))
=⟨ ap (ap to) (From.glue-β (winl x)) ⟩
ap to (FromGlue.f (winl x))
=⟨ ap-∙' to (smgluel (pt X)) (! (smgluel x)) ⟩
ap to (smgluel (pt X)) ∙' ap to (! (smgluel x))
=⟨ ap2 _∙'_
(To.smgluel-β (pt X))
(ap-! to (smgluel x) ∙ ap ! (To.smgluel-β x) ∙ !-! (cfglue (winl x))) ⟩
! (cfglue (winl (pt X))) ∙' cfglue (winl x)
=⟨ ap (λ p → ! p ∙' cfglue (winl x)) $
ap (cfglue (winl (pt X)) ∙'_)
( ap (ap cfcod) (! ∨-to-×-glue-β)
∙ ∘-ap cfcod ∨-to-× wglue)
∙ ↓-cst=app-out (apd cfglue wglue)
⟩
! (cfglue (winr (pt Y))) ∙' cfglue (winl x)
=⟨ ∙'=∙ (! (cfglue (winr (pt Y)))) (cfglue (winl x)) ⟩
! (cfglue (winr (pt Y))) ∙ cfglue (winl x)
=∎)
(λ y → ↓-∘=idf-in' to from $
ap to (ap from (cfglue (winr y)))
=⟨ ap (ap to) (From.glue-β (winr y)) ⟩
ap to (FromGlue.f (winr y))
=⟨ ap-∙' to (smgluer (pt Y)) (! (smgluer y)) ⟩
ap to (smgluer (pt Y)) ∙' ap to (! (smgluer y))
=⟨ ap2 _∙'_
(To.smgluer-β (pt Y))
(ap-! to (smgluer y) ∙ ap ! (To.smgluer-β y) ∙ !-! (cfglue (winr y))) ⟩
! (cfglue (winr (pt Y))) ∙' cfglue (winr y)
=⟨ ∙'=∙ (! (cfglue (winr (pt Y)))) (cfglue (winr y)) ⟩
! (cfglue (winr (pt Y))) ∙ cfglue (winr y)
=∎)
Smash-⊙equiv-Cof : ⊙Smash X Y ⊙≃ ⊙Cofiber (∨-⊙to-× {X = X} {Y = Y})
Smash-⊙equiv-Cof = ≃-to-⊙≃ Smash-equiv-Cof (! (cfglue (winl (pt X))))
|
{
"alphanum_fraction": 0.4324324324,
"avg_line_length": 41.6638655462,
"ext": "agda",
"hexsha": "a87a878e6e1575596b850003f1fb124ee7740df5",
"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/homotopy/SmashIsCofiber.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/homotopy/SmashIsCofiber.agda",
"max_line_length": 85,
"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/homotopy/SmashIsCofiber.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": 2121,
"size": 4958
}
|
------------------------------------------------------------------------
-- The abstract syntax is a set, and the semantics is propositional
------------------------------------------------------------------------
open import Atom
module Propositional (atoms : χ-atoms) where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (const)
open import Bijection equality-with-J using (_↔_)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Decision-procedures equality-with-J
open import Function-universe equality-with-J hiding (_∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import Cancellation atoms
open import Chi atoms
open import Deterministic atoms
open χ-atoms atoms
-- Exp has decidable equality.
mutual
_≟_ : Decidable-equality Exp
apply e₁₁ e₂₁ ≟ apply e₁₂ e₂₂ with e₁₁ ≟ e₁₂
... | no e₁₁≢e₁₂ = no (e₁₁≢e₁₂ ∘ proj₁ ∘ cancel-apply)
... | yes e₁₁≡e₁₂ = ⊎-map (cong₂ apply e₁₁≡e₁₂)
(_∘ proj₂ ∘ cancel-apply)
(e₂₁ ≟ e₂₂)
lambda x₁ e₁ ≟ lambda x₂ e₂ with x₁ V.≟ x₂
... | no x₁≢x₂ = no (x₁≢x₂ ∘ proj₁ ∘ cancel-lambda)
... | yes x₁≡x₂ = ⊎-map (cong₂ lambda x₁≡x₂)
(_∘ proj₂ ∘ cancel-lambda)
(e₁ ≟ e₂)
case e₁ bs₁ ≟ case e₂ bs₂ with e₁ ≟ e₂
... | no e₁≢e₂ = no (e₁≢e₂ ∘ proj₁ ∘ cancel-case)
... | yes e₁≡e₂ = ⊎-map (cong₂ case e₁≡e₂)
(_∘ proj₂ ∘ cancel-case)
(bs₁ ≟-B⋆ bs₂)
rec x₁ e₁ ≟ rec x₂ e₂ with x₁ V.≟ x₂
... | no x₁≢x₂ = no (x₁≢x₂ ∘ proj₁ ∘ cancel-rec)
... | yes x₁≡x₂ = ⊎-map (cong₂ rec x₁≡x₂)
(_∘ proj₂ ∘ cancel-rec)
(e₁ ≟ e₂)
var x₁ ≟ var x₂ = ⊎-map (cong var) (_∘ cancel-var) (x₁ V.≟ x₂)
const c₁ es₁ ≟ const c₂ es₂ with c₁ C.≟ c₂
... | no c₁≢c₂ = no (c₁≢c₂ ∘ proj₁ ∘ cancel-const)
... | yes c₁≡c₂ = ⊎-map (cong₂ const c₁≡c₂)
(_∘ proj₂ ∘ cancel-const)
(es₁ ≟-⋆ es₂)
apply _ _ ≟ lambda _ _ = no (λ ())
apply _ _ ≟ case _ _ = no (λ ())
apply _ _ ≟ rec _ _ = no (λ ())
apply _ _ ≟ var _ = no (λ ())
apply _ _ ≟ const _ _ = no (λ ())
lambda _ _ ≟ apply _ _ = no (λ ())
lambda _ _ ≟ case _ _ = no (λ ())
lambda _ _ ≟ rec _ _ = no (λ ())
lambda _ _ ≟ var _ = no (λ ())
lambda _ _ ≟ const _ _ = no (λ ())
case _ _ ≟ apply _ _ = no (λ ())
case _ _ ≟ lambda _ _ = no (λ ())
case _ _ ≟ rec _ _ = no (λ ())
case _ _ ≟ var _ = no (λ ())
case _ _ ≟ const _ _ = no (λ ())
rec _ _ ≟ apply _ _ = no (λ ())
rec _ _ ≟ lambda _ _ = no (λ ())
rec _ _ ≟ case _ _ = no (λ ())
rec _ _ ≟ var _ = no (λ ())
rec _ _ ≟ const _ _ = no (λ ())
var _ ≟ apply _ _ = no (λ ())
var _ ≟ lambda _ _ = no (λ ())
var _ ≟ case _ _ = no (λ ())
var _ ≟ rec _ _ = no (λ ())
var _ ≟ const _ _ = no (λ ())
const _ _ ≟ apply _ _ = no (λ ())
const _ _ ≟ lambda _ _ = no (λ ())
const _ _ ≟ case _ _ = no (λ ())
const _ _ ≟ rec _ _ = no (λ ())
const _ _ ≟ var _ = no (λ ())
_≟-B_ : Decidable-equality Br
branch c₁ xs₁ e₁ ≟-B branch c₂ xs₂ e₂ with c₁ C.≟ c₂
... | no c₁≢c₂ = no (c₁≢c₂ ∘ proj₁ ∘ cancel-branch)
... | yes c₁≡c₂ with List.Dec._≟_ V._≟_ xs₁ xs₂
... | no xs₁≢xs₂ = no (xs₁≢xs₂ ∘ proj₁ ∘ proj₂ ∘ cancel-branch)
... | yes xs₁≡xs₂ = ⊎-map (cong₂ (uncurry branch)
(cong₂ _,_ c₁≡c₂ xs₁≡xs₂))
(_∘ proj₂ ∘ proj₂ ∘ cancel-branch)
(e₁ ≟ e₂)
_≟-⋆_ : Decidable-equality (List Exp)
[] ≟-⋆ [] = yes refl
(e₁ ∷ es₁) ≟-⋆ (e₂ ∷ es₂) with e₁ ≟ e₂
... | no e₁≢e₂ = no (e₁≢e₂ ∘ List.cancel-∷-head)
... | yes e₁≡e₂ = ⊎-map (cong₂ _∷_ e₁≡e₂)
(_∘ List.cancel-∷-tail)
(es₁ ≟-⋆ es₂)
[] ≟-⋆ (_ ∷ _) = no (λ ())
(_ ∷ _) ≟-⋆ [] = no (λ ())
_≟-B⋆_ : Decidable-equality (List Br)
[] ≟-B⋆ [] = yes refl
(b₁ ∷ bs₁) ≟-B⋆ (b₂ ∷ bs₂) with b₁ ≟-B b₂
... | no b₁≢b₂ = no (b₁≢b₂ ∘ List.cancel-∷-head)
... | yes b₁≡b₂ = ⊎-map (cong₂ _∷_ b₁≡b₂)
(_∘ List.cancel-∷-tail)
(bs₁ ≟-B⋆ bs₂)
[] ≟-B⋆ (_ ∷ _) = no (λ ())
(_ ∷ _) ≟-B⋆ [] = no (λ ())
-- Exp is a set.
Exp-set : Is-set Exp
Exp-set = decidable⇒set _≟_
-- An alternative definition of the semantics.
data Lookup′ (c : Const) : List Br → List Var → Exp → Type where
here : ∀ {c′ xs xs′ e e′ bs} →
c ≡ c′ → xs ≡ xs′ → e ≡ e′ →
Lookup′ c (branch c′ xs′ e′ ∷ bs) xs e
there : ∀ {c′ xs′ e′ bs xs e} →
c ≢ c′ → Lookup′ c bs xs e →
Lookup′ c (branch c′ xs′ e′ ∷ bs) xs e
infixr 5 _∷_
infix 4 _[_←_]↦′_
data _[_←_]↦′_ (e : Exp) : List Var → List Exp → Exp → Type where
[] : ∀ {e′} → e ≡ e′ → e [ [] ← [] ]↦′ e′
_∷_ : ∀ {x xs e′ es′ e″ e‴} →
e‴ ≡ e″ [ x ← e′ ] → e [ xs ← es′ ]↦′ e″ →
e [ x ∷ xs ← e′ ∷ es′ ]↦′ e‴
infix 4 _⇓′_ _⇓⋆′_
mutual
data _⇓′_ : Exp → Exp → Type where
apply : ∀ {e₁ e₂ x e v₂ v} →
e₁ ⇓′ lambda x e → e₂ ⇓′ v₂ → e [ x ← v₂ ] ⇓′ v →
apply e₁ e₂ ⇓′ v
case : ∀ {e bs c es xs e′ e″ v} →
e ⇓′ const c es → Lookup′ c bs xs e′ →
e′ [ xs ← es ]↦′ e″ → e″ ⇓′ v →
case e bs ⇓′ v
rec : ∀ {x e v} → e [ x ← rec x e ] ⇓′ v → rec x e ⇓′ v
lambda : ∀ {x x′ e e′} →
x ≡ x′ → e ≡ e′ → lambda x e ⇓′ lambda x′ e′
const : ∀ {c c′ es vs} →
c ≡ c′ → es ⇓⋆′ vs → const c es ⇓′ const c′ vs
data _⇓⋆′_ : List Exp → List Exp → Type where
[] : [] ⇓⋆′ []
_∷_ : ∀ {e es v vs} → e ⇓′ v → es ⇓⋆′ vs → e ∷ es ⇓⋆′ v ∷ vs
-- The alternative definition is isomorphic to the other one.
Lookup↔Lookup′ : ∀ {c bs xs e} → Lookup c bs xs e ↔ Lookup′ c bs xs e
Lookup↔Lookup′ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to : ∀ {c bs xs e} → Lookup c bs xs e → Lookup′ c bs xs e
to here = here refl refl refl
to (there p₁ p₂) = there p₁ (to p₂)
from : ∀ {c bs xs e} → Lookup′ c bs xs e → Lookup c bs xs e
from (here refl refl refl) = here
from (there p₁ p₂) = there p₁ (from p₂)
from∘to : ∀ {c bs xs e} (p : Lookup c bs xs e) → from (to p) ≡ p
from∘to here = refl
from∘to (there p₁ p₂) rewrite from∘to p₂ = refl
to∘from : ∀ {c bs xs e} (p : Lookup′ c bs xs e) → to (from p) ≡ p
to∘from (here refl refl refl) = refl
to∘from (there p₁ p₂) rewrite to∘from p₂ = refl
↦↔↦′ : ∀ {e xs es e′} → e [ xs ← es ]↦ e′ ↔ e [ xs ← es ]↦′ e′
↦↔↦′ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to : ∀ {e xs es e′} → e [ xs ← es ]↦ e′ → e [ xs ← es ]↦′ e′
to [] = [] refl
to (∷ p) = refl ∷ to p
from : ∀ {e xs es e′} → e [ xs ← es ]↦′ e′ → e [ xs ← es ]↦ e′
from ([] refl) = []
from (refl ∷ p) = ∷ from p
from∘to : ∀ {e xs es e′} (p : e [ xs ← es ]↦ e′) → from (to p) ≡ p
from∘to [] = refl
from∘to (∷ p) rewrite from∘to p = refl
to∘from : ∀ {e xs es e′} (p : e [ xs ← es ]↦′ e′) → to (from p) ≡ p
to∘from ([] refl) = refl
to∘from (refl ∷ p) rewrite to∘from p = refl
⇓↔⇓′ : ∀ {e v} → e ⇓ v ↔ e ⇓′ v
⇓↔⇓′ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
mutual
to : ∀ {e v} → e ⇓ v → e ⇓′ v
to (apply p q r) = apply (to p) (to q) (to r)
to (case p q r s) = case (to p) (_↔_.to Lookup↔Lookup′ q)
(_↔_.to ↦↔↦′ r) (to s)
to (rec p) = rec (to p)
to lambda = lambda refl refl
to (const ps) = const refl (to⋆ ps)
to⋆ : ∀ {e v} → e ⇓⋆ v → e ⇓⋆′ v
to⋆ [] = []
to⋆ (p ∷ ps) = to p ∷ to⋆ ps
mutual
from : ∀ {e v} → e ⇓′ v → e ⇓ v
from (apply p q r) = apply (from p) (from q) (from r)
from (case p q r s) = case (from p) (_↔_.from Lookup↔Lookup′ q)
(_↔_.from ↦↔↦′ r) (from s)
from (rec p) = rec (from p)
from (lambda refl refl) = lambda
from (const refl ps) = const (from⋆ ps)
from⋆ : ∀ {e v} → e ⇓⋆′ v → e ⇓⋆ v
from⋆ [] = []
from⋆ (p ∷ ps) = from p ∷ from⋆ ps
mutual
from∘to : ∀ {e v} (p : e ⇓ v) → from (to p) ≡ p
from∘to (apply p q r) rewrite from∘to p | from∘to q | from∘to r
= refl
from∘to (case p q r s) rewrite from∘to p
| _↔_.left-inverse-of Lookup↔Lookup′ q
| _↔_.left-inverse-of ↦↔↦′ r
| from∘to s = refl
from∘to (rec p) rewrite from∘to p = refl
from∘to lambda = refl
from∘to (const ps) rewrite from⋆∘to⋆ ps = refl
from⋆∘to⋆ : ∀ {e v} (ps : e ⇓⋆ v) → from⋆ (to⋆ ps) ≡ ps
from⋆∘to⋆ [] = refl
from⋆∘to⋆ (p ∷ ps) rewrite from∘to p | from⋆∘to⋆ ps = refl
mutual
to∘from : ∀ {e v} (p : e ⇓′ v) → to (from p) ≡ p
to∘from (apply p q r) rewrite to∘from p | to∘from q | to∘from r
= refl
to∘from (case p q r s) rewrite to∘from p
| _↔_.right-inverse-of
Lookup↔Lookup′ q
| _↔_.right-inverse-of ↦↔↦′ r
| to∘from s = refl
to∘from (rec p) rewrite to∘from p = refl
to∘from (lambda refl refl) = refl
to∘from (const refl ps) rewrite to⋆∘from⋆ ps = refl
to⋆∘from⋆ : ∀ {e v} (ps : e ⇓⋆′ v) → to⋆ (from⋆ ps) ≡ ps
to⋆∘from⋆ [] = refl
to⋆∘from⋆ (p ∷ ps) rewrite to∘from p | to⋆∘from⋆ ps = refl
-- The alternative semantics is deterministic.
Lookup′-deterministic :
∀ {c bs xs₁ xs₂ e₁ e₂} →
Lookup′ c bs xs₁ e₁ → Lookup′ c bs xs₂ e₂ →
xs₁ ≡ xs₂ × e₁ ≡ e₂
Lookup′-deterministic p q =
Lookup-deterministic
(_↔_.from Lookup↔Lookup′ p) (_↔_.from Lookup↔Lookup′ q) refl
↦′-deterministic :
∀ {e xs es e₁ e₂} →
e [ xs ← es ]↦′ e₁ → e [ xs ← es ]↦′ e₂ → e₁ ≡ e₂
↦′-deterministic p q =
↦-deterministic (_↔_.from ↦↔↦′ p) (_↔_.from ↦↔↦′ q)
⇓′-deterministic : ∀ {e v₁ v₂} → e ⇓′ v₁ → e ⇓′ v₂ → v₁ ≡ v₂
⇓′-deterministic p q =
⇓-deterministic (_↔_.from ⇓↔⇓′ p) (_↔_.from ⇓↔⇓′ q)
-- The alternative semantics is propositional.
Lookup′-propositional :
∀ {c bs xs e} → Is-proposition (Lookup′ c bs xs e)
Lookup′-propositional (here p₁ p₂ p₃) (here q₁ q₂ q₃)
rewrite C.Name-set p₁ q₁
| decidable⇒set (List.Dec._≟_ V._≟_) p₂ q₂
| Exp-set p₃ q₃
= refl
Lookup′-propositional (there p₁ p₂) (there q₁ q₂)
rewrite ¬-propositional ext p₁ q₁
| Lookup′-propositional p₂ q₂
= refl
Lookup′-propositional (here c≡c′ _ _) (there c≢c′ _) =
⊥-elim (c≢c′ c≡c′)
Lookup′-propositional (there c≢c′ _) (here c≡c′ _ _) =
⊥-elim (c≢c′ c≡c′)
↦′-propositional :
∀ {e xs es e′} → Is-proposition (e [ xs ← es ]↦′ e′)
↦′-propositional ([] p) ([] q) rewrite Exp-set p q = refl
↦′-propositional (p₁ ∷ p₂) (q₁ ∷ q₂)
with ↦′-deterministic p₂ q₂
... | refl rewrite Exp-set p₁ q₁
| ↦′-propositional p₂ q₂
= refl
mutual
⇓′-propositional : ∀ {e v} → Is-proposition (e ⇓′ v)
⇓′-propositional (apply p₁ p₂ p₃) (apply q₁ q₂ q₃)
with ⇓′-deterministic p₁ q₁
... | refl rewrite ⇓′-propositional p₁ q₁
with ⇓′-deterministic p₂ q₂
... | refl rewrite ⇓′-propositional p₂ q₂
| ⇓′-propositional p₃ q₃
= refl
⇓′-propositional (case p₁ p₂ p₃ p₄) (case q₁ q₂ q₃ q₄)
with ⇓′-deterministic p₁ q₁
... | refl rewrite ⇓′-propositional p₁ q₁
with Lookup′-deterministic p₂ q₂
... | refl , refl rewrite Lookup′-propositional p₂ q₂
with ↦′-deterministic p₃ q₃
... | refl rewrite ↦′-propositional p₃ q₃
| ⇓′-propositional p₄ q₄
= refl
⇓′-propositional (rec p) (rec q)
rewrite ⇓′-propositional p q
= refl
⇓′-propositional (lambda p₁ p₂) (lambda q₁ q₂)
rewrite V.Name-set p₁ q₁
| Exp-set p₂ q₂
= refl
⇓′-propositional (const p ps) (const q qs)
rewrite C.Name-set p q
| ⇓⋆′-propositional ps qs
= refl
⇓⋆′-propositional : ∀ {es vs} → Is-proposition (es ⇓⋆′ vs)
⇓⋆′-propositional [] [] = refl
⇓⋆′-propositional (p ∷ ps) (q ∷ qs)
rewrite ⇓′-propositional p q
| ⇓⋆′-propositional ps qs
= refl
-- The semantics is propositional.
⇓-propositional : ∀ {e v} → Is-proposition (e ⇓ v)
⇓-propositional {e} {v} = $⟨ ⇓′-propositional ⟩
Is-proposition (e ⇓′ v) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse ⇓↔⇓′) 1 ⟩□
Is-proposition (e ⇓ v) □
|
{
"alphanum_fraction": 0.4770158252,
"avg_line_length": 33.3417085427,
"ext": "agda",
"hexsha": "eb34fac38f6015ad37c8a3becdc3f5eeca5972fd",
"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": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Propositional.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Propositional.agda",
"max_line_length": 94,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 5502,
"size": 13270
}
|
{-# OPTIONS --safe #-}
module Cubical.HITs.Sn.Properties where
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Path
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1 renaming (_·_ to _*_)
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation
-- open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Join
open import Cubical.Data.Bool
private
variable
ℓ : Level
IsoSucSphereSusp : (n : ℕ) → Iso (S₊ (suc n)) (Susp (S₊ n))
IsoSucSphereSusp zero = S¹IsoSuspBool
IsoSucSphereSusp (suc n) = idIso
-- Elimination principles for spheres
sphereElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isOfHLevel (suc n) (A x))
→ A (ptSn (suc n))
→ (x : S₊ (suc n)) → A x
sphereElim zero hlev pt = toPropElim hlev pt
sphereElim (suc n) hlev pt north = pt
sphereElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt
sphereElim (suc n) {A = A} hlev pt (merid a i) =
sphereElim n {A = λ a → PathP (λ i → A (merid a i)) pt (subst A (merid (ptSn (suc n))) pt)}
(λ a → isOfHLevelPathP' (suc n) (hlev south) _ _)
(λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∧ j))) (~ i) pt)
a i
sphereElim2 : ∀ {ℓ} (n : ℕ) {A : (S₊ (suc n)) → (S₊ (suc n)) → Type ℓ}
→ ((x y : S₊ (suc n)) → isOfHLevel (suc n) (A x y))
→ A (ptSn (suc n)) (ptSn (suc n))
→ (x y : S₊ (suc n)) → A x y
sphereElim2 n hlev pt = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → hlev _ _)
(sphereElim n (hlev _ ) pt)
private
compPath-lem : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : z ≡ y)
→ PathP (λ i → (p ∙ sym q) i ≡ y) p q
compPath-lem {y = y} p q i j =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → q (~ k ∨ j)
; (j = i1) → y })
(p (j ∨ i))
sphereToPropElim : (n : ℕ) {A : (S₊ (suc n)) → Type ℓ} → ((x : S₊ (suc n)) → isProp (A x))
→ A (ptSn (suc n))
→ (x : S₊ (suc n)) → A x
sphereToPropElim zero = toPropElim
sphereToPropElim (suc n) hlev pt north = pt
sphereToPropElim (suc n) {A = A} hlev pt south = subst A (merid (ptSn (suc n))) pt
sphereToPropElim (suc n) {A = A} hlev pt (merid a i) =
isProp→PathP {B = λ i → A (merid a i)} (λ _ → hlev _) pt (subst A (merid (ptSn (suc n))) pt) i
-- Elimination rule for fibrations (x : Sⁿ) → (y : Sᵐ) → A x y of h-Level (n + m).
-- The following principle is just the special case of the "Wedge Connectivity Lemma"
-- for spheres (See Cubical.Homotopy.WedgeConnectivity or chapter 8.6 in the HoTT book).
-- We prove it directly here for three reasons:
-- (i) it should perform better
-- (ii) we get a slightly stronger statement for spheres: one of the homotopies will, by design, be refl
-- (iii) the fact that the two homotopies only differ by (composition with) the homotopy leftFunction(base) ≡ rightFunction(base)
-- is close to trivial
wedgeconFun : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : S₊ (suc n)) (y : S₊ (suc m)) → A x y
wedgeconLeft : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : _) → wedgeconFun n m hLev f g hom (ptSn (suc n)) x ≡ f x
wedgeconRight : (n m : ℕ) {A : (S₊ (suc n)) → (S₊ (suc m)) → Type ℓ}
→ (hLev : ((x : S₊ (suc n)) (y : S₊ (suc m)) → isOfHLevel ((suc n) + (suc m)) (A x y)))
→ (f : (x : _) → A (ptSn (suc n)) x)
→ (g : (x : _) → A x (ptSn (suc m)))
→ (hom : g (ptSn (suc n)) ≡ f (ptSn (suc m)))
→ (x : _) → wedgeconFun n m hLev f g hom x (ptSn (suc m)) ≡ g x
wedgeconFun zero zero {A = A} hlev f g hom = F
where
helper : SquareP (λ i j → A (loop i) (loop j)) (cong f loop) (cong f loop)
(λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i)))
λ i → hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
helper = toPathP (isOfHLevelPathP' 1 (hlev _ _) _ _ _ _)
F : (x y : S¹) → A x y
F base y = f y
F (loop i) base = hcomp (λ k → λ { (i = i0) → hom k
; (i = i1) → hom k })
(g (loop i))
F (loop i) (loop j) = helper i j
wedgeconFun zero (suc m) {A = A} hlev f g hom = F₀
module _ where
transpLemma₀ : (x : S₊ (suc m)) → transport (λ i₁ → A base (merid x i₁)) (g base) ≡ f south
transpLemma₀ x = cong (transport (λ i₁ → A base (merid x i₁)))
hom
∙ (λ i → transp (λ j → A base (merid x (i ∨ j))) i
(f (merid x i)))
pathOverMerid₀ : (x : S₊ (suc m)) → PathP (λ i₁ → A base (merid x i₁))
(g base)
(transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base))
pathOverMerid₀ x i = hcomp (λ k → λ { (i = i0) → g base
; (i = i1) → (transpLemma₀ x ∙ sym (transpLemma₀ (ptSn (suc m)))) k})
(transp (λ i₁ → A base (merid x (i₁ ∧ i))) (~ i)
(g base))
pathOverMeridId₀ : pathOverMerid₀ (ptSn (suc m)) ≡ λ i → transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)
pathOverMeridId₀ =
(λ j i → hcomp (λ k → λ {(i = i0) → g base
; (i = i1) → rCancel (transpLemma₀ (ptSn (suc m))) j k})
(transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base)))
∙ λ j i → hfill (λ k → λ { (i = i0) → g base
; (i = i1) → transport (λ i₁ → A base (merid (ptSn (suc m)) i₁))
(g base)})
(inS (transp (λ i₁ → A base (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g base))) (~ j)
indStep₀ : (x : _) (a : _) → PathP (λ i → A x (merid a i))
(g x)
(subst (λ y → A x y) (merid (ptSn (suc m)))
(g x))
indStep₀ = wedgeconFun zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _)
pathOverMerid₀
(λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g a))
(sym pathOverMeridId₀)
F₀ : (x : S¹) (y : Susp (S₊ (suc m))) → A x y
F₀ x north = g x
F₀ x south = subst (λ y → A x y) (merid (ptSn (suc m))) (g x)
F₀ x (merid a i) = indStep₀ x a i
wedgeconFun (suc n) m {A = A} hlev f g hom = F₁
module _ where
transpLemma₁ : (x : S₊ (suc n)) → transport (λ i₁ → A (merid x i₁) (ptSn (suc m))) (f (ptSn (suc m))) ≡ g south
transpLemma₁ x = cong (transport (λ i₁ → A (merid x i₁) (ptSn (suc m))))
(sym hom)
∙ (λ i → transp (λ j → A (merid x (i ∨ j)) (ptSn (suc m))) i
(g (merid x i)))
pathOverMerid₁ : (x : S₊ (suc n)) → PathP (λ i₁ → A (merid x i₁) (ptSn (suc m)))
(f (ptSn (suc m)))
(transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))))
pathOverMerid₁ x i = hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → (transpLemma₁ x ∙ sym (transpLemma₁ (ptSn (suc n)))) k })
(transp (λ i₁ → A (merid x (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))
pathOverMeridId₁ : pathOverMerid₁ (ptSn (suc n)) ≡ λ i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
pathOverMeridId₁ =
(λ j i → hcomp (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → rCancel (transpLemma₁ (ptSn (suc n))) j k })
(transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))))
∙ λ j i → hfill (λ k → λ { (i = i0) → f (ptSn (suc m))
; (i = i1) → transport (λ i₁ → A (merid (ptSn (suc n)) i₁) (ptSn (suc m)))
(f (ptSn (suc m))) })
(inS (transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m))))) (~ j)
indStep₁ : (a : _) (y : _) → PathP (λ i → A (merid a i) y)
(f y)
(subst (λ x → A x y) (merid (ptSn (suc n)))
(f y))
indStep₁ = wedgeconFun n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _)
(λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i)
(f a))
pathOverMerid₁
pathOverMeridId₁
F₁ : (x : Susp (S₊ (suc n))) (y : S₊ (suc m)) → A x y
F₁ north y = f y
F₁ south y = subst (λ x → A x y) (merid (ptSn (suc n))) (f y)
F₁ (merid a i) y = indStep₁ a y i
wedgeconRight zero zero {A = A} hlev f g hom = right
where
right : (x : S¹) → _
right base = sym hom
right (loop i) j = hcomp (λ k → λ { (i = i0) → hom (~ j ∧ k)
; (i = i1) → hom (~ j ∧ k)
; (j = i1) → g (loop i) })
(g (loop i))
wedgeconRight zero (suc m) {A = A} hlev f g hom x = refl
wedgeconRight (suc n) m {A = A} hlev f g hom = right
where
lem : (x : _) → indStep₁ n m hlev f g hom x (ptSn (suc m)) ≡ _
lem = wedgeconRight n m (λ _ _ → isOfHLevelPathP' (suc (n + suc m)) (hlev _ _) _ _)
(λ a i → transp (λ i₁ → A (merid (ptSn (suc n)) (i₁ ∧ i)) a) (~ i)
(f a))
(pathOverMerid₁ n m hlev f g hom)
(pathOverMeridId₁ n m hlev f g hom)
right : (x : Susp (S₊ (suc n))) → _ ≡ g x
right north = sym hom
right south = cong (subst (λ x → A x (ptSn (suc m)))
(merid (ptSn (suc n))))
(sym hom)
∙ λ i → transp (λ j → A (merid (ptSn (suc n)) (i ∨ j)) (ptSn (suc m))) i
(g (merid (ptSn (suc n)) i))
right (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → transpLemma₁ n m hlev f g hom (ptSn (suc n)) j
; (j = i0) → lem a (~ k) i
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (i = i1) → compPath-lem (transpLemma₁ n m hlev f g hom a) (transpLemma₁ n m hlev f g hom (ptSn (suc n))) k j
; (j = i1) → g (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom (~ j)
; (j = i0) → transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(f (ptSn (suc m)))
; (j = i1) → transp (λ j → A (merid a (i ∧ (j ∨ k))) (ptSn (suc m))) (k ∨ ~ i)
(g (merid a (i ∧ k))) })
(transp (λ i₂ → A (merid a (i₂ ∧ i)) (ptSn (suc m))) (~ i)
(hom (~ j)))))
wedgeconLeft zero zero {A = A} hlev f g hom x = refl
wedgeconLeft zero (suc m) {A = A} hlev f g hom = help
where
left₁ : (x : _) → indStep₀ m hlev f g hom base x ≡ _
left₁ = wedgeconLeft zero m (λ _ _ → isOfHLevelPathP' (2 + m) (hlev _ _) _ _)
(pathOverMerid₀ m hlev f g hom)
(λ a i → transp (λ i₁ → A a (merid (ptSn (suc m)) (i₁ ∧ i))) (~ i)
(g a))
(sym (pathOverMeridId₀ m hlev f g hom))
help : (x : S₊ (suc (suc m))) → _
help north = hom
help south = cong (subst (A base) (merid (ptSn (suc m)))) hom
∙ λ i → transp (λ j → A base (merid (ptSn (suc m)) (i ∨ j))) i
(f (merid (ptSn (suc m)) i))
help (merid a i) j =
hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → transpLemma₀ m hlev f g hom (ptSn (suc m)) j
; (j = i0) → left₁ a (~ k) i
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (i = i1) → compPath-lem (transpLemma₀ m hlev f g hom a)
(transpLemma₀ m hlev f g hom (ptSn (suc m))) k j
; (j = i1) → f (merid a i)})
(hcomp (λ k → λ { (i = i0) → hom j
; (j = i0) → transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(g base)
; (j = i1) → transp (λ j → A base (merid a (i ∧ (j ∨ k)))) (k ∨ ~ i)
(f (merid a (i ∧ k)))})
(transp (λ i₂ → A base (merid a (i₂ ∧ i))) (~ i)
(hom j))))
wedgeconLeft (suc n) m {A = A} hlev f g hom _ = refl
---------- Connectedness -----------
sphereConnected : (n : HLevel) → isConnected (suc n) (S₊ n)
sphereConnected n = ∣ ptSn n ∣ , elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a → sym (spoke ∣_∣ (ptSn n)) ∙ spoke ∣_∣ a)
-- The fact that path spaces of Sn are connected can be proved directly for Sⁿ.
-- (Unfortunately, this does not work for higher paths)
pathIdTruncSⁿ : (n : ℕ) (x y : S₊ (suc n))
→ Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣
→ hLevelTrunc (suc n) (x ≡ y)
pathIdTruncSⁿ n = sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n))
(sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelTrunc (suc n))
λ _ → ∣ refl ∣)
pathIdTruncSⁿ⁻ : (n : ℕ) (x y : S₊ (suc n))
→ hLevelTrunc (suc n) (x ≡ y)
→ Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣
pathIdTruncSⁿ⁻ n x y = rec (isOfHLevelTrunc (2 + n) _ _)
(J (λ y _ → Path (hLevelTrunc (2 + n) (S₊ (suc n))) ∣ x ∣ ∣ y ∣) refl)
pathIdTruncSⁿretract : (n : ℕ) (x y : S₊ (suc n)) → (p : hLevelTrunc (suc n) (x ≡ y)) → pathIdTruncSⁿ n x y (pathIdTruncSⁿ⁻ n x y p) ≡ p
pathIdTruncSⁿretract n =
sphereElim n (λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelΠ (suc n) λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ y → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(J (λ y p → pathIdTruncSⁿ n (ptSn (suc n)) y (pathIdTruncSⁿ⁻ n (ptSn (suc n)) y ∣ p ∣) ≡ ∣ p ∣)
(cong (pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n))) (transportRefl refl) ∙ pm-help n))
where
pm-help : (n : ℕ) → pathIdTruncSⁿ n (ptSn (suc n)) (ptSn (suc n)) refl ≡ ∣ refl ∣
pm-help zero = refl
pm-help (suc n) = refl
isConnectedPathSⁿ : (n : ℕ) (x y : S₊ (suc n)) → isConnected (suc n) (x ≡ y)
isConnectedPathSⁿ n x y =
isContrRetract
(pathIdTruncSⁿ⁻ n x y)
(pathIdTruncSⁿ n x y)
(pathIdTruncSⁿretract n x y)
((isContr→isProp (sphereConnected (suc n)) ∣ x ∣ ∣ y ∣)
, isProp→isSet (isContr→isProp (sphereConnected (suc n))) _ _ _)
-- Equivalence Sⁿ*Sᵐ≃Sⁿ⁺ᵐ⁺¹
IsoSphereJoin : (n m : ℕ)
→ Iso (join (S₊ n) (S₊ m)) (S₊ (suc (n + m)))
IsoSphereJoin zero m =
compIso join-comm
(compIso (invIso Susp-iso-joinBool)
(invIso (IsoSucSphereSusp m)))
IsoSphereJoin (suc n) m =
compIso (Iso→joinIso
(subst (λ x → Iso (S₊ (suc x)) (join (S₊ n) Bool))
(+-comm n 0) (invIso (IsoSphereJoin n 0)))
idIso)
(compIso (equivToIso joinAssocDirect)
(compIso (Iso→joinIso idIso
(compIso join-comm
(compIso (invIso Susp-iso-joinBool)
(invIso (IsoSucSphereSusp m)))))
(compIso
(IsoSphereJoin n (suc m))
(pathToIso λ i → S₊ (suc (+-suc n m i))))))
-- Some lemmas on the H
rUnitS¹ : (x : S¹) → x * base ≡ x
rUnitS¹ base = refl
rUnitS¹ (loop i₁) = refl
commS¹ : (a x : S¹) → a * x ≡ x * a
commS¹ = wedgeconFun _ _ (λ _ _ → isGroupoidS¹ _ _)
(sym ∘ rUnitS¹)
rUnitS¹
refl
SuspS¹-hom : (a x : S¹)
→ Path (Path (hLevelTrunc 4 (S₊ 2)) _ _)
(cong ∣_∣ₕ (merid (a * x) ∙ sym (merid base)))
(cong ∣_∣ₕ (merid a ∙ sym (merid base))
∙ (cong ∣_∣ₕ (merid x ∙ sym (merid base))))
SuspS¹-hom = wedgeconFun _ _ (λ _ _ → isOfHLevelTrunc 4 _ _ _ _)
(λ x → lUnit _
∙ cong (_∙ cong ∣_∣ₕ (merid x ∙ sym (merid base)))
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base)))))
(λ x → (λ i → cong ∣_∣ₕ (merid (rUnitS¹ x i) ∙ sym (merid base)))
∙∙ rUnit _
∙∙ cong (cong ∣_∣ₕ (merid x ∙ sym (merid base)) ∙_)
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base)))))
(sym (l (cong ∣_∣ₕ (merid base ∙ sym (merid base)))
(cong (cong ∣_∣ₕ) (sym (rCancel (merid base))))))
where
l : ∀ {ℓ} {A : Type ℓ} {x : A} (p : x ≡ x) (P : refl ≡ p)
→ lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P
l p = J (λ p P → lUnit p ∙ cong (_∙ p) P ≡ rUnit p ∙ cong (p ∙_) P) refl
rCancelS¹ : (x : S¹) → ptSn 1 ≡ x * (invLooper x)
rCancelS¹ base = refl
rCancelS¹ (loop i) j =
hcomp (λ r → λ {(i = i0) → base ; (i = i1) → base ; (j = i0) → base})
base
SuspS¹-inv : (x : S¹) → Path (Path (hLevelTrunc 4 (S₊ 2)) _ _)
(cong ∣_∣ₕ (merid (invLooper x) ∙ sym (merid base)))
(cong ∣_∣ₕ (sym (merid x ∙ sym (merid base))))
SuspS¹-inv x = (lUnit _
∙∙ cong (_∙ cong ∣_∣ₕ (merid (invLooper x) ∙ sym (merid base)))
(sym (lCancel (cong ∣_∣ₕ (merid x ∙ sym (merid base)))))
∙∙ sym (assoc _ _ _))
∙∙ cong (sym (cong ∣_∣ₕ (merid x ∙ sym (merid base))) ∙_) lem
∙∙ (assoc _ _ _
∙∙ cong (_∙ (cong ∣_∣ₕ (sym (merid x ∙ sym (merid base)))))
(lCancel (cong ∣_∣ₕ (merid x ∙ sym (merid base))))
∙∙ sym (lUnit _))
where
lem : cong ∣_∣ₕ (merid x ∙ sym (merid base))
∙ cong ∣_∣ₕ (merid (invLooper x) ∙ sym (merid base))
≡ cong ∣_∣ₕ (merid x ∙ sym (merid base))
∙ cong ∣_∣ₕ (sym (merid x ∙ sym (merid base)))
lem = sym (SuspS¹-hom x (invLooper x))
∙ ((λ i → cong ∣_∣ₕ (merid (rCancelS¹ x (~ i)) ∙ sym (merid base)))
∙ cong (cong ∣_∣ₕ) (rCancel (merid base))) ∙ sym (rCancel _)
|
{
"alphanum_fraction": 0.4402318043,
"avg_line_length": 51.2896725441,
"ext": "agda",
"hexsha": "663f3e90203276bd6053ab7be30fd54aa9c56cf4",
"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": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ecavallo/cubical",
"max_forks_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"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": "ecavallo/cubical",
"max_issues_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_line_length": 138,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ecavallo/cubical",
"max_stars_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7427,
"size": 20362
}
|
open import Data.Product using ( ∃ ; _×_ ; _,_ ; proj₁ ; proj₂ )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.TBox.Interp using
( Interp ; Δ ; _⊨_≈_ ; con ; rol ; ≈-refl ; ≈-sym ; ≈-trans ; con-≈ ; rol-≈ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.Util using ( id ; _∘_ )
module Web.Semantic.DL.TBox.Interp.Morphism {Σ : Signature} where
infix 2 _≲_ _≃_
-- I ≲ J whenever J respects all the properties of I
data _≲_ (I J : Interp Σ) : Set where
morph :
(f : Δ I → Δ J) →
(≲-resp-≈ : ∀ {x y} → (I ⊨ x ≈ y) → (J ⊨ f x ≈ f y)) →
(≲-resp-con : ∀ {c x} → (x ∈ con I c) → (f x ∈ con J c)) →
(≲-resp-rol : ∀ {r x y} → ((x , y) ∈ rol I r) → ((f x , f y) ∈ rol J r)) →
(I ≲ J)
≲-image : ∀ {I J} → (I ≲ J) → Δ I → Δ J
≲-image (morph f ≲-resp-≈ ≲-resp-con ≲-resp-rol) = f
≲-image² : ∀ {I J} → (I ≲ J) → (Δ I × Δ I) → (Δ J × Δ J)
≲-image² I≲J (x , y) = (≲-image I≲J x , ≲-image I≲J y)
≲-resp-≈ : ∀ {I J} → (I≲J : I ≲ J) → ∀ {x y} → (I ⊨ x ≈ y) →
(J ⊨ ≲-image I≲J x ≈ ≲-image I≲J y)
≲-resp-≈ (morph f ≲-resp-≈ ≲-resp-con ≲-resp-rol) = ≲-resp-≈
≲-resp-con : ∀ {I J} → (I≲J : I ≲ J) → ∀ {c x} → (x ∈ con I c) →
(≲-image I≲J x ∈ con J c)
≲-resp-con (morph f ≲-resp-≈ ≲-resp-con ≲-resp-rol) = ≲-resp-con
≲-resp-rol : ∀ {I J} → (I≲J : I ≲ J) → ∀ {r xy} → (xy ∈ rol I r) →
(≲-image² I≲J xy ∈ rol J r)
≲-resp-rol (morph f ≲-resp-≈ ≲-resp-con ≲-resp-rol) {r} {x , y} = ≲-resp-rol
≲-refl : ∀ I → (I ≲ I)
≲-refl I = morph id id id id
≲-trans : ∀ {I J K} → (I ≲ J) → (J ≲ K) → (I ≲ K)
≲-trans I≲J J≲K = morph
(≲-image J≲K ∘ ≲-image I≲J)
(≲-resp-≈ J≲K ∘ ≲-resp-≈ I≲J)
(≲-resp-con J≲K ∘ ≲-resp-con I≲J)
(≲-resp-rol J≲K ∘ ≲-resp-rol I≲J)
-- I ≃ J whenever there is an isomprhism between I and J
data _≃_ (I J : Interp Σ) : Set where
iso :
(≃-impl-≲ : I ≲ J) →
(≃-impl-≳ : J ≲ I) →
(≃-iso : ∀ x → I ⊨ (≲-image ≃-impl-≳ (≲-image ≃-impl-≲ x)) ≈ x) →
(≃-iso⁻¹ : ∀ x → J ⊨ (≲-image ≃-impl-≲ (≲-image ≃-impl-≳ x)) ≈ x) →
(I ≃ J)
≃-impl-≲ : ∀ {I J} → (I ≃ J) → (I ≲ J)
≃-impl-≲ (iso ≃-impl-≲ ≃-impl-≳ ≃-iso ≃-iso⁻¹) = ≃-impl-≲
≃-impl-≳ : ∀ {I J} → (I ≃ J) → (J ≲ I)
≃-impl-≳ (iso ≃-impl-≲ ≃-impl-≳ ≃-iso ≃-iso⁻¹) = ≃-impl-≳
≃-image : ∀ {I J} → (I ≃ J) → Δ I → Δ J
≃-image I≃J = ≲-image (≃-impl-≲ I≃J)
≃-image² : ∀ {I J} → (I ≃ J) → (Δ I × Δ I) → (Δ J × Δ J)
≃-image² I≃J = ≲-image² (≃-impl-≲ I≃J)
≃-image⁻¹ : ∀ {I J} → (I ≃ J) → Δ J → Δ I
≃-image⁻¹ I≃J = ≲-image (≃-impl-≳ I≃J)
≃-image²⁻¹ : ∀ {I J} → (I ≃ J) → (Δ J × Δ J) → (Δ I × Δ I)
≃-image²⁻¹ I≃J = ≲-image² (≃-impl-≳ I≃J)
≃-iso : ∀ {I J} → (I≃J : I ≃ J) → ∀ x → (I ⊨ (≃-image⁻¹ I≃J (≃-image I≃J x)) ≈ x)
≃-iso (iso ≃-impl-≲ ≃-impl-≳ ≃-iso ≃-iso⁻¹) = ≃-iso
≃-iso⁻¹ : ∀ {I J} → (I≃J : I ≃ J) → ∀ x → (J ⊨ (≃-image I≃J (≃-image⁻¹ I≃J x)) ≈ x)
≃-iso⁻¹ (iso ≃-impl-≲ ≃-impl-≳ ≃-iso ≃-iso⁻¹) = ≃-iso⁻¹
≃-resp-≈ : ∀ {I J} → (I≃J : I ≃ J) → ∀ {x y} →
(I ⊨ x ≈ y) → (J ⊨ ≃-image I≃J x ≈ ≃-image I≃J y)
≃-resp-≈ I≃J = ≲-resp-≈ (≃-impl-≲ I≃J)
≃-refl-≈ : ∀ {I J} → (I≃J : I ≃ J) → ∀ {x y} →
(I ⊨ ≃-image⁻¹ I≃J x ≈ ≃-image⁻¹ I≃J y) → (J ⊨ x ≈ y)
≃-refl-≈ {I} {J} I≃J {x} {y} x≈y =
≈-trans J (≈-sym J (≃-iso⁻¹ I≃J x))
(≈-trans J (≃-resp-≈ I≃J x≈y) (≃-iso⁻¹ I≃J y))
≃-refl : ∀ I → (I ≃ I)
≃-refl I = iso (≲-refl I) (≲-refl I) (λ x → ≈-refl I) (λ x → ≈-refl I)
≃-sym : ∀ {I J} → (I ≃ J) → (J ≃ I)
≃-sym I≃J = iso (≃-impl-≳ I≃J) (≃-impl-≲ I≃J) (≃-iso⁻¹ I≃J) (≃-iso I≃J)
≃-trans : ∀ {I J K} → (I ≃ J) → (J ≃ K) → (I ≃ K)
≃-trans {I} {J} {K} I≃J J≃K = iso
(≲-trans (≃-impl-≲ I≃J) (≃-impl-≲ J≃K))
(≲-trans (≃-impl-≳ J≃K) (≃-impl-≳ I≃J))
(λ x → ≈-trans I (≲-resp-≈ (≃-impl-≳ I≃J) (≃-iso J≃K (≃-image I≃J x)))
(≃-iso I≃J x))
(λ x → ≈-trans K (≲-resp-≈ (≃-impl-≲ J≃K) (≃-iso⁻¹ I≃J (≃-image⁻¹ J≃K x)))
(≃-iso⁻¹ J≃K x))
|
{
"alphanum_fraction": 0.4307853953,
"avg_line_length": 35.25,
"ext": "agda",
"hexsha": "fbb4ad2c41be89a23b8031ea354ae56d5876ee56",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/TBox/Interp/Morphism.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/TBox/Interp/Morphism.agda",
"max_line_length": 83,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/TBox/Interp/Morphism.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 2348,
"size": 3807
}
|
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Data.Empty where
open import Light.Library.Data.Empty using (Library ; Dependencies)
open import Light.Level using (0ℓ)
open import Light.Variable.Sets
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record { Implementation }
where
module Implementation where
data Empty : Set where
eliminate : Empty → 𝕒
eliminate ()
|
{
"alphanum_fraction": 0.6972972973,
"avg_line_length": 27.75,
"ext": "agda",
"hexsha": "b3b4c80d61e5eb76097b14924f32f536937c8840",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Implementation/Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Implementation/Data/Empty.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Implementation/Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 103,
"size": 555
}
|
-- Andreas, 2018-06-19, issue #3130
-- Do not treat .(p) as projection pattern, but always as dot pattern.
record R : Set₁ where
field f : Set
open R
-- Shouldn't pass.
mkR : (A : Set) → R
mkR A .(f) = A
|
{
"alphanum_fraction": 0.6267942584,
"avg_line_length": 17.4166666667,
"ext": "agda",
"hexsha": "a51d6f70ce77bfc5497043a3ec5642b79bffbcf2",
"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/Issue3130ParenthesizedProjectionPattern.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/Issue3130ParenthesizedProjectionPattern.agda",
"max_line_length": 70,
"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/Issue3130ParenthesizedProjectionPattern.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": 77,
"size": 209
}
|
-- Alternative proof of LLPO => MP∨
{-# OPTIONS --without-K --safe #-}
module Constructive.Axiom.Properties.Alternative where
-- agda-stdlib
open import Level renaming (suc to lsuc; zero to lzero)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤; tt)
open import Data.Bool using (Bool; true; false; not)
open import Data.Sum as Sum
open import Data.Product as Prod
open import Data.Nat as ℕ using (ℕ; zero; suc; _≤_; s≤s; z≤n; _≤?_)
import Data.Nat.Properties as ℕₚ
import Data.Nat.Induction as ℕInd
open import Function.Base
import Induction.WellFounded as Ind
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Relation.Binary
using (tri≈; tri<; tri>; Rel; Trichotomous)
open import Relation.Binary.PropositionalEquality
-- agda-misc
open import Constructive.Axiom
open import Constructive.Combinators
open import Constructive.Common
-- LLPO => MP∨
record HasPropertiesForLLPO⇒MP∨
{a} r p (A : Set a) : Set (a ⊔ lsuc r ⊔ lsuc p)
where
field
_<_ : Rel A r
<-cmp : Trichotomous _≡_ _<_
<-all-dec : {P : A → Set p} → DecU P → DecU (λ n → ∀ i → i < n → P i)
<-wf : Ind.WellFounded _<_
llpo⇒mp∨ : ∀ {r p a} {A : Set a} →
HasPropertiesForLLPO⇒MP∨ r p A → LLPO A (p ⊔ a ⊔ r) → MP∨ A p
llpo⇒mp∨ {r} {p} {a} {A = A} has llpo {P = P} {Q} P? Q? ¬¬[∃x→Px⊎Qx] =
Sum.swap ¬¬∃Q⊎¬¬∃P
where
open HasPropertiesForLLPO⇒MP∨ has
-- ex. R 5
-- n : 0 1 2 3 4 5 6 7 8
-- P : 0 0 0 0 0 1 ? ? ?
-- Q : 0 0 0 0 0 0 ? ? ?
R S : A → Set (r ⊔ p ⊔ a)
R n = (∀ i → i < n → ¬ P i × ¬ Q i) × P n × ¬ Q n
S n = (∀ i → i < n → ¬ P i × ¬ Q i) × ¬ P n × Q n
lem : DecU (λ n → ∀ i → i < n → ¬ P i × ¬ Q i)
lem = <-all-dec (DecU-× (¬-DecU P?) (¬-DecU Q?))
R? : DecU R
R? = DecU-× lem (DecU-× P? (¬-DecU Q?))
S? : DecU S
S? = DecU-× lem (DecU-× (¬-DecU P?) Q?)
¬[∃R×∃S] : ¬ (∃ R × ∃ S)
¬[∃R×∃S] ((m , ∀i→i<m→¬Pi׬Qi , Pm , ¬Qm) ,
(n , ∀i→i<n→¬Pi׬Qi , ¬Pn , Qn)) with <-cmp m n
... | tri< m<n _ _ = proj₁ (∀i→i<n→¬Pi׬Qi m m<n) Pm
... | tri≈ _ m≡n _ = ¬Pn (subst P m≡n Pm)
... | tri> _ _ n<m = proj₂ (∀i→i<m→¬Pi׬Qi n n<m) Qn
-- use LLPO
¬∃R⊎¬∃S : ¬ ∃ R ⊎ ¬ ∃ S
¬∃R⊎¬∃S = llpo R? S? ¬[∃R×∃S]
-- Induction by _<_
byacc₁ : (∀ x → ¬ R x) → (∀ x → ¬ Q x) → ∀ x → Ind.Acc _<_ x → ¬ P x
byacc₁ ∀¬R ∀¬Q x (Ind.acc rs) Px =
∀¬R x ((λ i i<x → (λ Pi → byacc₁ ∀¬R ∀¬Q i (rs i i<x) Pi) , ∀¬Q i) , (Px , ∀¬Q x))
∀¬R→∀¬Q→∀¬P : (∀ x → ¬ R x) → (∀ x → ¬ Q x) → ∀ x → ¬ P x
∀¬R→∀¬Q→∀¬P ∀¬R ∀¬Q x Px = byacc₁ ∀¬R ∀¬Q x (<-wf x) Px
¬∃R→¬∃Q→¬∃P : ¬ ∃ R → ¬ ∃ Q → ¬ ∃ P
¬∃R→¬∃Q→¬∃P ¬∃R ¬∃Q = ∀¬P→¬∃P $ ∀¬R→∀¬Q→∀¬P (¬∃P→∀¬P ¬∃R) (¬∃P→∀¬P ¬∃Q)
byacc₂ : (∀ x → ¬ S x) → (∀ x → ¬ P x) → ∀ x → Ind.Acc _<_ x → ¬ Q x
byacc₂ ∀¬S ∀¬P x (Ind.acc rs) Qx =
∀¬S x ((λ i i<x → ∀¬P i , λ Qi → byacc₂ ∀¬S ∀¬P i (rs i i<x) Qi) , (∀¬P x , Qx))
∀¬S→∀¬P→∀¬Q : (∀ x → ¬ S x) → (∀ x → ¬ P x) → ∀ x → ¬ Q x
∀¬S→∀¬P→∀¬Q ∀¬S ∀¬P x Qx = byacc₂ ∀¬S ∀¬P x (<-wf x) Qx
¬∃S→¬∃P→¬∃Q : ¬ ∃ S → ¬ ∃ P → ¬ ∃ Q
¬∃S→¬∃P→¬∃Q ¬∃S ¬∃P = ∀¬P→¬∃P $ ∀¬S→∀¬P→∀¬Q (¬∃P→∀¬P ¬∃S) (¬∃P→∀¬P ¬∃P)
¬¬[∃P⊎∃Q] : ¬ ¬ (∃ P ⊎ ∃ Q)
¬¬[∃P⊎∃Q] = DN-map ∃-distrib-⊎ ¬¬[∃x→Px⊎Qx]
¬¬∃Q⊎¬¬∃P : ¬ ¬ ∃ Q ⊎ ¬ ¬ ∃ P
¬¬∃Q⊎¬¬∃P =
Sum.map
(λ ¬∃R ¬∃Q → ¬¬[∃P⊎∃Q] Sum.[ ¬∃R→¬∃Q→¬∃P ¬∃R ¬∃Q , ¬∃Q ])
(λ ¬∃S ¬∃P → ¬¬[∃P⊎∃Q] Sum.[ ¬∃P , ¬∃S→¬∃P→¬∃Q ¬∃S ¬∃P ])
¬∃R⊎¬∃S
|
{
"alphanum_fraction": 0.4584076055,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "61fb8386923b4fc2d870e4856ce66ea2ae9f265d",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Constructive/Axiom/Properties/Alternative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "Constructive/Axiom/Properties/Alternative.agda",
"max_line_length": 86,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Constructive/Axiom/Properties/Alternative.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 1839,
"size": 3366
}
|
-- Andreas, 2021-04-28, issue #5336
-- data...where is already extensible.
module _ where
module C where
postulate
Name QName : Set
variable
x y : C.Name
xs ys : C.QName
interleaved mutual
-- Scope of a declaration.
data Scope : Set
variable
sc sc' : Scope
-- Declarations in a scope.
data Decls (sc : Scope) : Set
variable
ds₀ ds ds' : Decls sc
-- A definition in a scope.
-- So far, we can only define modules, which hold declarations.
data Val : (sc : Scope) → Set
-- We use letter v ("value") for definitions.
variable
v v' : Val sc
-- A well-scoped name pointing to its definition.
data Name : (sc : Scope) → Val sc → Set
variable
n n' : Name sc v
-- A well-scoped declaration is one of
--
-- * A module definition.
-- * Importing the declarations of another module via `open`.
data Decl (sc : Scope) : Set where
modl : (x : C.Name) (ds : Decls sc) → Decl sc
opn : (n : Name sc v) → Decl sc
variable
d d' : Decl sc
-- A scope is a snoc list of lists of declarations.
data Scope where
ε : Scope
data Scope where
_▷_ : (sc : Scope) (ds : Decls sc) → Scope
-- Lists of declarations are also given in snoc-form.
data Decls where
ε : Decls sc
data Decls where
_▷_ : (ds : Decls sc) (d : Decl (sc ▷ ds)) → Decls sc
data Val where
-- The content of a module.
content : (ds : Decls sc) → Val sc
-- Qualifying a value that is taken from inside module x.
inside : (x : C.Name) (v : Val ((sc ▷ ds) ▷ ds')) → Val (sc ▷ (ds ▷ modl x ds'))
imp : (n : Name (sc ▷ ds₀) (content ds')) (v : Val ((sc ▷ ds₀) ▷ ds'))
→ Val (sc ▷ (ds₀ ▷ opn n))
-- Weakning from one scope to an extended scope.
data _⊆_ : (sc sc' : Scope) → Set
variable
τ : sc ⊆ sc'
-- Weakning by a list of declarations or a single declaration.
wk1 : sc ⊆ (sc ▷ ds)
wk01 : (sc ▷ ds) ⊆ (sc ▷ (ds ▷ d))
-- Weakening a definition.
data WkVal : (τ : sc ⊆ sc') → Val sc → Val sc' → Set
variable
wv wv' wv₀ : WkVal τ v v'
data WkDecl (τ : sc ⊆ sc') : Decl sc → Decl sc' → Set
variable
wd wd' : WkDecl τ d d'
data WkDecls : (τ : sc ⊆ sc') → Decls sc → Decls sc' → Set
variable
wds₀ wds wds' : WkDecls τ ds ds'
-- Names resolving in a list of declarations.
data DsName (sc : Scope) : (ds : Decls sc) → Val (sc ▷ ds) → Set -- where
variable
nds nds' : DsName sc ds v
-- Names resolving in a declaration.
data DName (sc : Scope) (ds₀ : Decls sc) : (d : Decl (sc ▷ ds₀)) → Val (sc ▷ (ds₀ ▷ d)) → Set where
modl : (wds : WkDecls wk01 ds ds')
→ DName sc ds₀ (modl x ds) (content ds')
inside : (n : DsName (sc ▷ ds₀) ds' v)
→ DName sc ds₀ (modl x ds') (inside x v)
imp : (n : Name (sc ▷ ds₀) (content ds'))
(nds : DsName (sc ▷ ds₀) ds' v)
→ DName sc ds₀ (opn n) (imp n v)
variable
nd nd' : DName sc ds d v
-- This finally allows us to define names resolving in a scope.
data DsName where
here : (nd : DName sc ds d v) → DsName sc (ds ▷ d) v
there : (w : WkVal wk01 v v') (nds : DsName sc ds v) → DsName sc (ds ▷ d) v'
data Name where
site : (nds : DsName sc ds v) → Name (sc ▷ ds) v
parent : (w : WkVal wk1 v v') (n : Name sc v) → Name (sc ▷ ds) v'
------------------------------------------------------------------------
-- Relating entities defined in a scope to their weakenings.
-- Weakenings are order-preserving embeddings.
data _⊆_ where
ε : ε ⊆ ε
_▷_ : (τ : sc ⊆ sc') (wds : WkDecls τ ds ds') → (sc ▷ ds) ⊆ (sc' ▷ ds')
_▷ʳ_ : (τ : sc ⊆ sc') (ds : Decls sc') → sc ⊆ (sc' ▷ ds)
data WkDecls where
ε : WkDecls τ ε ε
_▷_ : (ws : WkDecls τ ds ds') (wd : WkDecl (τ ▷ ws) d d') → WkDecls τ (ds ▷ d) (ds' ▷ d')
_▷ʳ_ : (ws : WkDecls τ ds ds') (d : Decl (_ ▷ ds')) → WkDecls τ ds (ds' ▷ d)
refl-⊆ : sc ⊆ sc
wkDecls-refl-⊆ : WkDecls τ ds ds
wkDecl-refl-⊆ : WkDecl τ d d
wkDecls-refl-⊆ {ds = ε} = ε
wkDecls-refl-⊆ {ds = ds ▷ d} = wkDecls-refl-⊆ ▷ wkDecl-refl-⊆
refl-⊆ {sc = ε} = ε
refl-⊆ {sc = sc ▷ ds} = refl-⊆ ▷ wkDecls-refl-⊆
-- We can now define the singleton weaknings.
-- By another list of declarations.
wk1 {ds = ds} = refl-⊆ ▷ʳ ds
-- By a single declaration.
wk01 {d = d} = refl-⊆ ▷ (wkDecls-refl-⊆ ▷ʳ d)
-- Weakning names
data WkName : (τ : sc ⊆ sc') (wv : WkVal τ v v') → Name sc v → Name sc' v' → Set
postulate
wkVal-refl-⊆ : WkVal τ v v
wkName-refl-⊆ : WkName τ wv n n
data WkDecl where
modl : (w : WkDecls τ ds ds') → WkDecl τ (modl x ds) (modl x ds')
opn : (wn : WkName τ wv n n' ) → WkDecl τ (opn n) (opn n')
wkDecl-refl-⊆ {d = modl x ds} = modl wkDecls-refl-⊆
wkDecl-refl-⊆ {d = opn n } = opn {wv = wkVal-refl-⊆} wkName-refl-⊆
-- We can prove that the identity weaking leaves definitions unchanged.
data WkVal where
content : (wds : WkDecls τ ds ds') → WkVal τ (content ds) (content ds')
inside : (wv : WkVal ((τ ▷ wds) ▷ wds') v v' )
→ WkVal (τ ▷ (wds ▷ modl wds')) (inside x v) (inside x v')
data WkName where
site : WkName τ wv (site nds) (site nds')
|
{
"alphanum_fraction": 0.5394983152,
"avg_line_length": 26.9797979798,
"ext": "agda",
"hexsha": "dd4259c0d0eb32bfeafbee7439fa28811b816f30",
"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": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue5336.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"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-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue5336.agda",
"max_line_length": 102,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue5336.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": 2046,
"size": 5342
}
|
{-# OPTIONS --rewriting #-}
{-# OPTIONS --no-fast-reduce #-}
open import Agda.Builtin.Equality
{-# BUILTIN REWRITE _≡_ #-}
data A : Set where
a b : A
postulate rew : a ≡ b
{-# REWRITE rew #-}
test : a ≡ b
test = refl
|
{
"alphanum_fraction": 0.600896861,
"avg_line_length": 14.8666666667,
"ext": "agda",
"hexsha": "2feaf49122a033e1989506ece4d770f4f50faa30",
"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/Issue4909.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/Issue4909.agda",
"max_line_length": 33,
"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/Issue4909.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": 70,
"size": 223
}
|
module Lvl.Functions where
open import Lvl
open import Numeral.Natural
add : ℕ → Lvl.Level → Lvl.Level
add ℕ.𝟎 ℓ = ℓ
add (ℕ.𝐒 n) ℓ = Lvl.𝐒(add n ℓ)
|
{
"alphanum_fraction": 0.6688311688,
"avg_line_length": 17.1111111111,
"ext": "agda",
"hexsha": "994ad6939da820ebf07418891a3845997998fef5",
"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": "Lvl/Functions.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": "Lvl/Functions.agda",
"max_line_length": 31,
"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": "Lvl/Functions.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": 68,
"size": 154
}
|
module RawSemantics where
open import Data.Maybe
open import Data.Nat hiding (_⊔_; _⊓_)
open import Data.Product
open import Data.Sum
open import Data.String using (String)
open import Data.Unit hiding (_≟_)
open import Data.Empty
open import Function using (_∘_)
open import Relation.Nullary
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_;_≢_; refl)
open Eq.≡-Reasoning
open import Level hiding (_⊔_) renaming (zero to lzero; suc to lsuc)
{- TODO:
* might be useful to distinguish positive and negative (refinement) types from the start
* subtyping of refinement types
* union types: want a rule to convert from a (union) type to a sum type using a decidable predicate
* intersection types
-}
Id = String
variable
x y : Id
ℓ ℓ′ : Level
n : ℕ
data Expr : Set where
Nat : ℕ → Expr
Var : Id → Expr
Lam : Id → Expr → Expr
App : Expr → Expr → Expr
Pair : Expr → Expr → Expr
LetPair : Id → Id → Expr → Expr → Expr
Fst Snd : Expr → Expr
Inl Inr : Expr → Expr
Case : Expr → Id → Expr → Id → Expr → Expr
-- raw types are the types which support standard execution
-- currently just simple types
data RawType : Set where
Nat : RawType
_⇒_ _⋆_ _⊹_ : RawType → RawType → RawType
ss⇒tt : ∀ {S S₁ T T₁ : RawType} → (S ⇒ S₁) ≡ (T ⇒ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⇒tt refl = refl , refl
ss⋆tt : ∀ {S S₁ T T₁ : RawType} → (S ⋆ S₁) ≡ (T ⋆ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⋆tt refl = refl , refl
ss⊹tt : ∀ {S S₁ T T₁ : RawType} → (S ⊹ S₁) ≡ (T ⊹ T₁) → (S ≡ T × S₁ ≡ T₁)
ss⊹tt refl = refl , refl
-- semantics of raw types
R⟦_⟧ : RawType → Set
R⟦ Nat ⟧ = ℕ
R⟦ S ⇒ T ⟧ = R⟦ S ⟧ → R⟦ T ⟧
R⟦ S ⋆ T ⟧ = R⟦ S ⟧ × R⟦ T ⟧
R⟦ S ⊹ T ⟧ = R⟦ S ⟧ ⊎ R⟦ T ⟧
data Env (A : Set ℓ) : Set ℓ where
· : Env A
_,_⦂_ : Env A → (x : Id) → (a : A) → Env A
data AllEnv (A : Set ℓ) (P : A → Set) : Env A → Set ℓ where
· : AllEnv A P ·
_,_ : ∀ {γ}{x : Id}{a : A} → AllEnv A P γ → P a → AllEnv A P (γ , x ⦂ a)
variable
L M N : Expr
RS RT RU RV RW : RawType
Δ Δ₁ Δ₂ : Env RawType
-- mapping a function over an environment
_⁺ : ∀ {A : Set ℓ′}{B : Set ℓ} → (A → B) → (Env A → Env B)
(f ⁺) · = ·
(f ⁺) (Φ , x ⦂ a) = (f ⁺) Φ , x ⦂ f a
RE⟦_⟧ : Env RawType → Env Set
RE⟦_⟧ = R⟦_⟧ ⁺
data _⦂_∈_ {A : Set ℓ} : Id → A → Env A → Set ℓ where
found : ∀ {a : A}{E : Env A} →
x ⦂ a ∈ (E , x ⦂ a)
there : ∀ {a a' : A}{E : Env A} →
x ⦂ a ∈ E →
-- x ≢ y →
x ⦂ a ∈ (E , y ⦂ a')
data iEnv : Env Set → Set where
· : iEnv ·
_,_⦂_ : ∀ {E}{A} → iEnv E → (x : Id) → (a : A) → iEnv (E , x ⦂ A)
data jEnv {A : Set ℓ} (⟦_⟧ : A → Set) : Env A → Set where
· : jEnv ⟦_⟧ ·
_,_⦂_ : ∀ {E}{A} → jEnv ⟦_⟧ E → (x : Id) → (a : ⟦ A ⟧) → jEnv ⟦_⟧ (E , x ⦂ A)
-- F here is a natural transformation
jEnvMap : {A : Set ℓ} {⟦_⟧ ⟦_⟧′ : A → Set}{E : Env A} →
(F : {a : A} → ⟦ a ⟧ → ⟦ a ⟧′) →
jEnv ⟦_⟧ E → jEnv ⟦_⟧′ E
jEnvMap F · = ·
jEnvMap F (env , x ⦂ ⟦a⟧) = (jEnvMap F env) , x ⦂ F ⟦a⟧
-- should be in terms of RawType for evaluation
data _⊢_⦂_ : Env RawType → Expr → RawType → Set₁ where
nat :
Δ ⊢ Nat n ⦂ Nat
var :
(x∈ : x ⦂ RT ∈ Δ) →
--------------------
Δ ⊢ Var x ⦂ RT
lam :
(Δ , x ⦂ RS) ⊢ M ⦂ RT →
--------------------
Δ ⊢ Lam x M ⦂ (RS ⇒ RT)
app :
Δ ⊢ M ⦂ (RS ⇒ RT) →
Δ ⊢ N ⦂ RS →
--------------------
Δ ⊢ App M N ⦂ RT
pair :
Δ ⊢ M ⦂ RS →
Δ ⊢ N ⦂ RT →
--------------------
Δ ⊢ Pair M N ⦂ (RS ⋆ RT)
pair-E :
Δ ⊢ M ⦂ (RS ⋆ RT) →
((Δ , x ⦂ RS) , y ⦂ RT) ⊢ N ⦂ RU →
------------------------------
Δ ⊢ LetPair x y M N ⦂ RU
pair-E1 :
Δ ⊢ M ⦂ (RS ⋆ RT) →
--------------------
Δ ⊢ Fst M ⦂ RS
pair-E2 :
Δ ⊢ M ⦂ (RS ⋆ RT) →
--------------------
Δ ⊢ Snd M ⦂ RT
sum-I1 :
Δ ⊢ M ⦂ RS →
--------------------
Δ ⊢ Inl M ⦂ (RS ⊹ RT)
sum-I2 :
Δ ⊢ N ⦂ RT →
--------------------
Δ ⊢ Inr N ⦂ (RS ⊹ RT)
sum-E :
Δ ⊢ L ⦂ (RS ⊹ RT) →
(Δ , x ⦂ RS) ⊢ M ⦂ RU →
(Δ , y ⦂ RT) ⊢ N ⦂ RV →
RW ≡ RU × RW ≡ RV →
--------------------
Δ ⊢ Case L x M y N ⦂ RW
glookup : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ : Env A}{a : A} →
(x ⦂ a ∈ Φ) → jEnv ⟦_⟧ Φ → ⟦ a ⟧
glookup found (γ , _ ⦂ a) = a
glookup (there x∈) (γ , _ ⦂ a) = glookup x∈ γ
{-
lookup : (x ⦂ RT ∈ Δ) → jEnv R⟦_⟧ Δ → R⟦ RT ⟧
lookup found (γ , _ ⦂ a) = a
lookup (there x∈) (γ , _ ⦂ a) = lookup x∈ γ
-}
eval : Δ ⊢ M ⦂ RT → jEnv R⟦_⟧ Δ → R⟦ RT ⟧
eval (nat{n = n}) γ = n
eval (var x∈) γ = glookup x∈ γ
eval (lam ⊢M) γ = λ s → eval ⊢M (γ , _ ⦂ s)
eval (app ⊢M ⊢N) γ = eval ⊢M γ (eval ⊢N γ)
eval (pair ⊢M ⊢N) γ = (eval ⊢M γ) , (eval ⊢N γ)
eval (pair-E ⊢M ⊢N) γ with eval ⊢M γ
... | vx , vy = eval ⊢N ((γ , _ ⦂ vx) , _ ⦂ vy)
eval (pair-E1 ⊢M) γ = proj₁ (eval ⊢M γ)
eval (pair-E2 ⊢M) γ = proj₂ (eval ⊢M γ)
eval (sum-I1 ⊢M) γ = inj₁ (eval ⊢M γ)
eval (sum-I2 ⊢N) γ = inj₂ (eval ⊢N γ)
eval (sum-E ⊢L ⊢M ⊢N (refl , refl)) γ =
[ (λ s → eval ⊢M (γ , _ ⦂ s)) , (λ t → eval ⊢N (γ , _ ⦂ t)) ] (eval ⊢L γ)
----------------------------------------------------------------------
-- refinement types that drive the incorrectness typing
data Type : Set₁ where
Base : (P : ℕ → Set) (p : ∀ n → Dec (P n)) → Type -- refinement
Nat : Type
_⇒_ _⋆_ : (S : Type) (T : Type) → Type
_⊹_ _⊹ˡ_ _⊹ʳ_ : (S : Type) (T : Type) → Type
T-Nat : Type
T-Nat = Base (λ n → ⊤) (λ n → yes tt) -- all natural numbers
-- characterize non-empty types
data ne : Type → Set where
ne-base : ∀ {P p} → (∃P : Σ ℕ P) → ne (Base P p)
ne-nat : ne Nat
ne-⇒ : ∀ {S T} → ne S → ne T → ne (S ⇒ T)
ne-⋆ : ∀ {S T} → ne S → ne T → ne (S ⋆ T)
ne-⊹L : ∀ {S T} → ne S → ne (S ⊹ T)
ne-⊹R : ∀ {S T} → ne T → ne (S ⊹ T)
∥_∥ : Type → RawType
∥ Base P p ∥ = Nat
∥ Nat ∥ = Nat
∥ S ⇒ S₁ ∥ = ∥ S ∥ ⇒ ∥ S₁ ∥
∥ S ⋆ S₁ ∥ = ∥ S ∥ ⋆ ∥ S₁ ∥
∥ S ⊹ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥
∥ S ⊹ˡ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥
∥ S ⊹ʳ S₁ ∥ = ∥ S ∥ ⊹ ∥ S₁ ∥
T⟦_⟧ : Type → Set
T⟦ Base P p ⟧ = Σ ℕ P
T⟦ Nat ⟧ = ℕ
T⟦ S ⇒ T ⟧ = T⟦ S ⟧ → T⟦ T ⟧
T⟦ S ⋆ T ⟧ = T⟦ S ⟧ × T⟦ T ⟧
T⟦ S ⊹ T ⟧ = T⟦ S ⟧ ⊎ T⟦ T ⟧
T⟦ S ⊹ˡ T ⟧ = T⟦ S ⟧
T⟦ S ⊹ʳ T ⟧ = T⟦ T ⟧
M⟦_⟧ V⟦_⟧ : Type → (Set → Set) → Set
V⟦ Base P p ⟧ m = Σ ℕ P
V⟦ Nat ⟧ m = ℕ
V⟦ T ⇒ T₁ ⟧ m = V⟦ T ⟧ m → M⟦ T₁ ⟧ m
V⟦ T ⋆ T₁ ⟧ m = V⟦ T ⟧ m × V⟦ T₁ ⟧ m
V⟦ T ⊹ T₁ ⟧ m = V⟦ T ⟧ m ⊎ V⟦ T₁ ⟧ m
V⟦ T ⊹ˡ T₁ ⟧ m = V⟦ T ⟧ m
V⟦ T ⊹ʳ T₁ ⟧ m = V⟦ T₁ ⟧ m
M⟦ T ⟧ m = m (V⟦ T ⟧ m)
E⟦_⟧ : Env Type → Env Set
E⟦_⟧ = T⟦_⟧ ⁺
∥_∥⁺ : Env Type → Env RawType
∥_∥⁺ = ∥_∥ ⁺
-- a value is a member of refinement type T
_∋_ : (T : Type) → R⟦ ∥ T ∥ ⟧ → Set
Base P p ∋ x = P x
Nat ∋ x = ⊤
(T ⇒ T₁) ∋ f = ∀ x → T ∋ x → T₁ ∋ f x
(T ⋆ T₁) ∋ (fst , snd) = T ∋ fst × T₁ ∋ snd
(T ⊹ T₁) ∋ inj₁ x = T ∋ x
(T ⊹ T₁) ∋ inj₂ y = T₁ ∋ y
(S ⊹ˡ T) ∋ inj₁ x = S ∋ x
(S ⊹ˡ T) ∋ inj₂ y = ⊥
(S ⊹ʳ T) ∋ inj₁ x = ⊥
(S ⊹ʳ T) ∋ inj₂ y = T ∋ y
-- operations on predicates
_∨_ : (P Q : ℕ → Set) → ℕ → Set
P ∨ Q = λ n → P n ⊎ Q n
_∧_ : (P Q : ℕ → Set) → ℕ → Set
P ∧ Q = λ n → P n × Q n
implies : ∀ {P Q : ℕ → Set} → (n : ℕ) → P n → (P n ⊎ Q n)
implies n Pn = inj₁ Pn
p*q->p : ∀ {P Q : ℕ → Set} → (n : ℕ) → (P n × Q n) → P n
p*q->p n (Pn , Qn) = Pn
dec-P∨Q : ∀ {P Q : ℕ → Set} → (p : ∀ n → Dec (P n)) (q : ∀ n → Dec (Q n)) → (∀ n → Dec ((P ∨ Q) n))
dec-P∨Q p q n with p n | q n
... | no ¬p | no ¬q = no [ ¬p , ¬q ]
... | no ¬p | yes !q = yes (inj₂ !q)
... | yes !p | no ¬q = yes (inj₁ !p)
... | yes !p | yes !q = yes (inj₁ !p)
dec-P∧Q : ∀ {P Q : ℕ → Set} → (p : ∀ n → Dec (P n)) (q : ∀ n → Dec (Q n)) → (∀ n → Dec ((P ∧ Q) n))
dec-P∧Q p q n with p n | q n
... | no ¬p | no ¬q = no (¬p ∘ proj₁)
... | no ¬p | yes !q = no (¬p ∘ proj₁)
... | yes !p | no ¬q = no (¬q ∘ proj₂)
... | yes !p | yes !q = yes (!p , !q)
_⊔_ _⊓_ : (S T : Type) {r : ∥ S ∥ ≡ ∥ T ∥} → Type
(Base P p ⊔ Base P₁ p₁) {refl} = Base (P ∨ P₁) (dec-P∨Q p p₁)
(Base P p ⊔ Nat) = Nat
(Nat ⊔ Base P p) = Nat
(Nat ⊔ Nat) = Nat
((S ⇒ S₁) ⊔ (T ⇒ T₁)) {r} with ss⇒tt r
... | sss , ttt = (S ⊓ T){sss} ⇒ (S₁ ⊔ T₁){ttt}
((S ⋆ S₁) ⊔ (T ⋆ T₁)) {r} with ss⋆tt r
... | sss , ttt = (S ⊔ T){sss} ⋆ (S₁ ⊔ T₁){ttt}
((S ⊹ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r
... | sss , ttt = (S ⊔ T){sss} ⊹ (S₁ ⊔ T₁){ttt}
((S ⊹ S₁) ⊔ (T ⊹ˡ T₁)) {r} with ss⊹tt r
... | sss , ttt = (S ⊔ T){sss} ⊹ S₁
((S ⊹ S₁) ⊔ (T ⊹ʳ T₁)) {r} with ss⊹tt r
... | sss , ttt = S ⊹ (S₁ ⊔ T₁){ttt}
((S ⊹ˡ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r
... | sss , ttt = ((S ⊔ T){sss}) ⊹ (S₁ ⊔ T₁){ttt}
((S ⊹ˡ S₁) ⊔ (T ⊹ˡ T₁)) {r} with ss⊹tt r
... | sss , ttt = ((S ⊔ T){sss}) ⊹ˡ ((S₁ ⊔ T₁){ttt})
((S ⊹ˡ S₁) ⊔ (T ⊹ʳ T₁)) {r} = S ⊹ T₁
((S ⊹ʳ S₁) ⊔ (T ⊹ T₁)) {r} with ss⊹tt r
... | sss , ttt = T ⊹ ((S₁ ⊔ T₁) {ttt})
((S ⊹ʳ S₁) ⊔ (T ⊹ˡ T₁)) {r} = T ⊹ S₁
((S ⊹ʳ S₁) ⊔ (T ⊹ʳ T₁)) {r} with ss⊹tt r
... | sss , ttt = (S ⊔ T) {sss} ⊹ (S₁ ⊔ T₁) {ttt}
Base P p ⊓ Base P₁ p₁ = Base (P ∧ P₁) (dec-P∧Q p p₁)
Base P p ⊓ Nat = Base P p
Nat ⊓ Base P p = Base P p
Nat ⊓ Nat = Nat
((S ⇒ S₁) ⊓ (T ⇒ T₁)){r} with ss⇒tt r
... | sss , ttt = (S ⊔ T){sss} ⇒ (S₁ ⊓ T₁){ttt}
((S ⋆ S₁) ⊓ (T ⋆ T₁)){r} with ss⋆tt r
... | sss , ttt = (S ⊓ T){sss} ⋆ (S₁ ⊓ T₁){ttt}
((S ⊹ S₁) ⊓ (T ⊹ T₁)){r} with ss⊹tt r
... | sss , ttt = (S ⊓ T){sss} ⊹ (S₁ ⊓ T₁){ttt}
((S ⊹ˡ S₁) ⊓ (T ⊹ T₁)) {r} = {!!}
((S ⊹ʳ S₁) ⊓ (T ⊹ T₁)) {r} = {!!}
((S ⊹ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}
((S ⊹ˡ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}
((S ⊹ʳ S₁) ⊓ (T ⊹ˡ T₁)) {r} = {!!}
((S ⊹ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}
((S ⊹ˡ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}
((S ⊹ʳ S₁) ⊓ (T ⊹ʳ T₁)) {r} = {!!}
variable
S T U S′ T′ U′ U″ : Type
Γ Γ₁ Γ₂ : Env Type
P : ℕ → Set
p : ∀ n → Dec (P n)
A : Set ℓ
a : A
Φ Φ₁ Φ₂ : Env A
⊔-preserves : ∀ S T {st : ∥ S ∥ ≡ ∥ T ∥} →
∥ (S ⊔ T){st} ∥ ≡ ∥ S ∥ × ∥ (S ⊔ T){st} ∥ ≡ ∥ T ∥
⊓-preserves : ∀ S T {st : ∥ S ∥ ≡ ∥ T ∥} →
∥ (S ⊓ T){st} ∥ ≡ ∥ S ∥ × ∥ (S ⊓ T){st} ∥ ≡ ∥ T ∥
⊔-preserves (Base P p) (Base P₁ p₁) {refl} = refl , refl
⊔-preserves (Base P p) Nat {st} = refl , refl
⊔-preserves Nat (Base P p) {st} = refl , refl
⊔-preserves Nat Nat {st} = refl , refl
⊔-preserves (S ⇒ S₁) (T ⇒ T₁) {st} with ss⇒tt st
... | sss , ttt with ⊓-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⋆ S₁) (T ⋆ T₁) {st} with ss⋆tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⊹ S₁) (T ⊹ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⊹ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s = refl , st
⊔-preserves (S ⊹ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⊹ˡ S₁) (T ⊹ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⊹ˡ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊔-preserves (S ⊹ˡ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st
... | sss , ttt rewrite sss | ttt = refl , refl
⊔-preserves (S ⊹ʳ S₁) (T ⊹ T₁) {st} with ss⊹tt st
... | sss , ttt rewrite sss with ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t rewrite sut=t = (Eq.sym st) , refl
⊔-preserves (S ⊹ʳ S₁) (T ⊹ˡ T₁) {st} with ss⊹tt st
... | sss , ttt rewrite sss = refl , st
⊔-preserves (S ⊹ʳ S₁) (T ⊹ʳ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊔-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s₁ , sut=t₁ rewrite sut=s | sut=s₁ = refl , st
⊓-preserves (Base P p) (Base P₁ p₂) {st} = refl , refl
⊓-preserves (Base P p) Nat {st} = refl , refl
⊓-preserves Nat (Base P p) {st} = refl , refl
⊓-preserves Nat Nat {st} = refl , refl
⊓-preserves (S ⇒ S₁) (T ⇒ T₁) {st} with ss⇒tt st
... | sss , ttt with ⊔-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st
⊓-preserves (S ⋆ S₁) (T ⋆ T₁) {st} with ss⋆tt st
... | sss , ttt with ⊓-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st
⊓-preserves (S ⊹ S₁) (T ⊹ T₁) {st} with ss⊹tt st
... | sss , ttt with ⊓-preserves S T {sss} | ⊓-preserves S₁ T₁ {ttt}
... | sut=s , sut=t | sut=s1 , sut=t1 rewrite sut=s | sut=s1 = refl , st
⊓-preserves (S ⊹ˡ S₁) (T ⊹ T₁) {st} = {!!}
⊓-preserves (S ⊹ʳ S₁) (T ⊹ T₁) {st} = {!!}
⊓-preserves S (T ⊹ˡ T₁) {st} = {!!}
⊓-preserves S (T ⊹ʳ T₁) {st} = {!!}
data Split {A : Set ℓ} : Env A → Env A → Env A → Set ℓ where
nil : Split · · ·
lft : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) (Γ₁ , x ⦂ a) Γ₂
rgt : ∀ {a : A}{Γ Γ₁ Γ₂ : Env A} → Split Γ Γ₁ Γ₂ → Split (Γ , x ⦂ a) Γ₁ (Γ₂ , x ⦂ a)
-- subtyping
data _<:_ : Type → Type → Set where
<:-refl :
T <: T
<:-base :
(P Q : ℕ → Set) →
{p : ∀ n → Dec (P n)}
{q : ∀ n → Dec (Q n)}
(p→q : ∀ n → P n → Q n) →
Base P p <: Base Q q
<:-base-nat : ∀ {p : ∀ n → Dec (P n)} →
Base P p <: Nat
<:-⇒ :
S′ <: S →
T <: T′ →
(S ⇒ T) <: (S′ ⇒ T′)
<:-⋆ :
S <: S′ →
T <: T′ →
(S ⋆ T) <: (S′ ⋆ T′)
<:-⊹ :
S <: S′ →
T <: T′ →
(S ⊹ T) <: (S′ ⊹ T′)
<:-⊹ˡ-⊹ :
S <: S′ →
(S ⊹ˡ T) <: (S′ ⊹ T)
<:-⊹ʳ-⊹ :
T <: T′ →
(S ⊹ʳ T) <: (S ⊹ T′)
-- subtyping is compatible with raw types
<:-raw : S <: T → ∥ S ∥ ≡ ∥ T ∥
<:-raw <:-refl = refl
<:-raw (<:-base P Q p→q) = refl
<:-raw <:-base-nat = refl
<:-raw (<:-⇒ s<:t s<:t₁) = Eq.cong₂ _⇒_ (Eq.sym (<:-raw s<:t)) (<:-raw s<:t₁)
<:-raw (<:-⋆ s<:t s<:t₁) = Eq.cong₂ _⋆_ (<:-raw s<:t) (<:-raw s<:t₁)
<:-raw (<:-⊹ s<:t s<:t₁) = Eq.cong₂ _⊹_ (<:-raw s<:t) (<:-raw s<:t₁)
<:-raw (<:-⊹ˡ-⊹ s<:t) = Eq.cong₂ _⊹_ (<:-raw s<:t) refl
<:-raw (<:-⊹ʳ-⊹ s<:t) = Eq.cong₂ _⊹_ refl (<:-raw s<:t)
<:-⊔ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → S <: (S ⊔ T){c}
<:-⊓ : ∀ S T → {c : ∥ S ∥ ≡ ∥ T ∥} → (S ⊓ T){c} <: S
<:-⊔ (Base P p) (Base P₁ p₁) {refl} = <:-base P (P ∨ P₁) implies
<:-⊔ (Base P p) Nat = <:-base-nat
<:-⊔ Nat (Base P p) = <:-refl
<:-⊔ Nat Nat = <:-refl
<:-⊔ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c
... | c1 , c2 = <:-⇒ (<:-⊓ S T) (<:-⊔ S₁ T₁)
<:-⊔ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c
... | c1 , c2 = <:-⋆ (<:-⊔ S T) (<:-⊔ S₁ T₁)
<:-⊔ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ (<:-⊔ S T) (<:-⊔ S₁ T₁)
<:-⊔ (S ⊹ S₁) (T ⊹ˡ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ (<:-⊔ S T) <:-refl
<:-⊔ (S ⊹ S₁) (T ⊹ʳ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ <:-refl (<:-⊔ S₁ T₁)
<:-⊔ (S ⊹ˡ S₁) (T ⊹ T₁) {c} with ss⊹tt c
... | c12 = {!<:-⊹!}
<:-⊔ (S ⊹ˡ S₁) (T ⊹ˡ T₁) = {!!}
<:-⊔ (S ⊹ˡ S₁) (T ⊹ʳ T₁) = {!!}
<:-⊔ (S ⊹ʳ S₁) T = {!!}
<:-⊓ (Base P p) (Base P₁ p₁) {refl} = <:-base (P ∧ P₁) P p*q->p
<:-⊓ (Base P p) Nat = <:-refl
<:-⊓ Nat (Base P p) = <:-base-nat
<:-⊓ Nat Nat = <:-refl
<:-⊓ (S ⇒ S₁) (T ⇒ T₁) {c} with ss⇒tt c
... | c1 , c2 = <:-⇒ (<:-⊔ S T) (<:-⊓ S₁ T₁)
<:-⊓ (S ⋆ S₁) (T ⋆ T₁) {c} with ss⋆tt c
... | c1 , c2 = <:-⋆ (<:-⊓ S T) (<:-⊓ S₁ T₁)
<:-⊓ (S ⊹ S₁) (T ⊹ T₁) {c} with ss⊹tt c
... | c1 , c2 = <:-⊹ (<:-⊓ S T) (<:-⊓ S₁ T₁)
<:-⊓ (S ⊹ S₁) (T ⊹ˡ T₁) = {!!}
<:-⊓ (S ⊹ S₁) (T ⊹ʳ T₁) = {!!}
<:-⊓ (S ⊹ˡ S₁) T = {!!}
<:-⊓ (S ⊹ʳ S₁) T = {!!}
-- subtyping generates an embedding and a projection
embed : (S <: T) → T⟦ S ⟧ → T⟦ T ⟧
embed <:-refl s = s
embed (<:-base P Q p→q) (s , p) = s , p→q s p
embed <:-base-nat (s , p) = s
embed (<:-⇒ s<:t s<:t₁) s = λ x → embed s<:t₁ (s (embed s<:t x))
embed (<:-⋆ s<:t s<:t₁) (s , t) = (embed s<:t s) , (embed s<:t₁ t)
embed (<:-⊹ s<:t s<:t₁) (inj₁ x) = inj₁ (embed s<:t x)
embed (<:-⊹ s<:t s<:t₁) (inj₂ y) = inj₂ (embed s<:t₁ y)
embed (<:-⊹ˡ-⊹ s<:t) s = inj₁ (embed s<:t s)
embed (<:-⊹ʳ-⊹ s<:t) s = inj₂ (embed s<:t s)
{- no definable
inject : T⟦ S ⟧ → V⟦ S ⟧ Maybe
eject : V⟦ S ⟧ Maybe → Maybe T⟦ S ⟧
inject {Base P p} s = s
inject {Nat} s = s
inject {S ⇒ S₁} s = λ x → eject{S} x >>= λ x₁ → let s₁ = s x₁ in just (inject {S₁} s₁)
inject {S ⋆ S₁} (s , s₁) = (inject{S} s) , (inject{S₁} s₁)
inject {S ⊹ S₁} (inj₁ x) = inj₁ (inject{S} x)
inject {S ⊹ S₁} (inj₂ y) = inj₂ (inject{S₁} y)
inject {S ⊹ˡ S₁} s = inject{S} s
inject {S ⊹ʳ S₁} s = inject{S₁} s
eject {Base P p} s = {!!}
eject {Nat} s = {!!}
eject {S ⇒ S₁} s = just (λ x → {!!})
eject {S ⋆ S₁} s = {!!}
eject {S ⊹ S₁} s = {!!}
eject {S ⊹ˡ S₁} s = {!!}
eject {S ⊹ʳ S₁} s = {!!}
-}
project : (S <: T) → V⟦ T ⟧ Maybe → M⟦ S ⟧ Maybe
project <:-refl t = just t
project (<:-base P Q {p = p} p→q) (t , qt)
with p t
... | no ¬p = nothing
... | yes p₁ = just (t , p₁)
project (<:-base-nat{p = p}) t
with p t
... | no ¬p = nothing
... | yes p₁ = just (t , p₁)
project (<:-⇒ s<:t s<:t₁) t = just λ s → project s<:t s >>= t >>= project s<:t₁
project (<:-⋆ s<:t s<:t₁) (s , t) = project s<:t s >>= λ x → project s<:t₁ t >>= λ x₁ → just (x , x₁)
project (<:-⊹ s<:t s<:t₁) (inj₁ x) = Data.Maybe.map inj₁ (project s<:t x)
project (<:-⊹ s<:t s<:t₁) (inj₂ y) = Data.Maybe.map inj₂ (project s<:t₁ y)
project (<:-⊹ˡ-⊹ s<:t) (inj₁ x) = project s<:t x
project (<:-⊹ˡ-⊹ s<:t) (inj₂ y) = nothing
project (<:-⊹ʳ-⊹ s<:t) (inj₁ x) = nothing
project (<:-⊹ʳ-⊹ s<:t) (inj₂ y) = project s<:t y
split-sym : Split Φ Φ₁ Φ₂ → Split Φ Φ₂ Φ₁
split-sym nil = nil
split-sym (lft sp) = rgt (split-sym sp)
split-sym (rgt sp) = lft (split-sym sp)
split-map : ∀ {A : Set ℓ}{B : Set ℓ′}{Φ Φ₁ Φ₂ : Env A} →
{f : A → B} → Split Φ Φ₁ Φ₂ → Split ((f ⁺) Φ) ((f ⁺) Φ₁) ((f ⁺) Φ₂)
split-map nil = nil
split-map (lft sp) = lft (split-map sp)
split-map (rgt sp) = rgt (split-map sp)
weaken-∈ : Split Φ Φ₁ Φ₂ → x ⦂ a ∈ Φ₁ → x ⦂ a ∈ Φ
weaken-∈ (lft sp) found = found
weaken-∈ (rgt sp) found = there (weaken-∈ sp found)
weaken-∈ (lft sp) (there x∈) = there (weaken-∈ sp x∈)
weaken-∈ (rgt sp) (there x∈) = there (weaken-∈ sp (there x∈))
weaken : Split Δ Δ₁ Δ₂ → Δ₁ ⊢ M ⦂ RT → Δ ⊢ M ⦂ RT
weaken sp (nat) = nat
weaken sp (var x∈) = var (weaken-∈ sp x∈)
weaken sp (lam ⊢M) = lam (weaken (lft sp) ⊢M)
weaken sp (app ⊢M ⊢N) = app (weaken sp ⊢M) (weaken sp ⊢N)
weaken sp (pair ⊢M ⊢N) = pair (weaken sp ⊢M) (weaken sp ⊢N)
weaken sp (pair-E ⊢M ⊢N) = pair-E (weaken sp ⊢M) (weaken (lft (lft sp)) ⊢N)
weaken sp (pair-E1 ⊢M) = pair-E1 (weaken sp ⊢M)
weaken sp (pair-E2 ⊢M) = pair-E2 (weaken sp ⊢M)
weaken sp (sum-I1 ⊢M) = sum-I1 (weaken sp ⊢M)
weaken sp (sum-I2 ⊢N) = sum-I2 (weaken sp ⊢N)
weaken sp (sum-E ⊢L ⊢M ⊢N (RT=RU , RT=RV)) =
sum-E (weaken sp ⊢L) (weaken (lft sp) ⊢M) (weaken (lft sp) ⊢N) (RT=RU , RT=RV)
-- incorrectness typing
-- a positive type contains refinements only in positive positions
mutual
data Pos : Type → Set where
Pos-Base : Pos (Base P p)
Pos-Nat : Pos Nat
Pos-⇒ : Neg S → Pos T → Pos (S ⇒ T)
Pos-⋆ : Pos S → Pos T → Pos (S ⋆ T)
Pos-⊹ : Pos S → Pos T → Pos (S ⊹ T)
Pos-⊹ˡ : Pos S → Pos (S ⊹ˡ T)
Pos-⊹ʳ : Pos T → Pos (S ⊹ʳ T)
data Neg : Type → Set where
Neg-Nat : Neg Nat
Neg-⇒ : Pos S → Neg T → Neg (S ⇒ T)
Neg-⋆ : Neg S → Neg T → Neg (S ⋆ T)
Neg-⊹ : Neg S → Neg T → Neg (S ⊹ T)
pos-unique : ∀ T → (pos pos' : Pos T) → pos ≡ pos'
neg-unique : ∀ T → (neg neg' : Neg T) → neg ≡ neg'
pos-unique (Base P p) Pos-Base Pos-Base = refl
pos-unique Nat Pos-Nat Pos-Nat = refl
pos-unique (T ⇒ T₁) (Pos-⇒ x pos) (Pos-⇒ x₁ pos') rewrite neg-unique T x x₁ | pos-unique T₁ pos pos' = refl
pos-unique (T ⋆ T₁) (Pos-⋆ pos pos₁) (Pos-⋆ pos' pos'') rewrite pos-unique T pos pos' | pos-unique T₁ pos₁ pos'' = refl
pos-unique (T ⊹ T₁) (Pos-⊹ pos pos₁) (Pos-⊹ pos' pos'') rewrite pos-unique T pos pos' | pos-unique T₁ pos₁ pos'' = refl
pos-unique (T ⊹ˡ T₁) (Pos-⊹ˡ pos) (Pos-⊹ˡ pos') rewrite pos-unique T pos pos' = refl
pos-unique (T ⊹ʳ T₁) (Pos-⊹ʳ pos) (Pos-⊹ʳ pos') rewrite pos-unique T₁ pos pos' = refl
--etc
neg-unique T neg neg' = {!!}
module positive-restricted where
toRaw : ∀ T → Pos T → T⟦ T ⟧ → R⟦ ∥ T ∥ ⟧
fromRaw : ∀ T → Neg T → R⟦ ∥ T ∥ ⟧ → T⟦ T ⟧
toRaw (Base P p) Pos-Base (n , pn) = n
toRaw Nat Pos-Nat t = t
toRaw (T ⇒ T₁) (Pos-⇒ neg pos₁) t = toRaw T₁ pos₁ ∘ t ∘ fromRaw T neg
toRaw (T ⋆ T₁) (Pos-⋆ pos pos₁) (t , t₁) = toRaw T pos t , (toRaw T₁ pos₁ t₁)
toRaw (T ⊹ T₁) (Pos-⊹ pos pos₁) (inj₁ x) = inj₁ (toRaw T pos x)
toRaw (T ⊹ T₁) (Pos-⊹ pos pos₁) (inj₂ y) = inj₂ (toRaw T₁ pos₁ y)
toRaw (S ⊹ˡ T) (Pos-⊹ˡ pos) x = inj₁ (toRaw S pos x)
toRaw (S ⊹ʳ T) (Pos-⊹ʳ pos) y = inj₂ (toRaw T pos y)
fromRaw (Base P p) () r
fromRaw Nat Neg-Nat r = r
fromRaw (T ⇒ T₁) (Neg-⇒ pos neg) r = fromRaw T₁ neg ∘ r ∘ toRaw T pos
fromRaw (T ⋆ T₁) (Neg-⋆ neg neg₁) (r , r₁) = fromRaw T neg r , fromRaw T₁ neg₁ r₁
fromRaw (T ⊹ T₁) (Neg-⊹ neg neg₁) (inj₁ x) = inj₁ (fromRaw T neg x)
fromRaw (T ⊹ T₁) (Neg-⊹ neg neg₁) (inj₂ y) = inj₂ (fromRaw T₁ neg₁ y)
toRawEnv : AllEnv Type Pos Γ → jEnv T⟦_⟧ Γ → jEnv R⟦_⟧ ∥ Γ ∥⁺
toRawEnv{·} posΓ · = ·
toRawEnv{Γ , _ ⦂ T} (posΓ , x₁) (γ , x ⦂ a) = toRawEnv{Γ} posΓ γ , x ⦂ toRaw T x₁ a
{-
-- attempt to map type (interpretation) to corresponding raw type (interpretation)
-- * must be monadic because of refinement
-- * fails at function types
module monadic where
toRaw : ∀ T → T⟦ T ⟧ → Maybe R⟦ ∥ T ∥ ⟧
fromRaw : ∀ T → R⟦ ∥ T ∥ ⟧ → Maybe T⟦ T ⟧
toRaw (Base P p) (n , Pn) = just n
toRaw Nat n = just n
toRaw (T ⇒ T₁) t = {!!}
toRaw (T ⋆ T₁) (t , t₁) = toRaw T t >>= (λ r → toRaw T₁ t₁ >>= (λ r₁ → just (r , r₁)))
toRaw (T ⊹ T₁) (inj₁ x) = Data.Maybe.map inj₁ (toRaw T x)
toRaw (T ⊹ T₁) (inj₂ y) = Data.Maybe.map inj₂ (toRaw T₁ y)
fromRaw (Base P p) r with p r
... | no ¬p = nothing
... | yes pr = just (r , pr)
fromRaw Nat r = just r
fromRaw (T ⇒ T₁) r = {!!}
fromRaw (T ⋆ T₁) (r , r₁) = fromRaw T r >>= (λ t → fromRaw T₁ r₁ >>= (λ t₁ → just (t , t₁)))
fromRaw (T ⊹ T₁) (inj₁ x) = Data.Maybe.map inj₁ (fromRaw T x)
fromRaw (T ⊹ T₁) (inj₂ y) = Data.Maybe.map inj₂ (fromRaw T₁ y)
-}
corr-sp : Split Γ Γ₁ Γ₂ → Split ∥ Γ ∥⁺ ∥ Γ₁ ∥⁺ ∥ Γ₂ ∥⁺
corr-sp nil = nil
corr-sp (lft sp) = lft (corr-sp sp)
corr-sp (rgt sp) = rgt (corr-sp sp)
postulate
ext : ∀ {A B : Set}{f g : A → B} → (∀ x → f x ≡ g x) → f ≡ g
unsplit-env : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A}→
Split Φ Φ₁ Φ₂ → jEnv ⟦_⟧ Φ₁ → jEnv ⟦_⟧ Φ₂ → jEnv ⟦_⟧ Φ
unsplit-env nil γ₁ γ₂ = ·
unsplit-env (lft sp) (γ₁ , _ ⦂ a) γ₂ = (unsplit-env sp γ₁ γ₂) , _ ⦂ a
unsplit-env (rgt sp) γ₁ (γ₂ , _ ⦂ a) = (unsplit-env sp γ₁ γ₂) , _ ⦂ a
unsplit-split : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A} →
(sp : Split Φ Φ₁ Φ₂) (γ₁ : jEnv ⟦_⟧ Φ₁) (γ₂ : jEnv ⟦_⟧ Φ₂) →
unsplit-env sp γ₁ γ₂ ≡ unsplit-env (split-sym sp) γ₂ γ₁
unsplit-split nil γ₁ γ₂ = refl
unsplit-split (lft sp) (γ₁ , _ ⦂ a) γ₂ rewrite unsplit-split sp γ₁ γ₂ = refl
unsplit-split (rgt sp) γ₁ (γ₂ , _ ⦂ a) rewrite unsplit-split sp γ₁ γ₂ = refl
lookup-unsplit : ∀ {A : Set ℓ} {⟦_⟧ : A → Set}{Φ Φ₁ Φ₂ : Env A}{a : A} →
(sp : Split Φ Φ₁ Φ₂) (γ₁ : jEnv ⟦_⟧ Φ₁) (γ₂ : jEnv ⟦_⟧ Φ₂) →
(x∈ : x ⦂ a ∈ Φ₁) →
glookup (weaken-∈ sp x∈) (unsplit-env sp γ₁ γ₂) ≡ glookup x∈ γ₁
lookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ found = refl
lookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) found = lookup-unsplit sp γ₁ γ₂ found
lookup-unsplit (lft sp) (γ₁ , _ ⦂ a) γ₂ (there x∈) = lookup-unsplit sp γ₁ γ₂ x∈
lookup-unsplit (rgt sp) γ₁ (γ₂ , _ ⦂ a) (there x∈) = lookup-unsplit sp γ₁ γ₂ (there x∈)
open positive-restricted
eval-unsplit' : (sp : Split Γ Γ₁ Γ₂) (γ₁ : jEnv T⟦_⟧ Γ₁) (γ₂ : jEnv T⟦_⟧ Γ₂) →
(posΓ₁ : AllEnv Type Pos Γ₁) (posΓ₂ : AllEnv Type Pos Γ₂) →
(⊢M : ∥ Γ₁ ∥⁺ ⊢ M ⦂ RT) →
eval (weaken (corr-sp sp) ⊢M) (unsplit-env (corr-sp sp) (toRawEnv posΓ₁ γ₁) (toRawEnv posΓ₂ γ₂)) ≡ eval ⊢M (toRawEnv posΓ₁ γ₁)
eval-unsplit' sp γ₁ γ₂ posΓ₁ posΓ₂ ⊢M = {!!}
{-
(eval (weaken (corr-sp sp) (corr ÷M))
(toRawEnv posΓ (unsplit-env sp γ₁ γ₂)))
-}
eval-unsplit : (sp : Split Δ Δ₁ Δ₂) (γ₁ : jEnv R⟦_⟧ Δ₁) (γ₂ : jEnv R⟦_⟧ Δ₂) →
(⊢M : Δ₁ ⊢ M ⦂ RT) →
eval (weaken sp ⊢M) (unsplit-env sp γ₁ γ₂) ≡ eval ⊢M γ₁
eval-unsplit sp γ₁ γ₂ (nat)= refl
eval-unsplit sp γ₁ γ₂ (var x∈) = lookup-unsplit sp γ₁ γ₂ x∈
eval-unsplit sp γ₁ γ₂ (lam ⊢M) = ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)
eval-unsplit sp γ₁ γ₂ (app ⊢M ⊢M₁)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl
eval-unsplit sp γ₁ γ₂ (pair ⊢M ⊢M₁)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M | eval-unsplit sp γ₁ γ₂ ⊢M₁ = refl
eval-unsplit sp γ₁ γ₂ (pair-E ⊢M ⊢N)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = eval-unsplit (lft (lft sp)) ((γ₁ , _ ⦂ _) , _ ⦂ _) γ₂ ⊢N
eval-unsplit sp γ₁ γ₂ (pair-E1 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (pair-E2 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (sum-I1 ⊢M)
rewrite eval-unsplit sp γ₁ γ₂ ⊢M = refl
eval-unsplit sp γ₁ γ₂ (sum-I2 ⊢N)
rewrite eval-unsplit sp γ₁ γ₂ ⊢N = refl
eval-unsplit sp γ₁ γ₂ (sum-E ⊢L ⊢M ⊢N (refl , refl))
rewrite eval-unsplit sp γ₁ γ₂ ⊢L
| ext (λ s → eval-unsplit (lft sp) (γ₁ , _ ⦂ s) γ₂ ⊢M)
| ext (λ t → eval-unsplit (lft sp) (γ₁ , _ ⦂ t) γ₂ ⊢N)
= refl
module rule-by-rule where
open positive-restricted
open Eq.≡-Reasoning
data _⊢_÷_ : Env Type → Expr → Type → Set₁ where
nat' :
--------------------
· ⊢ Nat n ÷ Base (_≡_ n) (_≟_ n)
var' :
( · , x ⦂ T) ⊢ Var x ÷ T
pair-I :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ M ÷ S →
Γ₂ ⊢ N ÷ T →
--------------------
Γ ⊢ Pair M N ÷ (S ⋆ T)
sum-I1 :
Γ ⊢ M ÷ S →
--------------------
Γ ⊢ Inl M ÷ (S ⊹ˡ T)
sum-I2 :
Γ ⊢ M ÷ T →
--------------------
Γ ⊢ Inr M ÷ (S ⊹ʳ T)
{- perhaps this rule should involve splitting between L and M,N -}
sum-Case :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ L ÷ (S ⊹ T) →
(Γ₂ , x ⦂ S) ⊢ M ÷ (U ⊹ˡ U′) →
(Γ₂ , y ⦂ T) ⊢ N ÷ (U ⊹ʳ U′) →
------------------------------
Γ ⊢ Case L x M y N ÷ (U ⊹ U′)
corr : Γ ⊢ M ÷ T → ∥ Γ ∥⁺ ⊢ M ⦂ ∥ T ∥
corr nat' =
nat
corr var' =
var found
corr (pair-I sp ÷M ÷N) =
pair (weaken (corr-sp sp) (corr ÷M)) (weaken (split-sym (corr-sp sp)) (corr ÷N))
corr (sum-I1 ÷M) =
sum-I1 (corr ÷M)
corr (sum-I2 ÷M) =
sum-I2 (corr ÷M)
corr (sum-Case sp ÷L ÷M ÷N) =
sum-E (weaken (corr-sp sp) (corr ÷L))
(weaken (split-sym (corr-sp (rgt sp))) (corr ÷M))
(weaken (split-sym (corr-sp (rgt sp))) (corr ÷N))
(refl , refl)
applySplit : {A : Set ℓ}{P : A → Set}{Θ Θ₁ Θ₂ : Env A} →
Split Θ Θ₁ Θ₂ → AllEnv A P Θ → AllEnv A P Θ₁ × AllEnv A P Θ₂
applySplit nil · = · , ·
applySplit (lft sp) (ae , x)
with applySplit sp ae
... | ae1 , ae2 = (ae1 , x) , ae2
applySplit (rgt sp) (ae , x)
with applySplit sp ae
... | ae1 , ae2 = ae1 , (ae2 , x)
lave' :
(÷M : Γ ⊢ M ÷ T) →
(posT : Pos T) →
(posΓ : AllEnv Type Pos Γ) →
∀ (t : T⟦ T ⟧) →
∃ λ (γ : jEnv T⟦_⟧ Γ) →
eval (corr ÷M) (toRawEnv posΓ γ) ≡ toRaw T posT t
lave' nat' Pos-Base posΓ (n , refl) = · , refl
lave' var' posT (· , posT') t rewrite pos-unique _ posT posT' = (· , _ ⦂ t) , refl
lave' (pair-I x ÷M ÷M₁) posT posΓ t = {!!}
lave' (sum-I1 ÷M) (Pos-⊹ˡ posT) posΓ t
with lave' ÷M posT posΓ t
... | γ , ih = γ , Eq.cong inj₁ ih
lave' (sum-I2 ÷M) (Pos-⊹ʳ posT) posΓ t
with lave' ÷M posT posΓ t
... | γ , ih = γ , Eq.cong inj₂ ih
lave' (sum-Case sp ÷M ÷M₁ ÷M₂) (Pos-⊹ posT posT₁) posΓ (inj₁ x)
with applySplit sp posΓ
... | posΓ₁ , posΓ₂
with lave' ÷M₁ (Pos-⊹ˡ posT) (posΓ₂ , {!!}) x
... | (γ₂ , _ ⦂ s) , ih₂
with lave' ÷M (Pos-⊹ {!!} {!!}) posΓ₁ (inj₁ s)
... | γ₁ , ih₁ =
let ih₂′ = {!eval-unsplit' sp γ₁ γ₂ posΓ₁ posΓ₂ (corr ÷M) !} in
(unsplit-env sp γ₁ γ₂) , {!!}
lave' (sum-Case sp ÷M ÷M₁ ÷M₂) (Pos-⊹ posT posT₁) posΓ (inj₂ y) = {!!}
lave :
(÷M : Γ ⊢ M ÷ T) →
(pos : Pos T) →
∀ (t : T⟦ T ⟧) →
∃ λ (γ : jEnv R⟦_⟧ ∥ Γ ∥⁺) →
eval (corr ÷M) γ ≡ toRaw T pos t
lave nat' Pos-Base (n , pn) = · , pn
lave var' pos t = (· , _ ⦂ toRaw _ pos t) , refl
lave (pair-I sp ÷M ÷N) (Pos-⋆ pos₁ pos₂) (t₁ , t₂)
with lave ÷M pos₁ t₁ | lave ÷N pos₂ t₂
... | γ₁ , ih₁ | γ₂ , ih₂ =
(unsplit-env (corr-sp sp) γ₁ γ₂) ,
Eq.cong₂ _,_
(begin (eval (weaken (corr-sp sp) (corr ÷M)) (unsplit-env (corr-sp sp) γ₁ γ₂)
≡⟨ eval-unsplit (corr-sp sp) γ₁ γ₂ (corr ÷M) ⟩
ih₁))
(begin (eval (weaken (split-sym (corr-sp sp)) (corr ÷N)) (unsplit-env (corr-sp sp) γ₁ γ₂)
≡⟨ Eq.cong (eval (weaken (split-sym (corr-sp sp)) (corr ÷N))) (unsplit-split (corr-sp sp) γ₁ γ₂) ⟩
eval (weaken (split-sym (corr-sp sp)) (corr ÷N)) (unsplit-env (split-sym (corr-sp sp)) γ₂ γ₁)
≡⟨ eval-unsplit (split-sym (corr-sp sp)) γ₂ γ₁ (corr ÷N) ⟩
ih₂))
lave (sum-I1 ÷M) (Pos-⊹ˡ pos) t
with lave ÷M pos t
... | γ , ih = γ , Eq.cong inj₁ ih
lave (sum-I2 ÷M) (Pos-⊹ʳ pos) t
with lave ÷M pos t
... | γ , ih = γ , Eq.cong inj₂ ih
lave (sum-Case sp ÷L ÷M ÷N) (Pos-⊹ p p₁) (inj₁ x)
with lave ÷M (Pos-⊹ˡ p) x
... | (γ₂ , _ ⦂ a) , ih₂
with lave ÷L {!!} (inj₁ {!!})
... | γ₁ , ih₁ = {!!}
lave (sum-Case sp ÷L ÷M ÷N) (Pos-⊹ p p₁) (inj₂ y) = {!!}
data _⊢_÷_ : Env Type → Expr → Type → Set₁ where
nat' :
--------------------
· ⊢ Nat n ÷ Base (_≡_ n) λ n₁ → n ≟ n₁
var1 :
( · , x ⦂ T) ⊢ Var x ÷ T
{-
var :
x ⦂ T ∈ Γ →
--------------------
Γ ⊢ Var x ÷ T
-}
lam :
(· , x ⦂ S) ⊢ M ÷ T →
--------------------
· ⊢ Lam x M ÷ (S ⇒ T)
pair :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ M ÷ S →
Γ₂ ⊢ N ÷ T →
--------------------
Γ ⊢ Pair M N ÷ (S ⋆ T)
pair-E1 :
Γ ⊢ M ÷ (S ⋆ T) →
--------------------
Γ ⊢ Fst M ÷ S
pair-E2 :
Γ ⊢ M ÷ (S ⋆ T) →
--------------------
Γ ⊢ Snd M ÷ T
sum-E :
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ L ÷ (S ⊹ T) →
(Γ₂ , x ⦂ S) ⊢ M ÷ U →
(Γ₂ , y ⦂ T) ⊢ N ÷ U →
--------------------
Γ ⊢ Case L x M y N ÷ U
sum-E′ : ∀ {ru′=ru″} →
Split Γ Γ₁ Γ₂ →
Γ₁ ⊢ L ÷ (S ⊹ T) →
(Γ₂ , x ⦂ S) ⊢ M ÷ U′ →
(Γ₂ , y ⦂ T) ⊢ N ÷ U″ →
U ≡ (U′ ⊔ U″){ru′=ru″} →
--------------------
Γ ⊢ Case L x M y N ÷ U
{-
`sub` :
Γ ⊢ M ÷ S →
T <: S →
--------------------
Γ ⊢ M ÷ T
-}
corr : Γ ⊢ M ÷ T → ∥ Γ ∥⁺ ⊢ M ⦂ ∥ T ∥
corr (nat') = nat
corr var1 = var found
-- corr (var x) = var x
corr (lam ⊢M) = lam (corr ⊢M)
corr (pair-E1 ÷M) = pair-E1 (corr ÷M)
corr (pair-E2 ÷M) = pair-E2 (corr ÷M)
corr (pair sp ÷M ÷N) =
pair (weaken (corr-sp sp) (corr ÷M)) (weaken (split-sym (corr-sp sp)) (corr ÷N))
corr (sum-E sp ÷L ÷M ÷N) =
sum-E (weaken (corr-sp sp) (corr ÷L))
(weaken (lft (split-sym (corr-sp sp))) (corr ÷M))
(weaken (lft (split-sym (corr-sp sp))) (corr ÷N))
(refl , refl)
corr (sum-E′ {S = S}{T = T}{U′ = U′}{U″ = U″}{U = U}{ru′=ru″ = ru′=ru″} sp ÷L ÷M ÷N refl) =
sum-E (weaken (corr-sp sp) (corr ÷L))
(weaken (lft (split-sym (corr-sp sp))) (corr ÷M))
(weaken (lft (split-sym (corr-sp sp))) (corr ÷N))
(⊔-preserves U′ U″)
-- pick one element of a type to demonstrate non-emptiness
one : ∀ (T : Type) {ne-T : ne T} → T⟦ T ⟧
one (Base P p) {ne-base ∃P} = ∃P
one Nat = zero
one (T ⇒ T₁) {ne-⇒ ne-T ne-T₁} = λ x → one T₁ {ne-T₁}
one (T ⋆ T₁) {ne-⋆ ne-T ne-T₁} = (one T {ne-T}) , (one T₁ {ne-T₁})
one (T ⊹ T₁) {ne-⊹L ne-T} = inj₁ (one T {ne-T})
one (T ⊹ T₁) {ne-⊹R ne-T₁} = inj₂ (one T₁ {ne-T₁})
{- not needed
many : iEnv E⟦ Γ ⟧
many {·} = ·
many {Γ , x ⦂ T} = many , x ⦂ one T
gen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → iEnv E⟦ Γ ⟧
gen found t = many , _ ⦂ t
gen (there x∈) t = (gen x∈ t) , _ ⦂ one {!!}
lookup-gen : (x∈ : x ⦂ T ∈ Γ) (t : T⟦ T ⟧) → lookup x∈ (gen x∈ t) ≡ t
lookup-gen found t = refl
lookup-gen (there x∈) t = lookup-gen x∈ t
-}
{-
-- soundness of the incorrectness rules
lave :
(÷M : Γ ⊢ M ÷ T) →
∀ (t : T⟦ T ⟧) →
∃ λ (γ : iEnv E⟦ Γ ⟧) →
eval (corr ÷M) γ ≡ t
lave nat' (n , refl) = · , refl
lave var1 t = (· , _ ⦂ t) , refl
-- lave (var x∈) t = (gen x∈ t) , lookup-gen x∈ t
lave (lam{x = x}{S = S} ÷M) t = · , ext aux
where
aux : (s : T⟦ S ⟧) → eval (corr ÷M) (· , x ⦂ s) ≡ t s
aux s with lave ÷M (t s)
... | (· , .x ⦂ a) , snd = {!!} -- impossible to complete!
lave (pair-E1 ÷M) t with lave ÷M (t , one {!!})
... | γ , ih = γ , Eq.cong proj₁ ih
lave (pair-E2 ÷M) t with lave ÷M (one {!!} , t)
... | γ , ih = γ , Eq.cong proj₂ ih
lave (pair sp ÷M ÷N) (s , t) with lave ÷M s | lave ÷N t
... | γ₁ , ih-M | γ₂ , ih-N =
unsplit-env sp γ₁ γ₂ ,
Eq.cong₂ _,_ (Eq.trans (eval-unsplit sp γ₁ γ₂ (corr ÷M)) ih-M)
(begin eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env sp γ₁ γ₂)
≡⟨ Eq.cong (eval (weaken (split-sym sp) (corr ÷N))) (unsplit-split sp γ₁ γ₂) ⟩
eval (weaken (split-sym sp) (corr ÷N)) (unsplit-env (split-sym sp) γ₂ γ₁)
≡⟨ eval-unsplit (split-sym sp) γ₂ γ₁ (corr ÷N) ⟩
ih-N)
-- works, but unsatisfactory!
-- this proof uses only one branch of the case
-- this choice is possible because both branches ÷M and ÷N have the same type
-- in general, U could be the union of the types of ÷M and ÷N
lave (sum-E{S = S}{T = T}{U = U} sp ÷L ÷M ÷N) u
with lave ÷M u | lave ÷N u
... | (γ₁ , x ⦂ s) , ih-M | (γ₂ , y ⦂ t) , ih-N
with lave ÷L (inj₁ s)
... | γ₀ , ih-L
=
unsplit-env sp γ₀ γ₁ ,
(begin [
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
(eval (weaken sp (corr ÷L)) (unsplit-env sp γ₀ γ₁))
≡⟨ Eq.cong [
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
] (eval-unsplit sp γ₀ γ₁ (corr ÷L)) ⟩
[
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
(eval (corr ÷L) γ₀)
≡⟨ Eq.cong
[
(λ s₁ →
eval (weaken (lft (split-sym sp)) (corr ÷M))
(unsplit-env sp γ₀ γ₁ , x ⦂ s₁))
,
(λ t₁ →
eval (weaken (lft (split-sym sp)) (corr ÷N))
(unsplit-env sp γ₀ γ₁ , y ⦂ t₁))
]
ih-L ⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env sp γ₀ γ₁ , x ⦂ s)
≡⟨ Eq.cong (λ γ → eval (weaken (lft (split-sym sp)) (corr ÷M)) (γ , x ⦂ s)) (unsplit-split sp γ₀ γ₁) ⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (split-sym sp) γ₁ γ₀ , x ⦂ s)
≡⟨⟩
eval (weaken (lft (split-sym sp)) (corr ÷M)) (unsplit-env (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀)
≡⟨ eval-unsplit (lft (split-sym sp)) (γ₁ , x ⦂ s) γ₀ (corr ÷M) ⟩
ih-M)
lave (sum-E′{S = S}{T = T}{U = U} sp ÷L ÷M ÷N uuu) u = {!!}
-}
-- unused stuff
{- unused - needed?
record _←_ (A B : Set) : Set where
field
func : A → B
back : ∀ (b : B) → ∃ λ (a : A) → func a ≡ b
open _←_
-}
|
{
"alphanum_fraction": 0.4770508232,
"avg_line_length": 32.0119156737,
"ext": "agda",
"hexsha": "fa99160e962b7be48717e73c349e8a47275ee48f",
"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": "91a5ff5267089e6ed0d2f6d3998633ba1842b397",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "proglang/incorrectness",
"max_forks_repo_path": "src/RawSemantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "91a5ff5267089e6ed0d2f6d3998633ba1842b397",
"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": "proglang/incorrectness",
"max_issues_repo_path": "src/RawSemantics.agda",
"max_line_length": 128,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "91a5ff5267089e6ed0d2f6d3998633ba1842b397",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "proglang/incorrectness",
"max_stars_repo_path": "src/RawSemantics.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-17T19:13:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-06-17T19:13:13.000Z",
"num_tokens": 17453,
"size": 34925
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Many properties which hold for `∼` also hold for `flip ∼`. Unlike
-- the module `Relation.Binary.Construct.Flip` this module does not
-- flip the underlying equality.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Construct.Converse where
open import Function
open import Data.Product
------------------------------------------------------------------------
-- Properties
module _ {a ℓ} {A : Set a} (∼ : Rel A ℓ) where
refl : Reflexive ∼ → Reflexive (flip ∼)
refl refl = refl
sym : Symmetric ∼ → Symmetric (flip ∼)
sym sym = sym
trans : Transitive ∼ → Transitive (flip ∼)
trans trans = flip trans
asym : Asymmetric ∼ → Asymmetric (flip ∼)
asym asym = asym
total : Total ∼ → Total (flip ∼)
total total x y = total y x
resp : ∀ {p} (P : A → Set p) → Symmetric ∼ →
P Respects ∼ → P Respects (flip ∼)
resp _ sym resp ∼ = resp (sym ∼)
max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥
max min = min
min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤
min max = max
module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} (∼ : Rel A ℓ₂) where
reflexive : Symmetric ≈ → (≈ ⇒ ∼) → (≈ ⇒ flip ∼)
reflexive sym impl = impl ∘ sym
irrefl : Symmetric ≈ → Irreflexive ≈ ∼ → Irreflexive ≈ (flip ∼)
irrefl sym irrefl x≈y y∼x = irrefl (sym x≈y) y∼x
antisym : Antisymmetric ≈ ∼ → Antisymmetric ≈ (flip ∼)
antisym antisym = flip antisym
compare : Trichotomous ≈ ∼ → Trichotomous ≈ (flip ∼)
compare cmp x y with cmp x y
... | tri< x<y x≉y y≮x = tri> y≮x x≉y x<y
... | tri≈ x≮y x≈y y≮x = tri≈ y≮x x≈y x≮y
... | tri> x≮y x≉y y<x = tri< y<x x≉y x≮y
module _ {a ℓ₁ ℓ₂} {A : Set a} (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where
resp₂ : ∼₁ Respects₂ ∼₂ → (flip ∼₁) Respects₂ ∼₂
resp₂ (resp₁ , resp₂) = resp₂ , resp₁
module _ {a b ℓ} {A : Set a} {B : Set b} (∼ : REL A B ℓ) where
dec : Decidable ∼ → Decidable (flip ∼)
dec dec = flip dec
------------------------------------------------------------------------
-- Structures
module _ {a ℓ} {A : Set a} {≈ : Rel A ℓ} where
isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈)
isEquivalence eq = record
{ refl = refl ≈ Eq.refl
; sym = sym ≈ Eq.sym
; trans = trans ≈ Eq.trans
}
where module Eq = IsEquivalence eq
isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈)
isDecEquivalence eq = record
{ isEquivalence = isEquivalence Dec.isEquivalence
; _≟_ = dec ≈ Dec._≟_
}
where module Dec = IsDecEquivalence eq
module _ {a ℓ₁ ℓ₂} {A : Set a} {≈ : Rel A ℓ₁} {∼ : Rel A ℓ₂} where
isPreorder : IsPreorder ≈ ∼ → IsPreorder ≈ (flip ∼)
isPreorder O = record
{ isEquivalence = O.isEquivalence
; reflexive = reflexive ∼ O.Eq.sym O.reflexive
; trans = trans ∼ O.trans
}
where module O = IsPreorder O
isPartialOrder : IsPartialOrder ≈ ∼ → IsPartialOrder ≈ (flip ∼)
isPartialOrder O = record
{ isPreorder = isPreorder O.isPreorder
; antisym = antisym ∼ O.antisym
}
where module O = IsPartialOrder O
isTotalOrder : IsTotalOrder ≈ ∼ → IsTotalOrder ≈ (flip ∼)
isTotalOrder O = record
{ isPartialOrder = isPartialOrder O.isPartialOrder
; total = total ∼ O.total
}
where module O = IsTotalOrder O
isDecTotalOrder : IsDecTotalOrder ≈ ∼ → IsDecTotalOrder ≈ (flip ∼)
isDecTotalOrder O = record
{ isTotalOrder = isTotalOrder O.isTotalOrder
; _≟_ = O._≟_
; _≤?_ = dec ∼ O._≤?_
}
where module O = IsDecTotalOrder O
isStrictPartialOrder : IsStrictPartialOrder ≈ ∼ →
IsStrictPartialOrder ≈ (flip ∼)
isStrictPartialOrder O = record
{ isEquivalence = O.isEquivalence
; irrefl = irrefl ∼ O.Eq.sym O.irrefl
; trans = trans ∼ O.trans
; <-resp-≈ = resp₂ ∼ ≈ O.<-resp-≈
}
where module O = IsStrictPartialOrder O
isStrictTotalOrder : IsStrictTotalOrder ≈ ∼ →
IsStrictTotalOrder ≈ (flip ∼)
isStrictTotalOrder O = record
{ isEquivalence = O.isEquivalence
; trans = trans ∼ O.trans
; compare = compare ∼ O.compare
}
where module O = IsStrictTotalOrder O
module _ {a ℓ} where
setoid : Setoid a ℓ → Setoid a ℓ
setoid S = record
{ isEquivalence = isEquivalence S.isEquivalence
}
where module S = Setoid S
decSetoid : DecSetoid a ℓ → DecSetoid a ℓ
decSetoid S = record
{ isDecEquivalence = isDecEquivalence S.isDecEquivalence
}
where module S = DecSetoid S
module _ {a ℓ₁ ℓ₂} where
preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂
preorder O = record
{ isPreorder = isPreorder O.isPreorder
}
where module O = Preorder O
poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂
poset O = record
{ isPartialOrder = isPartialOrder O.isPartialOrder
}
where module O = Poset O
totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂
totalOrder O = record
{ isTotalOrder = isTotalOrder O.isTotalOrder
}
where module O = TotalOrder O
decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂
decTotalOrder O = record
{ isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder
}
where module O = DecTotalOrder O
strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ →
StrictPartialOrder a ℓ₁ ℓ₂
strictPartialOrder O = record
{ isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder
}
where module O = StrictPartialOrder O
strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ →
StrictTotalOrder a ℓ₁ ℓ₂
strictTotalOrder O = record
{ isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder
}
where module O = StrictTotalOrder O
|
{
"alphanum_fraction": 0.5921655079,
"avg_line_length": 29.6331658291,
"ext": "agda",
"hexsha": "76e271c3a9eabafab9f4818af740a98d2d347145",
"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/Relation/Binary/Construct/Converse.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/Binary/Construct/Converse.agda",
"max_line_length": 72,
"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/Relation/Binary/Construct/Converse.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": 1986,
"size": 5897
}
|
-- {-# OPTIONS -v tc.conv:50 -v tc.reduce:100 -v tc:50 -v tc.term.expr.coind:15 -v tc.meta:20 #-}
-- 2012-03-15, reported by Nisse
module Issue585 where
open import Common.Coinduction
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
data Fin : ℕ → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
infixr 5 _∷_
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
lookup : ∀ {n A} → Fin n → Vec A n → A
lookup zero (x ∷ xs) = x
lookup (suc i) (x ∷ xs) = lookup i xs
infixl 9 _·_
data Tm (n : ℕ) : Set where
var : Fin n → Tm n
ƛ : Tm (suc n) → Tm n
_·_ : Tm n → Tm n → Tm n
infixr 8 _⇾_
data Ty : Set where
_⇾_ : ∞ Ty → ∞ Ty → Ty
Ctxt : ℕ → Set
Ctxt n = Vec Ty n
infix 4 _⊢_∈_
data _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty → Set where
var : ∀ {x} → Γ ⊢ var x ∈ lookup x Γ
ƛ : ∀ {t σ τ} → ♭ σ ∷ Γ ⊢ t ∈ ♭ τ → Γ ⊢ ƛ t ∈ σ ⇾ τ
_·_ : ∀ {t₁ t₂ σ τ} → Γ ⊢ t₁ ∈ σ ⇾ τ → Γ ⊢ t₂ ∈ ♭ σ →
Γ ⊢ t₁ · t₂ ∈ ♭ τ
Ω : Tm zero
Ω = ω · ω
where ω = ƛ (var zero · var zero)
Ω-has-any-type : ∀ τ → [] ⊢ Ω ∈ τ
Ω-has-any-type τ =
_·_ {σ = σ} {τ = ♯ _} (ƛ (var · var)) (ƛ (var · var))
where
σ : ∞ Ty
σ = ♯ (σ ⇾ ♯ _) -- τ)
-- If the last
-- underscore is replaced by τ, then the code checks successfully.
-- WAS: Agda seems to loop when checking Ω-has-any-type.
-- NOW: this should leave metas unsolved.
|
{
"alphanum_fraction": 0.5041958042,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "11e9e7da84e9afb1d156ffbd2c0f879dc8369363",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue585.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"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/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue585.agda",
"max_line_length": 97,
"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/Issue585.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": 649,
"size": 1430
}
|
module IPC.Metatheory.Gentzen-KripkeExploding where
open import IPC.Syntax.Gentzen public
open import IPC.Semantics.KripkeExploding public
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam {A} {B} t) γ = return {A ▻ B} λ ξ a →
eval t (mono⊩⋆ ξ γ , a)
eval (app {A} {B} t u) γ = bind {A ▻ B} {B} (eval t γ) λ ξ f →
_⟪$⟫_ {A} {B} f (eval u (mono⊩⋆ ξ γ))
eval (pair {A} {B} t u) γ = return {A ∧ B} (eval t γ , eval u γ)
eval (fst {A} {B} t) γ = bind {A ∧ B} {A} (eval t γ) (K π₁)
eval (snd {A} {B} t) γ = bind {A ∧ B} {B} (eval t γ) (K π₂)
eval unit γ = return {⊤} ∙
eval (boom {C} t) γ = bind {⊥} {C} (eval t γ) (K elim𝟘)
eval (inl {A} {B} t) γ = return {A ∨ B} (ι₁ (eval t γ))
eval (inr {A} {B} t) γ = return {A ∨ B} (ι₂ (eval t γ))
eval (case {A} {B} {C} t u v) γ = bind {A ∨ B} {C} (eval t γ) λ ξ s → elim⊎ s
(λ a → eval u (mono⊩⋆ ξ γ , λ ξ′ k → a ξ′ k))
(λ b → eval v (mono⊩⋆ ξ γ , λ ξ′ k → b ξ′ k))
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ World = Cx Ty
; _≤_ = _⊆_
; refl≤ = refl⊆
; trans≤ = trans⊆
; _⊪ᵅ_ = λ Γ P → Γ ⊢ α P
; mono⊪ᵅ = mono⊢
; _‼_ = λ Γ A → Γ ⊢ A
}
-- Soundness and completeness with respect to the canonical model.
mutual
reflectᶜ : ∀ {A Γ} → Γ ⊢ A → Γ ⊩ A
reflectᶜ {α P} t = return {α P} t
reflectᶜ {A ▻ B} t = return {A ▻ B} λ η a →
reflectᶜ {B} (app (mono⊢ η t) (reifyᶜ {A} a))
reflectᶜ {A ∧ B} t = return {A ∧ B} (reflectᶜ {A} (fst t) , reflectᶜ {B} (snd t))
reflectᶜ {⊤} t = return {⊤} ∙
reflectᶜ {⊥} t = λ η k → boom (mono⊢ η t)
reflectᶜ {A ∨ B} t = λ η k → case (mono⊢ η t)
(k weak⊆ (ι₁ (reflectᶜ {A} v₀)))
(k weak⊆ (ι₂ (reflectᶜ {B} (v₀))))
reifyᶜ : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ A
reifyᶜ {α P} k = k refl≤ λ η s → s
reifyᶜ {A ▻ B} k = k refl≤ λ η s → lam (reifyᶜ {B} (s weak⊆ (reflectᶜ {A} (v₀))))
reifyᶜ {A ∧ B} k = k refl≤ λ η s → pair (reifyᶜ {A} (π₁ s)) (reifyᶜ {B} (π₂ s))
reifyᶜ {⊤} k = k refl≤ λ η s → unit
reifyᶜ {⊥} k = k refl≤ λ η ()
reifyᶜ {A ∨ B} k = k refl≤ λ η s → elim⊎ s
(λ a → inl (reifyᶜ {A} (λ η′ k → a η′ k)))
(λ b → inr (reifyᶜ {B} (λ η′ k → b η′ k)))
reflectᶜ⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
reifyᶜ⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ Ξ
reifyᶜ⋆ {∅} ∙ = ∙
reifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reifyᶜ⋆ ts) (reifyᶜ⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = reifyᶜ (s refl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
|
{
"alphanum_fraction": 0.4501748252,
"avg_line_length": 33.9801980198,
"ext": "agda",
"hexsha": "060602877b50b42f5ad0aa2016bfd7612db56b69",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Metatheory/Gentzen-KripkeExploding.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Metatheory/Gentzen-KripkeExploding.agda",
"max_line_length": 83,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Metatheory/Gentzen-KripkeExploding.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1606,
"size": 3432
}
|
-- 2013-11-xx Andreas
-- Previous clauses did not reduce in later clauses under
-- a module telescope.
{-# OPTIONS --copatterns #-}
-- {-# OPTIONS -v interaction.give:20 -v tc.cc:60 -v reify.clause:60 -v tc.section.check:10 -v tc:90 #-}
-- {-# OPTIONS -v tc.lhs:20 #-}
-- {-# OPTIONS -v tc.cover:20 #-}
module Issue937 where
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
infixr 4 _,_
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
data _≤_ : Nat → Nat → Set where
z≤n : ∀ {n} → zero ≤ n
s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n
_<_ : Nat → Nat → Set
m < n = suc m ≤ n
ex : Σ Nat (λ n → zero < n)
proj₁ ex = suc zero
proj₂ ex = s≤s z≤n -- works
ex' : Σ Nat (λ n → zero < n)
proj₁ ex' = suc zero
proj₂ ex' = {! s≤s z≤n !}
module _ (A : Set) where
ex'' : Σ Nat (λ n → zero < n)
proj₁ ex'' = suc zero
proj₂ ex'' = s≤s z≤n -- works
ex''' : Σ Nat (λ n → zero < n)
proj₁ ex''' = suc zero
proj₂ ex''' = {! s≤s z≤n !}
-- The normalized goals should be printed as 1 ≤ 1
|
{
"alphanum_fraction": 0.5523724261,
"avg_line_length": 21.0754716981,
"ext": "agda",
"hexsha": "61303691611d08d83762c4f11eded95a4370c417",
"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/Issue937.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/Issue937.agda",
"max_line_length": 104,
"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/Issue937.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": 431,
"size": 1117
}
|
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness #-}
open import Data.Product
open import Data.Sum
open import Common
module Progress {ℙ : Set} (message : Message ℙ)
where
open import SessionType message
open import Transitions message
open import Session message
data Progress : Session -> Set where
win#def : ∀{T S} (w : Win T) (def : Defined S) -> Progress (T # S)
inp#out : ∀{f g} (W : Witness g) -> Progress (inp f # out g)
out#inp : ∀{f g} (W : Witness f) -> Progress (out f # inp g)
progress-sound : ∀{S} -> Progress S -> ProgressS S
progress-sound (win#def e def) = inj₁ (win#def e def)
progress-sound (inp#out (_ , !x)) = inj₂ (_ , sync inp (out !x))
progress-sound (out#inp (_ , !x)) = inj₂ (_ , sync (out !x) inp)
progress-complete : ∀{S} -> ProgressS S -> Progress S
progress-complete (inj₁ (win#def e def)) = win#def e def
progress-complete (inj₂ (_ , sync inp (out !x))) = inp#out (_ , !x)
progress-complete (inj₂ (_ , sync (out !x) inp)) = out#inp (_ , !x)
|
{
"alphanum_fraction": 0.7069128788,
"avg_line_length": 39.1111111111,
"ext": "agda",
"hexsha": "0389cf63b7090bdc41f8d1d0022171fcf4d6eddc",
"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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/Progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"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": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/Progress.agda",
"max_line_length": 68,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/Progress.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 554,
"size": 2112
}
|
open import Functional
open import Logic
open import Logic.Propositional
open import Type
module Relator.Ordering where
module From-[<][≡] {ℓ₁}{ℓ₂}{ℓ₃} {T : Type{ℓ₁}} (_<_ : T → T → Stmt{ℓ₂}) (_≡_ : T → T → Stmt{ℓ₃}) where
-- Greater than
_>_ : T → T → Stmt
_>_ = swap(_<_)
-- Lesser than or equals
_≤_ : T → T → Stmt
x ≤ y = (x < y) ∨ (x ≡ y)
-- Greater than or equals
_≥_ : T → T → Stmt
x ≥ y = (x > y) ∨ (x ≡ y)
-- In an open interval
_<_<_ : T → T → T → Stmt
x < y < z = (x < y) ∧ (y < z)
-- In an closed interval
_≤_≤_ : T → T → T → Stmt
x ≤ y ≤ z = (x ≤ y) ∧ (y ≤ z)
_≮_ : T → T → Stmt
_≮_ = (¬_) ∘₂ (_<_)
_≯_ : T → T → Stmt
_≯_ = (¬_) ∘₂ (_>_)
_≰_ : T → T → Stmt
_≰_ = (¬_) ∘₂ (_≤_)
_≱_ : T → T → Stmt
_≱_ = (¬_) ∘₂ (_≥_)
module From-[≤] {ℓ₁}{ℓ₂} {T : Type{ℓ₁}} (_≤_ : T → T → Stmt{ℓ₂}) where
-- Greater than or equals
_≥_ : T → T → Stmt
_≥_ = swap(_≤_)
_≰_ : T → T → Stmt
_≰_ = (¬_) ∘₂ (_≤_)
_≱_ : T → T → Stmt
_≱_ = swap(_≰_)
-- Greater than
_>_ : T → T → Stmt
_>_ = _≰_
-- Lesser than or equals
_<_ : T → T → Stmt
_<_ = swap(_>_)
-- In an open interval
_<_<_ : T → T → T → Stmt
x < y < z = (x < y) ∧ (y < z)
-- In an closed interval
_≤_≤_ : T → T → T → Stmt
x ≤ y ≤ z = (x ≤ y) ∧ (y ≤ z)
_≮_ : T → T → Stmt
_≮_ = (¬_) ∘₂ (_<_)
_≯_ : T → T → Stmt
_≯_ = (¬_) ∘₂ (_>_)
module From-[≤][<] {ℓ₁}{ℓ₂}{ℓ₃} {T : Type{ℓ₁}} (_≤_ : T → T → Stmt{ℓ₂}) (_<_ : T → T → Stmt{ℓ₃}) where
-- Greater than
_>_ : T → T → Stmt
_>_ = swap(_<_)
-- Greater than or equals
_≥_ : T → T → Stmt
_≥_ = swap(_≤_)
-- In an open interval
_<_<_ : T → T → T → Stmt
x < y < z = (x < y) ∧ (y < z)
-- In an closed interval
_≤_≤_ : T → T → T → Stmt
x ≤ y ≤ z = (x ≤ y) ∧ (y ≤ z)
_≮_ : T → T → Stmt
_≮_ = (¬_) ∘₂ (_<_)
_≯_ : T → T → Stmt
_≯_ = (¬_) ∘₂ (_>_)
_≰_ : T → T → Stmt
_≰_ = (¬_) ∘₂ (_≤_)
_≱_ : T → T → Stmt
_≱_ = (¬_) ∘₂ (_≥_)
module From-[≤][≢] {ℓ₁}{ℓ₂}{ℓ₃} {T : Type{ℓ₁}} (_≤_ : T → T → Stmt{ℓ₂}) (_≢_ : T → T → Stmt{ℓ₃}) where
-- Lesser than or equals
_<_ : T → T → Stmt
x < y = (x ≤ y) ∧ (x ≢ y)
-- Greater than
_>_ : T → T → Stmt
_>_ = swap(_<_)
-- Greater than or equals
_≥_ : T → T → Stmt
_≥_ = swap(_≤_)
-- In an open interval
_<_<_ : T → T → T → Stmt
x < y < z = (x < y) ∧ (y < z)
-- In an closed interval
_≤_≤_ : T → T → T → Stmt
x ≤ y ≤ z = (x ≤ y) ∧ (y ≤ z)
_≮_ : T → T → Stmt
_≮_ = (¬_) ∘₂ (_<_)
_≯_ : T → T → Stmt
_≯_ = (¬_) ∘₂ (_>_)
_≰_ : T → T → Stmt
_≰_ = (¬_) ∘₂ (_≤_)
_≱_ : T → T → Stmt
_≱_ = (¬_) ∘₂ (_≥_)
|
{
"alphanum_fraction": 0.4281894576,
"avg_line_length": 19.3925925926,
"ext": "agda",
"hexsha": "f6197a2778774a1f163d015581efa3a06f056c0c",
"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": "Relator/Ordering.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": "Relator/Ordering.agda",
"max_line_length": 102,
"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": "Relator/Ordering.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": 1336,
"size": 2618
}
|
{-
This second-order equational theory was created from the following second-order syntax description:
syntax Sub | S
type
L : 0-ary
T : 0-ary
term
vr : L -> T
sb : L.T T -> T
theory
(C) x y : T |> sb (a. x[], y[]) = x[]
(L) x : T |> sb (a. vr(a), x[]) = x[]
(R) a : L x : L.T |> sb (b. x[b], vr(a[])) = x[a[]]
(A) x : (L,L).T y : L.T z : T |> sb (a. sb (b. x[a,b], y[a]), z[]) = sb (b. sb (a. x[a, b], z[]), sb (a. y[a], z[]))
-}
module Sub.Equality where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Families.Build
open import SOAS.ContextMaps.Inductive
open import Sub.Signature
open import Sub.Syntax
open import SOAS.Metatheory.SecondOrder.Metasubstitution S:Syn
open import SOAS.Metatheory.SecondOrder.Equality S:Syn
private
variable
α β γ τ : ST
Γ Δ Π : Ctx
infix 1 _▹_⊢_≋ₐ_
-- Axioms of equality
data _▹_⊢_≋ₐ_ : ∀ 𝔐 Γ {α} → (𝔐 ▷ S) α Γ → (𝔐 ▷ S) α Γ → Set where
C : ⁅ T ⁆ ⁅ T ⁆̣ ▹ ∅ ⊢ sb 𝔞 𝔟 ≋ₐ 𝔞
L : ⁅ T ⁆̣ ▹ ∅ ⊢ sb (vr x₀) 𝔞 ≋ₐ 𝔞
R : ⁅ L ⁆ ⁅ L ⊩ T ⁆̣ ▹ ∅ ⊢ sb (𝔟⟨ x₀ ⟩) (vr 𝔞) ≋ₐ 𝔟⟨ 𝔞 ⟩
A : ⁅ L · L ⊩ T ⁆ ⁅ L ⊩ T ⁆ ⁅ T ⁆̣ ▹ ∅
⊢ sb (sb (𝔞⟨ x₁ ◂ x₀ ⟩) (𝔟⟨ x₀ ⟩)) 𝔠
≋ₐ sb (sb (𝔞⟨ x₀ ◂ x₁ ⟩) 𝔠) (sb (𝔟⟨ x₀ ⟩) 𝔠)
open EqLogic _▹_⊢_≋ₐ_
open ≋-Reasoning
|
{
"alphanum_fraction": 0.527027027,
"avg_line_length": 24.6666666667,
"ext": "agda",
"hexsha": "51be70bf3bcc28f9afc61859c6233e9aba46d642",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Sub/Equality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Sub/Equality.agda",
"max_line_length": 120,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Sub/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 659,
"size": 1332
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Functions.Definition
module Orders.Partial.Definition {a : _} (carrier : Set a) where
record PartialOrder {b : _} : Set (a ⊔ lsuc b) where
field
_<_ : Rel {a} {b} carrier
irreflexive : {x : carrier} → (x < x) → False
<Transitive : {a b c : carrier} → (a < b) → (b < c) → (a < c)
<WellDefined : {r s t u : carrier} → (r ≡ t) → (s ≡ u) → r < s → t < u
<WellDefined refl refl r<s = r<s
|
{
"alphanum_fraction": 0.6018018018,
"avg_line_length": 32.6470588235,
"ext": "agda",
"hexsha": "c5d1a5273b81901b87ce8b583d926c7bc2e1bfe9",
"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": "Orders/Partial/Definition.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": "Orders/Partial/Definition.agda",
"max_line_length": 72,
"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": "Orders/Partial/Definition.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": 199,
"size": 555
}
|
module x08-747Quantifiers-hc where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; z≤n; s≤s) -- added ≤
-- open import Data.Nat.Properties using (≤-refl)
open import Relation.Nullary using (¬_)
open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩) -- added proj₂
open import Data.Sum using (_⊎_; inj₁; inj₂ ) -- added inj₁, inj₂
open import Function using (_∘_) -- added
-- BEGIN: Copied from 747Isomorphism.
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
infix 0 _≃_
record _≃_ (A B : Set) : Set where
constructor mk-≃
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
-- END: Copied from 747Isomorphism.
-- Logical forall is ∀.
-- Forall elimination is function application.
∀-elim : ∀ {A : Set} {B : A → Set}
→ (L : ∀ (x : A) → B x)
→ (M : A)
-----------------
→ B M
∀-elim L M = L M
-- A → B is nicer syntax for ∀ (_ : A) → B.
-- 747/PLFA exercise: ForAllDistProd (1 point)
-- ∀ distributes over ×
-- (note: → distributes over × was shown in Connectives)
∀-distrib-× : ∀ {A : Set} {B C : A → Set} →
(∀ (a : A) → B a × C a) ≃ (∀ (a : A) → B a) × (∀ (a : A) → C a)
to ∀-distrib-× a→Ba×Ca = ⟨ proj₁ ∘ a→Ba×Ca , proj₂ ∘ a→Ba×Ca ⟩
from ∀-distrib-× ⟨ a→ba , a→ca ⟩ = λ a → ⟨ a→ba a , a→ca a ⟩
from∘to ∀-distrib-× a→Ba×Ca = refl
to∘from ∀-distrib-× ⟨ a→ba , a→ca ⟩ = refl
-- 747/PLFA exercise: SumForAllImpForAllSum (1 point)
-- disjunction of foralls implies a forall of disjunctions
⊎∀-implies-∀⊎ : ∀ {A : Set} {B C : A → Set} →
(∀ (a : A) → B a) ⊎ (∀ (a : A) → C a) → ∀ (a : A) → B a ⊎ C a
⊎∀-implies-∀⊎ (inj₁ a→ba) = inj₁ ∘ a→ba
⊎∀-implies-∀⊎ (inj₂ a→ca) = inj₂ ∘ a→ca
-- Existential quantification
-- a pair:
-- - a witness and
-- - a proof that the witness satisfies the property
data Σ (A : Set) (B : A → Set) : Set where
⟨_,_⟩ : (a : A) → B a → Σ A B
-- convenient syntax
Σ-syntax = Σ
infix 2 Σ-syntax
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
-- can use the RHS syntax in code,
-- but LHS will show up in displays of goal and context.
-- This syntax is equivalent to defining a dependent record type.
record Σ′ (A : Set) (B : A → Set) : Set where
field
proj₁′ : A
proj₂′ : B proj₁′
-- convention : library uses ∃ when domain of bound variable is implicit
∃ : ∀ {A : Set} (B : A → Set) → Set
∃ {A} B = Σ A B
-- syntax
∃-syntax = ∃
syntax ∃-syntax (λ x → B) = ∃[ x ] B
-- eliminate existential with a function
-- that consumes the witness and proof
-- and reaches a conclusion C
∃-elim : ∀ {A : Set} {B : A → Set} {C : Set}
→ (∀ a → B a → C)
→ ∃[ a ] B a
---------------
→ C
∃-elim a→Ba→C ⟨ a , Ba ⟩ = a→Ba→C a Ba
-- generalization of currying (from Connectives)
-- currying : ∀ {A B C : Set} → (A → B → C) ≃ (A × B → C)
∀∃-currying : ∀ {A : Set} {B : A → Set} {C : Set}
→ (∀ a → B a → C) ≃ (∃[ a ] B a → C)
_≃_.to ∀∃-currying a→Ba→C ⟨ a , Ba ⟩ = a→Ba→C a Ba
_≃_.from ∀∃-currying ∃xB a Ba = ∃xB ⟨ a , Ba ⟩
_≃_.from∘to ∀∃-currying a→Ba→C = refl
_≃_.to∘from ∀∃-currying ∃xB = extensionality λ { ⟨ a , Ba ⟩ → refl}
-- 747/PLFA exercise: ExistsDistSum (2 points)
-- existentials distribute over disjunction
∃-distrib-⊎ : ∀ {A : Set} {B C : A → Set} →
∃[ a ] (B a ⊎ C a) ≃ (∃[ a ] B a) ⊎ (∃[ a ] C a)
to ∃-distrib-⊎ ⟨ a , inj₁ Ba ⟩ = inj₁ ⟨ a , Ba ⟩
to ∃-distrib-⊎ ⟨ a , inj₂ Ca ⟩ = inj₂ ⟨ a , Ca ⟩
from ∃-distrib-⊎ (inj₁ ⟨ a , Ba ⟩) = ⟨ a , inj₁ Ba ⟩
from ∃-distrib-⊎ (inj₂ ⟨ a , Ca ⟩) = ⟨ a , inj₂ Ca ⟩
from∘to ∃-distrib-⊎ ⟨ a , inj₁ Ba ⟩ = refl
from∘to ∃-distrib-⊎ ⟨ a , inj₂ Ca ⟩ = refl
to∘from ∃-distrib-⊎ (inj₁ ⟨ a , Ba ⟩) = refl
to∘from ∃-distrib-⊎ (inj₂ ⟨ a , Ca ⟩) = refl
-- 747/PLFA exercise: ExistsProdImpProdExists (1 point)
-- existentials distribute over ×
∃×-implies-×∃ : ∀ {A : Set} {B C : A → Set} →
∃[ a ] (B a × C a) → (∃[ a ] B a) × (∃[ a ] C a)
∃×-implies-×∃ ⟨ a , ⟨ Ba , Ca ⟩ ⟩ = ⟨ ⟨ a , Ba ⟩ , ⟨ a , Ca ⟩ ⟩
-- existential example: revisiting even/odd.
-- mutually-recursive definitions of even and odd.
data even : ℕ → Set
data odd : ℕ → Set
data even where
even-zero : even zero
even-suc : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
data odd where
odd-suc : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
-- number is even iff it is double some other number
even-∃ : ∀ {n : ℕ} → even n → ∃[ m ] ( m * 2 ≡ n)
-- number is odd iff it is one plus double some other number
odd-∃ : ∀ {n : ℕ} → odd n → ∃[ m ] (1 + m * 2 ≡ n)
even-∃ even-zero = ⟨ zero , refl ⟩
even-∃ (even-suc odd-suc-x*2)
with odd-∃ odd-suc-x*2
... | ⟨ x , refl ⟩ = ⟨ suc x , refl ⟩
odd-∃ (odd-suc even-x*2)
with even-∃ even-x*2
... | ⟨ x , refl ⟩ = ⟨ x , refl ⟩
∃-even : ∀ {n : ℕ} → ∃[ m ] ( m * 2 ≡ n) → even n
∃-odd : ∀ {n : ℕ} → ∃[ m ] (1 + m * 2 ≡ n) → odd n
∃-even ⟨ zero , refl ⟩ = even-zero
∃-even ⟨ suc x , refl ⟩ = even-suc (∃-odd ⟨ x , refl ⟩)
∃-odd ⟨ x , refl ⟩ = odd-suc (∃-even ⟨ x , refl ⟩)
-- PLFA exercise: what if we write the arithmetic more "naturally"?
-- (Proof gets harder but is still doable).
-- 747/PLFA exercise: AltLE (3 points)
-- alternate definition of y ≤ z
-- (Optional exercise: Is this an isomorphism?)
+0 : ∀ (m : ℕ) → m + zero ≡ m
+0 zero = refl
+0 (suc m) = cong suc (+0 m)
open import x03-842Relations-hc-2 using (s≤s)
xxx : ∀ {m n : ℕ} → m ≤ n → suc (m + zero) ≤ suc n
xxx {m} {n} p rewrite +0 m = s≤s p
≤-refl : ∀ {n : ℕ}
-----
→ n ≤ n
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s (≤-refl {n})
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
aaa : ∀ {x y z : ℕ} → y + suc x ≡ z → y ≤ y + suc x
--aaa {x} {y} y+sucx≡z rewrite sym y+sucx≡z {- | +-suc y x -} = {!!}
aaa {zero} {zero} refl = z≤n
aaa {suc x} {zero} refl = z≤n
aaa {zero} {suc y} refl = s≤s {!!}
aaa {suc x} {suc y} refl = s≤s {!!}
zzz : ∀ {y z : ℕ} → y + zero ≡ z → y ≤ z
zzz {y} y+x≡z rewrite +0 y | y+x≡z | sym y+x≡z = ≤-refl {y}
∃-≤ : ∀ {y z : ℕ} → ( (y ≤ z) ⇔ ( ∃[ x ] (y + x ≡ z) ) )
{-
∃-≤ {y} {z} = record { to = λ { z≤n → ⟨ zero , {!!} ⟩ ; (s≤s y≤z) → {!!} }; from = {!!} }
-}
to ∃-≤ z≤n = ⟨ zero , {!!} ⟩
to ∃-≤ (s≤s z≤n) = ⟨ suc zero , {!!} ⟩
to ∃-≤ (s≤s (s≤s m≤n)) = ⟨ suc (suc zero) , {!!} ⟩
from ∃-≤ ⟨ zero , y+zero≡z ⟩ = zzz y+zero≡z
from ∃-≤ ⟨ suc x , y+sucx≡z ⟩ rewrite sym y+sucx≡z = {!!}
-- The negation of an existential is isomorphic to a universal of a negation.
¬∃≃∀¬ : ∀ {A : Set} {B : A → Set}
→ (¬ ∃[ a ] B a) ≃ ∀ a → ¬ B a
to ¬∃≃∀¬ = λ { ¬∃B a → λ Ba → ¬∃B ⟨ a , Ba ⟩ }
from ¬∃≃∀¬ = λ { a→¬Ba ⟨ a , Ba ⟩ → a→¬Ba a Ba }
from∘to ¬∃≃∀¬ = λ ¬∃B → {!!} -- TODO
to∘from ¬∃≃∀¬ = λ a→¬Ba → refl
-- 747/PLFA exercise: ExistsNegImpNegForAll (1 point)
-- Existence of negation implies negation of universal.
∃¬-implies-¬∀ : ∀ {A : Set} {B : A → Set}
→ ∃[ a ] (¬ B a)
--------------
→ ¬ (∀ a → B a)
∃¬-implies-¬∀ ⟨ a , ¬Ba ⟩ = λ a→Ba → ¬Ba (a→Ba a)
-- The converse cannot be proved in intuitionistic logic.
-- PLFA exercise: isomorphism between naturals and existence of canonical binary.
-- This is essentially what we did at the end of 747Isomorphism.
|
{
"alphanum_fraction": 0.4996077406,
"avg_line_length": 31.3442622951,
"ext": "agda",
"hexsha": "d62b1484b31d48665d78fcaf3a4417732e3d4fcd",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-hc.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-hc.agda",
"max_line_length": 89,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-hc.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 3318,
"size": 7648
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Unary.Any directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Any where
open import Data.Vec.Relation.Unary.Any public
|
{
"alphanum_fraction": 0.4393530997,
"avg_line_length": 28.5384615385,
"ext": "agda",
"hexsha": "26d1ee72713bb0e369b495af62ac33de2cd30b9a",
"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/Vec/Any.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/Vec/Any.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/Data/Vec/Any.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 60,
"size": 371
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.NaturalTransformation.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (iso to iIso)
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor.Base
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
open import Cubical.Categories.NaturalTransformation.Base
private
variable
ℓC ℓC' ℓD ℓD' : Level
open isIsoC
open NatIso
open NatTrans
open Category
open Functor
open Iso
module _ {C : Category ℓC ℓC'} {D : Category ℓD ℓD'} where
private
_⋆ᴰ_ : ∀ {x y z} (f : D [ x , y ]) (g : D [ y , z ]) → D [ x , z ]
f ⋆ᴰ g = f ⋆⟨ D ⟩ g
-- natural isomorphism is symmetric
symNatIso : ∀ {F G : Functor C D}
→ F ≅ᶜ G
→ G ≅ᶜ F
symNatIso η .trans .N-ob x = η .nIso x .inv
symNatIso η .trans .N-hom _ = sqLL η
symNatIso η .nIso x .inv = η .trans .N-ob x
symNatIso η .nIso x .sec = η .nIso x .ret
symNatIso η .nIso x .ret = η .nIso x .sec
-- Properties
-- path helpers
module NatTransP where
module _ {F G : Functor C D} where
-- same as Sigma version
NatTransΣ : Type (ℓ-max (ℓ-max ℓC ℓC') ℓD')
NatTransΣ = Σ[ ob ∈ ((x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]) ]
({x y : _ } (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (ob y) ≡ (ob x) ⋆ᴰ (G .F-hom f))
NatTransIsoΣ : Iso (NatTrans F G) NatTransΣ
NatTransIsoΣ .fun (natTrans N-ob N-hom) = N-ob , N-hom
NatTransIsoΣ .inv (N-ob , N-hom) = (natTrans N-ob N-hom)
NatTransIsoΣ .rightInv _ = refl
NatTransIsoΣ .leftInv _ = refl
NatTrans≡Σ : NatTrans F G ≡ NatTransΣ
NatTrans≡Σ = isoToPath NatTransIsoΣ
-- introducing paths
NatTrans-≡-intro : ∀ {αo βo : N-ob-Type F G}
{αh : N-hom-Type F G αo}
{βh : N-hom-Type F G βo}
→ (p : αo ≡ βo)
→ PathP (λ i → ({x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ (G .F-hom f))) αh βh
→ natTrans {F = F} {G} αo αh ≡ natTrans βo βh
NatTrans-≡-intro p q i = natTrans (p i) (q i)
module _ {F G : Functor C D} {α β : NatTrans F G} where
open Iso
private
αOb = α .N-ob
βOb = β .N-ob
αHom = α .N-hom
βHom = β .N-hom
-- path between natural transformations is the same as a pair of paths (between ob and hom)
NTPathIsoPathΣ : Iso (α ≡ β)
(Σ[ p ∈ (αOb ≡ βOb) ]
(PathP (λ i → ({x y : _} (f : _) → F ⟪ f ⟫ ⋆ᴰ (p i y) ≡ (p i x) ⋆ᴰ G ⟪ f ⟫))
αHom
βHom))
NTPathIsoPathΣ .fun p = (λ i → p i .N-ob) , (λ i → p i .N-hom)
NTPathIsoPathΣ .inv (po , ph) i = record { N-ob = po i ; N-hom = ph i }
NTPathIsoPathΣ .rightInv pσ = refl
NTPathIsoPathΣ .leftInv p = refl
NTPath≃PathΣ = isoToEquiv NTPathIsoPathΣ
NTPath≡PathΣ = ua NTPath≃PathΣ
module _ where
open NatTransP
-- if the target category has hom Sets, then any natural transformation is a set
isSetNatTrans : {F G : Functor C D} → isSet (NatTrans F G)
isSetNatTrans =
isSetRetract (fun NatTransIsoΣ) (inv NatTransIsoΣ) (leftInv NatTransIsoΣ)
(isSetΣSndProp (isSetΠ (λ _ → isSetHom D))
(λ _ → isPropImplicitΠ2 (λ _ _ → isPropΠ (λ _ → isSetHom D _ _))))
|
{
"alphanum_fraction": 0.5541137493,
"avg_line_length": 35.1650485437,
"ext": "agda",
"hexsha": "a79e1cc619f4f395fbd0b1cd161db758e313fdf3",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/NaturalTransformation/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/NaturalTransformation/Properties.agda",
"max_line_length": 130,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/NaturalTransformation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 1326,
"size": 3622
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Divisibility
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Divisibility where
open import Algebra
open import Data.Nat as Nat
open import Data.Nat.DivMod
open import Data.Nat.Properties
open import Data.Nat.Solver
open import Data.Fin using (Fin; zero; suc; toℕ)
import Data.Fin.Properties as FP
open import Data.Product
open import Function
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Binary
import Relation.Binary.Reasoning.PartialOrder as POR
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; sym; trans; cong; cong₂; subst)
open +-*-Solver
------------------------------------------------------------------------
-- m ∣ n is inhabited iff m divides n. Some sources, like Hardy and
-- Wright's "An Introduction to the Theory of Numbers", require m to
-- be non-zero. However, some things become a bit nicer if m is
-- allowed to be zero. For instance, _∣_ becomes a partial order, and
-- the gcd of 0 and 0 becomes defined.
infix 4 _∣_ _∤_
record _∣_ (m n : ℕ) : Set where
constructor divides
field quotient : ℕ
equality : n ≡ quotient * m
open _∣_ using (quotient) public
_∤_ : Rel ℕ _
m ∤ n = ¬ (m ∣ n)
------------------------------------------------------------------------
-- _∣_ is a partial order
∣⇒≤ : ∀ {m n} → m ∣ suc n → m ≤ suc n
∣⇒≤ (divides zero ())
∣⇒≤ {m} {n} (divides (suc q) eq) = begin
m ≤⟨ m≤m+n m (q * m) ⟩
suc q * m ≡⟨ sym eq ⟩
suc n ∎
where open ≤-Reasoning
∣-reflexive : _≡_ ⇒ _∣_
∣-reflexive {n} refl = divides 1 (sym (*-identityˡ n))
∣-refl : Reflexive _∣_
∣-refl = ∣-reflexive refl
∣-trans : Transitive _∣_
∣-trans (divides p refl) (divides q refl) =
divides (q * p) (sym (*-assoc q p _))
∣-antisym : Antisymmetric _≡_ _∣_
∣-antisym {m} {0} _ (divides q eq) = trans eq (*-comm q 0)
∣-antisym {0} {n} (divides p eq) _ = sym (trans eq (*-comm p 0))
∣-antisym {suc m} {suc n} (divides p eq₁) (divides q eq₂) =
≤-antisym (∣⇒≤ (divides p eq₁)) (∣⇒≤ (divides q eq₂))
∣-isPreorder : IsPreorder _≡_ _∣_
∣-isPreorder = record
{ isEquivalence = PropEq.isEquivalence
; reflexive = ∣-reflexive
; trans = ∣-trans
}
∣-preorder : Preorder _ _ _
∣-preorder = record { isPreorder = ∣-isPreorder }
∣-isPartialOrder : IsPartialOrder _≡_ _∣_
∣-isPartialOrder = record
{ isPreorder = ∣-isPreorder
; antisym = ∣-antisym
}
poset : Poset _ _ _
poset = record
{ Carrier = ℕ
; _≈_ = _≡_
; _≤_ = _∣_
; isPartialOrder = ∣-isPartialOrder
}
module ∣-Reasoning = POR poset
hiding (_≈⟨_⟩_)
renaming (_≤⟨_⟩_ to _∣⟨_⟩_)
------------------------------------------------------------------------
-- Simple properties of _∣_
infix 10 1∣_ _∣0
1∣_ : ∀ n → 1 ∣ n
1∣ n = divides n (sym (*-identityʳ n))
_∣0 : ∀ n → n ∣ 0
n ∣0 = divides 0 refl
n∣n : ∀ {n} → n ∣ n
n∣n = ∣-refl
n∣m*n : ∀ m {n} → n ∣ m * n
n∣m*n m = divides m refl
m∣m*n : ∀ {m} n → m ∣ m * n
m∣m*n n = divides n (*-comm _ n)
0∣⇒≡0 : ∀ {n} → 0 ∣ n → n ≡ 0
0∣⇒≡0 {n} 0∣n = ∣-antisym (n ∣0) 0∣n
∣1⇒≡1 : ∀ {n} → n ∣ 1 → n ≡ 1
∣1⇒≡1 {n} n∣1 = ∣-antisym n∣1 (1∣ n)
------------------------------------------------------------------------
-- Operators and divisibility
module _ where
open PropEq.≡-Reasoning
∣m⇒∣m*n : ∀ {i m} n → i ∣ m → i ∣ m * n
∣m⇒∣m*n {i} {m} n (divides q eq) = divides (q * n) $ begin
m * n ≡⟨ cong (_* n) eq ⟩
q * i * n ≡⟨ *-assoc q i n ⟩
q * (i * n) ≡⟨ cong (q *_) (*-comm i n) ⟩
q * (n * i) ≡⟨ sym (*-assoc q n i) ⟩
q * n * i ∎
∣n⇒∣m*n : ∀ {i} m {n} → i ∣ n → i ∣ m * n
∣n⇒∣m*n {i} m {n} (divides q eq) = divides (m * q) $ begin
m * n ≡⟨ cong (m *_) eq ⟩
m * (q * i) ≡⟨ sym (*-assoc m q i) ⟩
m * q * i ∎
∣m∣n⇒∣m+n : ∀ {i m n} → i ∣ m → i ∣ n → i ∣ m + n
∣m∣n⇒∣m+n (divides p refl) (divides q refl) =
divides (p + q) (sym (*-distribʳ-+ _ p q))
∣m+n∣m⇒∣n : ∀ {i m n} → i ∣ m + n → i ∣ m → i ∣ n
∣m+n∣m⇒∣n {i} {m} {n} (divides p m+n≡p*i) (divides q m≡q*i) =
divides (p ∸ q) $ begin
n ≡⟨ sym (m+n∸n≡m n m) ⟩
n + m ∸ m ≡⟨ cong (_∸ m) (+-comm n m) ⟩
m + n ∸ m ≡⟨ cong₂ _∸_ m+n≡p*i m≡q*i ⟩
p * i ∸ q * i ≡⟨ sym (*-distribʳ-∸ i p q) ⟩
(p ∸ q) * i ∎
∣m∸n∣n⇒∣m : ∀ i {m n} → n ≤ m → i ∣ m ∸ n → i ∣ n → i ∣ m
∣m∸n∣n⇒∣m i {m} {n} n≤m (divides p m∸n≡p*i) (divides q n≡q*o) =
divides (p + q) $ begin
m ≡⟨ sym (m+n∸m≡n n≤m) ⟩
n + (m ∸ n) ≡⟨ +-comm n (m ∸ n) ⟩
m ∸ n + n ≡⟨ cong₂ _+_ m∸n≡p*i n≡q*o ⟩
p * i + q * i ≡⟨ sym (*-distribʳ-+ i p q) ⟩
(p + q) * i ∎
*-cong : ∀ {i j} k → i ∣ j → k * i ∣ k * j
*-cong {i} {j} k (divides q j≡q*i) = divides q $ begin
k * j ≡⟨ cong (_*_ k) j≡q*i ⟩
k * (q * i) ≡⟨ sym (*-assoc k q i) ⟩
(k * q) * i ≡⟨ cong (_* i) (*-comm k q) ⟩
(q * k) * i ≡⟨ *-assoc q k i ⟩
q * (k * i) ∎
/-cong : ∀ {i j} k → suc k * i ∣ suc k * j → i ∣ j
/-cong {i} {j} k (divides q eq) =
divides q (*-cancelʳ-≡ j (q * i) (begin
j * (suc k) ≡⟨ *-comm j (suc k) ⟩
(suc k) * j ≡⟨ eq ⟩
q * ((suc k) * i) ≡⟨ cong (q *_) (*-comm (suc k) i) ⟩
q * (i * (suc k)) ≡⟨ sym (*-assoc q i (suc k)) ⟩
(q * i) * (suc k) ∎))
m%n≡0⇒n∣m : ∀ m n → m % (suc n) ≡ 0 → suc n ∣ m
m%n≡0⇒n∣m m n eq = divides (m div (suc n)) (begin
m ≡⟨ a≡a%n+[a/n]*n m n ⟩
m % (suc n) + m div (suc n) * (suc n) ≡⟨ cong₂ _+_ eq refl ⟩
m div (suc n) * (suc n) ∎)
n∣m⇒m%n≡0 : ∀ m n → suc n ∣ m → m % (suc n) ≡ 0
n∣m⇒m%n≡0 m n (divides v eq) = begin
m % (suc n) ≡⟨ cong (_% (suc n)) eq ⟩
(v * suc n) % (suc n) ≡⟨ kn%n≡0 v n ⟩
0 ∎
m%n≡0⇔n∣m : ∀ m n → m % (suc n) ≡ 0 ⇔ suc n ∣ m
m%n≡0⇔n∣m m n = equivalence (m%n≡0⇒n∣m m n) (n∣m⇒m%n≡0 m n)
-- Divisibility is decidable.
infix 4 _∣?_
_∣?_ : Decidable _∣_
zero ∣? zero = yes (0 ∣0)
zero ∣? suc m = no ((λ()) ∘′ 0∣⇒≡0)
suc n ∣? m = Dec.map (m%n≡0⇔n∣m m n) (m % (suc n) ≟ 0)
------------------------------------------------------------------------
-- DEPRECATED - please use new names as continuing support for the old
-- names is not guaranteed.
∣-+ = ∣m∣n⇒∣m+n
{-# WARNING_ON_USAGE ∣-+
"Warning: ∣-+ was deprecated in v0.14.
Please use ∣m∣n⇒∣m+n instead."
#-}
∣-∸ = ∣m+n∣m⇒∣n
{-# WARNING_ON_USAGE ∣-∸
"Warning: ∣-∸ was deprecated in v0.14.
Please use ∣m+n∣m⇒∣n instead."
#-}
∣-* = n∣m*n
{-# WARNING_ON_USAGE ∣-*
"Warning: ∣-* was deprecated in v0.14.
Please use n∣m*n instead."
#-}
nonZeroDivisor-lemma : ∀ m q (r : Fin (1 + m)) → toℕ r ≢ 0 →
1 + m ∤ toℕ r + q * (1 + m)
nonZeroDivisor-lemma m zero r r≢zero (divides zero eq) = r≢zero $ begin
toℕ r ≡⟨ sym (*-identityˡ (toℕ r)) ⟩
1 * toℕ r ≡⟨ eq ⟩
0 ∎
where open PropEq.≡-Reasoning
nonZeroDivisor-lemma m zero r r≢zero (divides (suc q) eq) =
i+1+j≰i m $ begin
m + suc (q * suc m) ≡⟨ +-suc m (q * suc m) ⟩
suc (m + q * suc m) ≡⟨ sym eq ⟩
1 * toℕ r ≡⟨ *-identityˡ (toℕ r) ⟩
toℕ r ≤⟨ FP.toℕ≤pred[n] r ⟩
m ∎
where open ≤-Reasoning
nonZeroDivisor-lemma m (suc q) r r≢zero d =
nonZeroDivisor-lemma m q r r≢zero (∣m+n∣m⇒∣n d' ∣-refl)
where
lem = solve 3 (λ m r q → r :+ (m :+ q) := m :+ (r :+ q))
refl (suc m) (toℕ r) (q * suc m)
d' = subst (1 + m ∣_) lem d
{-# WARNING_ON_USAGE nonZeroDivisor-lemma
"Warning: nonZeroDivisor-lemma was deprecated in v0.17."
#-}
|
{
"alphanum_fraction": 0.4706410256,
"avg_line_length": 30.3501945525,
"ext": "agda",
"hexsha": "21e9db07e1a8f32aa672875550a3d411f5c90c75",
"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/Divisibility.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/Divisibility.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/Data/Nat/Divisibility.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3547,
"size": 7800
}
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 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.Prelude
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open WithAbsVote
module LibraBFT.Concrete.Obligations.VotesOnce
(𝓔 : EpochConfig)
(𝓥 : VoteEvidence 𝓔)
where
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 𝓥
open import LibraBFT.Concrete.Intermediate 𝓔 𝓥
-------------------
-- * VotesOnce * --
-------------------
module _ {ℓ}(𝓢 : IntermediateSystemState ℓ) where
open IntermediateSystemState 𝓢
Type : Set ℓ
Type = ∀{α v v'}
→ Meta-Honest-Member α
→ vMember v ≡ α → HasBeenSent v
→ vMember v' ≡ α → HasBeenSent v'
→ vRound v ≡ vRound v'
→ vBlockUID v ≡ vBlockUID v'
-- NOTE: It is interesting that this does not require the timeout signature (or even
-- presence/lack thereof) to be the same. The abstract proof goes through without out it, so I
-- am leaving it out for now, but I'm curious what if anything could go wrong if an honest
-- author can send different votes for the same epoch and round that differ on timeout
-- signature. Maybe something for liveness?
proof : Type → VotesOnlyOnceRule InSys
proof glob-inv α hα {q} {q'} q∈sys q'∈sys va va' VO≡
with ∈QC⇒HasBeenSent q∈sys hα va
| ∈QC⇒HasBeenSent q'∈sys hα va'
...| sent-cv | sent-cv'
with glob-inv hα (sym (∈QC-Member q va)) sent-cv
(sym (∈QC-Member q' va')) sent-cv'
VO≡
...| bId≡
= Vote-η VO≡ (trans (sym (∈QC-Member q va)) (∈QC-Member q' va'))
bId≡
|
{
"alphanum_fraction": 0.6373684211,
"avg_line_length": 38,
"ext": "agda",
"hexsha": "f32ee2c34392d93590e4f2327b1c0900e95d5044",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Concrete/Obligations/VotesOnce.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Concrete/Obligations/VotesOnce.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Concrete/Obligations/VotesOnce.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 582,
"size": 1900
}
|
------------------------------------------------------------------------------
-- Testing the use of local hints
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LocalHints where
postulate
D : Set
zero : D
data N : D → Set where
zN : N zero
postulate 0-N : N zero
{-# ATP prove 0-N zN #-}
|
{
"alphanum_fraction": 0.376953125,
"avg_line_length": 24.380952381,
"ext": "agda",
"hexsha": "f0393687aafdb7a777b8f6a88611733d29bbf467",
"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/LocalHints.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/LocalHints.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/LocalHints.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": 96,
"size": 512
}
|
{-# OPTIONS --cubical --safe #-}
-- Free join semilattice
module Algebra.Construct.Free.Semilattice where
open import Algebra.Construct.Free.Semilattice.Definition public
open import Algebra.Construct.Free.Semilattice.Eliminators public
open import Algebra.Construct.Free.Semilattice.Union public using (_∪_; 𝒦-semilattice)
open import Algebra.Construct.Free.Semilattice.Homomorphism public using (μ; ∙-hom)
|
{
"alphanum_fraction": 0.812195122,
"avg_line_length": 41,
"ext": "agda",
"hexsha": "41adc3b4847509483128f96c44f6dae7cb55252e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice.agda",
"max_line_length": 86,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 106,
"size": 410
}
|
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
record R {A : Set} {B : A → Set} p@ab : Set where
field
prf : p ≡ p
|
{
"alphanum_fraction": 0.6886227545,
"avg_line_length": 20.875,
"ext": "agda",
"hexsha": "a1935196ab1ce603a29d70b58576eaf8e29da5f9",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/NoLetInRecordTele.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/NoLetInRecordTele.agda",
"max_line_length": 49,
"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/NoLetInRecordTele.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": 58,
"size": 167
}
|
module PreludeList where
open import AlonzoPrelude as Prelude
open import PreludeNat
infixr 50 _::_ _++_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
[_] : {A : Set} -> A -> List A
[ x ] = x :: []
length : {A : Set} -> List A -> Nat
length [] = 0
length (_ :: xs) = 1 + length xs
map : {A B : Set} -> (A -> B) -> List A -> List B
map f [] = []
map f (x :: xs) = f x :: map f xs
_++_ : {A : Set} -> List A -> List A -> List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
zipWith : {A B C : Set} -> (A -> B -> C) -> List A -> List B -> List C
zipWith f [] [] = []
zipWith f (x :: xs) (y :: ys) = f x y :: zipWith f xs ys
zipWith f [] (_ :: _) = []
zipWith f (_ :: _) [] = []
foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
foldr f z [] = z
foldr f z (x :: xs) = f x (foldr f z xs)
foldl : {A B : Set} -> (B -> A -> B) -> B -> List A -> B
foldl f z [] = z
foldl f z (x :: xs) = foldl f (f z x) xs
replicate : {A : Set} -> Nat -> A -> List A
replicate zero x = []
replicate (suc n) x = x :: replicate n x
iterate : {A : Set} -> Nat -> (A -> A) -> A -> List A
iterate zero f x = []
iterate (suc n) f x = x :: iterate n f (f x)
splitAt : {A : Set} -> Nat -> List A -> List A × List A
splitAt zero xs = < [] , xs >
splitAt (suc n) [] = < [] , [] >
splitAt (suc n) (x :: xs) = add x $ splitAt n xs
where
add : _ -> List _ × List _ -> List _ × List _
add x < ys , zs > = < x :: ys , zs >
reverse : {A : Set} -> List A -> List A
reverse xs = foldl (flip _::_) [] xs
|
{
"alphanum_fraction": 0.4522968198,
"avg_line_length": 25.7272727273,
"ext": "agda",
"hexsha": "4b5dbe09c3e3553e281201ca40edbc12cc8e59f7",
"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/Alonzo/PreludeList.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/Alonzo/PreludeList.agda",
"max_line_length": 70,
"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/Alonzo/PreludeList.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": 624,
"size": 1698
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Functor.Core where
open import Level
open import Function renaming (id to id→; _∘_ to _●_) using ()
open import Relation.Binary hiding (_⇒_)
import Relation.Binary.Reasoning.Setoid as SetoidR
import Categories.Morphism as M
private
variable
o ℓ e o′ ℓ′ e′ o′′ ℓ′′ e′′ : Level
C D : Category o ℓ e
record Functor (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
eta-equality
private module C = Category C
private module D = Category D
field
F₀ : C.Obj → D.Obj
F₁ : ∀ {A B} (f : C [ A , B ]) → D [ F₀ A , F₀ B ]
identity : ∀ {A} → D [ F₁ (C.id {A}) ≈ D.id ]
homomorphism : ∀ {X Y Z} {f : C [ X , Y ]} {g : C [ Y , Z ]} →
D [ F₁ (C [ g ∘ f ]) ≈ D [ F₁ g ∘ F₁ f ] ]
F-resp-≈ : ∀ {A B} {f g : C [ A , B ]} → C [ f ≈ g ] → D [ F₁ f ≈ F₁ g ]
op : Functor C.op D.op
op = record
{ F₀ = F₀
; F₁ = F₁
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = F-resp-≈
}
Endofunctor : Category o ℓ e → Set _
Endofunctor C = Functor C C
id : ∀ {C : Category o ℓ e} → Endofunctor C
id {C = C} = record
{ F₀ = id→
; F₁ = id→
; identity = refl
; homomorphism = refl
; F-resp-≈ = id→
}
where open Category.Equiv C
infixr 9 _∘F_
-- note that this definition could be shortened a lot by inlining the definitions for
-- identity′ and homomorphism′, but the definitions below are simpler to understand.
_∘F_ : ∀ {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {E : Category o′′ ℓ′′ e′′}
→ Functor D E → Functor C D → Functor C E
_∘F_ {C = C} {D = D} {E = E} F G = record
{ F₀ = F₀ ● G₀
; F₁ = F₁ ● G₁
; identity = identity′
; homomorphism = homomorphism′
; F-resp-≈ = F-resp-≈ ● G-resp-≈
}
where
module C = Category C
module D = Category D
module E = Category E
module F = Functor F
module G = Functor G
open F
open G renaming (F₀ to G₀; F₁ to G₁; F-resp-≈ to G-resp-≈)
identity′ : ∀ {A} → E [ F₁ (G₁ (C.id {A})) ≈ E.id ]
identity′ = begin
F₁ (G₁ C.id) ≈⟨ F-resp-≈ G.identity ⟩
F₁ D.id ≈⟨ F.identity ⟩
E.id ∎
where open SetoidR E.hom-setoid
homomorphism′ : ∀ {X Y Z} {f : C [ X , Y ]} {g : C [ Y , Z ]}
→ E [ F₁ (G₁ (C [ g ∘ f ])) ≈ E [ F₁ (G₁ g) ∘ F₁ (G₁ f) ] ]
homomorphism′ {f = f} {g = g} = begin
F₁ (G₁ (C [ g ∘ f ])) ≈⟨ F-resp-≈ G.homomorphism ⟩
F₁ (D [ G₁ g ∘ G₁ f ]) ≈⟨ F.homomorphism ⟩
E [ F₁ (G₁ g) ∘ F₁ (G₁ f) ] ∎
where open SetoidR E.hom-setoid
|
{
"alphanum_fraction": 0.5246704331,
"avg_line_length": 28.8586956522,
"ext": "agda",
"hexsha": "f53d81e447f124b2c39c7b5eee73bbd19f30f6a8",
"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/Functor/Core.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/Functor/Core.agda",
"max_line_length": 98,
"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/Functor/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1072,
"size": 2655
}
|
module *-comm where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Induction′ using (+-assoc; +-comm; +-suc)
open import +-swap using (+-swap)
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm zero zero = refl
*-comm zero (suc n) =
begin
zero * (suc n)
≡⟨⟩
zero
≡⟨⟩
zero + (zero * n)
≡⟨ *-comm zero n ⟩
zero + (n * zero)
≡⟨⟩
(suc n) * zero
∎
*-comm (suc m) zero =
begin
(suc m) * zero
≡⟨⟩
zero + (m * zero)
≡⟨ *-comm m zero ⟩
(zero * m)
≡⟨⟩
zero
≡⟨⟩
zero * (suc m)
∎
*-comm (suc m) (suc n) =
begin
(suc m) * (suc n)
≡⟨⟩
(suc n) + (m * (suc n))
≡⟨ cong ((suc n) +_) (*-comm m (suc n)) ⟩
(suc n) + ((suc n) * m)
≡⟨⟩
(suc n) + (m + (n * m))
≡⟨ +-swap (suc n) m (n * m) ⟩
m + ((suc n) + (n * m))
≡⟨ sym (+-assoc m (suc n) (n * m)) ⟩
(m + (suc n)) + (n * m)
≡⟨ cong (_+ (n * m)) (+-suc m n) ⟩
suc (m + n) + (n * m)
≡⟨ cong suc (+-assoc m n (n * m)) ⟩
(suc m) + (n + (n * m))
≡⟨ cong (λ m*n → (suc m) + (n + m*n)) (*-comm n m) ⟩
(suc m) + (n + (m * n))
≡⟨⟩
(suc m) + ((suc m) * n)
≡⟨ cong ((suc m) +_) (*-comm ((suc m)) n) ⟩
(suc m) + (n * (suc m))
≡⟨⟩
(suc n) * (suc m)
∎
|
{
"alphanum_fraction": 0.427626745,
"avg_line_length": 21.6031746032,
"ext": "agda",
"hexsha": "3ae5ddd83b84966acc00ff15050c803fd3af409f",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/induction/*-comm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/induction/*-comm.agda",
"max_line_length": 54,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/induction/*-comm.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 689,
"size": 1361
}
|
{-
Maybe structure: X ↦ Maybe (S X)
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Structures.Relational.Maybe where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.RelationalStructure
open import Cubical.Data.Unit
open import Cubical.Data.Empty
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
open import Cubical.Structures.Maybe
private
variable
ℓ ℓ₁ ℓ₁' : Level
-- Structured relations
preservesSetsMaybe : {S : Type ℓ → Type ℓ₁} → preservesSets S → preservesSets (MaybeStructure S)
preservesSetsMaybe p setX = isOfHLevelMaybe 0 (p setX)
MaybeRelStr : {S : Type ℓ → Type ℓ₁} {ℓ₁' : Level}
→ StrRel S ℓ₁' → StrRel (λ X → Maybe (S X)) ℓ₁'
MaybeRelStr ρ R = MaybeRel (ρ R)
open SuitableStrRel
maybeSuitableRel : {S : Type ℓ → Type ℓ₁} {ρ : StrRel S ℓ₁'}
→ SuitableStrRel S ρ
→ SuitableStrRel (MaybeStructure S) (MaybeRelStr ρ)
maybeSuitableRel θ .quo (X , nothing) R _ .fst = nothing , _
maybeSuitableRel θ .quo (X , nothing) R _ .snd (nothing , _) = refl
maybeSuitableRel θ .quo (X , just s) R c .fst =
just (θ .quo (X , s) R c .fst .fst) , θ .quo (X , s) R c .fst .snd
maybeSuitableRel θ .quo (X , just s) R c .snd (just s' , r) =
cong (λ {(t , r') → just t , r'}) (θ .quo (X , s) R c .snd (s' , r))
maybeSuitableRel θ .symmetric R {nothing} {nothing} r = _
maybeSuitableRel θ .symmetric R {just s} {just t} r = θ .symmetric R r
maybeSuitableRel θ .transitive R R' {nothing} {nothing} {nothing} r r' = _
maybeSuitableRel θ .transitive R R' {just s} {just t} {just u} r r' = θ .transitive R R' r r'
maybeSuitableRel θ .prop propR nothing nothing = isOfHLevelLift 1 isPropUnit
maybeSuitableRel θ .prop propR nothing (just y) = isOfHLevelLift 1 isProp⊥
maybeSuitableRel θ .prop propR (just x) nothing = isOfHLevelLift 1 isProp⊥
maybeSuitableRel θ .prop propR (just x) (just y) = θ .prop propR x y
maybeRelMatchesEquiv : {S : Type ℓ → Type ℓ₁} (ρ : StrRel S ℓ₁') {ι : StrEquiv S ℓ₁'}
→ StrRelMatchesEquiv ρ ι
→ StrRelMatchesEquiv (MaybeRelStr ρ) (MaybeEquivStr ι)
maybeRelMatchesEquiv ρ μ (X , nothing) (Y , nothing) _ = idEquiv _
maybeRelMatchesEquiv ρ μ (X , nothing) (Y , just y) _ = idEquiv _
maybeRelMatchesEquiv ρ μ (X , just x) (Y , nothing) _ = idEquiv _
maybeRelMatchesEquiv ρ μ (X , just x) (Y , just y) = μ (X , x) (Y , y)
|
{
"alphanum_fraction": 0.7039552537,
"avg_line_length": 40.3709677419,
"ext": "agda",
"hexsha": "4f24e357b67e6dc282701a76026a6bd84d6dfeba",
"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/Relational/Maybe.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/Relational/Maybe.agda",
"max_line_length": 96,
"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/Relational/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 897,
"size": 2503
}
|
{-# OPTIONS --sized-types #-}
module SizedTypesVarSwap where
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
bad : {i j : Size} -> Nat {i} -> Nat {j} -> Nat {∞}
bad (suc x) y = bad (suc y) x
bad zero y = y
|
{
"alphanum_fraction": 0.5311778291,
"avg_line_length": 20.619047619,
"ext": "agda",
"hexsha": "3e0be8ad22d5cc9f793ddab0c236f31fec6195a3",
"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/SizedTypesVarSwap.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/SizedTypesVarSwap.agda",
"max_line_length": 52,
"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/SizedTypesVarSwap.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": 155,
"size": 433
}
|
module Pi.Opsem where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Base
open import Pi.Syntax
infix 1 _↦_
-- Base combinators
base : ∀ {A B} (c : A ↔ B) → Set
base unite₊l = ⊤
base uniti₊l = ⊤
base swap₊ = ⊤
base assocl₊ = ⊤
base assocr₊ = ⊤
base unite⋆l = ⊤
base uniti⋆l = ⊤
base swap⋆ = ⊤
base assocl⋆ = ⊤
base assocr⋆ = ⊤
base absorbr = ⊤
base factorzl = ⊤
base dist = ⊤
base factor = ⊤
base _ = ⊥
base-is-prop : ∀ {A B} (c : A ↔ B) → is-prop (base c)
base-is-prop unite₊l tt tt = refl
base-is-prop uniti₊l tt tt = refl
base-is-prop swap₊ tt tt = refl
base-is-prop assocl₊ tt tt = refl
base-is-prop assocr₊ tt tt = refl
base-is-prop unite⋆l tt tt = refl
base-is-prop uniti⋆l tt tt = refl
base-is-prop swap⋆ tt tt = refl
base-is-prop assocl⋆ tt tt = refl
base-is-prop assocr⋆ tt tt = refl
base-is-prop absorbr tt tt = refl
base-is-prop factorzl tt tt = refl
base-is-prop dist tt tt = refl
base-is-prop factor tt tt = refl
-- Evaluator for base combinators
δ : ∀ {A B} (c : A ↔ B) {_ : base c} → ⟦ A ⟧ → ⟦ B ⟧
δ unite₊l (inj₂ v) = v
δ uniti₊l v = inj₂ v
δ swap₊ (inj₁ x) = inj₂ x
δ swap₊ (inj₂ y) = inj₁ y
δ assocl₊ (inj₁ v) = inj₁ (inj₁ v)
δ assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
δ assocl₊ (inj₂ (inj₂ v)) = inj₂ v
δ assocr₊ (inj₁ (inj₁ v)) = inj₁ v
δ assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
δ assocr₊ (inj₂ v) = inj₂ (inj₂ v)
δ unite⋆l (tt , v) = v
δ uniti⋆l v = (tt , v)
δ swap⋆ (x , y) = (y , x)
δ assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
δ assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
δ absorbr ()
δ factorzl ()
δ dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
δ dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
δ factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
δ factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
-- Context
data Context : {A B : 𝕌} → Set where
☐ : ∀ {A B} → Context {A} {B}
☐⨾_•_ : ∀ {A B C} → (c₂ : B ↔ C) → Context {A} {C} → Context {A} {B}
_⨾☐•_ : ∀ {A B C} → (c₁ : A ↔ B) → Context {A} {C} → Context {B} {C}
☐⊕_•_ : ∀ {A B C D} → (c₂ : C ↔ D) → Context {A +ᵤ C} {B +ᵤ D} → Context {A} {B}
_⊕☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → Context {A +ᵤ C} {B +ᵤ D} → Context {C} {D}
☐⊗[_,_]•_ : ∀ {A B C D} → (c₂ : C ↔ D) → ⟦ C ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {A} {B}
[_,_]⊗☐•_ : ∀ {A B C D} → (c₁ : A ↔ B) → ⟦ B ⟧ → Context {A ×ᵤ C} {B ×ᵤ D} → Context {C} {D}
-- Machine state
data State : Set where
⟨_∣_∣_⟩ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Context {A} {B} → State
[_∣_∣_] : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Context {A} {B} → State
-- Reduction relation
data _↦_ : State → State → Set where
↦₁ : ∀ {A B} {c : A ↔ B} {b : base c} {v : ⟦ A ⟧} {κ : Context} → ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ δ c {b} v ∣ κ ]
↦₂ : ∀ {A} {v : ⟦ A ⟧} {κ : Context} → ⟨ id↔ ∣ v ∣ κ ⟩ ↦ [ id↔ ∣ v ∣ κ ]
↦₃ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ A ⟧} {κ : Context}
→ ⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩ ↦ ⟨ c₁ ∣ v ∣ ☐⨾ c₂ • κ ⟩
↦₄ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {κ : Context}
→ ⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊕ c₂ • κ ⟩
↦₅ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ C ⟧} {κ : Context}
→ ⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩ ↦ ⟨ c₂ ∣ y ∣ c₁ ⊕☐• κ ⟩
↦₆ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ A ⟧} {y : ⟦ C ⟧} {κ : Context}
→ ⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩ ↦ ⟨ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ⟩
↦₇ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ B ⟧} {κ : Context}
→ [ c₁ ∣ v ∣ ☐⨾ c₂ • κ ] ↦ ⟨ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ⟩
↦₈ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ C ⟧} {κ : Context}
→ [ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ] ↦ ⟨ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ⟩
↦₉ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {y : ⟦ D ⟧} {κ : Context}
→ [ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ] ↦ [ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ]
↦₁₀ : ∀ {A B C} {c₁ : A ↔ B} {c₂ : B ↔ C} {v : ⟦ C ⟧} {κ : Context}
→ [ c₂ ∣ v ∣ (c₁ ⨾☐• κ) ] ↦ [ c₁ ⨾ c₂ ∣ v ∣ κ ]
↦₁₁ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {x : ⟦ B ⟧} {κ : Context}
→ [ c₁ ∣ x ∣ ☐⊕ c₂ • κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ]
↦₁₂ : ∀ {A B C D} {c₁ : A ↔ B} {c₂ : C ↔ D} {y : ⟦ D ⟧} {κ : Context}
→ [ c₂ ∣ y ∣ c₁ ⊕☐• κ ] ↦ [ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ]
|
{
"alphanum_fraction": 0.4542601979,
"avg_line_length": 37.3243243243,
"ext": "agda",
"hexsha": "feb5a5f4330167cefe3ac4aef9f7be8c6f1e82b1",
"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": "Pi/Opsem.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": "Pi/Opsem.agda",
"max_line_length": 106,
"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": "Pi/Opsem.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": 2304,
"size": 4143
}
|
------------------------------------------------------------------------
-- Atoms
------------------------------------------------------------------------
module Atom where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bag-equivalence equality-with-J
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Path.Isomorphisms.Univalence equality-with-paths
open import Equivalence equality-with-J as Eq using (_≃_)
open import Finite-subset.Listed equality-with-paths as S
using (Finite-subset-of; _∉_)
open import Function-universe equality-with-J hiding (id)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
using (∥_∥; ∣_∣)
open import Injection equality-with-J using (Injective)
import Nat equality-with-J as Nat
open import Univalence-axiom equality-with-J
-- Atoms.
record Atoms : Type₁ where
field
-- The type of atoms.
Name : Type
-- The type must be countably infinite.
countably-infinite : Name ↔ ℕ
-- Atoms have decidable equality.
_≟_ : Decidable-equality Name
_≟_ = Bijection.decidable-equality-respects
(inverse countably-infinite) Nat._≟_
-- Membership test.
member : (x : Name) (xs : List Name) → Dec (x ∈ xs)
member x [] = no (λ ())
member x (y ∷ xs) with x ≟ y
... | yes x≡y = yes (inj₁ x≡y)
... | no x≢y with member x xs
... | yes x∈xs = yes (inj₂ x∈xs)
... | no x∉xs = no [ x≢y , x∉xs ]
-- Conversions.
name : ℕ → Name
name = _↔_.from countably-infinite
code : Name → ℕ
code = _↔_.to countably-infinite
-- The name function is injective.
name-injective : Injective name
name-injective = _↔_.injective (inverse countably-infinite)
-- Distinct natural numbers are mapped to distinct names.
distinct-codes→distinct-names : ∀ {m n} → m ≢ n → name m ≢ name n
distinct-codes→distinct-names {m} {n} m≢n =
name m ≡ name n ↝⟨ name-injective ⟩
m ≡ n ↝⟨ m≢n ⟩□
⊥ □
-- One can always find a name that is distinct from the names in a
-- given finite set of names.
fresh :
(ns : Finite-subset-of Name) →
∃ λ (n : Name) → n ∉ ns
fresh ns =
Σ-map name
(λ {m} →
→-cong-→
(name m S.∈ ns ↝⟨ (λ ∈ns → ∣ name m , ∈ns
, _↔_.right-inverse-of countably-infinite _
∣) ⟩
∥ (∃ λ n → n S.∈ ns × code n ≡ m) ∥ ↔⟨ inverse S.∈map≃ ⟩□
m S.∈ S.map code ns □)
id)
(S.fresh (S.map code ns))
-- Name is a set.
Name-set : Is-set Name
Name-set = decidable⇒set _≟_
-- One implementation of atoms, using natural numbers.
ℕ-atoms : Atoms
Atoms.Name ℕ-atoms = ℕ
Atoms.countably-infinite ℕ-atoms = Bijection.id
-- Two sets of atoms, one for constants and one for variables.
record χ-atoms : Type₁ where
field
const-atoms var-atoms : Atoms
module C = Atoms const-atoms renaming (Name to Const)
module V = Atoms var-atoms renaming (Name to Var)
open C public using (Const)
open V public using (Var)
-- One implementation of χ-atoms, using natural numbers.
χ-ℕ-atoms : χ-atoms
χ-atoms.const-atoms χ-ℕ-atoms = ℕ-atoms
χ-atoms.var-atoms χ-ℕ-atoms = ℕ-atoms
-- The type of atoms is isomorphic to the unit type.
Atoms↔⊤ : Atoms ↔ ⊤
Atoms↔⊤ =
Atoms ↝⟨ eq ⟩
(∃ λ (Name : Type) → Name ↔ ℕ) ↝⟨ ∃-cong (λ _ → Eq.↔↔≃′ ext ℕ-set) ⟩
(∃ λ (Name : Type) → Name ≃ ℕ) ↝⟨ singleton-with-≃-↔-⊤ ext univ ⟩□
⊤ □
where
open Atoms
eq : Atoms ↔ ∃ λ (Name : Type) → Name ↔ ℕ
eq = record
{ surjection = record
{ logical-equivalence = record
{ to = λ a → Name a , countably-infinite a
; from = uncurry λ N c →
record { Name = N; countably-infinite = c }
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
-- The χ-atoms type is isomorphic to the unit type.
χ-atoms↔⊤ : χ-atoms ↔ ⊤
χ-atoms↔⊤ =
χ-atoms ↝⟨ eq ⟩
Atoms × Atoms ↝⟨ Atoms↔⊤ ×-cong Atoms↔⊤ ⟩
⊤ × ⊤ ↝⟨ ×-right-identity ⟩□
⊤ □
where
open χ-atoms
eq : χ-atoms ↔ Atoms × Atoms
eq = record
{ surjection = record
{ logical-equivalence = record
{ to = λ a → const-atoms a , var-atoms a
; from = uncurry λ c v →
record { const-atoms = c; var-atoms = v }
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
-- If a property holds for one choice of atoms, then it holds for any
-- other choice of atoms.
invariant :
∀ {p} (P : χ-atoms → Type p) →
∀ a₁ a₂ → P a₁ → P a₂
invariant P a₁ a₂ =
subst P (mono₁ 0 (_⇔_.from contractible⇔↔⊤ χ-atoms↔⊤) a₁ a₂)
-- If a property holds for χ-ℕ-atoms, then it holds for any choice of
-- atoms.
one-can-restrict-attention-to-χ-ℕ-atoms :
∀ {p} (P : χ-atoms → Type p) →
P χ-ℕ-atoms → ∀ a → P a
one-can-restrict-attention-to-χ-ℕ-atoms P p a =
invariant P χ-ℕ-atoms a p
|
{
"alphanum_fraction": 0.5656261753,
"avg_line_length": 28.2872340426,
"ext": "agda",
"hexsha": "b1c04a7f1fac5477ae174f6a8f6d49bad4dbc668",
"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": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Atom.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Atom.agda",
"max_line_length": 104,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Atom.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 1732,
"size": 5318
}
|
{-# OPTIONS --without-K --safe #-}
open import Level using (Level)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Data.Nat using (ℕ; zero; suc)
open import Data.Vec using (Vec; []; _∷_; _++_; foldr; map; replicate)
open import Data.Vec.Properties
open import FLA.Algebra.Structures
open import FLA.Algebra.Properties.Field
open import FLA.Algebra.LinearAlgebra
open import FLA.Data.Vec.Properties
module FLA.Algebra.LinearAlgebra.Properties where
private
variable
ℓ : Level
A : Set ℓ
m n p q : ℕ
module _ ⦃ F : Field A ⦄ where
open Field F
+ⱽ-assoc : (v₁ v₂ v₃ : Vec A n)
→ v₁ +ⱽ v₂ +ⱽ v₃ ≡ v₁ +ⱽ (v₂ +ⱽ v₃)
+ⱽ-assoc [] [] [] = refl
+ⱽ-assoc (v₁ ∷ vs₁) (v₂ ∷ vs₂) (v₃ ∷ vs₃) rewrite
+ⱽ-assoc vs₁ vs₂ vs₃
| +-assoc v₁ v₂ v₃
= refl
+ⱽ-comm : (v₁ v₂ : Vec A n) → v₁ +ⱽ v₂ ≡ v₂ +ⱽ v₁
+ⱽ-comm [] [] = refl
+ⱽ-comm (x₁ ∷ vs₁) (x₂ ∷ vs₂) =
begin
x₁ + x₂ ∷ vs₁ +ⱽ vs₂ ≡⟨ cong ((x₁ + x₂) ∷_) (+ⱽ-comm vs₁ vs₂) ⟩
x₁ + x₂ ∷ vs₂ +ⱽ vs₁ ≡⟨ cong (_∷ vs₂ +ⱽ vs₁) (+-comm x₁ x₂) ⟩
x₂ + x₁ ∷ vs₂ +ⱽ vs₁ ∎
v+0ᶠⱽ≡v : (v : Vec A n) → v +ⱽ (replicate 0ᶠ) ≡ v
v+0ᶠⱽ≡v [] = refl
v+0ᶠⱽ≡v (v ∷ vs) = cong₂ _∷_ (+0ᶠ v) (v+0ᶠⱽ≡v vs)
0ᶠⱽ+v≡v : (v : Vec A n) → (replicate 0ᶠ) +ⱽ v ≡ v
0ᶠⱽ+v≡v v = trans (+ⱽ-comm (replicate 0ᶠ) v) (v+0ᶠⱽ≡v v)
0ᶠ∘ⱽv≡0ᶠⱽ : (v : Vec A n) → 0ᶠ ∘ⱽ v ≡ replicate 0ᶠ
0ᶠ∘ⱽv≡0ᶠⱽ [] = refl
0ᶠ∘ⱽv≡0ᶠⱽ (v ∷ vs) = cong₂ _∷_ (0ᶠ*a≡0ᶠ v) (0ᶠ∘ⱽv≡0ᶠⱽ vs)
c∘ⱽ0ᶠⱽ≡0ᶠⱽ : {n : ℕ} → (c : A) → c ∘ⱽ replicate {n = n} 0ᶠ ≡ replicate 0ᶠ
c∘ⱽ0ᶠⱽ≡0ᶠⱽ {zero} c = refl
c∘ⱽ0ᶠⱽ≡0ᶠⱽ {suc n} c = cong₂ _∷_ (a*0ᶠ≡0ᶠ c) (c∘ⱽ0ᶠⱽ≡0ᶠⱽ c)
v*ⱽ0ᶠⱽ≡0ᶠⱽ : {n : ℕ} → (v : Vec A n) → v *ⱽ replicate 0ᶠ ≡ replicate 0ᶠ
v*ⱽ0ᶠⱽ≡0ᶠⱽ [] = refl
v*ⱽ0ᶠⱽ≡0ᶠⱽ (v ∷ vs) = cong₂ _∷_ (a*0ᶠ≡0ᶠ v) (v*ⱽ0ᶠⱽ≡0ᶠⱽ vs)
map-*c-≡c∘ⱽ : (c : A) (v : Vec A n) → map (_* c) v ≡ c ∘ⱽ v
map-*c-≡c∘ⱽ c [] = refl
map-*c-≡c∘ⱽ c (v ∷ vs) = cong₂ _∷_ (*-comm v c) (map-*c-≡c∘ⱽ c vs)
replicate-distr-+ : {n : ℕ} → (u v : A)
→ replicate {n = n} (u + v) ≡ replicate u +ⱽ replicate v
replicate-distr-+ u v = sym (zipWith-replicate _+_ u v)
-- This should work for any linear function (I think), instead of just -_,
*ⱽ-map--ⱽ : (a v : Vec A n)
→ a *ⱽ (map -_ v) ≡ map -_ (a *ⱽ v)
*ⱽ-map--ⱽ [] [] = refl
*ⱽ-map--ⱽ (a ∷ as) (v ∷ vs) = begin
(a ∷ as) *ⱽ map -_ (v ∷ vs)
≡⟨⟩
(a * - v) ∷ (as *ⱽ map -_ vs)
≡⟨ cong ((a * - v) ∷_) (*ⱽ-map--ⱽ as vs) ⟩
(a * - v) ∷ (map -_ (as *ⱽ vs))
≡⟨ cong (_∷ (map -_ (as *ⱽ vs))) (a*-b≡-[a*b] a v) ⟩
(- (a * v)) ∷ (map -_ (as *ⱽ vs))
≡⟨⟩
map -_ ((a ∷ as) *ⱽ (v ∷ vs))
∎
-ⱽ≡-1ᶠ∘ⱽ : (v : Vec A n) → map -_ v ≡ (- 1ᶠ) ∘ⱽ v
-ⱽ≡-1ᶠ∘ⱽ [] = refl
-ⱽ≡-1ᶠ∘ⱽ (v ∷ vs) = begin
map -_ (v ∷ vs) ≡⟨⟩
(- v) ∷ map -_ vs ≡⟨ cong₂ (_∷_) (-a≡-1ᶠ*a v) (-ⱽ≡-1ᶠ∘ⱽ vs) ⟩
(- 1ᶠ * v) ∷ (- 1ᶠ) ∘ⱽ vs ≡⟨⟩
(- 1ᶠ) ∘ⱽ (v ∷ vs) ∎
*ⱽ-assoc : (v₁ v₂ v₃ : Vec A n)
→ v₁ *ⱽ v₂ *ⱽ v₃ ≡ v₁ *ⱽ (v₂ *ⱽ v₃)
*ⱽ-assoc [] [] [] = refl
*ⱽ-assoc (v₁ ∷ vs₁) (v₂ ∷ vs₂) (v₃ ∷ vs₃) rewrite
*ⱽ-assoc vs₁ vs₂ vs₃
| *-assoc v₁ v₂ v₃
= refl
*ⱽ-comm : (v₁ v₂ : Vec A n) → v₁ *ⱽ v₂ ≡ v₂ *ⱽ v₁
*ⱽ-comm [] [] = refl
*ⱽ-comm (v₁ ∷ vs₁) (v₂ ∷ vs₂) rewrite
*ⱽ-comm vs₁ vs₂
| *-comm v₁ v₂
= refl
*ⱽ-distr-+ⱽ : (a u v : Vec A n)
→ a *ⱽ (u +ⱽ v) ≡ a *ⱽ u +ⱽ a *ⱽ v
*ⱽ-distr-+ⱽ [] [] [] = refl
*ⱽ-distr-+ⱽ (a ∷ as) (u ∷ us) (v ∷ vs) rewrite
*ⱽ-distr-+ⱽ as us vs
| *-distr-+ a u v
= refl
*ⱽ-distr--ⱽ : (a u v : Vec A n)
→ a *ⱽ (u -ⱽ v) ≡ a *ⱽ u -ⱽ a *ⱽ v
*ⱽ-distr--ⱽ a u v = begin
a *ⱽ (u -ⱽ v) ≡⟨⟩
a *ⱽ (u +ⱽ (map (-_) v)) ≡⟨ *ⱽ-distr-+ⱽ a u (map -_ v) ⟩
a *ⱽ u +ⱽ a *ⱽ (map -_ v) ≡⟨ cong (a *ⱽ u +ⱽ_) (*ⱽ-map--ⱽ a v) ⟩
a *ⱽ u +ⱽ (map -_ (a *ⱽ v)) ≡⟨⟩
a *ⱽ u -ⱽ a *ⱽ v ∎
-- Homogeneity of degree 1 for linear maps
*ⱽ∘ⱽ≡∘ⱽ*ⱽ : (c : A) (u v : Vec A n)
→ u *ⱽ c ∘ⱽ v ≡ c ∘ⱽ (u *ⱽ v)
*ⱽ∘ⱽ≡∘ⱽ*ⱽ c [] [] = refl
*ⱽ∘ⱽ≡∘ⱽ*ⱽ c (u ∷ us) (v ∷ vs) rewrite
*ⱽ∘ⱽ≡∘ⱽ*ⱽ c us vs
| *-assoc u c v
| *-comm u c
| sym (*-assoc c u v)
= refl
∘ⱽ*ⱽ-assoc : (c : A) (u v : Vec A n)
→ c ∘ⱽ (u *ⱽ v) ≡ (c ∘ⱽ u) *ⱽ v
∘ⱽ*ⱽ-assoc c [] [] = refl
∘ⱽ*ⱽ-assoc c (u ∷ us) (v ∷ vs) = cong₂ (_∷_) (*-assoc c u v)
(∘ⱽ*ⱽ-assoc c us vs)
∘ⱽ-distr-+ⱽ : (c : A) (u v : Vec A n)
→ c ∘ⱽ (u +ⱽ v) ≡ c ∘ⱽ u +ⱽ c ∘ⱽ v
∘ⱽ-distr-+ⱽ c [] [] = refl
∘ⱽ-distr-+ⱽ c (u ∷ us) (v ∷ vs) rewrite
∘ⱽ-distr-+ⱽ c us vs
| *-distr-+ c u v
= refl
∘ⱽ-comm : (a b : A) (v : Vec A n) → a ∘ⱽ (b ∘ⱽ v) ≡ b ∘ⱽ (a ∘ⱽ v)
∘ⱽ-comm a b [] = refl
∘ⱽ-comm a b (v ∷ vs) = cong₂ _∷_ (trans (trans (*-assoc a b v)
(cong (_* v) (*-comm a b)))
(sym (*-assoc b a v)))
(∘ⱽ-comm a b vs)
+ⱽ-flip-++ : (a b : Vec A n) → (c d : Vec A m)
→ (a ++ c) +ⱽ (b ++ d) ≡ a +ⱽ b ++ c +ⱽ d
+ⱽ-flip-++ [] [] c d = refl
+ⱽ-flip-++ (a ∷ as) (b ∷ bs) c d rewrite +ⱽ-flip-++ as bs c d = refl
∘ⱽ-distr-++ : (c : A) (a : Vec A n) (b : Vec A m)
→ c ∘ⱽ (a ++ b) ≡ (c ∘ⱽ a) ++ (c ∘ⱽ b)
∘ⱽ-distr-++ c [] b = refl
∘ⱽ-distr-++ c (a ∷ as) b rewrite ∘ⱽ-distr-++ c as b = refl
replicate[a*b]≡a∘ⱽreplicate[b] : {n : ℕ} (a b : A) →
replicate {n = n} (a * b) ≡ a ∘ⱽ replicate b
replicate[a*b]≡a∘ⱽreplicate[b] {n = n} a b = sym (map-replicate (a *_) b n)
replicate[a*b]≡b∘ⱽreplicate[a] : {n : ℕ} (a b : A) →
replicate {n = n} (a * b) ≡ b ∘ⱽ replicate a
replicate[a*b]≡b∘ⱽreplicate[a] a b = trans (cong replicate (*-comm a b))
(replicate[a*b]≡a∘ⱽreplicate[b] b a)
sum[0ᶠⱽ]≡0ᶠ : {n : ℕ} → sum (replicate {n = n} 0ᶠ) ≡ 0ᶠ
sum[0ᶠⱽ]≡0ᶠ {n = zero} = refl
sum[0ᶠⱽ]≡0ᶠ {n = suc n} = begin
sum (0ᶠ ∷ replicate {n = n} 0ᶠ) ≡⟨⟩
0ᶠ + sum (replicate {n = n} 0ᶠ) ≡⟨ cong (0ᶠ +_) (sum[0ᶠⱽ]≡0ᶠ {n}) ⟩
0ᶠ + 0ᶠ ≡⟨ 0ᶠ+0ᶠ≡0ᶠ ⟩
0ᶠ ∎
sum-distr-+ⱽ : (v₁ v₂ : Vec A n) → sum (v₁ +ⱽ v₂) ≡ sum v₁ + sum v₂
sum-distr-+ⱽ [] [] = sym (0ᶠ+0ᶠ≡0ᶠ)
sum-distr-+ⱽ (v₁ ∷ vs₁) (v₂ ∷ vs₂) rewrite
sum-distr-+ⱽ vs₁ vs₂
| +-assoc (v₁ + v₂) (foldr (λ v → A) _+_ 0ᶠ vs₁) (foldr (λ v → A) _+_ 0ᶠ vs₂)
| sym (+-assoc v₁ v₂ (foldr (λ v → A) _+_ 0ᶠ vs₁))
| +-comm v₂ (foldr (λ v → A) _+_ 0ᶠ vs₁)
| +-assoc v₁ (foldr (λ v → A) _+_ 0ᶠ vs₁) v₂
| sym (+-assoc (v₁ + (foldr (λ v → A) _+_ 0ᶠ vs₁)) v₂ (foldr (λ v → A) _+_ 0ᶠ vs₂))
= refl
sum[c∘ⱽv]≡c*sum[v] : (c : A) (v : Vec A n) → sum (c ∘ⱽ v) ≡ c * sum v
sum[c∘ⱽv]≡c*sum[v] c [] = sym (a*0ᶠ≡0ᶠ c)
sum[c∘ⱽv]≡c*sum[v] c (v ∷ vs) = begin
sum (c ∘ⱽ (v ∷ vs)) ≡⟨⟩
c * v + sum (c ∘ⱽ vs) ≡⟨ cong (c * v +_) (sum[c∘ⱽv]≡c*sum[v] c vs) ⟩
c * v + c * sum vs ≡⟨ sym (*-distr-+ c v (sum vs)) ⟩
c * (v + sum vs) ≡⟨⟩
c * sum (v ∷ vs) ∎
⟨⟩-comm : (v₁ v₂ : Vec A n)
→ ⟨ v₁ , v₂ ⟩ ≡ ⟨ v₂ , v₁ ⟩
⟨⟩-comm v₁ v₂ = cong sum (*ⱽ-comm v₁ v₂)
-- Should we show bilinearity?
-- ∀ λ ∈ F, B(λv, w) ≡ B(v, λw) ≡ λB(v, w)
-- B(v₁ + v₂, w) ≡ B(v₁, w) + B(v₂, w) ∧ B(v, w₁ + w₂) ≡ B(v, w₁) + B(v, w₂)
-- Additivity in both arguments
⟨x+y,z⟩≡⟨x,z⟩+⟨y,z⟩ : (x y z : Vec A n)
→ ⟨ x +ⱽ y , z ⟩ ≡ (⟨ x , z ⟩) + (⟨ y , z ⟩)
⟨x+y,z⟩≡⟨x,z⟩+⟨y,z⟩ x y z = begin
⟨ x +ⱽ y , z ⟩
≡⟨⟩
sum ((x +ⱽ y) *ⱽ z )
≡⟨ cong sum (*ⱽ-comm (x +ⱽ y) z) ⟩
sum (z *ⱽ (x +ⱽ y))
≡⟨ cong sum (*ⱽ-distr-+ⱽ z x y) ⟩
sum (z *ⱽ x +ⱽ z *ⱽ y)
≡⟨ sum-distr-+ⱽ (z *ⱽ x) (z *ⱽ y) ⟩
sum (z *ⱽ x) + sum (z *ⱽ y)
≡⟨⟩
⟨ z , x ⟩ + ⟨ z , y ⟩
≡⟨ cong (_+ ⟨ z , y ⟩) (⟨⟩-comm z x) ⟩
⟨ x , z ⟩ + ⟨ z , y ⟩
≡⟨ cong (⟨ x , z ⟩ +_ ) (⟨⟩-comm z y) ⟩
⟨ x , z ⟩ + ⟨ y , z ⟩
∎
⟨x,y+z⟩≡⟨x,y⟩+⟨x,z⟩ : (x y z : Vec A n)
→ ⟨ x , y +ⱽ z ⟩ ≡ (⟨ x , y ⟩) + (⟨ x , z ⟩)
⟨x,y+z⟩≡⟨x,y⟩+⟨x,z⟩ x y z =
begin
⟨ x , y +ⱽ z ⟩ ≡⟨ ⟨⟩-comm x (y +ⱽ z) ⟩
⟨ y +ⱽ z , x ⟩ ≡⟨ ⟨x+y,z⟩≡⟨x,z⟩+⟨y,z⟩ y z x ⟩
⟨ y , x ⟩ + ⟨ z , x ⟩ ≡⟨ cong (_+ ⟨ z , x ⟩) (⟨⟩-comm y x) ⟩
⟨ x , y ⟩ + ⟨ z , x ⟩ ≡⟨ cong (⟨ x , y ⟩ +_ ) (⟨⟩-comm z x) ⟩
⟨ x , y ⟩ + ⟨ x , z ⟩ ∎
⟨a++b,c++d⟩≡⟨a,c⟩+⟨b,d⟩ : (a : Vec A m) → (b : Vec A n) → (c : Vec A m) → (d : Vec A n)
→ ⟨ a ++ b , c ++ d ⟩ ≡ ⟨ a , c ⟩ + ⟨ b , d ⟩
⟨a++b,c++d⟩≡⟨a,c⟩+⟨b,d⟩ [] b [] d rewrite 0ᶠ+ (⟨ b , d ⟩) = refl
⟨a++b,c++d⟩≡⟨a,c⟩+⟨b,d⟩ (a ∷ as) b (c ∷ cs) d =
begin
⟨ a ∷ as ++ b , c ∷ cs ++ d ⟩
≡⟨⟩
(a * c) + ⟨ as ++ b , cs ++ d ⟩
≡⟨ cong ((a * c) +_) (⟨a++b,c++d⟩≡⟨a,c⟩+⟨b,d⟩ as b cs d) ⟩
(a * c) + (⟨ as , cs ⟩ + ⟨ b , d ⟩)
≡⟨ +-assoc (a * c) ⟨ as , cs ⟩ ⟨ b , d ⟩ ⟩
((a * c) + ⟨ as , cs ⟩) + ⟨ b , d ⟩
≡⟨⟩
⟨ a ∷ as , c ∷ cs ⟩ + ⟨ b , d ⟩
∎
⟨a,b⟩+⟨c,d⟩≡⟨a++c,b++d⟩ : (a b : Vec A m) → (c d : Vec A n)
→ ⟨ a , b ⟩ + ⟨ c , d ⟩ ≡ ⟨ a ++ c , b ++ d ⟩
⟨a,b⟩+⟨c,d⟩≡⟨a++c,b++d⟩ a b c d = sym (⟨a++b,c++d⟩≡⟨a,c⟩+⟨b,d⟩ a c b d)
|
{
"alphanum_fraction": 0.4030042918,
"avg_line_length": 35.4372623574,
"ext": "agda",
"hexsha": "af38b72a60338eefc2a8905148212700790ba90a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-09-07T19:55:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-12T20:34:17.000Z",
"max_forks_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "turion/functional-linear-algebra",
"max_forks_repo_path": "src/FLA/Algebra/LinearAlgebra/Properties.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_issues_repo_issues_event_max_datetime": "2022-01-07T05:27:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-01T01:42:12.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "turion/functional-linear-algebra",
"max_issues_repo_path": "src/FLA/Algebra/LinearAlgebra/Properties.agda",
"max_line_length": 89,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "turion/functional-linear-algebra",
"max_stars_repo_path": "src/FLA/Algebra/LinearAlgebra/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-07T05:28:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-22T20:49:34.000Z",
"num_tokens": 5529,
"size": 9320
}
|
module Problem1 where
-- 1.1
data Nat : Set where
zero : Nat
suc : Nat -> Nat
-- 1.2
infixl 60 _+_
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
-- 1.3
infixl 70 _*_
_*_ : Nat -> Nat -> Nat
zero * m = zero
suc n * m = m + n * m
-- 1.4
infix 30 _==_
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
assoc : (x y z : Nat) -> x + (y + z) == (x + y) + z
assoc zero y z = refl
assoc (suc x) y z = cong suc (assoc x y z)
-- Alternative solution using 'with'. Note that in order
-- to be able to pattern match on the induction hypothesis
-- we have to abstract (using with) over the left hand side
-- of the equation.
assoc' : (x y z : Nat) -> x + (y + z) == (x + y) + z
assoc' zero y z = refl
assoc' (suc x) y z with x + (y + z) | assoc x y z
... | .((x + y) + z) | refl = refl
|
{
"alphanum_fraction": 0.5145945946,
"avg_line_length": 18.8775510204,
"ext": "agda",
"hexsha": "21f1196d3561e0d31e897f3c05729118caca04c0",
"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": "examples/SummerSchool07/Solutions/Problem1.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": "examples/SummerSchool07/Solutions/Problem1.agda",
"max_line_length": 63,
"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": "examples/SummerSchool07/Solutions/Problem1.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": 363,
"size": 925
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Solver for monoid equalities
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Solver.Monoid {m₁ m₂} (M : Monoid m₁ m₂) where
open import Data.Fin as Fin hiding (_≟_)
import Data.Fin.Properties as Fin
open import Data.List.Base hiding (lookup)
import Data.List.Relation.Binary.Equality.DecPropositional as ListEq
open import Data.Maybe as Maybe
using (Maybe; decToMaybe; From-just; from-just)
open import Data.Nat.Base using (ℕ)
open import Data.Product
open import Data.Vec using (Vec; lookup)
open import Function using (_∘_; _$_)
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
import Relation.Binary.Reflection
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open Monoid M
open import Relation.Binary.Reasoning.Setoid setoid
------------------------------------------------------------------------
-- Monoid expressions
-- There is one constructor for every operation, plus one for
-- variables; there may be at most n variables.
infixr 5 _⊕_
data Expr (n : ℕ) : Set where
var : Fin n → Expr n
id : Expr n
_⊕_ : Expr n → Expr n → Expr n
-- An environment contains one value for every variable.
Env : ℕ → Set _
Env n = Vec Carrier n
-- The semantics of an expression is a function from an environment to
-- a value.
⟦_⟧ : ∀ {n} → Expr n → Env n → Carrier
⟦ var x ⟧ ρ = lookup ρ x
⟦ id ⟧ ρ = ε
⟦ e₁ ⊕ e₂ ⟧ ρ = ⟦ e₁ ⟧ ρ ∙ ⟦ e₂ ⟧ ρ
------------------------------------------------------------------------
-- Normal forms
-- A normal form is a list of variables.
Normal : ℕ → Set
Normal n = List (Fin n)
-- The semantics of a normal form.
⟦_⟧⇓ : ∀ {n} → Normal n → Env n → Carrier
⟦ [] ⟧⇓ ρ = ε
⟦ x ∷ nf ⟧⇓ ρ = lookup ρ x ∙ ⟦ nf ⟧⇓ ρ
-- A normaliser.
normalise : ∀ {n} → Expr n → Normal n
normalise (var x) = x ∷ []
normalise id = []
normalise (e₁ ⊕ e₂) = normalise e₁ ++ normalise e₂
-- The normaliser is homomorphic with respect to _++_/_∙_.
homomorphic : ∀ {n} (nf₁ nf₂ : Normal n) (ρ : Env n) →
⟦ nf₁ ++ nf₂ ⟧⇓ ρ ≈ (⟦ nf₁ ⟧⇓ ρ ∙ ⟦ nf₂ ⟧⇓ ρ)
homomorphic [] nf₂ ρ = begin
⟦ nf₂ ⟧⇓ ρ ≈⟨ sym $ identityˡ _ ⟩
ε ∙ ⟦ nf₂ ⟧⇓ ρ ∎
homomorphic (x ∷ nf₁) nf₂ ρ = begin
lookup ρ x ∙ ⟦ nf₁ ++ nf₂ ⟧⇓ ρ ≈⟨ ∙-congˡ (homomorphic nf₁ nf₂ ρ) ⟩
lookup ρ x ∙ (⟦ nf₁ ⟧⇓ ρ ∙ ⟦ nf₂ ⟧⇓ ρ) ≈⟨ sym $ assoc _ _ _ ⟩
lookup ρ x ∙ ⟦ nf₁ ⟧⇓ ρ ∙ ⟦ nf₂ ⟧⇓ ρ ∎
-- The normaliser preserves the semantics of the expression.
normalise-correct :
∀ {n} (e : Expr n) (ρ : Env n) → ⟦ normalise e ⟧⇓ ρ ≈ ⟦ e ⟧ ρ
normalise-correct (var x) ρ = begin
lookup ρ x ∙ ε ≈⟨ identityʳ _ ⟩
lookup ρ x ∎
normalise-correct id ρ = begin
ε ∎
normalise-correct (e₁ ⊕ e₂) ρ = begin
⟦ normalise e₁ ++ normalise e₂ ⟧⇓ ρ ≈⟨ homomorphic (normalise e₁) (normalise e₂) ρ ⟩
⟦ normalise e₁ ⟧⇓ ρ ∙ ⟦ normalise e₂ ⟧⇓ ρ ≈⟨ ∙-cong (normalise-correct e₁ ρ) (normalise-correct e₂ ρ) ⟩
⟦ e₁ ⟧ ρ ∙ ⟦ e₂ ⟧ ρ ∎
------------------------------------------------------------------------
-- "Tactics"
open module R = Relation.Binary.Reflection
setoid var ⟦_⟧ (⟦_⟧⇓ ∘ normalise) normalise-correct
public using (solve; _⊜_)
-- We can decide if two normal forms are /syntactically/ equal.
infix 5 _≟_
_≟_ : ∀ {n} → Decidable {A = Normal n} _≡_
nf₁ ≟ nf₂ = Dec.map′ ≋⇒≡ ≡⇒≋ (nf₁ ≋? nf₂)
where open ListEq Fin._≟_
-- We can also give a sound, but not necessarily complete, procedure
-- for determining if two expressions have the same semantics.
prove′ : ∀ {n} (e₁ e₂ : Expr n) → Maybe (∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ)
prove′ e₁ e₂ =
Maybe.map lemma $ decToMaybe (normalise e₁ ≟ normalise e₂)
where
lemma : normalise e₁ ≡ normalise e₂ → ∀ ρ → ⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
lemma eq ρ =
R.prove ρ e₁ e₂ (begin
⟦ normalise e₁ ⟧⇓ ρ ≡⟨ P.cong (λ e → ⟦ e ⟧⇓ ρ) eq ⟩
⟦ normalise e₂ ⟧⇓ ρ ∎)
-- This procedure can be combined with from-just.
prove : ∀ n (es : Expr n × Expr n) →
From-just (uncurry prove′ es)
prove _ = from-just ∘ uncurry prove′
|
{
"alphanum_fraction": 0.5662423385,
"avg_line_length": 30.5179856115,
"ext": "agda",
"hexsha": "266add0fe6419395aff1794fe89820518e7b48b2",
"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/Solver/Monoid.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/Solver/Monoid.agda",
"max_line_length": 106,
"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/Solver/Monoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1541,
"size": 4242
}
|
open import Oscar.Prelude
open import Oscar.Data.¶
open import Oscar.Data.Fin
open import Oscar.Data.Term
module Oscar.Data.Substitunction where
module Substitunction {𝔭} (𝔓 : Ø 𝔭) where
open Term 𝔓
Substitunction : ¶ → ¶ → Ø 𝔭
Substitunction m n = ¶⟨< m ⟩ → Term n
module SubstitunctionOperator {𝔭} (𝔓 : Ø 𝔭) where
open Substitunction 𝔓
_⊸_ = Substitunction
|
{
"alphanum_fraction": 0.7108753316,
"avg_line_length": 17.9523809524,
"ext": "agda",
"hexsha": "7ef33a57f6ed07d03e5a1f1c8cfddc558419db28",
"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/Oscar/Data/Substitunction.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/Oscar/Data/Substitunction.agda",
"max_line_length": 49,
"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/Oscar/Data/Substitunction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 137,
"size": 377
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.HLevels
module Cubical.Algebra.Magma.Construct.Free {ℓ} (Aˢ : hSet ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Magma
open import Cubical.Data.Empty.Polymorphic
open import Cubical.Data.Prod
A = ⟨ Aˢ ⟩
isSetA = Aˢ .snd
------------------------------------------------------------------------
-- The free magma type
data FreeM : Type ℓ where
inj : A → FreeM
_•_ : Op₂ FreeM
------------------------------------------------------------------------
-- Proof the free magma is a set
module FreeMPath where
Cover : FreeM → FreeM → Type ℓ
Cover (inj x) (inj y) = x ≡ y
Cover (inj x) (y₁ • y₂) = ⊥
Cover (x₁ • x₂) (inj y) = ⊥
Cover (x₁ • x₂) (y₁ • y₂) = Cover x₁ y₁ × Cover x₂ y₂
isPropCover : ∀ x y → isProp (Cover x y)
isPropCover (inj x) (inj y) = isSetA x y
isPropCover (inj x) (y₁ • y₂) = isProp⊥
isPropCover (x₁ • x₂) (inj y) = isProp⊥
isPropCover (x₁ • x₂) (y₁ • y₂) = isPropProd (isPropCover x₁ y₁) (isPropCover x₂ y₂)
reflCover : ∀ x → Cover x x
reflCover (inj x) = refl
reflCover (x • y) = reflCover x , reflCover y
encode : ∀ x y → x ≡ y → Cover x y
encode x _ = J (λ y _ → Cover x y) (reflCover x)
encodeRefl : ∀ x → encode x x refl ≡ reflCover x
encodeRefl x = JRefl (λ y _ → Cover x y) (reflCover x)
decode : ∀ x y → Cover x y → x ≡ y
decode (inj x) (inj y) p = cong inj p
decode (inj x) (y₁ • y₂) ()
decode (x₁ • x₂) (inj y) ()
decode (x₁ • x₂) (y₁ • y₂) (p , q) = cong₂ _•_ (decode x₁ y₁ p) (decode x₂ y₂ q)
decodeRefl : ∀ x → decode x x (reflCover x) ≡ refl
decodeRefl (inj x) = refl
decodeRefl (x • y) i j = decodeRefl x i j • decodeRefl y i j
decodeEncode : ∀ x y → (p : x ≡ y) → decode x y (encode x y p) ≡ p
decodeEncode x _ =
J (λ y p → decode x y (encode x y p) ≡ p)
(cong (decode x x) (encodeRefl x) ? decodeRefl x)
isSetFreeM : isSet FreeM
isSetFreeM x y =
isOfHLevelRetract 1
(FreeMPath.encode x y)
(FreeMPath.decode x y)
(FreeMPath.decodeEncode x y)
(FreeMPath.isPropCover x y)
------------------------------------------------------------------------
-- The free magma
FreeM-isMagma : IsMagma FreeM _•_
FreeM-isMagma = record { is-set = isSetFreeM }
FreeMagma : Magma ℓ
FreeMagma = record { isMagma = FreeM-isMagma }
|
{
"alphanum_fraction": 0.5747078464,
"avg_line_length": 28.8674698795,
"ext": "agda",
"hexsha": "5a9b5c5e5a871d83e76ec0f8919a1736ec1c14b1",
"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/Magma/Construct/Free.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/Magma/Construct/Free.agda",
"max_line_length": 86,
"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/Magma/Construct/Free.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 877,
"size": 2396
}
|
open import SOAS.Common
open import SOAS.Families.Core
open import Categories.Object.Initial
open import SOAS.Coalgebraic.Strength
import SOAS.Metatheory.MetaAlgebra
-- Traversals parametrised by a pointed coalgebra
module SOAS.Metatheory.Traversal {T : Set}
(⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ) (⅀:Str : Strength ⅀F)
(𝔛 : Familyₛ) (open SOAS.Metatheory.MetaAlgebra ⅀F 𝔛)
(𝕋:Init : Initial 𝕄etaAlgebras)
where
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Abstract.Hom
import SOAS.Abstract.Coalgebra as →□ ; open →□.Sorted
import SOAS.Abstract.Box as □ ; open □.Sorted
open import SOAS.Metatheory.Algebra ⅀F
open import SOAS.Metatheory.Semantics ⅀F ⅀:Str 𝔛 𝕋:Init
open Strength ⅀:Str
private
variable
Γ Δ Θ Π : Ctx
α β : T
𝒫 𝒬 𝒜 : Familyₛ
-- Parametrised interpretation into an internal hom
module Traversal (𝒫ᴮ : Coalgₚ 𝒫)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(φ : 𝒫 ⇾̣ 𝒜)(χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗) where
open Coalgₚ 𝒫ᴮ
-- Under the assumptions 𝒜 and 〖 𝒫 , 𝒜 〗 are both meta-algebras
𝒜ᵃ : MetaAlg 𝒜
𝒜ᵃ = record { 𝑎𝑙𝑔 = 𝑎𝑙𝑔 ; 𝑣𝑎𝑟 = λ x → φ (η x) ; 𝑚𝑣𝑎𝑟 = χ }
Travᵃ : MetaAlg 〖 𝒫 , 𝒜 〗
Travᵃ = record
{ 𝑎𝑙𝑔 = λ t σ → 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 t σ)
; 𝑣𝑎𝑟 = λ x σ → φ (σ x)
; 𝑚𝑣𝑎𝑟 = λ 𝔪 ε σ → χ 𝔪 (λ 𝔫 → ε 𝔫 σ)
}
-- 〖 𝒫 , 𝒜 〗 is also a pointed □-coalgebra
Travᵇ : Coalg 〖 𝒫 , 𝒜 〗
Travᵇ = record { r = λ h ρ σ → h (σ ∘ ρ) ; counit = refl ; comult = refl }
Travᴮ : Coalgₚ 〖 𝒫 , 𝒜 〗
Travᴮ = record { ᵇ = Travᵇ ; η = λ x σ → φ (σ x) ; r∘η = refl }
open Semantics Travᵃ public renaming (𝕤𝕖𝕞 to 𝕥𝕣𝕒𝕧)
-- Traversal-specific homomorphism properties that incorporate a substitution
𝕥⟨𝕧⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ} → 𝕥𝕣𝕒𝕧 (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
𝕥⟨𝕧⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕧⟩
𝕥⟨𝕞⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ 𝕥𝕣𝕒𝕧 (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → 𝕥𝕣𝕒𝕧 (ε p) σ)
𝕥⟨𝕞⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕞⟩
𝕥⟨𝕒⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ 𝕥𝕣𝕒𝕧 (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ 𝕥𝕣𝕒𝕧 t) σ)
𝕥⟨𝕒⟩ {σ = σ} = cong (λ - → - σ) ⟨𝕒⟩
-- Congruence in the two arguments of 𝕥𝕣𝕒𝕧
𝕥≈₁ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t₁ t₂ : 𝕋 α Γ} → t₁ ≡ t₂ → 𝕥𝕣𝕒𝕧 t₁ σ ≡ 𝕥𝕣𝕒𝕧 t₂ σ
𝕥≈₁ {σ = σ} p = cong (λ - → 𝕥𝕣𝕒𝕧 - σ) p
𝕥≈₂ : {σ₁ σ₂ : Γ ~[ 𝒫 ]↝ Δ}{t : 𝕋 α Γ}
→ ({τ : T}{x : ℐ τ Γ} → σ₁ x ≡ σ₂ x)
→ 𝕥𝕣𝕒𝕧 t σ₁ ≡ 𝕥𝕣𝕒𝕧 t σ₂
𝕥≈₂ {t = t} p = cong (𝕥𝕣𝕒𝕧 t) (dext′ p)
-- A pointed meta-Λ-algebra induces 𝕒𝕝𝕘 traversal into □ 𝒜
module □Traversal {𝒜} (𝒜ᵃ : MetaAlg 𝒜) =
Traversal ℐᴮ (MetaAlg.𝑎𝑙𝑔 𝒜ᵃ) (MetaAlg.𝑣𝑎𝑟 𝒜ᵃ) (MetaAlg.𝑚𝑣𝑎𝑟 𝒜ᵃ)
-- Corollary: □ lifts to an endofunctor on pointed meta-Λ-algebras
□ᵃ : (𝒜ᵃ : MetaAlg 𝒜) → MetaAlg (□ 𝒜)
□ᵃ = □Traversal.Travᵃ
-- Helper records for proving equality of maps f, g out of 𝕋,
-- with 0, 1 or 2 parameters
record MapEq₀ (𝒜 : Familyₛ)(f g : 𝕋 ⇾̣ 𝒜) : Set where
field
ᵃ : MetaAlg 𝒜
open Semantics ᵃ
open 𝒜
field
f⟨𝑣⟩ : {x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) ≡ 𝑣𝑎𝑟 x
f⟨𝑚⟩ : {𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) ≡ 𝑚𝑣𝑎𝑟 𝔪 (f ∘ ε)
f⟨𝑎⟩ : {t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) ≡ 𝑎𝑙𝑔 (⅀₁ f t)
g⟨𝑣⟩ : {x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) ≡ 𝑣𝑎𝑟 x
g⟨𝑚⟩ : {𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) ≡ 𝑚𝑣𝑎𝑟 𝔪 (g ∘ ε)
g⟨𝑎⟩ : {t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) ≡ 𝑎𝑙𝑔 (⅀₁ g t)
fᵃ : MetaAlg⇒ 𝕋ᵃ ᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = f⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = f⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = f⟨𝑚⟩ }
gᵃ : MetaAlg⇒ 𝕋ᵃ ᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = g⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = g⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = g⟨𝑚⟩ }
≈ : (t : 𝕋 α Γ) → f t ≡ g t
≈ t = eq fᵃ gᵃ t
record MapEq₁ (𝒫ᴮ : Coalgₚ 𝒫)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(f g : 𝕋 ⇾̣ 〖 𝒫 , 𝒜 〗) : Set where
field
φ : 𝒫 ⇾̣ 𝒜
χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗
open Traversal 𝒫ᴮ 𝑎𝑙𝑔 φ χ
field
f⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
f⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → f (ε p) σ)
f⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ f t) σ)
g⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) σ ≡ φ (σ x)
g⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) σ ≡ χ 𝔪 (λ p → g (ε p) σ)
g⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) σ ≡ 𝑎𝑙𝑔 (str 𝒫ᴮ 𝒜 (⅀₁ g t) σ)
fᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ f⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = dext′ f⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ f⟨𝑚⟩ }
gᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ g⟨𝑎⟩ ; ⟨𝑣𝑎𝑟⟩ = dext′ g⟨𝑣⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ g⟨𝑚⟩ }
≈ : {σ : Γ ~[ 𝒫 ]↝ Δ}(t : 𝕋 α Γ) → f t σ ≡ g t σ
≈ {σ = σ} t = cong (λ - → - σ) (eq fᵃ gᵃ t)
record MapEq₂ (𝒫ᴮ : Coalgₚ 𝒫)(𝒬ᴮ : Coalgₚ 𝒬)(𝑎𝑙𝑔 : ⅀ 𝒜 ⇾̣ 𝒜)
(f g : 𝕋 ⇾̣ 〖 𝒫 , 〖 𝒬 , 𝒜 〗 〗) : Set where
field
φ : 𝒬 ⇾̣ 𝒜
ϕ : 𝒫 ⇾̣ 〖 𝒬 , 𝒜 〗
χ : 𝔛 ⇾̣ 〖 𝒜 , 𝒜 〗
open Traversal 𝒫ᴮ (Traversal.𝒜.𝑎𝑙𝑔 𝒬ᴮ 𝑎𝑙𝑔 φ χ) ϕ (λ 𝔪 ε σ → χ 𝔪 (λ 𝔫 → ε 𝔫 σ))
field
f⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{x : ℐ α Γ}
→ f (𝕧𝕒𝕣 x) σ ς ≡ ϕ (σ x) ς
f⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ f (𝕞𝕧𝕒𝕣 𝔪 ε) σ ς ≡ χ 𝔪 (λ 𝔫 → f (ε 𝔫) σ ς)
f⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{t : ⅀ 𝕋 α Γ}
→ f (𝕒𝕝𝕘 t) σ ς ≡ 𝑎𝑙𝑔 (str 𝒬ᴮ 𝒜 (str 𝒫ᴮ 〖 𝒬 , 𝒜 〗 (⅀₁ f t) σ) ς)
g⟨𝑣⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{x : ℐ α Γ}
→ g (𝕧𝕒𝕣 x) σ ς ≡ ϕ (σ x) ς
g⟨𝑚⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{𝔪 : 𝔛 α Π}{ε : Π ~[ 𝕋 ]↝ Γ}
→ g (𝕞𝕧𝕒𝕣 𝔪 ε) σ ς ≡ χ 𝔪 (λ 𝔫 → g (ε 𝔫) σ ς)
g⟨𝑎⟩ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}{t : ⅀ 𝕋 α Γ}
→ g (𝕒𝕝𝕘 t) σ ς ≡ 𝑎𝑙𝑔 (str 𝒬ᴮ 𝒜 (str 𝒫ᴮ 〖 𝒬 , 𝒜 〗 (⅀₁ g t) σ) ς)
fᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ f
fᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ (dext′ f⟨𝑎⟩) ; ⟨𝑣𝑎𝑟⟩ = dext′ (dext′ f⟨𝑣⟩)
; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ (dext′ f⟨𝑚⟩) }
gᵃ : MetaAlg⇒ 𝕋ᵃ Travᵃ g
gᵃ = record { ⟨𝑎𝑙𝑔⟩ = dext′ (dext′ g⟨𝑎⟩) ; ⟨𝑣𝑎𝑟⟩ = dext′ (dext′ g⟨𝑣⟩)
; ⟨𝑚𝑣𝑎𝑟⟩ = dext′ (dext′ g⟨𝑚⟩) }
≈ : {σ : Γ ~[ 𝒫 ]↝ Δ}{ς : Δ ~[ 𝒬 ]↝ Θ}(t : 𝕋 α Γ) → f t σ ς ≡ g t σ ς
≈ {σ = σ}{ς} t = cong (λ - → - σ ς) (eq fᵃ gᵃ t)
-- Interaction of traversal and interpretation
module _ (𝒫ᴮ : Coalgₚ 𝒫)(𝒜ᵃ : MetaAlg 𝒜)(φ : 𝒫 ⇾̣ 𝒜) where
open MetaAlg 𝒜ᵃ
open Coalgₚ 𝒫ᴮ
open Semantics 𝒜ᵃ
open Traversal 𝒫ᴮ 𝑎𝑙𝑔 φ 𝑚𝑣𝑎𝑟 using (𝕥𝕣𝕒𝕧 ; 𝕥⟨𝕒⟩ ; 𝕥⟨𝕧⟩ ; 𝕥⟨𝕞⟩)
open ≡-Reasoning
-- Traversal with the point of 𝒫 is the same as direct interpretation
𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 : (φ∘η≈𝑣𝑎𝑟 : ∀{α Γ}{v : ℐ α Γ} → φ (η v) ≡ 𝑣𝑎𝑟 v){t : 𝕋 α Γ}
→ 𝕥𝕣𝕒𝕧 t η ≡ 𝕤𝕖𝕞 t
𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 φ∘η≈𝑣𝑎𝑟 {t = t} = Semantics.eq 𝒜ᵃ (record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → trans 𝕥⟨𝕒⟩ (cong 𝑎𝑙𝑔 (begin
str 𝒫ᴮ 𝒜 (⅀₁ 𝕥𝕣𝕒𝕧 t) η
≡⟨ str-nat₁ (ηᴮ⇒ 𝒫ᴮ) (⅀₁ 𝕥𝕣𝕒𝕧 t) id ⟩
str ℐᴮ 𝒜 (⅀₁ (λ{ h ρ → h (η ∘ ρ)}) ((⅀₁ 𝕥𝕣𝕒𝕧 t))) id
≡⟨ str-unit 𝒜 ((⅀₁ (λ{ h ρ → h (η ∘ ρ)}) ((⅀₁ 𝕥𝕣𝕒𝕧 t)))) ⟩
⅀₁ (i 𝒜) (⅀₁ (λ { h ρ → h (η ∘ ρ) }) (⅀₁ 𝕥𝕣𝕒𝕧 t))
≡˘⟨ trans ⅀.homomorphism ⅀.homomorphism ⟩
⅀₁ (λ t → 𝕥𝕣𝕒𝕧 t η) t
∎))}
; ⟨𝑣𝑎𝑟⟩ = λ{ {v = v} → trans 𝕥⟨𝕧⟩ φ∘η≈𝑣𝑎𝑟 }
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪}{ε} → 𝕥⟨𝕞⟩ } }) 𝕤𝕖𝕞ᵃ⇒ t
-- Traversal with the point of 𝒫 into 𝕋 is the identity
𝕥𝕣𝕒𝕧-η≈id : (𝒫ᴮ : Coalgₚ 𝒫)(open Coalgₚ 𝒫ᴮ)(φ : 𝒫 ⇾̣ 𝕋)
(φ∘η≈𝑣𝑎𝑟 : ∀{α Γ}{v : ℐ α Γ} → φ (η v) ≡ 𝕧𝕒𝕣 v){t : 𝕋 α Γ}
→ Traversal.𝕥𝕣𝕒𝕧 𝒫ᴮ 𝕒𝕝𝕘 φ 𝕞𝕧𝕒𝕣 t η ≡ t
𝕥𝕣𝕒𝕧-η≈id 𝒫ᴮ φ φ∘η≈𝑣𝑎𝑟 = trans (𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 𝒫ᴮ 𝕋ᵃ φ φ∘η≈𝑣𝑎𝑟) 𝕤𝕖𝕞-id
-- Corollaries for ℐ-parametrised traversals
□𝕥𝕣𝕒𝕧-id≈𝕤𝕖𝕞 : (𝒜ᵃ : MetaAlg 𝒜){t : 𝕋 α Γ}
→ □Traversal.𝕥𝕣𝕒𝕧 𝒜ᵃ t id ≡ Semantics.𝕤𝕖𝕞 𝒜ᵃ t
□𝕥𝕣𝕒𝕧-id≈𝕤𝕖𝕞 𝒜ᵃ {t} = 𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 ℐᴮ 𝒜ᵃ (MetaAlg.𝑣𝑎𝑟 𝒜ᵃ) refl
□𝕥𝕣𝕒𝕧-id≈id : {t : 𝕋 α Γ} → □Traversal.𝕥𝕣𝕒𝕧 𝕋ᵃ t id ≡ t
□𝕥𝕣𝕒𝕧-id≈id = 𝕥𝕣𝕒𝕧-η≈id ℐᴮ 𝕧𝕒𝕣 refl
|
{
"alphanum_fraction": 0.473529804,
"avg_line_length": 34.2420091324,
"ext": "agda",
"hexsha": "23385b98dc79a7c64c7623c9cb8519dc1f4dccee",
"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": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "k4rtik/agda-soas",
"max_forks_repo_path": "SOAS/Metatheory/Traversal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"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": "k4rtik/agda-soas",
"max_issues_repo_path": "SOAS/Metatheory/Traversal.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "k4rtik/agda-soas",
"max_stars_repo_path": "SOAS/Metatheory/Traversal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5767,
"size": 7499
}
|
module Category.Functor.Const where
open import Category.Functor using (RawFunctor ; module RawFunctor )
open import Category.Functor.Lawful
open import Relation.Binary.PropositionalEquality using (refl)
Const : ∀ {l₁ l₂} (R : Set l₂) (_ : Set l₁) → Set l₂
Const R _ = R
constFunctor : ∀ {l₁} {R : Set l₁} → RawFunctor (Const {l₁} R)
constFunctor = record { _<$>_ = λ _ z → z }
constLawfulFunctor : ∀ {l₁} {R : Set l₁} → LawfulFunctorImp (constFunctor {l₁} {R})
constLawfulFunctor = record { <$>-identity = refl ; <$>-compose = refl }
|
{
"alphanum_fraction": 0.6763636364,
"avg_line_length": 36.6666666667,
"ext": "agda",
"hexsha": "37295079d21f39350f7cf621adad431b4082833b",
"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": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crisoagf/agda-optics",
"max_forks_repo_path": "src/Category/Functor/Const.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"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": "crisoagf/agda-optics",
"max_issues_repo_path": "src/Category/Functor/Const.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "308afeeaa905870dbf1a995fa82e8825dfaf2d74",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crisoagf/agda-optics",
"max_stars_repo_path": "src/Category/Functor/Const.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 184,
"size": 550
}
|
module MLib.Algebra.PropertyCode where
open import MLib.Prelude
open import MLib.Finite
open import MLib.Algebra.PropertyCode.RawStruct public
open import MLib.Algebra.PropertyCode.Core as Core public
using (Property; Properties; Code; IsSubcode; _∈ₚ_; _⇒ₚ_; ⟦_⟧P)
renaming (⇒ₚ-weaken to weaken)
open Core.PropKind public
open Core.PropertyC using (_on_; _is_for_; _⟨_⟩ₚ_) public
import Relation.Unary as U using (Decidable)
open import Relation.Binary as B using (Setoid)
open import Data.List.All as All using (All; _∷_; []) public
open import Data.List.Any using (Any; here; there)
open import Data.Bool using (_∨_)
open import Category.Applicative
record Struct {k} (code : Code k) c ℓ : Set (sucˡ (c ⊔ˡ ℓ ⊔ˡ k)) where
open Code code public
field
rawStruct : RawStruct K c ℓ
Π : Properties code
open RawStruct rawStruct public
open Properties Π public
field
reify : ∀ {π} → π ∈ₚ Π → ⟦ π ⟧P rawStruct
Hasₚ : (Π′ : Properties code) → Set
Hasₚ Π′ = Π′ ⇒ₚ Π
Has : List (Property K) → Set
Has = Hasₚ ∘ Core.fromList
Has₁ : Property K → Set
Has₁ π = Hasₚ (Core.singleton π)
use : ∀ π ⦃ hasπ : π ∈ₚ Π ⦄ → ⟦ π ⟧P rawStruct
use _ ⦃ hasπ ⦄ = reify hasπ
from : ∀ {Π′} (hasΠ′ : Hasₚ Π′) π ⦃ hasπ : π ∈ₚ Π′ ⦄ → ⟦ π ⟧P rawStruct
from hasΠ′ _ ⦃ hasπ ⦄ = use _ ⦃ Core.⇒ₚ-MP hasπ hasΠ′ ⦄
substruct : ∀ {k′} {code′ : Code k′} → IsSubcode code′ code → Struct code′ c ℓ
substruct isSub = record
{ rawStruct = record
{ Carrier = Carrier
; _≈_ = _≈_
; appOp = appOp ∘ Core.subK→supK isSub
; isRawStruct = isRawStruct′
}
; Π = Core.subcodeProperties isSub Π
; reify = Core.reinterpret isSub rawStruct isRawStruct′ _ ∘ reify ∘ Core.fromSubcode isSub
}
where
isRawStruct′ = record
{ isEquivalence = isEquivalence
; congⁿ = congⁿ ∘ Core.subK→supK isSub
}
toSubstruct :
∀ {k′} {code′ : Code k′} (isSub : IsSubcode code′ code) →
∀ {Π′ : Properties code′} (hasΠ′ : Hasₚ (Core.supcodeProperties isSub Π′)) →
Π′ ⇒ₚ Core.subcodeProperties isSub Π
toSubstruct isSub hasΠ′ = Core.→ₚ-⇒ₚ λ π hasπ →
Core.fromSupcode isSub
(Core.⇒ₚ-→ₚ hasΠ′
(Core.mapProperty (Core.subK→supK isSub) π)
(Core.fromSupcode′ isSub hasπ))
|
{
"alphanum_fraction": 0.645631068,
"avg_line_length": 29.0512820513,
"ext": "agda",
"hexsha": "d01d571db09094efe8ff066e174a27752ae62e47",
"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": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Algebra/PropertyCode.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"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": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Algebra/PropertyCode.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Algebra/PropertyCode.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 860,
"size": 2266
}
|
{-# OPTIONS --safe #-}
module Cubical.Data.FinData.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; _·_; +-assoc)
open import Cubical.Data.Bool.Base
open import Cubical.Relation.Nullary
private
variable
ℓ : Level
A B : Type ℓ
data Fin : ℕ → Type₀ where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
-- useful patterns
pattern one = suc zero
pattern two = suc one
toℕ : ∀ {n} → Fin n → ℕ
toℕ zero = 0
toℕ (suc i) = suc (toℕ i)
fromℕ : (n : ℕ) → Fin (suc n)
fromℕ zero = zero
fromℕ (suc n) = suc (fromℕ n)
toFromId : ∀ (n : ℕ) → toℕ (fromℕ n) ≡ n
toFromId zero = refl
toFromId (suc n) = cong suc (toFromId n)
¬Fin0 : ¬ Fin 0
¬Fin0 ()
_==_ : ∀ {n} → Fin n → Fin n → Bool
zero == zero = true
zero == suc _ = false
suc _ == zero = false
suc m == suc n = m == n
weakenFin : {n : ℕ} → Fin n → Fin (suc n)
weakenFin zero = zero
weakenFin (suc i) = suc (weakenFin i)
predFin : {n : ℕ} → Fin (suc (suc n)) → Fin (suc n)
predFin zero = zero
predFin (suc x) = x
foldrFin : ∀ {n} → (A → B → B) → B → (Fin n → A) → B
foldrFin {n = zero} _ b _ = b
foldrFin {n = suc n} f b l = f (l zero) (foldrFin f b (l ∘ suc))
elim
: ∀(P : ∀{k} → Fin k → Type ℓ)
→ (∀{k} → P {suc k} zero)
→ (∀{k} → {fn : Fin k} → P fn → P (suc fn))
→ {k : ℕ} → (fn : Fin k) → P fn
elim P fz fs {zero} = ⊥.rec ∘ ¬Fin0
elim P fz fs {suc k} zero = fz
elim P fz fs {suc k} (suc fj) = fs (elim P fz fs fj)
rec : ∀{k} → (a0 aS : A) → Fin k → A
rec a0 aS zero = a0
rec a0 aS (suc x) = aS
FinVec : (A : Type ℓ) (n : ℕ) → Type ℓ
FinVec A n = Fin n → A
replicateFinVec : (n : ℕ) → A → FinVec A n
replicateFinVec _ a _ = a
_++Fin_ : {n m : ℕ} → FinVec A n → FinVec A m → FinVec A (n + m)
_++Fin_ {n = zero} _ W i = W i
_++Fin_ {n = suc n} V _ zero = V zero
_++Fin_ {n = suc n} V W (suc i) = ((V ∘ suc) ++Fin W) i
|
{
"alphanum_fraction": 0.5636456212,
"avg_line_length": 23.380952381,
"ext": "agda",
"hexsha": "a994130a44160e67265e82b31b1ee4f8e1a6bf06",
"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": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/FinData/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"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": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/FinData/Base.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/FinData/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 842,
"size": 1964
}
|
module Issue784.Values where
open import Data.Bool using (Bool; true; false; not)
open import Data.String public using (String)
open import Data.String.Properties public using (_≟_)
open import Function public
open import Data.List using (List; []; _∷_; _++_; [_]; filterᵇ) renaming (map to mapL)
open import Data.List.Relation.Unary.Any public using (Any; here; there) renaming (map to mapA; any to anyA)
open import Data.Product public using (Σ; Σ-syntax; proj₁; proj₂; _,_; _×_) renaming (map to mapΣ)
open import Data.Unit public using (⊤)
open import Data.Unit.NonEta public using (Unit; unit)
open import Data.Empty public using (⊥; ⊥-elim)
open import Relation.Binary.Core hiding (_⇔_) public
open import Relation.Nullary hiding (Irrelevant) public
import Level
open import Relation.Binary.PropositionalEquality public hiding ([_]) renaming (cong to ≡-cong; cong₂ to ≡-cong₂)
open import Relation.Binary.PropositionalEquality.Core public renaming (sym to ≡-sym; trans to ≡-trans)
{-
≢-sym : ∀ {ℓ} {A : Set ℓ} {x y : A} → x ≢ y → y ≢ x
≢-sym x≢y = x≢y ∘ ≡-sym
-}
≡-elim : ∀ {ℓ} {X Y : Set ℓ} → X ≡ Y → X → Y
≡-elim refl p = p
≡-elim′ : ∀ {a ℓ} {A : Set a} {x y : A} → (P : A → Set ℓ) → x ≡ y → P x → P y
≡-elim′ P = ≡-elim ∘ (≡-cong P)
Named : ∀ {ℓ} (A : Set ℓ) → Set ℓ
Named A = String × A
NamedType : ∀ ℓ → Set (Level.suc ℓ)
NamedType ℓ = Named (Set ℓ)
NamedValue : ∀ ℓ → Set (Level.suc ℓ)
NamedValue ℓ = Named (Σ[ A ∈ Set ℓ ] A)
Names : Set
Names = List String
Types : ∀ ℓ → Set (Level.suc ℓ)
Types ℓ = List (NamedType ℓ)
Values : ∀ ℓ → Set (Level.suc ℓ)
Values ℓ = List (NamedValue ℓ)
names : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names
names = mapL proj₁
types : ∀ {ℓ} → Values ℓ → Types ℓ
types = mapL (mapΣ id proj₁)
infix 4 _∈_ _∉_
_∈_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∈ xs = Any (_≡_ x) xs
_∉_ : ∀ {ℓ} {A : Set ℓ} → A → List A → Set ℓ
x ∉ xs = ¬ x ∈ xs
x∉y∷l⇒x≢y : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ≢ y
x∉y∷l⇒x≢y x∉y∷l x≡y = x∉y∷l $ here x≡y
x∉y∷l⇒x∉l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ∉ y ∷ l → x ∉ l
x∉y∷l⇒x∉l x∉y∷l x∈l = x∉y∷l $ there x∈l
x≢y⇒x∉l⇒x∉y∷l : ∀ {ℓ} {A : Set ℓ} {x y : A} {l : List A} → x ≢ y → x ∉ l → x ∉ y ∷ l
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (here x≡y) = x≢y x≡y
x≢y⇒x∉l⇒x∉y∷l x≢y x∉l (there x∈l) = x∉l x∈l
infix 5 _∋!_ _∈?_
_∈?_ : (s : String) (n : Names) → Dec (s ∈ n)
s ∈? [] = no λ()
s ∈? (h ∷ t) with s ≟ h
... | yes s≡h = yes $ here s≡h
... | no s≢h with s ∈? t
... | yes s∈t = yes $ there s∈t
... | no s∉t = no $ x≢y⇒x∉l⇒x∉y∷l s≢h s∉t
_∋!_ : Names → String → Bool
l ∋! e with e ∈? l
... | yes _ = true
... | no _ = false
infix 4 _⊆_ _⊈_
_⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys
_⊈_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
xs ⊈ ys = ¬ xs ⊆ ys
infixl 5 _∪_
_∪_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → List A
_∪_ = _++_
infixl 6 _∩_
_∩_ : Names → Names → Names
x ∩ y = filterᵇ (_∋!_ y) x
infixl 6 _∖_ _∖∖_
_∖_ : Names → Names → Names
_∖_ x y = filterᵇ (not ∘ _∋!_ y) x
_∖∖_ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
_∖∖_ l n = filterᵇ (not ∘ _∋!_ n ∘ proj₁) l
filter-∈ : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Names → List (Named A)
filter-∈ l n = filterᵇ (_∋!_ n ∘ proj₁) l
infixr 5 _∷_
data NonRepetitive {ℓ} {A : Set ℓ} : List A → Set ℓ where
[] : NonRepetitive []
_∷_ : ∀ {x xs} → x ∉ xs → NonRepetitive xs → NonRepetitive (x ∷ xs)
infix 4 _≋_
data _≋_ {ℓ} {A : Set ℓ} : List A → List A → Set ℓ where
refl : ∀ {l} → l ≋ l
perm : ∀ {l} l₁ x₁ x₂ l₂ → l ≋ l₁ ++ x₂ ∷ x₁ ∷ l₂ → l ≋ l₁ ++ x₁ ∷ x₂ ∷ l₂
NonRepetitiveNames : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames = NonRepetitive ∘ names
NonRepetitiveTypes : ∀ ℓ → Set (Level.suc ℓ)
NonRepetitiveTypes ℓ = Σ[ t ∈ Types ℓ ] NonRepetitiveNames t
-- lemmas
∪-assoc : ∀ {l} {A : Set l} (x y z : List A) → (x ∪ y) ∪ z ≡ x ∪ (y ∪ z)
∪-assoc [] y z = refl
∪-assoc (x ∷ xs) y z = ≡-elim′ (λ e → x ∷ e ≡ (x ∷ xs) ∪ (y ∪ z)) (≡-sym $ ∪-assoc xs y z) refl
≡⇒≋ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≡ y → x ≋ y
≡⇒≋ refl = refl
private
∈-perm : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∈ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∈ l₁ ++ e₂ ∷ e₁ ∷ l₂
∈-perm [] e₁ e₂ l₂ (here .{e₁} .{e₂ ∷ l₂} px) = there $ here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (here .{e₂} .{l₂} px)) = here px
∈-perm [] e₁ e₂ l₂ (there .{e₁} .{e₂ ∷ l₂} (there .{e₂} .{l₂} pxs)) = there $ there pxs
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (here .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} px) = here px
∈-perm (h₁ ∷ t₁) e₁ e₂ l₂ (there .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} pxs) = there $ ∈-perm t₁ e₁ e₂ l₂ pxs
≋⇒⊆ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → x ⊆ y
≋⇒⊆ refl p = p
≋⇒⊆ {x = x} {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} (perm l₁ x₁ x₂ l₂ p) {e} e∈x = ∈-perm l₁ x₂ x₁ l₂ $ ≋⇒⊆ p e∈x
≋-trans : ∀ {l} {A : Set l} {x y z : List A} → x ≋ y → y ≋ z → x ≋ z
≋-trans p refl = p
≋-trans p₁ (perm l₁ x₁ x₂ l₂ p₂) = perm l₁ x₁ x₂ l₂ $ ≋-trans p₁ p₂
≋-sym : ∀ {l} {A : Set l} {x y : List A} → x ≋ y → y ≋ x
≋-sym refl = refl
≋-sym (perm l₁ x₁ x₂ l₂ p) = ≋-trans (perm l₁ x₂ x₁ l₂ refl) (≋-sym p)
≋-del-ins-r : ∀ {l} {A : Set l} (l₁ : List A) (x : A) (l₂ l₃ : List A) → (l₁ ++ x ∷ l₂ ++ l₃) ≋ (l₁ ++ l₂ ++ x ∷ l₃)
≋-del-ins-r l₁ x [] l₃ = refl
≋-del-ins-r l₁ x (h ∷ t) l₃ = ≋-trans p₀ p₅
where p₀ : (l₁ ++ x ∷ h ∷ t ++ l₃) ≋ (l₁ ++ h ∷ x ∷ t ++ l₃)
p₀ = perm l₁ h x (t ++ l₃) refl
p₁ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ ((l₁ ++ [ h ]) ++ t ++ x ∷ l₃)
p₁ = ≋-del-ins-r (l₁ ++ [ h ]) x t l₃
p₂ : (l₁ ++ [ h ]) ++ t ++ x ∷ l₃ ≡ l₁ ++ h ∷ t ++ x ∷ l₃
p₂ = ∪-assoc l₁ [ h ] (t ++ x ∷ l₃)
p₃ : (l₁ ++ [ h ]) ++ x ∷ t ++ l₃ ≡ l₁ ++ h ∷ x ∷ t ++ l₃
p₃ = ∪-assoc l₁ [ h ] (x ∷ t ++ l₃)
p₄ : ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₄ = ≡-elim′ (λ y → ((l₁ ++ [ h ]) ++ x ∷ t ++ l₃) ≋ y) p₂ p₁
p₅ : (l₁ ++ h ∷ x ∷ t ++ l₃) ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)
p₅ = ≡-elim′ (λ y → y ≋ (l₁ ++ h ∷ t ++ x ∷ l₃)) p₃ p₄
≋-del-ins-l : ∀ {l} {A : Set l} (l₁ l₂ : List A) (x : A) (l₃ : List A) → (l₁ ++ l₂ ++ x ∷ l₃) ≋ (l₁ ++ x ∷ l₂ ++ l₃)
≋-del-ins-l l₁ l₂ x l₃ = ≋-sym $ ≋-del-ins-r l₁ x l₂ l₃
x∪[]≡x : ∀ {ℓ} {A : Set ℓ} (x : List A) → x ∪ [] ≡ x
x∪[]≡x [] = refl
x∪[]≡x (h ∷ t) = ≡-trans p₀ p₁
where p₀ : (h ∷ t) ++ [] ≡ h ∷ t ++ []
p₀ = ∪-assoc [ h ] t []
p₁ : h ∷ t ++ [] ≡ h ∷ t
p₁ = ≡-cong (λ x → h ∷ x) (x∪[]≡x t)
x∖[]≡x : (x : Names) → x ∖ [] ≡ x
x∖[]≡x [] = refl
x∖[]≡x (h ∷ t) = ≡-cong (_∷_ h) (x∖[]≡x t)
t∖[]≡t : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) → t ∖∖ [] ≡ t
t∖[]≡t [] = refl
t∖[]≡t (h ∷ t) = ≡-cong (_∷_ h) (t∖[]≡t t)
e∷x≋e∷y : ∀ {ℓ} {A : Set ℓ} (e : A) {x y : List A} → x ≋ y → e ∷ x ≋ e ∷ y
e∷x≋e∷y _ refl = refl
e∷x≋e∷y x (perm l₁ e₁ e₂ l₂ p) = perm (x ∷ l₁) e₁ e₂ l₂ (e∷x≋e∷y x p)
∪-sym : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ∪ y ≋ y ∪ x
∪-sym [] y = ≡-elim′ (λ z → y ≋ z) (≡-sym $ x∪[]≡x y) refl
∪-sym x [] = ≡-elim′ (λ z → z ≋ x) (≡-sym $ x∪[]≡x x) refl
∪-sym x (y ∷ ys) = ≡-elim′ (λ z → x ++ (y ∷ ys) ≋ z) p₃ (≋-trans p₁ p₂) where
p₁ : x ++ (y ∷ ys) ≋ y ∷ (x ++ ys)
p₁ = ≋-del-ins-l [] x y ys
p₂ : y ∷ (x ++ ys) ≋ y ∷ (ys ++ x)
p₂ = e∷x≋e∷y y $ ∪-sym x ys
p₃ : y ∷ (ys ++ x) ≡ (y ∷ ys) ++ x
p₃ = ∪-assoc [ y ] ys x
y≋ỳ⇒x∪y≋x∪ỳ : ∀ {ℓ} {A : Set ℓ} (x : List A) {y ỳ : List A} → y ≋ ỳ → x ∪ y ≋ x ∪ ỳ
y≋ỳ⇒x∪y≋x∪ỳ [] p = p
y≋ỳ⇒x∪y≋x∪ỳ (h ∷ t) p = e∷x≋e∷y h (y≋ỳ⇒x∪y≋x∪ỳ t p)
x≋x̀⇒x∪y≋x̀∪y : ∀ {ℓ} {A : Set ℓ} {x x̀ : List A} → x ≋ x̀ → (y : List A) → x ∪ y ≋ x̀ ∪ y
x≋x̀⇒x∪y≋x̀∪y {x = x} {x̀ = x̀} p y = ≋-trans (∪-sym x y) $ ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ y p) (∪-sym y x̀)
x⊆y≋z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ y → y ≋ z → x ⊆ z
x⊆y≋z x⊆y refl = x⊆y
x⊆y≋z {x = x} {y = y} {z = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} x⊆y (perm l₁ x₁ x₂ l₂ p) = ∈-perm l₁ x₂ x₁ l₂ ∘ x⊆y≋z x⊆y p
x≋y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ≋ y → x ⊆ z → y ⊆ z
x≋y⊆z refl x⊆z = x⊆z
x≋y⊆z {y = .(l₁ ++ x₁ ∷ x₂ ∷ l₂)} {z = z} (perm l₁ x₁ x₂ l₂ p) x⊆z = x≋y⊆z p x⊆z ∘ ∈-perm l₁ x₁ x₂ l₂
x⊆x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → x ⊆ x ∪ y
x⊆x∪y .(x ∷ xs) y (here {x} {xs} px) = here px
x⊆x∪y .(x ∷ xs) y (there {x} {xs} pxs) = there $ x⊆x∪y xs y pxs
x∪y⊆z⇒x⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → x ⊆ z
x∪y⊆z⇒x⊆z x y x∪y⊆z = x∪y⊆z ∘ x⊆x∪y x y
x∪y⊆z⇒y⊆z : ∀ {ℓ} {A : Set ℓ} (x y : List A) {z : List A} → x ∪ y ⊆ z → y ⊆ z
x∪y⊆z⇒y⊆z x y = x∪y⊆z⇒x⊆z y x ∘ x≋y⊆z (∪-sym x y)
n-x∪y : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → names (x ∪ y) ≡ names x ∪ names y
n-x∪y [] _ = refl
n-x∪y {ℓ} (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = [ proj₁ x ]
nxs = names xs
ny = names y
p₁ : nx ∪ names (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (n-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
t-x∪y : ∀ {ℓ} (x y : Values ℓ) → types (x ∪ y) ≡ types x ∪ types y
t-x∪y [] _ = refl
t-x∪y (x ∷ xs) y = ≡-trans p₁ p₂ where
nx = types [ x ]
nxs = types xs
ny = types y
p₁ : nx ∪ types (xs ∪ y) ≡ nx ∪ (nxs ∪ ny)
p₁ = ≡-cong (λ z → nx ∪ z) (t-x∪y xs y)
p₂ : nx ∪ (nxs ∪ ny) ≡ (nx ∪ nxs) ∪ ny
p₂ = ≡-sym $ ∪-assoc nx nxs ny
n-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → names x ≋ names y
n-x≋y refl = refl
n-x≋y (perm {x} l₁ e₁ e₂ l₂ p) = p₃ where
n-l₁e₁e₂l₂ : ∀ e₁ e₂ → names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
n-l₁e₁e₂l₂ e₁ e₂ = ≡-trans p₁ $ ≡-trans p₂ p₃ where
p₁ : names (l₁ ++ e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names (e₁ ∷ e₂ ∷ l₂)
p₁ = n-x∪y l₁ (e₁ ∷ e₂ ∷ l₂)
p₂ : names l₁ ++ names (e₁ ∷ e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂)
p₂ = ≡-cong (λ z → names l₁ ++ z) (n-x∪y [ e₁ ] (e₂ ∷ l₂))
p₃ : names l₁ ++ names [ e₁ ] ++ names (e₂ ∷ l₂) ≡ names l₁ ++ names [ e₁ ] ++ names [ e₂ ] ++ names l₂
p₃ = ≡-cong (λ z → names l₁ ++ names [ e₁ ] ++ z) (n-x∪y [ e₂ ] l₂)
p₁ : names x ≋ names l₁ ++ proj₁ e₂ ∷ proj₁ e₁ ∷ names l₂
p₁ = ≡-elim′ (λ z → names x ≋ z) (n-l₁e₁e₂l₂ e₂ e₁) (n-x≋y p)
p₂ : names x ≋ names l₁ ++ proj₁ e₁ ∷ proj₁ e₂ ∷ names l₂
p₂ = perm (names l₁) (proj₁ e₁) (proj₁ e₂) (names l₂) p₁
p₃ : names x ≋ names (l₁ ++ e₁ ∷ e₂ ∷ l₂)
p₃ = ≡-elim′ (λ z → names x ≋ z) (≡-sym $ n-l₁e₁e₂l₂ e₁ e₂) p₂
n-types : ∀ {ℓ} (x : Values ℓ) → names (types x) ≡ names x
n-types [] = refl
n-types (x ∷ xs) = ≡-cong (λ z → proj₁ x ∷ z) (n-types xs)
nr-x≋y : ∀ {ℓ} {A : Set ℓ} {x y : List A} → x ≋ y → NonRepetitive x → NonRepetitive y
nr-x≋y refl u = u
nr-x≋y {y = .(l₁ ++ e₁ ∷ e₂ ∷ l₂)} (perm l₁ e₁ e₂ l₂ p) u = ≋-step l₁ e₂ e₁ l₂ (nr-x≋y p u) where
∉-step : ∀ {ℓ} {A : Set ℓ} {x : A} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → x ∉ l₁ ++ e₁ ∷ e₂ ∷ l₂ → x ∉ l₁ ++ e₂ ∷ e₁ ∷ l₂
∉-step l₁ e₁ e₂ l₂ x∉l x∈l = ⊥-elim $ x∉l $ ∈-perm l₁ e₂ e₁ l₂ x∈l
≋-step : ∀ {ℓ} {A : Set ℓ} (l₁ : List A) (e₁ : A) (e₂ : A) (l₂ : List A) → NonRepetitive (l₁ ++ e₁ ∷ e₂ ∷ l₂) → NonRepetitive (l₁ ++ e₂ ∷ e₁ ∷ l₂)
≋-step [] e₁ e₂ l₂ (_∷_ .{e₁} .{e₂ ∷ l₂} e₁∉e₂∷l₂ (_∷_ .{e₂} .{l₂} e₂∉l₂ pU)) = e₂∉e₁∷l₂ ∷ e₁∉l₂ ∷ pU where
e₁∉l₂ = e₁ ∉ l₂ ∋ x∉y∷l⇒x∉l e₁∉e₂∷l₂
e₂∉e₁∷l₂ = e₂ ∉ e₁ ∷ l₂ ∋ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e₁∉e₂∷l₂) e₂∉l₂
≋-step (h₁ ∷ t₁) e₁ e₂ l₂ (_∷_ .{h₁} .{t₁ ++ e₁ ∷ e₂ ∷ l₂} p∉ pU) = ∉-step t₁ e₁ e₂ l₂ p∉ ∷ ≋-step t₁ e₁ e₂ l₂ pU
nr-x⇒nr-t-x : ∀ {ℓ} {x : Values ℓ} → NonRepetitiveNames x → NonRepetitiveNames (types x)
nr-x⇒nr-t-x {x = x} = ≡-elim′ NonRepetitive (≡-sym $ n-types x)
n-x∖y : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (x ∖∖ y) ≡ names x ∖ y
n-x∖y [] _ = refl
n-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = n-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (xs ∖∖ ny)) ≡ proj₁ x ∷ names (xs ∖∖ ny)
p₁ = n-x∪y [ x ] (xs ∖∖ ny)
p₂ : proj₁ x ∷ names (xs ∖∖ ny) ≡ proj₁ x ∷ (names xs ∖ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-x∖y xs ny)
t-x∖y : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (x ∖∖ y) ≡ types x ∖∖ y
t-x∖y [] _ = refl
t-x∖y (x ∷ xs) ny with not $ ny ∋! proj₁ x
... | false = t-x∖y xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ (xs ∖∖ ny)) ≡ x̀ ∪ types (xs ∖∖ ny)
p₁ = t-x∪y [ x ] (xs ∖∖ ny)
p₂ : x̀ ∪ types (xs ∖∖ ny) ≡ x̀ ∪ (types xs ∖∖ ny)
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-x∖y xs ny)
n-filter-∈ : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → names (filter-∈ x y) ≡ names x ∩ y
n-filter-∈ [] _ = refl
n-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = n-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
p₁ : names (x ∷ (filter-∈ xs ny)) ≡ proj₁ x ∷ names (filter-∈ xs ny)
p₁ = n-x∪y [ x ] (filter-∈ xs ny)
p₂ : proj₁ x ∷ names (filter-∈ xs ny) ≡ proj₁ x ∷ (names xs ∩ ny)
p₂ = ≡-cong (λ z → proj₁ x ∷ z) (n-filter-∈ xs ny)
t-filter-∈ : ∀ {ℓ} (x : Values ℓ) (y : Names) → types (filter-∈ x y) ≡ filter-∈ (types x) y
t-filter-∈ [] _ = refl
t-filter-∈ (x ∷ xs) ny with ny ∋! proj₁ x
... | false = t-filter-∈ xs ny
... | true = ≡-trans p₁ p₂ where
x̀ = types [ x ]
p₁ : types (x ∷ filter-∈ xs ny) ≡ x̀ ∪ types (filter-∈ xs ny)
p₁ = t-x∪y [ x ] (filter-∈ xs ny)
p₂ : x̀ ∪ types (filter-∈ xs ny) ≡ x̀ ∪ filter-∈ (types xs) ny
p₂ = ≡-cong (λ z → x̀ ∪ z) (t-filter-∈ xs ny)
[]⊆x : ∀ {ℓ} {A : Set ℓ} (x : List A) → [] ⊆ x
[]⊆x _ ()
∀x∉[] : ∀ {ℓ} {A : Set ℓ} {x : A} → x ∉ []
∀x∉[] ()
x⊆[]⇒x≡[] : ∀ {ℓ} {A : Set ℓ} {x : List A} → x ⊆ [] → x ≡ []
x⊆[]⇒x≡[] {x = []} _ = refl
x⊆[]⇒x≡[] {x = _ ∷ _} x⊆[] = ⊥-elim $ ∀x∉[] $ x⊆[] (here refl)
x∩y⊆x : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (y : Names) → filter-∈ x y ⊆ x
x∩y⊆x [] _ = λ()
x∩y⊆x (h ∷ t) y with y ∋! proj₁ h
... | false = there ∘ x∩y⊆x t y
... | true = f where
f : h ∷ filter-∈ t y ⊆ h ∷ t
f (here {x = .h} p) = here p
f (there {xs = .(filter-∈ t y)} p) = there $ x∩y⊆x t y p
e∈x⇒e∈y∪x : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ y ∪ x
e∈x⇒e∈y∪x [] = id
e∈x⇒e∈y∪x (h ∷ t) = there ∘ e∈x⇒e∈y∪x t
e∈x⇒e∈x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x : List A} (y : List A) → e ∈ x → e ∈ x ∪ y
e∈x⇒e∈x∪y {e = e} {x = x} y e∈x = x⊆y≋z f (∪-sym y x) (e ∈ [ e ] ∋ here refl) where
f : [ e ] ⊆ y ∪ x
f {è} (here {x = .e} p) = ≡-elim′ (λ z → z ∈ y ∪ x) (≡-sym p) (e∈x⇒e∈y∪x y e∈x)
f (there ())
x∪y⊆x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ⊆ x̀ → y ⊆ ỳ → x ∪ y ⊆ x̀ ∪ ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = []} _ y⊆ỳ = y⊆ỳ
x∪y⊆x̀∪ỳ {x = []} {x̀ = _ ∷ t̀} _ y⊆ỳ = there ∘ x∪y⊆x̀∪ỳ ([]⊆x t̀) y⊆ỳ
x∪y⊆x̀∪ỳ {x = h ∷ t} {x̀ = x̀} {y = y} {ỳ = ỳ} x⊆x̀ y⊆ỳ = f where
f : (h ∷ t) ∪ y ⊆ x̀ ∪ ỳ
f {e} (here {x = .h} e≡h) = e∈x⇒e∈x∪y ỳ (x⊆x̀ $ here e≡h)
f {e} (there {xs = .(t ∪ y)} p) = x∪y⊆x̀∪ỳ (x∪y⊆z⇒y⊆z [ h ] t x⊆x̀) y⊆ỳ p
x∖y⊆x : (x y : Names) → x ∖ y ⊆ x
x∖y⊆x [] _ = λ()
x∖y⊆x (h ∷ t) y with y ∋! h
... | true = there ∘ x∖y⊆x t y
... | false = x∪y⊆x̀∪ỳ (≋⇒⊆ $ ≡⇒≋ $ refl {x = [ h ]}) (x∖y⊆x t y)
t≋t∖n∪t∩n : ∀ {ℓ} {A : Set ℓ} (t : List (Named A)) (n : Names) → t ≋ (t ∖∖ n) ∪ filter-∈ t n
t≋t∖n∪t∩n [] _ = refl
t≋t∖n∪t∩n (h ∷ t) n with n ∋! proj₁ h
... | false = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
... | true = ≋-trans p₁ p₂ where
p₁ : h ∷ t ≋ (h ∷ (t ∖∖ n)) ∪ filter-∈ t n
p₁ = e∷x≋e∷y h $ t≋t∖n∪t∩n t n
p₂ : (h ∷ (t ∖∖ n)) ∪ filter-∈ t n ≋ (t ∖∖ n) ∪ (h ∷ filter-∈ t n)
p₂ = ≋-del-ins-r [] h (t ∖∖ n) (filter-∈ t n)
e₁∈x⇒e₂∉x⇒e≢e₂ : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ x → e₂ ∉ x → e₁ ≢ e₂
e₁∈x⇒e₂∉x⇒e≢e₂ e₁∈x e₂∉x refl = e₂∉x e₁∈x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x : ∀ {ℓ} {A : Set ℓ} {e₁ e₂ : A} {x : List A} → e₁ ∈ e₂ ∷ x → e₁ ≢ e₂ → e₁ ∈ x
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (here e₁≡e₂) e₁≢e₂ = ⊥-elim $ e₁≢e₂ e₁≡e₂
e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (there e₁∈x) _ = e₁∈x
x⊆e∷y⇒e∉x⇒x⊆y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ e ∷ y → e ∉ x → x ⊆ y
x⊆e∷y⇒e∉x⇒x⊆y {e = e} {x = x} {y = y} x⊆e∷y e∉x {è} è∈x = e₁∈e₂∷x⇒e₁≢e₂⇒e₁∈x (x⊆e∷y è∈x) (e₁∈x⇒e₂∉x⇒e≢e₂ è∈x e∉x)
n-e∉l⇒e∉l : ∀ {ℓ} {A : Set ℓ} {e : Named A} {l : List (Named A)} → proj₁ e ∉ names l → e ∉ l
n-e∉l⇒e∉l {e = e} n-e∉l (here {x = è} p) = ⊥-elim $ n-e∉l $ here $ ≡-cong proj₁ p
n-e∉l⇒e∉l n-e∉l (there p) = n-e∉l⇒e∉l (x∉y∷l⇒x∉l n-e∉l) p
nr-names⇒nr : ∀ {ℓ} {A : Set ℓ} {l : List (Named A)} → NonRepetitiveNames l → NonRepetitive l
nr-names⇒nr {l = []} [] = []
nr-names⇒nr {l = _ ∷ _} (nh∉nt ∷ nr-t) = n-e∉l⇒e∉l nh∉nt ∷ nr-names⇒nr nr-t
e∉x⇒e∉y⇒e∉x∪y : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → e ∉ x → e ∉ y → e ∉ x ∪ y
e∉x⇒e∉y⇒e∉x∪y {x = []} _ e∉y e∈y = ⊥-elim $ e∉y e∈y
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (here e≡h) = ⊥-elim $ e∉x $ here e≡h
e∉x⇒e∉y⇒e∉x∪y {x = h ∷ t} e∉x e∉y (there e∈t∪y) = e∉x⇒e∉y⇒e∉x∪y (x∉y∷l⇒x∉l e∉x) e∉y e∈t∪y
nr-x∖y∪y : {x y : Names} → NonRepetitive x → NonRepetitive y → NonRepetitive (x ∖ y ∪ y)
nr-x∖y∪y {x = []} _ nr-y = nr-y
nr-x∖y∪y {x = x ∷ xs} {y = y} (x∉xs ∷ nr-xs) nr-y with x ∈? y
... | yes x∈y = nr-x∖y∪y nr-xs nr-y
... | no x∉y = e∉x⇒e∉y⇒e∉x∪y (⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y) x∉y ∷ nr-x∖y∪y nr-xs nr-y
e∉l∖[e] : (e : String) (l : Names) → e ∉ l ∖ [ e ]
e∉l∖[e] _ [] = λ()
e∉l∖[e] e (h ∷ t) with h ≟ e
... | yes _ = e∉l∖[e] e t
... | no h≢e = x≢y⇒x∉l⇒x∉y∷l (≢-sym h≢e) (e∉l∖[e] e t)
e∉l⇒l∖e≡l : {e : String} {l : Names} → e ∉ l → l ∖ [ e ] ≡ l
e∉l⇒l∖e≡l {e = e} {l = []} _ = refl
e∉l⇒l∖e≡l {e = e} {l = h ∷ t} e∉l with h ∈? [ e ]
... | yes h∈e = ⊥-elim $ x≢y⇒x∉l⇒x∉y∷l (≢-sym $ x∉y∷l⇒x≢y e∉l) (λ()) h∈e
... | no h∉e = ≡-cong (_∷_ h) (e∉l⇒l∖e≡l $ x∉y∷l⇒x∉l e∉l)
e∈l⇒nr-l⇒l∖e∪e≋l : {e : String} {l : Names} → e ∈ l → NonRepetitive l → l ∖ [ e ] ∪ [ e ] ≋ l
e∈l⇒nr-l⇒l∖e∪e≋l {l = []} () _
e∈l⇒nr-l⇒l∖e∪e≋l {e = e} {l = h ∷ t} e∈h∷t (h∉t ∷ nr-t) with h ∈? [ e ]
... | yes (here h≡e) = ≋-trans (≡⇒≋ $ ≡-trans p₁ p₂) (∪-sym t [ h ]) where
p₁ : t ∖ [ e ] ∪ [ e ] ≡ t ∖ [ h ] ∪ [ h ]
p₁ = ≡-cong (λ x → t ∖ [ x ] ∪ [ x ]) (≡-sym h≡e)
p₂ : t ∖ [ h ] ∪ [ h ] ≡ t ∪ [ h ]
p₂ = ≡-cong (λ x → x ∪ [ h ]) (e∉l⇒l∖e≡l h∉t)
... | yes (there ())
... | no h∉e with e∈h∷t
... | here e≡h = ⊥-elim ∘ h∉e ∘ here ∘ ≡-sym $ e≡h
... | there e∈t = e∷x≋e∷y _ $ e∈l⇒nr-l⇒l∖e∪e≋l e∈t nr-t
nr-x∖y : {x : Names} → NonRepetitive x → (y : Names) → NonRepetitive (x ∖ y)
nr-x∖y {x = []} _ _ = []
nr-x∖y {x = x ∷ xs} (x∉xs ∷ nr-xs) y with x ∈? y
... | yes x∈y = nr-x∖y nr-xs y
... | no x∉y = ⊥-elim ∘ x∉xs ∘ x∖y⊆x xs y ∷ nr-x∖y nr-xs y
x⊆y⇒e∉y⇒e∉x : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → x ⊆ y → e ∉ y → e ∉ x
x⊆y⇒e∉y⇒e∉x x⊆y e∉y e∈x = e∉y $ x⊆y e∈x
e∈n-l⇒∃è,n-è≡e×è∈l : ∀ {ℓ} {A : Set ℓ} {e : String} {l : List (Named A)} → e ∈ names l → Σ[ è ∈ Named A ] (e ≡ proj₁ è × è ∈ l)
e∈n-l⇒∃è,n-è≡e×è∈l {l = []} ()
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (here e≡n-h) = h , e≡n-h , here refl
e∈n-l⇒∃è,n-è≡e×è∈l {l = h ∷ t} (there e∈n-t) with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-t
... | è , n-è≡e , è∈l = è , n-è≡e , there è∈l
x⊆y⇒nx⊆ny : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ⊆ y → names x ⊆ names y
x⊆y⇒nx⊆ny {x = x} {y = y} x⊆y {e} e∈n-x with e ∈? names y
... | yes e∈n-y = e∈n-y
... | no e∉n-y with e∈n-l⇒∃è,n-è≡e×è∈l e∈n-x
... | è , e≡n-è , è∈x = ⊥-elim $ x⊆y⇒e∉y⇒e∉x x⊆y (n-e∉l⇒e∉l $ ≡-elim′ (λ z → z ∉ names y) e≡n-è e∉n-y) è∈x
nr-x⇒nr-x∩y : ∀ {ℓ} {A : Set ℓ} {x : List (Named A)} → NonRepetitiveNames x → (y : Names) → NonRepetitiveNames (filter-∈ x y)
nr-x⇒nr-x∩y {x = []} _ _ = []
nr-x⇒nr-x∩y {x = h ∷ t} (h∉t ∷ nr-t) y with y ∋! proj₁ h
... | false = nr-x⇒nr-x∩y nr-t y
... | true = x⊆y⇒e∉y⇒e∉x (x⊆y⇒nx⊆ny $ x∩y⊆x t y) h∉t ∷ nr-x⇒nr-x∩y nr-t y
e∈l⇒[e]⊆l : ∀ {ℓ} {A : Set ℓ} {e : A} {l : List A} → e ∈ l → [ e ] ⊆ l
e∈l⇒[e]⊆l e∈l (here è≡e) = ≡-elim′ (λ x → x ∈ _) (≡-sym è≡e) e∈l
e∈l⇒[e]⊆l e∈l (there ())
a∈x⇒x≋y⇒a∈y : ∀ {ℓ} {A : Set ℓ} {x y : List A} {a : A} → a ∈ x → x ≋ y → a ∈ y
a∈x⇒x≋y⇒a∈y a∈x x≋y = x⊆y≋z (e∈l⇒[e]⊆l a∈x) x≋y (here refl)
x⊆z⇒y⊆z⇒x∪y⊆z : ∀ {ℓ} {A : Set ℓ} {x y z : List A} → x ⊆ z → y ⊆ z → x ∪ y ⊆ z
x⊆z⇒y⊆z⇒x∪y⊆z {x = []} _ y⊆z = y⊆z
x⊆z⇒y⊆z⇒x∪y⊆z {x = h ∷ t} {y = y} {z = z} x⊆z y⊆z = f where
f : (h ∷ t) ∪ y ⊆ z
f {e} (here e≡h) = x⊆z $ here e≡h
f {e} (there e∈t∪y) = x⊆z⇒y⊆z⇒x∪y⊆z (x∪y⊆z⇒y⊆z [ h ] t x⊆z) y⊆z e∈t∪y
x⊆x∖y∪y : (x y : Names) → x ⊆ x ∖ y ∪ y
x⊆x∖y∪y [] _ = []⊆x _
x⊆x∖y∪y (h ∷ t) y with h ∈? y
x⊆x∖y∪y (h ∷ t) y | yes h∈y = x⊆z⇒y⊆z⇒x∪y⊆z (e∈l⇒[e]⊆l $ e∈x⇒e∈y∪x (t ∖ y) h∈y) (x⊆x∖y∪y t y)
x⊆x∖y∪y (h ∷ t) y | no _ = x∪y⊆x̀∪ỳ ([ h ] ⊆ [ h ] ∋ ≋⇒⊆ refl) (x⊆x∖y∪y t y)
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ : {e₁ e₂ : String} {l : Names} → e₁ ∈ l → e₁ ∉ l ∖ [ e₂ ] → e₁ ≡ e₂
e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ {e₁ = e₁} {e₂ = e₂} {l = l} e₁∈l e₁∉l∖e₂ with e₁ ≟ e₂
... | yes e₁≡e₂ = e₁≡e₂
... | no e₁≢e₂ = ⊥-elim $ p₄ e₁∈l where
p₁ : e₁ ∉ [ e₂ ] ∪ (l ∖ [ e₂ ])
p₁ = x≢y⇒x∉l⇒x∉y∷l e₁≢e₂ e₁∉l∖e₂
p₂ : [ e₂ ] ∪ (l ∖ [ e₂ ]) ≋ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₂ = ∪-sym [ e₂ ] (l ∖ [ e₂ ])
p₃ : e₁ ∉ (l ∖ [ e₂ ]) ∪ [ e₂ ]
p₃ = p₁ ∘ ≋⇒⊆ (∪-sym (l ∖ [ e₂ ]) [ e₂ ])
p₄ : e₁ ∉ l
p₄ = x⊆y⇒e∉y⇒e∉x (x⊆x∖y∪y l [ e₂ ]) p₃
e∉x⇒x∩y≋x∩y∖e : {e : String} {x : Names} (y : Names) → e ∉ x → x ∩ y ≡ x ∩ (y ∖ [ e ])
e∉x⇒x∩y≋x∩y∖e {x = []} _ _ = refl
e∉x⇒x∩y≋x∩y∖e {e = e} {x = h ∷ t} y e∉x with h ∈? y | h ∈? (y ∖ [ e ])
... | yes h∈y | yes h∈y∖e = ≡-cong (_∷_ h) $ e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
... | yes h∈y | no h∉y∖e = ⊥-elim $ e∉x e∈x where
e∈x : e ∈ h ∷ t
e∈x = here $ ≡-sym $ e₁∈l⇒e₁∉l∖e₂⇒e₁≡e₂ h∈y h∉y∖e
... | no h∉y | yes h∈y∖e = ⊥-elim $ h∉y $ x∖y⊆x y [ e ] h∈y∖e
... | no h∉y | no h∉y∖e = e∉x⇒x∩y≋x∩y∖e y $ x∉y∷l⇒x∉l e∉x
y⊆x⇒x∩y≋y : {x y : Names} → NonRepetitive y → NonRepetitive x → y ⊆ x → x ∩ y ≋ y
y⊆x⇒x∩y≋y {x = []} _ _ y⊆[] = ≡⇒≋ $ ≡-elim′ (λ y → [] ∩ y ≡ y) (≡-sym $ x⊆[]⇒x≡[] y⊆[]) refl
y⊆x⇒x∩y≋y {x = h ∷ t} {y = y} nr-y (h∉t ∷ nr-t) y⊆h∷t with h ∈? y
... | yes h∈y = ≋-trans (∪-sym [ h ] (t ∩ y)) p₄ where
p₁ : t ∩ y ≋ t ∩ (y ∖ [ h ])
p₁ = ≡⇒≋ $ e∉x⇒x∩y≋x∩y∖e y h∉t
p₂ : t ∩ (y ∖ [ h ]) ≋ y ∖ [ h ]
p₂ = y⊆x⇒x∩y≋y (nr-x∖y nr-y [ h ]) nr-t $ x⊆e∷y⇒e∉x⇒x⊆y (y⊆h∷t ∘ x∖y⊆x y [ h ]) (e∉l∖[e] h y)
p₃ : y ∖ [ h ] ∪ [ h ] ≋ y
p₃ = e∈l⇒nr-l⇒l∖e∪e≋l h∈y nr-y
p₄ : t ∩ y ∪ [ h ] ≋ y
p₄ = ≋-trans (x≋x̀⇒x∪y≋x̀∪y (≋-trans p₁ p₂) [ h ]) p₃
... | no h∉y = y⊆x⇒x∩y≋y nr-y nr-t $ x⊆e∷y⇒e∉x⇒x⊆y y⊆h∷t h∉y
x∪y∖n≡x∖n∪y∖n : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) (n : Names) → (x ∪ y) ∖∖ n ≡ (x ∖∖ n) ∪ (y ∖∖ n)
x∪y∖n≡x∖n∪y∖n [] _ _ = refl
x∪y∖n≡x∖n∪y∖n (h ∷ t) y n with proj₁ h ∈? n
... | yes _ = x∪y∖n≡x∖n∪y∖n t y n
... | no _ = ≡-cong (_∷_ h) (x∪y∖n≡x∖n∪y∖n t y n)
n-x⊆n⇒x∖n≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) (n : Names) → names x ⊆ n → x ∖∖ n ≡ []
n-x⊆n⇒x∖n≡[] [] _ _ = refl
n-x⊆n⇒x∖n≡[] (h ∷ t) n n-x⊆n with proj₁ h ∈? n
... | yes _ = n-x⊆n⇒x∖n≡[] t n $ x∪y⊆z⇒y⊆z [ proj₁ h ] (names t) (x≋y⊆z (≡⇒≋ $ n-x∪y [ h ] t) n-x⊆n)
... | no h∉n = ⊥-elim $ h∉n $ n-x⊆n (proj₁ h ∈ proj₁ h ∷ names t ∋ here refl)
x∖x≡[] : ∀ {ℓ} {A : Set ℓ} (x : List (Named A)) → x ∖∖ names x ≡ []
x∖x≡[] x = n-x⊆n⇒x∖n≡[] x (names x) (≋⇒⊆ refl)
nr-[a] : ∀ {ℓ} {A : Set ℓ} {a : A} → NonRepetitive [ a ]
nr-[a] = (λ()) ∷ []
x≋y⇒x∖n≋y∖n : ∀ {ℓ} {A : Set ℓ} {x y : List (Named A)} → x ≋ y → (n : Names) → x ∖∖ n ≋ y ∖∖ n
x≋y⇒x∖n≋y∖n refl _ = refl
x≋y⇒x∖n≋y∖n {x = x} (perm l₁ x₁ x₂ l₂ p) n = ≋-trans p₀ $ ≋-trans (≡⇒≋ p₅) $ ≋-trans pg (≡⇒≋ $ ≡-sym g₅) where
p₀ : x ∖∖ n ≋ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ∖∖ n
p₀ = x≋y⇒x∖n≋y∖n p n
p₁ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n
p₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₂ ] ++ [ x₁ ] ++ l₂) n
p₂ : l₁ ∖∖ n ++ ([ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n
p₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] ([ x₁ ] ++ l₂) n)
p₃ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ ([ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n
p₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] l₂ n)
p₄ : l₁ ∖∖ n ++ [ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n) (l₂ ∖∖ n))
p₅ : (l₁ ++ [ x₂ ] ++ [ x₁ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n
p₅ = ≡-trans p₁ $ ≡-trans p₂ $ ≡-trans p₃ p₄
pg : l₁ ∖∖ n ++ ([ x₂ ] ∖∖ n ++ [ x₁ ] ∖∖ n) ++ l₂ ∖∖ n ≋ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
pg = y≋ỳ⇒x∪y≋x∪ỳ (l₁ ∖∖ n) $ x≋x̀⇒x∪y≋x̀∪y (∪-sym ([ x₂ ] ∖∖ n) ([ x₁ ] ∖∖ n)) (l₂ ∖∖ n)
g₁ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n
g₁ = x∪y∖n≡x∖n∪y∖n l₁ ([ x₁ ] ++ [ x₂ ] ++ l₂) n
g₂ : l₁ ∖∖ n ++ ([ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n
g₂ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₁ ] ([ x₂ ] ++ l₂) n)
g₃ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ ([ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n
g₃ = ≡-cong (λ z → l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ z) (x∪y∖n≡x∖n∪y∖n [ x₂ ] l₂ n)
g₄ : l₁ ∖∖ n ++ [ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n ++ l₂ ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₄ = ≡-cong (λ z → l₁ ∖∖ n ++ z) (≡-sym $ ∪-assoc ([ x₁ ] ∖∖ n) ([ x₂ ] ∖∖ n) (l₂ ∖∖ n))
g₅ : (l₁ ++ [ x₁ ] ++ [ x₂ ] ++ l₂) ∖∖ n ≡ l₁ ∖∖ n ++ ([ x₁ ] ∖∖ n ++ [ x₂ ] ∖∖ n) ++ l₂ ∖∖ n
g₅ = ≡-trans g₁ $ ≡-trans g₂ $ ≡-trans g₃ g₄
nr-x∪y⇒e∈x⇒e∈y⇒⊥ : ∀ {ℓ} {A : Set ℓ} {e : A} {x y : List A} → NonRepetitive (x ∪ y) → e ∈ x → e ∈ y → ⊥
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = []} _ ()
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (here e≡h) = h∉t∪y ∘ e∈x⇒e∈y∪x t ∘ ≡-elim′ (λ x → x ∈ _) e≡h
nr-x∪y⇒e∈x⇒e∈y⇒⊥ {x = h ∷ t} (h∉t∪y ∷ nr-t∪y) (there e∈t) = nr-x∪y⇒e∈x⇒e∈y⇒⊥ nr-t∪y e∈t
nr-x∪y⇒x∖y≡x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) → NonRepetitiveNames (x ∪ y) → y ∖∖ names x ≡ y
nr-x∪y⇒x∖y≡x x y nr-x∪y = f₀ y (≋⇒⊆ refl) where
f₀ : ∀ t → t ⊆ y → t ∖∖ names x ≡ t
f₀ [] _ = refl
f₀ (h ∷ t) h∷t⊆y with proj₁ h ∈? names x
... | yes h∈x = ⊥-elim $ nr-x∪y⇒e∈x⇒e∈y⇒⊥ (≡-elim′ NonRepetitive (n-x∪y x y) nr-x∪y) h∈x (x⊆y⇒nx⊆ny h∷t⊆y $ here refl)
... | no _ = ≡-cong (_∷_ h) (f₀ t $ x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y)
t≋t₁∪t₂⇒t∖t₁≋t₂ : ∀ {ℓ} {A : Set ℓ} {t : List (Named A)} → NonRepetitiveNames t → (t₁ t₂ : List (Named A)) → t ≋ t₁ ∪ t₂ → t ∖∖ names t₁ ≋ t₂
t≋t₁∪t₂⇒t∖t₁≋t₂ {t = t} nr-t t₁ t₂ t≋t₁∪t₂ = ≋-trans p₂ (≡⇒≋ $ nr-x∪y⇒x∖y≡x t₁ t₂ $ nr-x≋y (n-x≋y t≋t₁∪t₂) nr-t) where
n-t₁ = names t₁
p₁ : t ∖∖ n-t₁ ≋ (t₁ ∖∖ n-t₁) ∪ (t₂ ∖∖ n-t₁)
p₁ = ≋-trans (x≋y⇒x∖n≋y∖n t≋t₁∪t₂ n-t₁) (≡⇒≋ $ x∪y∖n≡x∖n∪y∖n t₁ t₂ n-t₁)
p₂ : t ∖∖ n-t₁ ≋ t₂ ∖∖ n-t₁
p₂ = ≡-elim′ (λ x → t ∖∖ n-t₁ ≋ x ∪ (t₂ ∖∖ n-t₁)) (x∖x≡[] t₁) p₁
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ : ∀ {ℓ} {A : Set ℓ} {x x̀ y ỳ : List A} → x ≋ x̀ → y ≋ ỳ → x ∪ y ≋ x̀ ∪ ỳ
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ (refl {y}) = x≋x̀⇒x∪y≋x̀∪y x≋x̀ y
x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ {x = x} {x̀ = x̀} {y = y} {ỳ = ._} x≋x̀ (perm l₁ x₁ x₂ l₂ y≋l₁x₂x₁l₂) = ≋-trans p₁ $ ≋-trans p₂ $ ≋-trans p₃ p₄ where
p₁ : x ∪ y ≋ x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂)
p₁ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ x≋x̀ y≋l₁x₂x₁l₂
p₂ : x̀ ∪ (l₁ ++ x₂ ∷ x₁ ∷ l₂) ≋ (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂
p₂ = ≡⇒≋ $ ≡-sym $ ∪-assoc x̀ l₁ (x₂ ∷ x₁ ∷ l₂)
p₃ : (x̀ ∪ l₁) ++ x₂ ∷ x₁ ∷ l₂ ≋ (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂
p₃ = perm (x̀ ∪ l₁) x₁ x₂ l₂ refl
p₄ : (x̀ ∪ l₁) ++ x₁ ∷ x₂ ∷ l₂ ≋ x̀ ∪ (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₄ = ≡⇒≋ $ ∪-assoc x̀ l₁ (x₁ ∷ x₂ ∷ l₂)
x∖y∪y≋y∖x∪x : ∀ {ℓ} {A : Set ℓ} (x y : List (Named A)) →
let nx = names x
ny = names y
in filter-∈ x ny ≋ filter-∈ y nx → x ∖∖ ny ∪ y ≋ y ∖∖ nx ∪ x
x∖y∪y≋y∖x∪x x y p₀ = ≋-trans p₁ $ ≋-trans p₂ p₃ where
nx = names x
ny = names y
p₁ : x ∖∖ ny ∪ y ≋ x ∖∖ ny ∪ y ∖∖ nx ∪ filter-∈ y nx
p₁ = ≋-trans (y≋ỳ⇒x∪y≋x∪ỳ (x ∖∖ ny) (t≋t∖n∪t∩n y nx)) (≡⇒≋ $ ≡-sym $ ∪-assoc (x ∖∖ ny) (y ∖∖ nx) (filter-∈ y nx))
p₂ : (x ∖∖ ny ∪ y ∖∖ nx) ∪ filter-∈ y nx ≋ (y ∖∖ nx ∪ x ∖∖ ny) ∪ filter-∈ x ny
p₂ = x≋x̀⇒y≋ỳ⇒x∪y≋x̀∪ỳ (∪-sym (x ∖∖ ny) (y ∖∖ nx)) (≋-sym p₀)
p₃ : y ∖∖ nx ∪ x ∖∖ ny ∪ filter-∈ x ny ≋ y ∖∖ nx ∪ x
p₃ = ≋-trans (≡⇒≋ $ ∪-assoc (y ∖∖ nx) (x ∖∖ ny) (filter-∈ x ny)) (≋-sym $ y≋ỳ⇒x∪y≋x∪ỳ (y ∖∖ nx) (t≋t∖n∪t∩n x ny))
names⇒named : Names → List (Named Unit)
names⇒named = mapL (λ x → x , unit)
nn-x∪y≡nn-x∪nn-y : ∀ x y → names⇒named (x ∪ y) ≡ names⇒named x ∪ names⇒named y
nn-x∪y≡nn-x∪nn-y [] y = refl
nn-x∪y≡nn-x∪nn-y (h ∷ t) y = ≡-cong (_∷_ _) (nn-x∪y≡nn-x∪nn-y t y)
nn-x≡x : ∀ x → names (names⇒named x) ≡ x
nn-x≡x [] = refl
nn-x≡x (h ∷ t) = ≡-cong (_∷_ h) (nn-x≡x t)
x≋y⇒nn-x≋nn-y : ∀ {x y} → x ≋ y → names⇒named x ≋ names⇒named y
x≋y⇒nn-x≋nn-y refl = refl
x≋y⇒nn-x≋nn-y {x = x} {y = ._} (perm l₁ x₁ x₂ l₂ x≋l₁x₂x₁l₂) = ≋-trans p₁ p₂ where
p₁ : names⇒named x ≋ names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂
p₁ = ≋-trans (x≋y⇒nn-x≋nn-y x≋l₁x₂x₁l₂) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y l₁ (x₂ ∷ x₁ ∷ l₂))
p₂ : names⇒named l₁ ++ (x₂ , unit) ∷ (x₁ , unit) ∷ names⇒named l₂ ≋ names⇒named (l₁ ++ x₁ ∷ x₂ ∷ l₂)
p₂ = ≋-trans (perm (names⇒named l₁) (x₁ , unit) (x₂ , unit) (names⇒named l₂) refl) (≡⇒≋ $ ≡-sym $ nn-x∪y≡nn-x∪nn-y l₁ (x₁ ∷ x₂ ∷ l₂))
x≋y∪z⇒x∖y≋z : {x : Names} → NonRepetitive x → (y z : Names) → x ≋ y ∪ z → x ∖ y ≋ z
x≋y∪z⇒x∖y≋z {x} nr-x y z x≋y∪z = ≋-trans (≡⇒≋ $ ≡-sym $ ≡-trans p₂ p₃) (≋-trans p₁ $ ≡⇒≋ $ nn-x≡x z) where
ux = names⇒named x
uy = names⇒named y
uz = names⇒named z
ux≋uy∪uz : ux ≋ uy ∪ uz
ux≋uy∪uz = ≋-trans (x≋y⇒nn-x≋nn-y x≋y∪z) (≡⇒≋ $ nn-x∪y≡nn-x∪nn-y y z)
p₁ : names (ux ∖∖ names uy) ≋ names uz
p₁ = n-x≋y $ t≋t₁∪t₂⇒t∖t₁≋t₂ (≡-elim′ NonRepetitive (≡-sym $ nn-x≡x x) nr-x) uy uz ux≋uy∪uz
p₂ : names (ux ∖∖ names uy) ≡ names ux ∖ names uy
p₂ = n-x∖y ux (names uy)
p₃ : names ux ∖ names uy ≡ x ∖ y
p₃ = ≡-cong₂ _∖_ (nn-x≡x x) (nn-x≡x y)
h∈x⇒∃t,x≋h∷t : ∀ {ℓ} {A : Set ℓ} {h : A} {x : List A} → h ∈ x → NonRepetitive x → Σ[ t ∈ List A ] x ≋ h ∷ t
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (here {x = x} {xs = xs} h≡x) (x∉xs ∷ nr-xs) = xs , ≡⇒≋ (≡-cong (λ z → z ∷ xs) (≡-sym h≡x))
h∈x⇒∃t,x≋h∷t {h = h} .{x = x ∷ xs} (there {x = x} {xs = xs} h∈xs) (x∉xs ∷ nr-xs) =
let t , xs≋h∷t = ((Σ[ t ∈ List _ ] xs ≋ h ∷ t) ∋ h∈x⇒∃t,x≋h∷t h∈xs nr-xs)
p₁ : x ∷ xs ≋ x ∷ h ∷ t
p₁ = y≋ỳ⇒x∪y≋x∪ỳ [ x ] xs≋h∷t
p₂ : x ∷ h ∷ t ≋ h ∷ x ∷ t
p₂ = ≋-del-ins-l [] [ x ] h t
in x ∷ t , ≋-trans p₁ p₂
nr-x∪y⇒nr-y : ∀ {ℓ} {A : Set ℓ} (x y : List A) → NonRepetitive (x ∪ y) → NonRepetitive y
nr-x∪y⇒nr-y [] _ nr-y = nr-y
nr-x∪y⇒nr-y (h ∷ t) y (_ ∷ nr-t∪y) = nr-x∪y⇒nr-y t y nr-t∪y
x⊆y⇒∃x̀,y≋x∪x̀ : ∀ {ℓ} {A : Set ℓ} {x y : List A} → NonRepetitive x → NonRepetitive y → x ⊆ y → Σ[ x̀ ∈ List A ] y ≋ x ∪ x̀
x⊆y⇒∃x̀,y≋x∪x̀ {x = []} {y = y} _ _ _ = y , refl
x⊆y⇒∃x̀,y≋x∪x̀ {x = h ∷ t} {y = y} (h∉t ∷ nr-t) nr-y h∷t⊆y =
let ỳ , y≋h∷ỳ = h∈x⇒∃t,x≋h∷t (h∷t⊆y (h ∈ h ∷ t ∋ here refl)) nr-y
p₁ : t ⊆ ỳ
p₁ = x⊆e∷y⇒e∉x⇒x⊆y (x⊆y≋z (x∪y⊆z⇒y⊆z [ h ] t h∷t⊆y) y≋h∷ỳ) h∉t
nr-ỳ = nr-x∪y⇒nr-y [ h ] ỳ $ nr-x≋y y≋h∷ỳ nr-y
t̀ , ỳ≋t∪t̀ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t nr-ỳ p₁
p₂ : h ∷ ỳ ≋ (h ∷ t) ∪ t̀
p₂ = y≋ỳ⇒x∪y≋x∪ỳ [ h ] ỳ≋t∪t̀
in t̀ , ≋-trans y≋h∷ỳ p₂
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₂ ≋ t₁ ∪ t₂ ∖∖ names t₁
t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ {t₁ = t₁} {t₂ = t₂} nr-nt₁ nr-nt₂ t₁⊆t₂ = ≋-trans p₁ $ y≋ỳ⇒x∪y≋x∪ỳ t₁ p₆ where
n-t₁ = names t₁
nr-t₁ = nr-names⇒nr nr-nt₁
nr-t₂ = nr-names⇒nr nr-nt₂
t̀₁,t₁∪t̀₁≋t₂ = x⊆y⇒∃x̀,y≋x∪x̀ nr-t₁ nr-t₂ t₁⊆t₂
t̀₁ = proj₁ t̀₁,t₁∪t̀₁≋t₂
p₁ : t₂ ≋ t₁ ∪ t̀₁
p₁ = proj₂ t̀₁,t₁∪t̀₁≋t₂
p₂ : t₂ ∖∖ n-t₁ ≋ (t₁ ∪ t̀₁) ∖∖ n-t₁
p₂ = x≋y⇒x∖n≋y∖n p₁ n-t₁
p₃ : (t₁ ∪ t̀₁) ∖∖ n-t₁ ≡ t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁
p₃ = x∪y∖n≡x∖n∪y∖n t₁ t̀₁ n-t₁
p₄ : t₁ ∖∖ n-t₁ ∪ t̀₁ ∖∖ n-t₁ ≡ t̀₁ ∖∖ n-t₁
p₄ = ≡-cong (λ x → x ∪ t̀₁ ∖∖ n-t₁) (x∖x≡[] t₁)
p₅ : t̀₁ ∖∖ n-t₁ ≡ t̀₁
p₅ = nr-x∪y⇒x∖y≡x t₁ t̀₁ $ nr-x≋y (n-x≋y p₁) nr-nt₂
p₆ : t̀₁ ≋ t₂ ∖∖ n-t₁
p₆ = ≋-sym $ ≋-trans p₂ $ ≡⇒≋ $ ≡-trans p₃ $ ≡-trans p₄ p₅
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ : ∀ {ℓ} {A : Set ℓ} {t₁ t₂ : List (Named A)} → NonRepetitiveNames t₁ → NonRepetitiveNames t₂ → t₁ ⊆ t₂ → t₁ ≋ filter-∈ t₂ (names t₁)
t₁⊆t₂⇒t₁≋f∈-t₂-nt₁ {t₁ = t₁} {t₂ = t₂} nr-t₁ nr-t₂ t₁⊆t₂ = ≋-trans (≋-sym p₃) p₄ where
nt₁ = names t₁
p₁ : t₂ ≋ t₂ ∖∖ nt₁ ∪ t₁
p₁ = ≋-trans (t₁⊆t₂⇒t₂≋t₁∪t₂∖nt₁ nr-t₁ nr-t₂ t₁⊆t₂) (∪-sym t₁ (t₂ ∖∖ nt₁))
p₂ : t₂ ≋ t₂ ∖∖ nt₁ ∪ filter-∈ t₂ nt₁
p₂ = t≋t∖n∪t∩n t₂ nt₁
p₃ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ t₁
p₃ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) t₁ p₁
p₄ : t₂ ∖∖ names (t₂ ∖∖ nt₁) ≋ filter-∈ t₂ nt₁
p₄ = t≋t₁∪t₂⇒t∖t₁≋t₂ nr-t₂ (t₂ ∖∖ nt₁) (filter-∈ t₂ nt₁) p₂
-- /lemmas
-- assertions
infix 4 _s-≢!_
_s-≢!_ : String → String → Set
x s-≢! y with x ≟ y
... | yes _ = ⊥
... | no _ = ⊤
s-≢!⇒≢? : ∀ {x y} → x s-≢! y → x ≢ y
s-≢!⇒≢? {x} {y} x≢!y with x ≟ y
s-≢!⇒≢? () | yes _
s-≢!⇒≢? _ | no p = p
s-NonRepetitive? : (n : Names) → Dec (NonRepetitive n)
s-NonRepetitive? [] = yes []
s-NonRepetitive? (h ∷ t) with h ∈? t | s-NonRepetitive? t
... | no h∉t | yes nr-t = yes (h∉t ∷ nr-t)
... | yes h∈t | _ = no f where
f : NonRepetitive (_ ∷ _) → _
f (h∉t ∷ _) = h∉t h∈t
... | _ | no ¬nr-t = no f where
f : NonRepetitive (_ ∷ _) → _
f (_ ∷ nr-t) = ¬nr-t nr-t
s-NonRepetitive! : Names → Set
s-NonRepetitive! n with s-NonRepetitive? n
... | yes _ = ⊤
... | no _ = ⊥
NonRepetitiveNames! : ∀ {ℓ} {A : Set ℓ} → List (Named A) → Set
NonRepetitiveNames! = s-NonRepetitive! ∘ names
s-nr!⇒nr : {n : Names} → s-NonRepetitive! n → NonRepetitive n
s-nr!⇒nr {n = n} _ with s-NonRepetitive? n
s-nr!⇒nr _ | yes p = p
s-nr!⇒nr () | no _
-- /assertions
|
{
"alphanum_fraction": 0.4316689934,
"avg_line_length": 43.6101036269,
"ext": "agda",
"hexsha": "f1047f57da1f840bb336cbe0e8aaa5b830deba34",
"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/LibSucceed/Issue784/Values.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/LibSucceed/Issue784/Values.agda",
"max_line_length": 151,
"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/LibSucceed/Issue784/Values.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 21872,
"size": 33667
}
|
{-# OPTIONS --without-K #-}
module mini-lob where
open import common
infixl 2 _▻_
infixl 3 _‘’_
infixr 1 _‘→’_
infixl 3 _‘’ₐ_
mutual
data Context : Set where
ε : Context
_▻_ : (Γ : Context) → Type Γ → Context
data Type : Context → Set where
_‘’_ : ∀ {Γ A} → Type (Γ ▻ A) → Term {Γ} A → Type Γ
‘Typeε’ : Type ε
‘□’ : Type (ε ▻ ‘Typeε’)
_‘→’_ : ∀ {Γ} → Type Γ → Type Γ → Type Γ
‘⊤’ : ∀ {Γ} → Type Γ
‘⊥’ : ∀ {Γ} → Type Γ
data Term : {Γ : Context} → Type Γ → Set where
⌜_⌝ : Type ε → Term {ε} ‘Typeε’
_‘’ₐ_ : ∀ {Γ A B} → Term {Γ} (A ‘→’ B) → Term {Γ} A → Term {Γ} B
Lӧb : ∀ {X} → Term {ε} (‘□’ ‘’ ⌜ X ⌝ ‘→’ X) → Term {ε} X
‘tt’ : ∀ {Γ} → Term {Γ} ‘⊤’
□ : Type ε → Set _
□ = Term {ε}
max-level : Level
max-level = lzero
mutual
Context⇓ : (Γ : Context) → Set (lsuc max-level)
Context⇓ ε = ⊤
Context⇓ (Γ ▻ T) = Σ (Context⇓ Γ) (Type⇓ {Γ} T)
Type⇓ : {Γ : Context} → Type Γ → Context⇓ Γ → Set max-level
Type⇓ (T ‘’ x) Γ⇓ = Type⇓ T (Γ⇓ , Term⇓ x Γ⇓)
Type⇓ ‘Typeε’ Γ⇓ = Lifted (Type ε)
Type⇓ ‘□’ Γ⇓ = Lifted (Term {ε} (lower (Σ.proj₂ Γ⇓)))
Type⇓ (A ‘→’ B) Γ⇓ = Type⇓ A Γ⇓ → Type⇓ B Γ⇓
Type⇓ ‘⊤’ Γ⇓ = ⊤
Type⇓ ‘⊥’ Γ⇓ = ⊥
Term⇓ : ∀ {Γ : Context} {T : Type Γ} → Term T → (Γ⇓ : Context⇓ Γ) → Type⇓ T Γ⇓
Term⇓ ⌜ x ⌝ Γ⇓ = lift x
Term⇓ (f ‘’ₐ x) Γ⇓ = Term⇓ f Γ⇓ (Term⇓ x Γ⇓)
Term⇓ (Lӧb □‘X’→X) Γ⇓ = Term⇓ □‘X’→X Γ⇓ (lift (Lӧb □‘X’→X))
Term⇓ ‘tt’ Γ⇓ = tt
⌞_⌟ : Type ε → Set _
⌞ T ⌟ = Type⇓ T tt
‘¬’_ : ∀ {Γ} → Type Γ → Type Γ
‘¬’ T = T ‘→’ ‘⊥’
lӧb : ∀ {‘X’} → □ (‘□’ ‘’ ⌜ ‘X’ ⌝ ‘→’ ‘X’) → ⌞ ‘X’ ⌟
lӧb f = Term⇓ (Lӧb f) tt
incompleteness : ¬ □ (‘¬’ (‘□’ ‘’ ⌜ ‘⊥’ ⌝))
incompleteness = lӧb
soundness : ¬ □ ‘⊥’
soundness x = Term⇓ x tt
non-emptyness : Σ (Type ε) (λ T → □ T)
non-emptyness = ‘⊤’ , ‘tt’
|
{
"alphanum_fraction": 0.4617117117,
"avg_line_length": 25.014084507,
"ext": "agda",
"hexsha": "86f9f56a8d2b450ff926508f5b532e16da053547",
"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/mini-lob.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/mini-lob.agda",
"max_line_length": 80,
"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/mini-lob.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": 1027,
"size": 1776
}
|
{-# OPTIONS --without-K --safe #-}
module Bundles where
open import Algebra.Core
open import Quasigroup.Structures
open import Relation.Binary
open import Level
open import Algebra.Bundles
open import Algebra.Structures
open import Structures
record InverseSemigroup c ℓ : Set (suc (c ⊔ ℓ)) where
infixl 7 _∙_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_∙_ : Op₂ Carrier
isInverseSemigroup : IsInverseSemigroup _≈_ _∙_
open IsInverseSemigroup isInverseSemigroup public
magma : Magma c ℓ
magma = record { isMagma = isMagma }
open Magma magma public
using (_≉_; rawMagma)
record Rng c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
isRng : IsRng _≈_ _+_ _*_ -_ 0#
open IsRng isRng public
+-abelianGroup : AbelianGroup _ _
+-abelianGroup = record { isAbelianGroup = +-isAbelianGroup }
*-semigroup : Semigroup _ _
*-semigroup = record { isSemigroup = *-isSemigroup }
open AbelianGroup +-abelianGroup public
using () renaming (group to +-group; invertibleMagma to +-invertibleMagma; invertibleUnitalMagma to +-invertibleUnitalMagma)
open Semigroup *-semigroup public
using () renaming
( rawMagma to *-rawMagma
; magma to *-magma
)
record NonAssociativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isNonAssociativeRing : IsNonAssociativeRing _≈_ _+_ _*_ -_ 0# 1#
open IsNonAssociativeRing isNonAssociativeRing public
+-abelianGroup : AbelianGroup _ _
+-abelianGroup = record { isAbelianGroup = +-isAbelianGroup }
*-unitalmagma : UnitalMagma _ _
*-unitalmagma = record { isUnitalMagma = *-isUnitalMagma }
open AbelianGroup +-abelianGroup public
using () renaming (group to +-group; invertibleMagma to +-invertibleMagma; invertibleUnitalMagma to +-invertibleUnitalMagma)
open UnitalMagma *-unitalmagma public
using () renaming
( rawMagma to *-rawMagma
; magma to *-magma
)
|
{
"alphanum_fraction": 0.6274747475,
"avg_line_length": 26.902173913,
"ext": "agda",
"hexsha": "07e27c6b43aefd8a93352755ff0a9a5c5446306a",
"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": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Bundles.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Bundles.agda",
"max_line_length": 128,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 797,
"size": 2475
}
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- From: Hancock (2008). (Ordinal-theoretic) proof theory.
module Ordinals where
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
data Ω : Set where
zero : Ω
succ : Ω → Ω
limN : (ℕ → Ω) → Ω
inj : ℕ → Ω
inj zero = zero
inj (succ n) = succ (inj n)
ω : Ω
ω = limN (λ n → inj n)
ω+1 : Ω
ω+1 = succ ω
data Ω₂ : Set where
zero : Ω₂
succ : Ω₂ → Ω₂
limN : (ℕ → Ω₂) → Ω₂
limΩ : (Ω → Ω₂) → Ω₂
inj₁ : Ω → Ω₂
inj₁ zero = zero
inj₁ (succ o) = succ (inj₁ o)
inj₁ (limN f) = limN (λ n → inj₁ (f n))
ω₁ : Ω₂
ω₁ = limΩ (λ o → inj₁ o)
|
{
"alphanum_fraction": 0.5188284519,
"avg_line_length": 17.0714285714,
"ext": "agda",
"hexsha": "e6a40264eb05d39657d354e03ba874505ff65112",
"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/Ordinals.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/Ordinals.agda",
"max_line_length": 58,
"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/Ordinals.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": 305,
"size": 717
}
|
-- Andreas, 2019-11-12, issue #4168b
--
-- Meta variable solver should not use uncurrying
-- if the record type contains erased fields.
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
open import Common.IO
P : (A B : Set) → (A → B) → Set
P A B f = (y : B) → Σ A (λ x → f x ≡ y)
record R (A B : Set) : Set where
field
to : A → B
from : B → A
from-to : (x : A) → from (to x) ≡ x
p : (A B : Set) (r : R A B) → P A B (R.to r)
p _ _ r y = R.from r y , to-from y
where
postulate
to-from : ∀ x → R.to r (R.from r x) ≡ x
record Box (A : Set) : Set where
constructor box
field
@0 unbox : A
test : (A : Set) → P (Box A) (Box (Box A)) (box {A = Box A})
test A = p _ _ (record
{ to = box {A = _}
; from = λ { (box (box x)) → box {A = A} x }
-- at first, a postponed type checking problem ?from
; from-to = λ x → refl {A = Box A} {x = _}
})
-- from-to creates constraint
--
-- x : Box A |- ?from (box x) = x : Box A
--
-- This was changed to
--
-- y : Box (Box A) |- ?from y = unbox y : Box A
--
-- which is an invalid transformation since x is not
-- guaranteed to be in erased context.
-- As a consequence, compilation (GHC backend) failed.
-- A variant with a non-erased field.
record ⊤ : Set where
record Box' (A : Set) : Set where
constructor box'
field
unit : ⊤
@0 unbox' : A
test' : (A : Set) → P (Box' A) (Box' (Box' A)) (box' {A = Box' A} _)
test' A = p _ _ (record
{ to = box' {A = _} _
; from = λ { (box' _ (box' _ x)) → box' {A = A} _ x }
; from-to = λ x → refl {A = Box' A} {x = _}
})
main : IO ⊤
main = return _
|
{
"alphanum_fraction": 0.5388379205,
"avg_line_length": 23.3571428571,
"ext": "agda",
"hexsha": "5d621278a0f78d67ce15bd0746e50fa30430518b",
"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": "a2a54ce1b97fe103fbe1b961ffda95fe6313abf0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "k-bx/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue4168-4185.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a2a54ce1b97fe103fbe1b961ffda95fe6313abf0",
"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": "k-bx/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue4168-4185.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a2a54ce1b97fe103fbe1b961ffda95fe6313abf0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "k-bx/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue4168-4185.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 607,
"size": 1635
}
|
open import Data.Product using ( _×_ ; _,_ ; proj₁ ; proj₂ )
open import Data.Sum using ( inj₁ ; inj₂ )
open import Data.Unit using ( tt )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Relation.Unary using ( _∈_ ; _⊆_ )
open import Web.Semantic.DL.ABox using
( ABox ; Assertions ; ε ; _,_ ; _∼_ ; _∈₁_ ; _∈₂_ )
open import Web.Semantic.DL.ABox.Interp using
( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using
( _≲_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ; _≋_ )
open import Web.Semantic.DL.ABox.Model using
( _⟦_⟧₀ ; _⊨a_ ; Assertions✓ )
open import Web.Semantic.DL.Concept using
( ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 )
open import Web.Semantic.DL.Concept.Model using ( _⟦_⟧₁ ; ⟦⟧₁-resp-≈ )
open import Web.Semantic.DL.Integrity using
( Unique ; Mediator ; Initial ; _>>_ ; _⊕_⊨_ ; _,_ )
open import Web.Semantic.DL.KB using ( KB ; tbox ; abox )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Role using ( ⟨_⟩ ; ⟨_⟩⁻¹ )
open import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ ; ⟦⟧₂-resp-≈ )
open import Web.Semantic.DL.Sequent using
( Γ ; γ ; _⊕_⊢_∼_ ; _⊕_⊢_∈₁_ ; _⊕_⊢_∈₂_
; ∼-assert ; ∼-import ;∼-refl ; ∼-sym ; ∼-trans ; ∼-≤1
; ∈₂-assert ; ∈₂-import ; ∈₂-resp-∼ ; ∈₂-subsum
; ∈₂-refl ; ∈₂-trans ; ∈₂-inv-I ; ∈₂-inv-E
; ∈₁-assert ; ∈₁-import ; ∈₁-resp-∼ ; ∈₁-subsum
; ∈₁-⊤-I ; ∈₁-⊓-I ; ∈₁-⊓-E₁ ; ∈₁-⊓-E₂
; ∈₁-⊔-I₁ ; ∈₁-⊔-I₂ ; ∈₁-∃-I ; ∈₁-∀-E )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using
( TBox ; Axioms ; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Tra )
open import Web.Semantic.DL.TBox.Interp using
( interp ; Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans ; con-≈ ; rol-≈ ) renaming
( Interp to Interp′ )
open import Web.Semantic.DL.TBox.Interp.Morphism using
( morph ; ≲-image ; ≲-resp-≈ ; ≲-resp-con ; ≲-resp-rol )
open import Web.Semantic.DL.TBox.Minimizable using
( LHS ; RHS ; μTBox
; ⟨_⟩ ; ⊤ ; ⊥ ; _⊓_ ; _⊔_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1
; ε ; _,_ ;_⊑₁_ ; _⊑₂_ ; Ref ; Tra )
open import Web.Semantic.DL.TBox.Model using ( _⊨t_ ; Axioms✓ )
open import Web.Semantic.Util using
( Subset ; ⊆-refl ; id ; _∘_ ; _⊕_⊕_ ; _[⊕]_[⊕]_ ; inode ; bnode ; enode )
module Web.Semantic.DL.Sequent.Model {Σ : Signature} {W X Y : Set} where
infix 5 _⊞_
minimal′ : Interp Σ X → KB Σ (X ⊕ W ⊕ Y) → Interp′ Σ
minimal′ I KB =
interp (Γ I KB) (λ x y → (I ⊕ KB ⊢ x ∼ y)) ∼-refl ∼-sym ∼-trans
(λ c x → I ⊕ KB ⊢ x ∈₁ ⟨ c ⟩) (λ r xy → I ⊕ KB ⊢ xy ∈₂ ⟨ r ⟩)
(λ c → ∈₁-resp-∼) (λ r → ∈₂-resp-∼)
minimal : Interp Σ X → KB Σ (X ⊕ W ⊕ Y) → Interp Σ (X ⊕ W ⊕ Y)
minimal I KB = (minimal′ I KB , γ I KB)
complete₂ : ∀ I KB R {xy} → (xy ∈ minimal′ I KB ⟦ R ⟧₂) → (I ⊕ KB ⊢ xy ∈₂ R)
complete₂ I KB ⟨ r ⟩ {(x , y)} xy∈⟦r⟧ = xy∈⟦r⟧
complete₂ I KB ⟨ r ⟩⁻¹ {(x , y)} yx∈⟦r⟧ = ∈₂-inv-I yx∈⟦r⟧
complete₁ : ∀ I KB {C x} → (C ∈ LHS) → (x ∈ minimal′ I KB ⟦ C ⟧₁) →
(I ⊕ KB ⊢ x ∈₁ C)
complete₁ I KB ⟨ c ⟩ x∈⟦c⟧ =
x∈⟦c⟧
complete₁ I KB ⊤ _ =
∈₁-⊤-I
complete₁ I KB (C ⊓ D) (x∈⟦C⟧ , x∈⟦D⟧) =
∈₁-⊓-I (complete₁ I KB C x∈⟦C⟧) (complete₁ I KB D x∈⟦D⟧)
complete₁ I KB (C ⊔ D) (inj₁ x∈⟦C⟧) =
∈₁-⊔-I₁ (complete₁ I KB C x∈⟦C⟧)
complete₁ I KB (C ⊔ D) (inj₂ x∈⟦D⟧) =
∈₁-⊔-I₂ (complete₁ I KB D x∈⟦D⟧)
complete₁ I KB (∃⟨ R ⟩ C) (y , xy∈⟦R⟧ , y∈⟦C⟧) =
∈₁-∃-I (complete₂ I KB R xy∈⟦R⟧) (complete₁ I KB C y∈⟦C⟧)
complete₁ I KB ⊥ ()
sound₂ : ∀ I KB R {xy} → (I ⊕ KB ⊢ xy ∈₂ R) → (xy ∈ minimal′ I KB ⟦ R ⟧₂)
sound₂ I KB ⟨ r ⟩ {(x , y)} ⊢xy∈r = ⊢xy∈r
sound₂ I KB ⟨ r ⟩⁻¹ {(x , y)} ⊢xy∈r⁻ = ∈₂-inv-E ⊢xy∈r⁻
sound₁ : ∀ I KB {C x} → (C ∈ RHS) → (I ⊕ KB ⊢ x ∈₁ C) →
(x ∈ minimal′ I KB ⟦ C ⟧₁)
sound₁ I KB ⟨ c ⟩ ⊢x∈c =
⊢x∈c
sound₁ I KB ⊤ ⊢x∈⊤ =
tt
sound₁ I KB (C ⊓ D) ⊢x∈C⊓D =
(sound₁ I KB C (∈₁-⊓-E₁ ⊢x∈C⊓D) , sound₁ I KB D (∈₁-⊓-E₂ ⊢x∈C⊓D))
sound₁ I KB (∀[ R ] C) ⊢x∈∀RC = λ y xy∈⟦R⟧ →
sound₁ I KB C (∈₁-∀-E ⊢x∈∀RC (complete₂ I KB R xy∈⟦R⟧))
sound₁ I KB (≤1 R) ⊢x∈≤1R = λ y z xy∈⟦R⟧ xz∈⟦R⟧ →
∼-≤1 ⊢x∈≤1R (complete₂ I KB R xy∈⟦R⟧) (complete₂ I KB R xz∈⟦R⟧)
minimal-⊨ : ∀ I KB → (tbox KB ∈ μTBox) → (minimal I KB ⊨ KB)
minimal-⊨ I KB μT =
( minimal-tbox μT (⊆-refl (Axioms (tbox KB)))
, minimal-abox (abox KB) (⊆-refl (Assertions (abox KB)))) where
minimal-tbox : ∀ {T} → (T ∈ μTBox) → (Axioms T ⊆ Axioms (tbox KB)) →
minimal′ I KB ⊨t T
minimal-tbox ε ε⊆T =
tt
minimal-tbox (U , V) UV⊆T =
( minimal-tbox U (λ u → UV⊆T (inj₁ u))
, minimal-tbox V (λ v → UV⊆T (inj₂ v)) )
minimal-tbox (C ⊑₁ D) C⊑₁D∈T = λ x∈⟦C⟧ →
sound₁ I KB D (∈₁-subsum (complete₁ I KB C x∈⟦C⟧) (C⊑₁D∈T refl))
minimal-tbox (Q ⊑₂ R) Q⊑₁R∈T = λ xy∈⟦Q⟧ →
sound₂ I KB R (∈₂-subsum (complete₂ I KB Q xy∈⟦Q⟧) (Q⊑₁R∈T refl))
minimal-tbox (Ref R) RefR∈T = λ x →
sound₂ I KB R (∈₂-refl x (RefR∈T refl))
minimal-tbox (Tra R) TraR∈T = λ xy∈⟦R⟧ yz∈⟦R⟧ →
sound₂ I KB R (∈₂-trans
(complete₂ I KB R xy∈⟦R⟧) (complete₂ I KB R yz∈⟦R⟧) (TraR∈T refl))
minimal-abox : ∀ A → (Assertions A ⊆ Assertions (abox KB)) →
minimal I KB ⊨a A
minimal-abox ε ε⊆A =
tt
minimal-abox (B , C) BC⊆A =
( minimal-abox B (λ b → BC⊆A (inj₁ b))
, minimal-abox C (λ c → BC⊆A (inj₂ c)) )
minimal-abox (x ∼ y) x∼y⊆A =
∼-assert (x∼y⊆A refl)
minimal-abox (x ∈₁ c) x∈C⊆A =
sound₁ I KB ⟨ c ⟩ (∈₁-assert (x∈C⊆A refl))
minimal-abox ((x , y) ∈₂ r) xy∈R⊆A =
sound₂ I KB ⟨ r ⟩ (∈₂-assert (xy∈R⊆A refl))
minimal-≳ : ∀ I KB → (I ≲ inode * minimal I KB)
minimal-≳ I KB = (morph inode ∼-import ∈₁-import ∈₂-import , λ x → ∼-refl)
minimal-≲ : ∀ I KB J → (I ≲ inode * J) → (J ⊨ KB) → (minimal I KB ≲ J)
minimal-≲ I KB J I≲J (J⊨T , J⊨A) =
(morph f minimal-≈ minimal-con minimal-rol , fγ≈j) where
f : Γ I KB → Δ ⌊ J ⌋
f = (≲-image ≲⌊ I≲J ⌋) [⊕] (ind J ∘ bnode) [⊕] (ind J ∘ enode)
fγ≈j : ∀ x → ⌊ J ⌋ ⊨ f (γ I KB x) ≈ ind J x
fγ≈j (inode x) = ≲-resp-ind I≲J x
fγ≈j (bnode v) = ≈-refl ⌊ J ⌋
fγ≈j (enode y) = ≈-refl ⌊ J ⌋
mutual
minimal-≈ : ∀ {x y} → (I ⊕ KB ⊢ x ∼ y) → (⌊ J ⌋ ⊨ f x ≈ f y)
minimal-≈ (∼-assert x∼y∈A) =
≈-trans ⌊ J ⌋ (fγ≈j _)
(≈-trans ⌊ J ⌋ (Assertions✓ J (abox KB) x∼y∈A J⊨A)
(≈-sym ⌊ J ⌋ (fγ≈j _)))
minimal-≈ (∼-import x≈y) =
≲-resp-≈ ≲⌊ I≲J ⌋ x≈y
minimal-≈ ∼-refl =
≈-refl ⌊ J ⌋
minimal-≈ (∼-sym x∼y) =
≈-sym ⌊ J ⌋ (minimal-≈ x∼y)
minimal-≈ (∼-trans x∼y y∼z) =
≈-trans ⌊ J ⌋ (minimal-≈ x∼y) (minimal-≈ y∼z)
minimal-≈ (∼-≤1 x∈≤1R xy∈R xz∈R) =
minimal-con x∈≤1R _ _ (minimal-rol xy∈R) (minimal-rol xz∈R)
minimal-con : ∀ {x C} → (I ⊕ KB ⊢ x ∈₁ C) → (f x ∈ ⌊ J ⌋ ⟦ C ⟧₁)
minimal-con (∈₁-assert x∈c∈A) =
con-≈ ⌊ J ⌋ _ (Assertions✓ J (abox KB) x∈c∈A J⊨A)
(≈-sym ⌊ J ⌋ (fγ≈j _))
minimal-con (∈₁-import x∈⟦c⟧) =
≲-resp-con ≲⌊ I≲J ⌋ x∈⟦c⟧
minimal-con {x} {C} (∈₁-resp-∼ x∈C x∼y) =
⟦⟧₁-resp-≈ ⌊ J ⌋ C (minimal-con x∈C) (minimal-≈ x∼y)
minimal-con (∈₁-subsum x∈C C⊑D∈T) =
Axioms✓ ⌊ J ⌋ (tbox KB) C⊑D∈T J⊨T (minimal-con x∈C)
minimal-con ∈₁-⊤-I =
tt
minimal-con (∈₁-⊓-I x∈C x∈D) =
(minimal-con x∈C , minimal-con x∈D)
minimal-con (∈₁-⊓-E₁ x∈C⊓D) =
proj₁ (minimal-con x∈C⊓D)
minimal-con (∈₁-⊓-E₂ x∈C⊓D) =
proj₂ (minimal-con x∈C⊓D)
minimal-con (∈₁-⊔-I₁ x∈C) =
inj₁ (minimal-con x∈C)
minimal-con (∈₁-⊔-I₂ x∈D) =
inj₂ (minimal-con x∈D)
minimal-con (∈₁-∀-E x∈[R]C xy∈R) =
minimal-con x∈[R]C _ (minimal-rol xy∈R)
minimal-con (∈₁-∃-I xy∈R y∈C) =
(_ , minimal-rol xy∈R , minimal-con y∈C)
minimal-rol : ∀ {x y R} → (I ⊕ KB ⊢ (x , y) ∈₂ R) →
((f x , f y) ∈ ⌊ J ⌋ ⟦ R ⟧₂)
minimal-rol (∈₂-assert xy∈r∈A) =
rol-≈ ⌊ J ⌋ _ (fγ≈j _) (Assertions✓ J (abox KB) xy∈r∈A J⊨A)
(≈-sym ⌊ J ⌋ (fγ≈j _))
minimal-rol (∈₂-import xy∈⟦r⟧) =
≲-resp-rol ≲⌊ I≲J ⌋ xy∈⟦r⟧
minimal-rol {x} {y} {R} (∈₂-resp-∼ w∼x xy∈R y∼z) =
⟦⟧₂-resp-≈ ⌊ J ⌋ R (minimal-≈ w∼x) (minimal-rol xy∈R) (minimal-≈ y∼z)
minimal-rol (∈₂-subsum xy∈Q Q⊑R∈T) =
Axioms✓ ⌊ J ⌋ (tbox KB) Q⊑R∈T J⊨T (minimal-rol xy∈Q)
minimal-rol (∈₂-refl x RefR∈T) =
Axioms✓ ⌊ J ⌋ (tbox KB) RefR∈T J⊨T _
minimal-rol (∈₂-trans xy∈R yz∈R TraR∈T) =
Axioms✓ ⌊ J ⌋ (tbox KB) TraR∈T J⊨T
(minimal-rol xy∈R) (minimal-rol yz∈R)
minimal-rol (∈₂-inv-I xy∈r) =
minimal-rol xy∈r
minimal-rol (∈₂-inv-E xy∈r⁻) =
minimal-rol xy∈r⁻
minimal-≋ : ∀ I KB K I≲K K⊨KB →
(I≲K ≋ minimal-≳ I KB >> minimal-≲ I KB K I≲K K⊨KB)
minimal-≋ I KB K I≲K (K⊨T , K⊨A) = λ x → ≈-refl ⌊ K ⌋
minimal-uniq : ∀ I KB K I≲K →
Unique I (minimal I KB) K (minimal-≳ I KB) I≲K
minimal-uniq I KB K I≲K J≲₁K J≲₂K I≲K≋I≲J≲₁K I≲K≋I≲J≲₂K (inode x) =
≈-trans ⌊ K ⌋ (≈-sym ⌊ K ⌋ (I≲K≋I≲J≲₁K x)) (I≲K≋I≲J≲₂K x)
minimal-uniq I KB K I≲K J≲₁K J≲₂K I≲K≋I≲J≲₁K I≲K≋I≲J≲₂K (bnode v) =
≈-trans ⌊ K ⌋ (≲-resp-ind J≲₁K (bnode v))
(≈-sym ⌊ K ⌋ (≲-resp-ind J≲₂K (bnode v)))
minimal-uniq I KB K I≲K J≲₁K J≲₂K I≲K≋I≲J≲₁K I≲K≋I≲J≲₂K (enode y) =
≈-trans ⌊ K ⌋ (≲-resp-ind J≲₁K (enode y))
(≈-sym ⌊ K ⌋ (≲-resp-ind J≲₂K (enode y)))
minimal-med : ∀ I KB → Mediator I (minimal I KB) (minimal-≳ I KB) KB
minimal-med I KB K I≲K K⊨KB =
( minimal-≲ I KB K I≲K K⊨KB
, minimal-≋ I KB K I≲K K⊨KB
, minimal-uniq I KB K I≲K)
minimal-init : ∀ I KB → (tbox KB ∈ μTBox) → Initial I KB (minimal I KB)
minimal-init I KB μKB =
(minimal-≳ I KB
, minimal-⊨ I KB μKB
, minimal-med I KB)
_⊞_ : Interp Σ X → KB Σ (X ⊕ W ⊕ Y) → Interp Σ Y
I ⊞ KB = enode * minimal I KB
⊞-sound : ∀ I KB₁ KB₂ → (tbox KB₁ ∈ μTBox) → (I ⊞ KB₁ ⊨ KB₂) → (I ⊕ KB₁ ⊨ KB₂)
⊞-sound I KB₁ KB₂ μKB₁ ⊨KB₂ = (minimal I KB₁ , minimal-init I KB₁ μKB₁ , ⊨KB₂)
|
{
"alphanum_fraction": 0.5147164393,
"avg_line_length": 39.8,
"ext": "agda",
"hexsha": "377c6172890a440ed2d41bf0f67760450a370728",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Sequent/Model.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Sequent/Model.agda",
"max_line_length": 78,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Sequent/Model.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 5271,
"size": 9751
}
|
------------------------------------------------------------------------
-- A simplification of Hinze.Section2-4
------------------------------------------------------------------------
module Hinze.Simplified.Section2-4 where
open import Stream.Programs
open import Stream.Equality
open import Stream.Pointwise hiding (⟦_⟧)
open import Hinze.Lemmas
open import Codata.Musical.Notation hiding (∞)
open import Data.Nat renaming (suc to 1+)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality
renaming (module ≡-Reasoning to ER)
open import Algebra.Structures
import Data.Nat.Properties as Nat
private
module CS = IsCommutativeSemiring Nat.+-*-isCommutativeSemiring
open import Data.Product
------------------------------------------------------------------------
-- Abbreviations
2* : ℕ → ℕ
2* n = 2 * n
1+2* : ℕ → ℕ
1+2* n = 1 + 2 * n
2+2* : ℕ → ℕ
2+2* n = 2 + 2 * n
------------------------------------------------------------------------
-- Definitions
nat : Prog ℕ
nat = 0 ≺ ♯ (1+ · nat)
fac : Prog ℕ
fac = 1 ≺ ♯ (1+ · nat ⟨ _*_ ⟩ fac)
fib : Prog ℕ
fib = 0 ≺ ♯ (fib ⟨ _+_ ⟩ (1 ≺ ♯ fib))
bin : Prog ℕ
bin = 0 ≺ ♯ (1+2* · bin ⋎ 2+2* · bin)
------------------------------------------------------------------------
-- Laws and properties
const-is-∞ : ∀ {A} {x : A} {xs} →
xs ≊ x ≺♯ xs → xs ≊ x ∞
const-is-∞ {x = x} {xs} eq =
xs
≊⟨ eq ⟩
x ≺♯ xs
≊⟨ refl ≺ ♯ const-is-∞ eq ⟩
x ≺♯ x ∞
≡⟨ refl ⟩
x ∞
∎
nat-lemma₁ : 0 ≺♯ 1+2* · nat ⋎ 2+2* · nat ≊ 2* · nat ⋎ 1+2* · nat
nat-lemma₁ =
0 ≺♯ 1+2* · nat ⋎ 2+2* · nat
≊⟨ refl ≺ ♯ ⋎-cong
(1+2* · nat) (1+2* · nat) (1+2* · nat ∎)
(2+2* · nat) (2* · 1+ · nat) (lemma 2 nat) ⟩
0 ≺♯ 1+2* · nat ⋎ 2* · 1+ · nat
≡⟨ refl ⟩
2* · nat ⋎ 1+2* · nat
∎
where
lemma : ∀ m s → (λ n → m + m * n) · s ≊ _*_ m · 1+ · s
lemma m = pointwise 1 (λ s → (λ n → m + m * n) · s)
(λ s → _*_ m · 1+ · s)
(λ n → sym (ER.begin
m * (1 + n)
ER.≡⟨ proj₁ CS.distrib m 1 n ⟩
m * 1 + m * n
ER.≡⟨ cong (λ x → x + m * n)
(proj₂ CS.*-identity m) ⟩
m + m * n
ER.∎))
nat-lemma₂ : nat ≊ 2* · nat ⋎ 1+2* · nat
nat-lemma₂ =
nat
≡⟨ refl ⟩
0 ≺♯ 1+ · nat
≊⟨ refl ≺ ♯ ·-cong 1+ nat (2* · nat ⋎ 1+2* · nat) nat-lemma₂ ⟩
0 ≺♯ 1+ · (2* · nat ⋎ 1+2* · nat)
≊⟨ ≅-sym (refl ≺ ♯ ⋎-map 1+ (2* · nat) (1+2* · nat)) ⟩
0 ≺♯ 1+ · 2* · nat ⋎ 1+ · 1+2* · nat
≊⟨ refl ≺ ♯ ⋎-cong (1+ · 2* · nat) (1+2* · nat)
(map-fusion 1+ 2* nat)
(1+ · 1+2* · nat) (2+2* · nat)
(map-fusion 1+ 1+2* nat) ⟩
0 ≺♯ 1+2* · nat ⋎ 2+2* · nat
≊⟨ nat-lemma₁ ⟩
2* · nat ⋎ 1+2* · nat
∎
nat≊bin : nat ≊ bin
nat≊bin =
nat
≊⟨ nat-lemma₂ ⟩
2* · nat ⋎ 1+2* · nat
≊⟨ ≅-sym nat-lemma₁ ⟩
0 ≺♯ 1+2* · nat ⋎ 2+2* · nat
≊⟨ refl ≺ coih ⟩
0 ≺♯ 1+2* · bin ⋎ 2+2* · bin
≡⟨ refl ⟩
bin
∎
where
coih = ♯ ⋎-cong (1+2* · nat) (1+2* · bin)
(·-cong 1+2* nat bin nat≊bin)
(2+2* · nat) (2+2* · bin)
(·-cong 2+2* nat bin nat≊bin)
iterate-fusion
: ∀ {A B} (h : A → B) (f₁ : A → A) (f₂ : B → B) →
(∀ x → h (f₁ x) ≡ f₂ (h x)) →
∀ x → h · iterate f₁ x ≊ iterate f₂ (h x)
iterate-fusion h f₁ f₂ hyp x =
h · iterate f₁ x
≡⟨ refl ⟩
h x ≺♯ h · iterate f₁ (f₁ x)
≊⟨ refl ≺ ♯ iterate-fusion h f₁ f₂ hyp (f₁ x) ⟩
h x ≺♯ iterate f₂ (h (f₁ x))
≡⟨ cong (λ y → ⟦ h x ≺♯ iterate f₂ y ⟧) (hyp x) ⟩
h x ≺♯ iterate f₂ (f₂ (h x))
≡⟨ refl ⟩
iterate f₂ (h x)
∎
nat-iterate : nat ≊ iterate 1+ 0
nat-iterate =
nat
≡⟨ refl ⟩
0 ≺ ♯ (1+ · nat)
≊⟨ refl ≺ ♯ ·-cong 1+ nat (iterate 1+ 0) nat-iterate ⟩
0 ≺♯ 1+ · iterate 1+ 0
≊⟨ refl ≺ ♯ iterate-fusion 1+ 1+ 1+ (λ _ → refl) 0 ⟩
0 ≺♯ iterate 1+ 1
≡⟨ refl ⟩
iterate 1+ 0
∎
|
{
"alphanum_fraction": 0.3211374031,
"avg_line_length": 33.0855263158,
"ext": "agda",
"hexsha": "7b90be345c3f4e274d4b018646ef08cfca027217",
"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": "Hinze/Simplified/Section2-4.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": "Hinze/Simplified/Section2-4.agda",
"max_line_length": 102,
"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": "Hinze/Simplified/Section2-4.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": 1798,
"size": 5029
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of homogeneous binary relations
------------------------------------------------------------------------
-- This file contains some core definitions which are reexported by
-- Relation.Binary or Relation.Binary.PropositionalEquality.
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Core where
open import Agda.Builtin.Equality using (_≡_) renaming (refl to ≡-refl)
open import Data.Maybe.Base using (Maybe)
open import Data.Product using (_×_)
open import Data.Sum.Base using (_⊎_)
open import Function using (_on_; flip)
open import Level
open import Relation.Nullary using (Dec; ¬_)
------------------------------------------------------------------------
-- Binary relations
-- Heterogeneous binary relations
REL : ∀ {a b} → Set a → Set b → (ℓ : Level) → Set (a ⊔ b ⊔ suc ℓ)
REL A B ℓ = A → B → Set ℓ
-- Homogeneous binary relations
Rel : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)
Rel A ℓ = REL A A ℓ
------------------------------------------------------------------------
-- Simple properties of binary relations
infixr 4 _⇒_ _=[_]⇒_
-- Implication/containment. Could also be written ⊆.
_⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL A B ℓ₂ → Set _
P ⇒ Q = ∀ {i j} → P i j → Q i j
-- Generalised implication. If P ≡ Q it can be read as "f preserves P".
_=[_]⇒_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
Rel A ℓ₁ → (A → B) → Rel B ℓ₂ → Set _
P =[ f ]⇒ Q = P ⇒ (Q on f)
-- A synonym, along with a binary variant.
_Preserves_⟶_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
(A → B) → Rel A ℓ₁ → Rel B ℓ₂ → Set _
f Preserves P ⟶ Q = P =[ f ]⇒ Q
_Preserves₂_⟶_⟶_ :
∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c} →
(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)
-- Reflexivity of _∼_ can be expressed as _≈_ ⇒ _∼_, for some
-- underlying equality _≈_. However, the following variant is often
-- easier to use.
Reflexive : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Reflexive _∼_ = ∀ {x} → x ∼ x
-- Irreflexivity is defined using an underlying equality.
Irreflexive : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL A B ℓ₂ → Set _
Irreflexive _≈_ _<_ = ∀ {x y} → x ≈ y → ¬ (x < y)
-- Generalised symmetry.
Sym : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL B A ℓ₂ → Set _
Sym P Q = P ⇒ flip Q
Symmetric : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Symmetric _∼_ = Sym _∼_ _∼_
-- Generalised transitivity.
Trans : ∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c} →
REL A B ℓ₁ → REL B C ℓ₂ → REL A C ℓ₃ → Set _
Trans P Q R = ∀ {i j k} → P i j → Q j k → R i k
-- A variant of Trans.
TransFlip : ∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c} →
REL A B ℓ₁ → REL B C ℓ₂ → REL A C ℓ₃ → Set _
TransFlip P Q R = ∀ {i j k} → Q j k → P i j → R i k
Transitive : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Transitive _∼_ = Trans _∼_ _∼_ _∼_
-- Generalised antisymmetry
Antisym : ∀ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL B A ℓ₂ → REL A B ℓ₃ → Set _
Antisym R S E = ∀ {i j} → R i j → S j i → E i j
Antisymmetric : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
Antisymmetric _≈_ _≤_ = Antisym _≤_ _≤_ _≈_
Asymmetric : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Asymmetric _<_ = ∀ {x y} → x < y → ¬ (y < x)
-- Generalised connex.
Conn : ∀ {a b p q} {A : Set a} {B : Set b} → REL A B p → REL B A q → Set _
Conn P Q = ∀ x y → P x y ⊎ Q y x
Total : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Total _∼_ = Conn _∼_ _∼_
data Tri {a b c} (A : Set a) (B : Set b) (C : Set c) :
Set (a ⊔ b ⊔ c) where
tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C
tri≈ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C
tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C
Trichotomous : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
Trichotomous _≈_ _<_ = ∀ x y → Tri (x < y) (x ≈ y) (x > y)
where _>_ = flip _<_
Max : ∀ {a ℓ} {A : Set a} {b} {B : Set b} → REL A B ℓ → B → Set _
Max _≤_ T = ∀ x → x ≤ T
Maximum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
Maximum = Max
Min : ∀ {a ℓ} {A : Set a} {b} {B : Set b} → REL A B ℓ → A → Set _
Min R = Max (flip R)
Minimum : ∀ {a ℓ} {A : Set a} → Rel A ℓ → A → Set _
Minimum = Min
_⟶_Respects_ : ∀ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} →
(A → Set ℓ₁) → (B → Set ℓ₂) → REL A B ℓ₃ → Set _
P ⟶ Q Respects _∼_ = ∀ {x y} → x ∼ y → P x → Q y
_Respects_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → (A → Set ℓ₁) → Rel A ℓ₂ → Set _
P Respects _∼_ = P ⟶ P Respects _∼_
_Respectsʳ_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} → REL A B ℓ₁ → Rel B ℓ₂ → Set _
P Respectsʳ _∼_ = ∀ {x} → (P x) Respects _∼_
_Respectsˡ_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} → REL A B ℓ₁ → Rel A ℓ₂ → Set _
P Respectsˡ _∼_ = ∀ {y} → (flip P y) Respects _∼_
_Respects₂_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Rel A ℓ₁ → Rel A ℓ₂ → Set _
P Respects₂ _∼_ = (P Respectsʳ _∼_) × (P Respectsˡ _∼_)
Substitutive : ∀ {a ℓ₁} {A : Set a} → Rel A ℓ₁ → (ℓ₂ : Level) → Set _
Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_
Decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} → REL A B ℓ → Set _
Decidable _∼_ = ∀ x y → Dec (x ∼ y)
WeaklyDecidable : ∀ {a b ℓ} {A : Set a} {B : Set b} → REL A B ℓ → Set _
WeaklyDecidable _∼_ = ∀ x y → Maybe (x ∼ y)
Irrelevant : ∀ {a b ℓ} {A : Set a} {B : Set b} → REL A B ℓ → Set _
Irrelevant _∼_ = ∀ {x y} (a b : x ∼ y) → a ≡ b
record NonEmpty {a b ℓ} {A : Set a} {B : Set b}
(T : REL A B ℓ) : Set (a ⊔ b ⊔ ℓ) where
constructor nonEmpty
field
{x} : A
{y} : B
proof : T x y
------------------------------------------------------------------------
-- Equivalence relations
-- The preorders of this library are defined in terms of an underlying
-- equivalence relation, and hence equivalence relations are not
-- defined in terms of preorders.
record IsEquivalence {a ℓ} {A : Set a}
(_≈_ : Rel A ℓ) : Set (a ⊔ ℓ) where
field
refl : Reflexive _≈_
sym : Symmetric _≈_
trans : Transitive _≈_
reflexive : _≡_ ⇒ _≈_
reflexive ≡-refl = refl
|
{
"alphanum_fraction": 0.5060163645,
"avg_line_length": 31.6395939086,
"ext": "agda",
"hexsha": "8c14a58c789bfbaf27c6fbb9891695ddbfcfb207",
"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/Binary/Core.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/Binary/Core.agda",
"max_line_length": 83,
"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/Binary/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2573,
"size": 6233
}
|
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
module Number.Base where
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Data.Nat renaming (ℕ to Nat)
open import Cubical.Data.Unit.Base -- Unit
open import Cubical.Data.Empty -- ⊥
open import Number.Postulates
open import Number.Bundles
data NumberKind : Type where
isNat : NumberKind
isInt : NumberKind
isRat : NumberKind
isReal : NumberKind
isComplex : NumberKind
-- NumberKindEnumeration
NLE : NumberKind → Nat
NLE isNat = 0
NLE isInt = 1
NLE isRat = 2
NLE isReal = 3
NLE isComplex = 4
-- inverse of NumberKindEnumeration
NLE⁻¹ : Nat → NumberKind
NLE⁻¹ 0 = isNat
NLE⁻¹ 1 = isInt
NLE⁻¹ 2 = isRat
NLE⁻¹ 3 = isReal
NLE⁻¹ 4 = isComplex
NLE⁻¹ x = isComplex -- doesn't matter
-- proof of inversity
NLE⁻¹-isRetraction : ∀ x → NLE⁻¹ (NLE x) ≡ x
NLE⁻¹-isRetraction isNat = refl
NLE⁻¹-isRetraction isInt = refl
NLE⁻¹-isRetraction isRat = refl
NLE⁻¹-isRetraction isReal = refl
NLE⁻¹-isRetraction isComplex = refl
-- order lifted from Nat
open import Enumeration NLE NLE⁻¹ NLE⁻¹-isRetraction using () renaming
( _≤'_ to _≤ₙₗ_
; min' to minₙₗ
; max' to maxₙₗ
; max-implies-≤' to max-implies-≤ₙₗ₂
) public
data PositivityKindOrderedRing : Type where
anyPositivityᵒʳ : PositivityKindOrderedRing
isNonzeroᵒʳ : PositivityKindOrderedRing
isNonnegativeᵒʳ : PositivityKindOrderedRing
isPositiveᵒʳ : PositivityKindOrderedRing
isNegativeᵒʳ : PositivityKindOrderedRing
isNonpositiveᵒʳ : PositivityKindOrderedRing
data PositivityKindField : Type where
anyPositivityᶠ : PositivityKindField
isNonzeroᶠ : PositivityKindField
PositivityKindType : NumberKind → Type
PositivityKindType isNat = PositivityKindOrderedRing
PositivityKindType isInt = PositivityKindOrderedRing
PositivityKindType isRat = PositivityKindOrderedRing
PositivityKindType isReal = PositivityKindOrderedRing
PositivityKindType isComplex = PositivityKindField
NumberProp = Σ NumberKind PositivityKindType
module PatternsType where
-- ordered ring patterns
pattern X = anyPositivityᵒʳ
pattern X⁺⁻ = isNonzeroᵒʳ
pattern X₀⁺ = isNonnegativeᵒʳ
pattern X⁺ = isPositiveᵒʳ
pattern X⁻ = isNegativeᵒʳ
pattern X₀⁻ = isNonpositiveᵒʳ
-- field patterns (overlapping)
pattern X = anyPositivityᶠ
pattern X⁺⁻ = isNonzeroᶠ
module PatternsProp where
-- ordered ring patterns
pattern ⁇x⁇ = anyPositivityᵒʳ
pattern x#0 = isNonzeroᵒʳ
pattern 0≤x = isNonnegativeᵒʳ
pattern 0<x = isPositiveᵒʳ
pattern x<0 = isNegativeᵒʳ
pattern x≤0 = isNonpositiveᵒʳ
-- field patterns (overlapping)
pattern ⁇x⁇ = anyPositivityᶠ
pattern x#0 = isNonzeroᶠ
open PatternsProp
coerce-PositivityKind-OR2F : PositivityKindOrderedRing → PositivityKindField
coerce-PositivityKind-OR2F ⁇x⁇ = ⁇x⁇
coerce-PositivityKind-OR2F x#0 = x#0
coerce-PositivityKind-OR2F 0≤x = ⁇x⁇
coerce-PositivityKind-OR2F 0<x = x#0
coerce-PositivityKind-OR2F x<0 = x#0
coerce-PositivityKind-OR2F x≤0 = ⁇x⁇
coerce-PositivityKind-F2OR : PositivityKindField → PositivityKindOrderedRing
coerce-PositivityKind-F2OR ⁇x⁇ = ⁇x⁇
coerce-PositivityKind-F2OR x#0 = x#0
coerce-PositivityKind-OR2 : PositivityKindOrderedRing → (to : NumberKind) → PositivityKindType to
coerce-PositivityKind-OR2 pl isNat = pl
coerce-PositivityKind-OR2 pl isInt = pl
coerce-PositivityKind-OR2 pl isRat = pl
coerce-PositivityKind-OR2 pl isReal = pl
coerce-PositivityKind-OR2 pl isComplex = coerce-PositivityKind-OR2F pl
coerce-PositivityKind-F2 : PositivityKindField → (to : NumberKind) → PositivityKindType to
coerce-PositivityKind-F2 pl isNat = coerce-PositivityKind-F2OR pl
coerce-PositivityKind-F2 pl isInt = coerce-PositivityKind-F2OR pl
coerce-PositivityKind-F2 pl isRat = coerce-PositivityKind-F2OR pl
coerce-PositivityKind-F2 pl isReal = coerce-PositivityKind-F2OR pl
coerce-PositivityKind-F2 pl isComplex = pl
coerce-PositivityKind : (from to : NumberKind) → PositivityKindType from → PositivityKindType to
coerce-PositivityKind isNat to x = coerce-PositivityKind-OR2 x to
coerce-PositivityKind isInt to x = coerce-PositivityKind-OR2 x to
coerce-PositivityKind isRat to x = coerce-PositivityKind-OR2 x to
coerce-PositivityKind isReal to x = coerce-PositivityKind-OR2 x to
coerce-PositivityKind isComplex to x = coerce-PositivityKind-F2 x to
-- NumberKind interpretation
NumberKindLevel : NumberKind → Level
NumberKindLevel isNat = ℕℓ
NumberKindLevel isInt = ℤℓ
NumberKindLevel isRat = ℚℓ
NumberKindLevel isReal = ℝℓ
NumberKindLevel isComplex = ℂℓ
NumberKindProplevel : NumberKind → Level
NumberKindProplevel isNat = ℕℓ'
NumberKindProplevel isInt = ℤℓ'
NumberKindProplevel isRat = ℚℓ'
NumberKindProplevel isReal = ℝℓ'
NumberKindProplevel isComplex = ℂℓ'
NumberKindInterpretation : (x : NumberKind) → Type (NumberKindLevel x)
NumberKindInterpretation isNat = let open ℕ* in ℕ
NumberKindInterpretation isInt = let open ℤ* in ℤ
NumberKindInterpretation isRat = let open ℚ* in ℚ
NumberKindInterpretation isReal = let open ℝ* in ℝ
NumberKindInterpretation isComplex = let open ℂ* in ℂ
-- PositivityKind interpretation
PositivityKindInterpretation : (nl : NumberKind) → PositivityKindType nl → (x : NumberKindInterpretation nl) → Type (NumberKindProplevel nl)
PositivityKindInterpretation isNat ⁇x⁇ x = Unit
PositivityKindInterpretation isNat x#0 x = let open ℕ in x # 0f
PositivityKindInterpretation isNat 0≤x x = let open ℕ in 0f ≤ x
PositivityKindInterpretation isNat 0<x x = let open ℕ in 0f < x
PositivityKindInterpretation isNat x≤0 x = let open ℕ in x ≤ 0f
PositivityKindInterpretation isNat x<0 x = ⊥
PositivityKindInterpretation isInt ⁇x⁇ x = Lift Unit
PositivityKindInterpretation isInt x#0 x = let open ℤ in x # 0f
PositivityKindInterpretation isInt 0≤x x = let open ℤ in 0f ≤ x
PositivityKindInterpretation isInt 0<x x = let open ℤ in 0f < x
PositivityKindInterpretation isInt x≤0 x = let open ℤ in x ≤ 0f
PositivityKindInterpretation isInt x<0 x = let open ℤ in x < 0f
PositivityKindInterpretation isRat ⁇x⁇ x = Lift Unit
PositivityKindInterpretation isRat x#0 x = let open ℚ in x # 0f
PositivityKindInterpretation isRat 0≤x x = let open ℚ in 0f ≤ x
PositivityKindInterpretation isRat 0<x x = let open ℚ in 0f < x
PositivityKindInterpretation isRat x≤0 x = let open ℚ in x ≤ 0f
PositivityKindInterpretation isRat x<0 x = let open ℚ in x < 0f
PositivityKindInterpretation isReal ⁇x⁇ x = Lift Unit
PositivityKindInterpretation isReal x#0 x = let open ℝ in x # 0f
PositivityKindInterpretation isReal 0≤x x = let open ℝ in 0f ≤ x
PositivityKindInterpretation isReal 0<x x = let open ℝ in 0f < x
PositivityKindInterpretation isReal x≤0 x = let open ℝ in x ≤ 0f
PositivityKindInterpretation isReal x<0 x = let open ℝ in x < 0f
PositivityKindInterpretation isComplex ⁇x⁇ x = Lift Unit
PositivityKindInterpretation isComplex x#0 x = let open ℂ in x # 0f
NumberLevel : NumberKind → Level
NumberLevel l = ℓ-max (NumberKindLevel l) (NumberKindProplevel l)
-- NumberProp interpretation
NumberInterpretation : ((l , p) : NumberProp) → Type (NumberLevel l)
NumberInterpretation (level , positivity) = Σ (NumberKindInterpretation level) (PositivityKindInterpretation level positivity)
-- generic number type
data Number (p : NumberProp) : Type (NumberLevel (fst p)) where
_,,_ : (x : NumberKindInterpretation (fst p))
→ (PositivityKindInterpretation (fst p) (snd p) x)
→ Number p
num : ∀{(l , p) : NumberProp} → Number (l , p) → NumberKindInterpretation l
num (p ,, q) = p
prp : ∀{pp@(l , p) : NumberProp} → (x : Number pp) → PositivityKindInterpretation l p (num x)
prp (p ,, q) = q
pop : ∀{p : NumberProp} → Number p → NumberInterpretation p
pop (x ,, p) = x , p
open PatternsType
{- NOTE: overlapping patterns makes this possible:
_ : NumberProp'
_ = isRat , X⁺⁻
_ : NumberProp'
_ = isComplex , X⁺⁻
-}
|
{
"alphanum_fraction": 0.7343297975,
"avg_line_length": 36.5462555066,
"ext": "agda",
"hexsha": "74c9ce4d13c26c3d971e125f4214c56339cc867f",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Base.agda",
"max_line_length": 140,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 2898,
"size": 8296
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Operations on and properties of decidable relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Decidable where
open import Level using (Level)
open import Function.Base
open import Function.Equality using (_⟨$⟩_; module Π)
open import Function.Equivalence using (_⇔_; equivalence; module Equivalence)
open import Function.Injection using (Injection; module Injection)
open import Relation.Binary using (Setoid; module Setoid; Decidable)
open import Relation.Nullary
private
variable
p q : Level
P : Set p
Q : Set q
------------------------------------------------------------------------
-- Re-exporting the core definitions
open import Relation.Nullary.Decidable.Core public
------------------------------------------------------------------------
-- Maps
map : P ⇔ Q → Dec P → Dec Q
map P⇔Q = map′ (to ⟨$⟩_) (from ⟨$⟩_)
where open Equivalence P⇔Q
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂}
(inj : Injection A B)
where
open Injection inj
open Setoid A using () renaming (_≈_ to _≈A_)
open Setoid B using () renaming (_≈_ to _≈B_)
-- If there is an injection from one setoid to another, and the
-- latter's equivalence relation is decidable, then the former's
-- equivalence relation is also decidable.
via-injection : Decidable _≈B_ → Decidable _≈A_
via-injection dec x y =
map′ injective (Π.cong to) (dec (to ⟨$⟩ x) (to ⟨$⟩ y))
|
{
"alphanum_fraction": 0.5681536555,
"avg_line_length": 31.0384615385,
"ext": "agda",
"hexsha": "b7e2c0265b44b24979dcc76215d19118fb4f8974",
"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/Nullary/Decidable.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/Nullary/Decidable.agda",
"max_line_length": 77,
"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/Nullary/Decidable.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": 1614
}
|
module Impossible where
-- The only way to trigger an __IMPOSSIBLE__ that isn't a bug.
{-# IMPOSSIBLE #-}
|
{
"alphanum_fraction": 0.7222222222,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "a0ec74f0e3deed159eacd3810506d3a42120f155",
"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": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/Impossible.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"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-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/Impossible.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/Impossible.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": 30,
"size": 108
}
|
module Web.Semantic.DL.Category.Properties.Composition where
open import Web.Semantic.DL.Category.Properties.Composition.RespectsEquiv
public using ( compose-resp-≣ )
open import Web.Semantic.DL.Category.Properties.Composition.LeftUnit
public using ( compose-unit₁ )
open import Web.Semantic.DL.Category.Properties.Composition.RightUnit
public using ( compose-unit₂ )
open import Web.Semantic.DL.Category.Properties.Composition.Assoc
public using ( compose-assoc )
|
{
"alphanum_fraction": 0.8113207547,
"avg_line_length": 34.0714285714,
"ext": "agda",
"hexsha": "d8cb0679039151c8026481b8d33cc762915e05ff",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition.agda",
"max_line_length": 73,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 110,
"size": 477
}
|
{-# OPTIONS -v scope.import:10 #-}
import Common.Level
import Common.Level
|
{
"alphanum_fraction": 0.7236842105,
"avg_line_length": 15.2,
"ext": "agda",
"hexsha": "56d03e5a0c546ffea5276ace74276fee06133ef7",
"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/Issue1770.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/Issue1770.agda",
"max_line_length": 34,
"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/Issue1770.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": 17,
"size": 76
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the sublist relation. This is commonly
-- known as Order Preserving Embeddings (OPE).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Sublist.Propositional
{a} {A : Set a} where
open import Data.List.Relation.Binary.Equality.Propositional using (≋⇒≡)
import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist
open import Data.List.Relation.Unary.Any using (Any)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Unary using (Pred)
------------------------------------------------------------------------
-- Re-export definition and operations from setoid sublists
open SetoidSublist (setoid A) public
hiding
(lookup; ⊆-reflexive; ⊆-antisym
; ⊆-isPreorder; ⊆-isPartialOrder
; ⊆-preorder; ⊆-poset
)
------------------------------------------------------------------------
-- Additional operations
module _ {p} {P : Pred A p} where
lookup : ∀ {xs ys} → xs ⊆ ys → Any P xs → Any P ys
lookup = SetoidSublist.lookup (setoid A) (subst _)
------------------------------------------------------------------------
-- Relational properties
⊆-reflexive : _≡_ ⇒ _⊆_
⊆-reflexive refl = ⊆-refl
⊆-antisym : Antisymmetric _≡_ _⊆_
⊆-antisym xs⊆ys ys⊆xs = ≋⇒≡ (SetoidSublist.⊆-antisym (setoid A) xs⊆ys ys⊆xs)
⊆-isPreorder : IsPreorder _≡_ _⊆_
⊆-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ⊆-reflexive
; trans = ⊆-trans
}
⊆-isPartialOrder : IsPartialOrder _≡_ _⊆_
⊆-isPartialOrder = record
{ isPreorder = ⊆-isPreorder
; antisym = ⊆-antisym
}
⊆-preorder : Preorder a a a
⊆-preorder = record
{ isPreorder = ⊆-isPreorder
}
⊆-poset : Poset a a a
⊆-poset = record
{ isPartialOrder = ⊆-isPartialOrder
}
|
{
"alphanum_fraction": 0.5658636597,
"avg_line_length": 28.2753623188,
"ext": "agda",
"hexsha": "14d11b5ef187f67caeaca439012a5944f7df96c4",
"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/Sublist/Propositional.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/Sublist/Propositional.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/List/Relation/Binary/Sublist/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 588,
"size": 1951
}
|
{-# OPTIONS --without-K --safe #-}
module Function where
open import Level
infixr 9 _∘_ _∘′_
_∘_ : ∀ {A : Type a} {B : A → Type b} {C : {x : A} → B x → Type c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
{-# INLINE _∘_ #-}
_∘′_ : (B → C) → (A → B) → A → C
f ∘′ g = λ x → f (g x)
{-# INLINE _∘′_ #-}
flip : ∀ {A : Type a} {B : Type b} {C : A → B → Type c} →
((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y)
flip f = λ y x → f x y
{-# INLINE flip #-}
id : ∀ {A : Type a} → A → A
id x = x
{-# INLINE id #-}
const : A → B → A
const x _ = x
{-# INLINE const #-}
infixr -1 _$_
_$_ : ∀ {A : Type a} {B : A → Type b}
→ (∀ (x : A) → B x)
→ (x : A)
→ B x
f $ x = f x
{-# INLINE _$_ #-}
infixl 0 _|>_
_|>_ : ∀ {A : Type a} {B : A → Type b}
→ (x : A)
→ (∀ (x : A) → B x)
→ B x
_|>_ = flip _$_
{-# INLINE _|>_ #-}
infixl 1 _⟨_⟩_
_⟨_⟩_ : A → (A → B → C) → B → C
x ⟨ f ⟩ y = f x y
{-# INLINE _⟨_⟩_ #-}
infixl 0 the
the : (A : Type a) → A → A
the _ x = x
{-# INLINE the #-}
syntax the A x = x ⦂ A
infix 0 case_of_
case_of_ : A → (A → B) → B
case x of f = f x
{-# INLINE case_of_ #-}
|
{
"alphanum_fraction": 0.3989941324,
"avg_line_length": 18.9365079365,
"ext": "agda",
"hexsha": "17e79a7fec0312b9c147daf4e2f85a1dc70b2ef0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"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": "oisdk/agda-playground",
"max_issues_repo_path": "Function.agda",
"max_line_length": 68,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Function.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 541,
"size": 1193
}
|
module FileNotFound where
import A.B.WildGoose
|
{
"alphanum_fraction": 0.8333333333,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "4d7037b37514f8ca86ab4a04084fc20432b5f296",
"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/FileNotFound.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/FileNotFound.agda",
"max_line_length": 25,
"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/FileNotFound.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": 13,
"size": 48
}
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import groups.KernelImage
module cohomology.ChainComplex where
record ChainComplex i : Type (lsucc i) where
field
head : AbGroup i
chain : ℕ → AbGroup i
augment : AbGroup.grp (chain 0) →ᴳ AbGroup.grp head
boundary : ∀ n → (AbGroup.grp (chain (S n)) →ᴳ AbGroup.grp (chain n))
record CochainComplex i : Type (lsucc i) where
field
head : AbGroup i
cochain : ℕ → AbGroup i
augment : AbGroup.grp head →ᴳ AbGroup.grp (cochain 0)
coboundary : ∀ n → (AbGroup.grp (cochain n) →ᴳ AbGroup.grp (cochain (S n)))
homology-group : ∀ {i} → ChainComplex i
→ (n : ℤ) → Group i
homology-group cc (pos 0) = Ker/Im cc.augment (cc.boundary 0) (snd (cc.chain 0))
where module cc = ChainComplex cc
homology-group cc (pos (S n)) = Ker/Im (cc.boundary n) (cc.boundary (S n)) (snd (cc.chain (S n)))
where module cc = ChainComplex cc
homology-group {i} cc (negsucc _) = Lift-group {j = i} Unit-group
cohomology-group : ∀ {i} → CochainComplex i
→ (n : ℤ) → Group i
cohomology-group cc (pos 0) = Ker/Im (cc.coboundary 0) cc.augment (snd (cc.cochain 0))
where module cc = CochainComplex cc
cohomology-group cc (pos (S n)) = Ker/Im (cc.coboundary (S n)) (cc.coboundary n) (snd (cc.cochain (S n)))
where module cc = CochainComplex cc
cohomology-group {i} cc (negsucc _) = Lift-group {j = i} Unit-group
complex-dualize : ∀ {i j} → ChainComplex i → AbGroup j
→ CochainComplex (lmax i j)
complex-dualize {i} {j} cc G = record {M} where
module cc = ChainComplex cc
module M where
head : AbGroup (lmax i j)
head = hom-abgroup (AbGroup.grp cc.head) G
cochain : ℕ → AbGroup (lmax i j)
cochain n = hom-abgroup (AbGroup.grp (cc.chain n)) G
augment : AbGroup.grp head →ᴳ AbGroup.grp (cochain 0)
augment = pre∘ᴳ-hom G cc.augment
coboundary : ∀ n → (AbGroup.grp (cochain n) →ᴳ AbGroup.grp (cochain (S n)))
coboundary n = pre∘ᴳ-hom G (cc.boundary n)
|
{
"alphanum_fraction": 0.6335129838,
"avg_line_length": 37.7962962963,
"ext": "agda",
"hexsha": "89ed69bd73e6c61363da66f3c55b03c54a248a68",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/ChainComplex.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/ChainComplex.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/ChainComplex.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 695,
"size": 2041
}
|
{-# OPTIONS -v tc.lhs.shadow:30 #-}
{-# OPTIONS --copatterns #-}
module PatternShadowsConstructor4 where
module A where
data B : Set where
x : B
data C : Set where
c : B → C
open A using (C; c)
record R : Set where
field
fst : C → C
snd : A.B
open R
r : R
fst r (c x) = x
snd r = A.B.x
|
{
"alphanum_fraction": 0.5621118012,
"avg_line_length": 12.3846153846,
"ext": "agda",
"hexsha": "3c4ffd7307e20cdc16fc1714108470a00c66f4a5",
"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/PatternShadowsConstructor4.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/PatternShadowsConstructor4.agda",
"max_line_length": 39,
"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/fail/PatternShadowsConstructor4.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": 110,
"size": 322
}
|
module Logic.WeaklyClassical where
import Lvl
open import Functional
open import Logic.Names
open import Logic.Predicate
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Type
private variable ℓ : Lvl.Level
private variable T X Y : Type{ℓ}
private variable P : T → Type{ℓ}
-- TODO: What should (¬¬ P → P) for a P be called? DoubleNegation? Stable proposition?
[⊤]-doubleNegation : DoubleNegationOn(⊤)
[⊤]-doubleNegation = const [⊤]-intro
[⊥]-doubleNegation : DoubleNegationOn(⊥)
[⊥]-doubleNegation = apply id
[¬]-doubleNegation : DoubleNegationOn(¬ X)
[¬]-doubleNegation = _∘ apply
[∧]-doubleNegation : DoubleNegationOn(X) → DoubleNegationOn(Y) → DoubleNegationOn(X ∧ Y)
[∧]-doubleNegation nnxx nnyy nnxy = [∧]-intro (nnxx(nx ↦ nnxy(nx ∘ [∧]-elimₗ))) (nnyy(ny ↦ nnxy(ny ∘ [∧]-elimᵣ)))
[→]-doubleNegation : DoubleNegationOn(Y) → DoubleNegationOn(X → Y)
[→]-doubleNegation nnyy nnxy x = nnyy(ny ↦ nnxy(xy ↦ (ny ∘ xy) x))
[∀]-doubleNegation-distribute : (∀{x} → DoubleNegationOn(P(x))) → DoubleNegationOn(∀{x} → P(x))
[∀]-doubleNegation-distribute annp nnap = annp(npx ↦ nnap(npx $_))
doubleNegation-to-callCC : DoubleNegationOn(X) → DoubleNegationOn(Y) → (((X → Y) → X) → X)
doubleNegation-to-callCC dx dy xyx = dx(nx ↦ nx(xyx(dy ∘ const ∘ nx)))
|
{
"alphanum_fraction": 0.6978361669,
"avg_line_length": 34.972972973,
"ext": "agda",
"hexsha": "d6a608c01bdc4ca7b8a571d7c9926ca73fb397c4",
"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": "Logic/WeaklyClassical.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": "Logic/WeaklyClassical.agda",
"max_line_length": 113,
"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": "Logic/WeaklyClassical.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": 466,
"size": 1294
}
|
-- Solutions to ExerciseSession2
{-# OPTIONS --cubical #-}
module SolutionsSession2 where
open import Part1
open import Part2
open import ExerciseSession1
-- Exercise 1
JEq : {x : A} (P : (z : A) → x ≡ z → Type ℓ'')
(d : P x refl) → J P d refl ≡ d
JEq P p d = transportRefl p d
-- Exercise 2
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b = sym (p a) ∙ p b
-- Exercise 3
isProp→isProp' : isProp A → isProp' A
isProp→isProp' p x y = p x y , isProp→isSet p _ _ (p x y)
-- Exercise 4
isContr→isContr≡ : isContr A → (x y : A) → isContr (x ≡ y)
isContr→isContr≡ h = isProp→isProp' (isContr→isProp h)
-- Exercise 5
fromPathP : {A : I → Type ℓ} {x : A i0} {y : A i1}
→ PathP A x y
→ transport (λ i → A i) x ≡ y
fromPathP {A = A} p i = transp (λ j → A (i ∨ j)) i (p i)
-- The converse is harder to prove so we give it:
toPathP : {A : I → Type ℓ} {x : A i0} {y : A i1}
→ transport (λ i → A i) x ≡ y
→ PathP A x y
toPathP {A = A} {x = x} p i =
hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
-- Exercise 6
Σ≡Prop : {B : A → Type ℓ'} {u v : Σ A B} (h : (x : A) → isProp (B x))
→ (p : fst u ≡ fst v) → u ≡ v
Σ≡Prop {B = B} {u = u} {v = v} h p =
ΣPathP (p , toPathP (h _ (transport (λ i → B (p i)) (snd u)) (snd v)))
-- Exercice 7 (thanks Loïc for the slick proof!)
isPropIsContr : isProp (isContr A)
isPropIsContr (c0 , h0) (c1 , h1) j =
h0 c1 j , λ y i → hcomp (λ k → λ { (i = i0) → h0 (h0 c1 j) k;
(i = i1) → h0 y k;
(j = i0) → h0 (h0 y i) k;
(j = i1) → h0 (h1 y i) k}) c0
-- Exercises about Part 3:
-- Exercise 8 (a bit longer, but very good):
open import Cubical.Data.Nat
open import Cubical.Data.Int hiding (addEq ; subEq)
-- Compose sucPathInt with itself n times. Transporting along this
-- will be addition, transporting with it backwards will be subtraction.
-- a) Define a path "addEq n" by composing sucPathInt with itself n
-- times.
addEq : ℕ → Int ≡ Int
addEq zero = refl
addEq (suc n) = (addEq n) ∙ sucPathInt
-- b) Define another path "subEq n" by composing "sym sucPathInt" with
-- itself n times.
subEq : ℕ → Int ≡ Int
subEq zero = refl
subEq (suc n) = (subEq n) ∙ sym sucPathInt
-- c) Define addition on integers by pattern-matching and transporting
-- along addEq/subEq appropriately.
_+Int_ : Int → Int → Int
m +Int pos n = transport (addEq n) m
m +Int negsuc n = transport (subEq (suc n)) m
-- d) Do some concrete computations using _+Int_ (this would not work
-- in HoTT as the transport would be stuck!)
-- Exercise 9: prove that hSet is not an hSet
open import Cubical.Data.Bool renaming (notEq to notPath)
open import Cubical.Data.Empty
-- Just define hSets of level 0 for simplicity
hSet : Type₁
hSet = Σ[ A ∈ Type₀ ] isSet A
-- Bool is an hSet
BoolSet : hSet
BoolSet = Bool , isSetBool
notPath≢refl : (notPath ≡ refl) → ⊥
notPath≢refl e = true≢false (transport (λ i → transport (e i) true ≡ false) refl)
¬isSet-hSet : isSet hSet → ⊥
¬isSet-hSet h = notPath≢refl (cong (cong fst) (h BoolSet BoolSet p refl))
where
p : BoolSet ≡ BoolSet
p = Σ≡Prop (λ A → isPropIsSet {A = A}) notPath
-- Exercise 10: squivalence between FinData and Fin
-- Thanks to Elies for the PR with the code. On the development
-- version of the library there is now:
--
-- open import Cubical.Data.Fin using (FinData≡Fin)
|
{
"alphanum_fraction": 0.598913665,
"avg_line_length": 27.7619047619,
"ext": "agda",
"hexsha": "df867fde78127db5d16213cab2089c4430147030",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-08-02T16:16:34.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-08-02T16:16:34.000Z",
"max_forks_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "williamdemeo/EPIT-2020",
"max_forks_repo_path": "04-cubical-type-theory/material/SolutionsSession2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"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": "williamdemeo/EPIT-2020",
"max_issues_repo_path": "04-cubical-type-theory/material/SolutionsSession2.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "19d72759e18e05d2c509f62d23a998573270140c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "williamdemeo/EPIT-2020",
"max_stars_repo_path": "04-cubical-type-theory/material/SolutionsSession2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1268,
"size": 3498
}
|
open import x1-Base
module x2-Sort
{X : Set}
{_≈_ : Rel X}
{_≤_ : Rel X}
(_≤?_ : Decidable _≤_)
(ord : TotalOrder _≈_ _≤_)
where
open TotalOrder ord using (total; equivalence)
open Equivalence equivalence using (refl)
-- represent bounded lists, but want bounds to be open
-- so lift X in a type that contains a top and bottom elements
data ⊥X⊤ : Set where
⊤ ⊥ : ⊥X⊤
⟦_⟧ : X → ⊥X⊤
-- lift ordering to work with ⊥X⊤
data _≤̂_ : Rel ⊥X⊤ where
⊥≤̂ : ∀ {x} → ⊥ ≤̂ x
≤̂⊤ : ∀ {x} → x ≤̂ ⊤
≤-lift : ∀ {x y} → x ≤ y → ⟦ x ⟧ ≤̂ ⟦ y ⟧
-- bounded, ordered lists
-- elements ordered according to ≤ relation
data OList (l u : ⊥X⊤) : Set where
-- nil works with any bounds l ≤ u
nil : l ≤̂ u
→ OList l u
-- cons x to a list with x as a lower bound,
-- return a list with lower bound l, l ≤̂ ⟦ x ⟧
cons : ∀ x
(xs : OList ⟦ x ⟧ u)
→ l ≤̂ ⟦ x ⟧
→ OList l u
toList : ∀ {l u} → OList l u → List X
toList (nil _) = []
toList (cons x xs _) = x ∷ toList xs
insert : ∀ {l u} x
→ OList l u
→ l ≤̂ ⟦ x ⟧
→ ⟦ x ⟧ ≤̂ u
→ OList l u
insert x (nil _) l≤̂⟦x⟧ ⟦x⟧≤̂u =
cons x (nil ⟦x⟧≤̂u)
l≤̂⟦x⟧
insert x L@(cons x' xs l≤̂⟦x'⟧) l≤̂⟦x⟧ ⟦x⟧≤̂u with x ≤? x'
... | left x≤x' =
cons x (cons x' xs (≤-lift x≤x'))
l≤̂⟦x⟧
... | (right x≤x'→Empty) =
cons x' (insert x xs ([ ≤-lift
, (λ y≤x → absurd (x≤x'→Empty y≤x)) ]
(total x' x))
⟦x⟧≤̂u)
l≤̂⟦x'⟧
-- Insertion sort uses OList ⊥ ⊤ to represent a sorted list with open bounds:
isort' : List X → OList ⊥ ⊤
isort' = foldr (λ x xs → insert x xs ⊥≤̂ ≤̂⊤) (nil ⊥≤̂)
isort : List X → List X
isort xs = toList (isort' xs)
------------------------------------------------------------------------------
-- Tree sort (more efficient)
-- bounded, ordered binary tree
data Tree (l u : ⊥X⊤) : Set where
leaf : l ≤̂ u
→ Tree l u
node : (x : X)
→ Tree l ⟦ x ⟧
→ Tree ⟦ x ⟧ u
→ Tree l u
t-insert : ∀ {l u}
→ (x : X)
→ Tree l u
→ l ≤̂ ⟦ x ⟧
→ ⟦ x ⟧ ≤̂ u
→ Tree l u
t-insert x (leaf _) l≤x x≤u =
node x (leaf l≤x) (leaf x≤u)
t-insert x (node y ly yu) l≤x x≤u with x ≤? y
... | left x≤y =
node y (t-insert x ly l≤x (≤-lift x≤y)) yu
... | right x>y =
node y ly (t-insert x yu ([ (λ x≤y → absurd (x>y x≤y)) , ≤-lift ] (total x y)) x≤u)
t-fromList : List X → Tree ⊥ ⊤
t-fromList = foldr (λ x xs → t-insert x xs ⊥≤̂ ≤̂⊤) (leaf ⊥≤̂)
-- OList concatenation, including inserting a new element in the middle
_⇒_++_ : ∀ {l u} x
→ OList l ⟦ x ⟧
→ OList ⟦ x ⟧ u
→ OList l u
x ⇒ nil l≤u ++ xu = cons x xu l≤u
x ⇒ cons y yx l≤y ++ xu = cons y (x ⇒ yx ++ xu) l≤y
t-flatten : ∀ {l u} → Tree l u → OList l u
t-flatten (leaf l≤u) = (nil l≤u)
t-flatten (node x lx xu) = x ⇒ t-flatten lx ++ t-flatten xu
t-sort' : List X → OList ⊥ ⊤
t-sort' xs = t-flatten (foldr (λ x xs → t-insert x xs ⊥≤̂ ≤̂⊤) (leaf ⊥≤̂) xs)
t-sort : List X → List X
t-sort xs = toList (t-sort' xs)
|
{
"alphanum_fraction": 0.4484867013,
"avg_line_length": 27.9572649573,
"ext": "agda",
"hexsha": "e4fe205117764a6ed39498f25236df220563c072",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x2-Sort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x2-Sort.agda",
"max_line_length": 85,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x2-Sort.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 1382,
"size": 3271
}
|
{-# OPTIONS --prop --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
postulate
A : Prop
a : A
B : Set
b : B
f : A → B → Set₁
g : B → Set₁
rew₁ : ∀ y → f a y ≡ g y
rew₂ : ∀ x → f x b ≡ Set
rew₃ : ∀ y → g y ≡ Set
{-# REWRITE rew₁ rew₂ rew₃ #-}
|
{
"alphanum_fraction": 0.5692307692,
"avg_line_length": 17.1052631579,
"ext": "agda",
"hexsha": "31fe9142c146df5df4820bff3bc5d8bfedb63dfb",
"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/RewritingGlobalConfluenceWithProp.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/RewritingGlobalConfluenceWithProp.agda",
"max_line_length": 53,
"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/RewritingGlobalConfluenceWithProp.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": 128,
"size": 325
}
|
test = forall (_Set_ : Set) → Set
|
{
"alphanum_fraction": 0.6176470588,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "df38eb987d8e9bc7a5d87312752e0df168d068a2",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/ValidNamePartSet.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/ValidNamePartSet.agda",
"max_line_length": 33,
"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/ValidNamePartSet.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": 12,
"size": 34
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.