text
stringlengths 4
690k
|
|---|
-- 2012-02-13 Andreas: testing correct polarity of data types
-- sized types are the only source of subtyping, I think...
{-# OPTIONS --sized-types #-}
module DataPolarity where
open import Common.Size
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {↑ size}
suc : {size : Size} -> Nat {size} -> Nat {↑ size}
data Pair (A : Set) : Set where
_,_ : A -> A -> Pair A
split : {i : Size} → Nat {i} → Pair (Nat {i})
split zero = zero , zero
split (suc n) with split n
... | (l , r) = suc r , l
-- this should work, due to the monotonicity of Pair
-- without subtyping, Agda would complain about i != ↑ i
MyPair : Nat → Set → Set
MyPair zero A = Pair A
MyPair (suc n) A = MyPair n A
-- polarity should be preserved by functions
mysplit : {i : Size} → (n : Nat {i}) → MyPair (suc zero) (Nat {i})
mysplit zero = zero , zero
mysplit (suc n) with mysplit n
... | (l , r) = suc r , l
|
{-# OPTIONS --allow-unsolved-metas #-}
module Control.Lens where
open import Function using (id; _∘_; const; flip)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Axiom.FunctionExtensionality
open import Util.Equality
open import Control.Functor renaming (Comp to _•_)
open import Control.Functor.NaturalTransformation renaming (Id to Nid; Comp to _·_)
-- S-combinator.
apply : ∀ {A B C : Set} → (A → B → C) → (A → B) → A → C
apply f g a = f a (g a)
-- Flipped S-combinator (flipped apply).
flipply : ∀ {O A B : Set} → (A → O → B) → (O → A) → O → B
flipply f g o = f (g o) o
record GetSetLens (O I : Set) : Set where
-- Operations.
field
get : O → I
set : I → O → O
-- Laws.
field
set-set : ∀ {i j} → set i ∘ set j ≡ set i
get-set : ∀ {i} → get ∘ set i ≡ const i
set-get : flipply set get ≡ id -- ∀ {o} → set (get o) o ≡ o
-- A variant of GetSetLens
record GetsModifyLens (O I : Set) : Set₁ where
-- Operations.
field
gets : ∀ {J} → (I → J) → O → J
modify : (I → I) → O → O
-- Laws.
field
-- modify is an endofunctor in the discrete category I.
modify-id :
modify id ≡ id
modify-∘ : ∀ {f g} →
modify g ∘ modify f ≡ modify (g ∘ f)
-- Free theorem for gets.
gets-free : ∀ {J K} {f : J → K} (g : I → J) →
f ∘ gets g ≡ gets (f ∘ g)
gets-modify : ∀ {J} {f : I → I} {g : I → J} →
gets g ∘ modify f ≡ gets (g ∘ f)
-- set (get o) o ≡ o
-- modify (const (gets id o)) o ≡ o
-- modify (const (gets f o)) o ≡ modify f o
-- modify (λ i → g (gets f o) i) o ≡ modify (λ i → g i (f i)) o
-- apply (flip modify) (g ∘ gets f) ≡ modify (apply g f)
modify-gets : ∀ {J} {g : I → J} (s : J → I → I) →
flipply modify (s ∘ gets g) ≡ modify (flipply s g)
getSetLens : GetSetLens O I
getSetLens = record
{ get = gets id
; set = modify ∘ const
; set-set = modify-∘
; get-set = get-set
; set-get = set-get
}
where
get : O → I
get = gets id
set : I → O → O
set = modify ∘ const
get-set : ∀ {i} → get ∘ set i ≡ const i
get-set {i} =
begin
get ∘ set i ≡⟨⟩
gets id ∘ modify (const i) ≡⟨ gets-modify ⟩
gets (id ∘ const i) ≡⟨⟩
gets (const i ∘ id) ≡⟨ sym (gets-free id) ⟩
const i ∘ get ≡⟨⟩
const i
∎
set-get : flipply set get ≡ id
set-get = begin
flipply set get ≡⟨⟩
flipply (modify ∘ const) (gets id) ≡⟨⟩
flipply modify (const ∘ gets id) ≡⟨ modify-gets const ⟩
modify (flipply const id) ≡⟨⟩
modify id ≡⟨ modify-id ⟩
id ∎
open GetSetLens getSetLens public
-- van Laarhoven lenses
record Lens (O I : Set) : Set₁ where
-- Single operation: Functorial modify.
field
modify! : ∀ (FF : Functor) → let F = Functor.F FF in
(I → F I) → (O → F O)
-- Laws
-- 0. Free theorem:
field
modify!-free : (FF GG : Functor) (N : NatTrans FF GG) →
let open Functor FF using () renaming (F to F; map to mapF) in
let open Functor GG using () renaming (F to G; map to mapG) in
let open NatTrans N using () renaming (eta to η) in
(f : I → F I) →
η ∘ modify! FF f ≡ modify! GG (η ∘ f)
-- 1. Identity law: -- Generalize?
modify!-id :
modify! Id id ≡ id
-- 2. Composition law:
modify!-∘ : (FF GG : Functor) →
let open Functor FF using () renaming (F to F; map to mapF) in
let open Functor GG using () renaming (F to G; map to mapG) in
{f : I → F I} →
{g : I → G I} →
mapF (modify! GG g) ∘ modify! FF f
≡ modify! (FF • GG) (mapF g ∘ f)
getsModifyLens : GetsModifyLens O I
getsModifyLens = record
{ gets = gets
; modify = modify
; modify-id = modify!-id
; modify-∘ = modify-∘
; gets-free = λ {J}{K}{f} g → gets-free f g
; gets-modify = gets-modify
; modify-gets = modify-gets
}
where
-- gets and modify
gets : ∀ {J} → (I → J) → (O → J)
gets {J = J} = modify! (Const J)
modify : (I → I) → O → O
modify = modify! Id
-- Laws of gets and modify.
modify-∘ : ∀ {f g} → modify g ∘ modify f ≡ modify (g ∘ f)
modify-∘ = modify!-∘ Id Id
gets-free : ∀ {J K} (f : J → K) (g : I → J) → f ∘ gets g ≡ gets (f ∘ g)
gets-free {J = J}{K = K} f g = modify!-free (Const J) (Const K) (ConstNat f) g
gets-modify : ∀ {J} {f : I → I} {g : I → J} →
gets g ∘ modify f ≡ gets (g ∘ f)
gets-modify {J = J} = modify!-∘ Id (Const J)
modify-gets : ∀ {J} {g : I → J} (s : J → I → I) →
flipply modify (s ∘ gets g) ≡ modify (flipply s g)
modify-gets = {!!} -- TODO! Difficult.
open GetsModifyLens getsModifyLens public
-- Every GetSetLens is a van Laarhoven lens ??
lensFromGetSet : ∀ {O I} → GetSetLens O I → Lens O I
lensFromGetSet {O = O}{I = I} l = record
{ modify! = modify!
; modify!-free = {!!}
; modify!-id = set-get
; modify!-∘ = modify!-∘
}
where
open GetSetLens l
module Define-modify! (FF : Functor) where
open Functor FF
modify! : (I → F I) → (O → F O)
modify! f = apply (map ∘ flip set) (f ∘ get)
derivation-of-modify : ∀ f → modify! f ≡ apply (map ∘ flip set) (f ∘ get)
derivation-of-modify f = begin
modify! f
≡⟨⟩ (λ o → f (get o) <&> λ i → set i o)
≡⟨⟩ (λ o → ((λ o → map (λ i → set i o)) o) ((f ∘ get) o))
≡⟨⟩ apply (λ o → map (λ i → set i o)) (f ∘ get)
≡⟨⟩ apply (λ o → map (flip set o)) (f ∘ get)
≡⟨⟩ apply (map ∘ flip set) (f ∘ get)
∎
open Define-modify!
modify!-free : (FF GG : Functor) (N : NatTrans FF GG) →
let open Functor FF using () renaming (F to F; map to mapF) in
let open Functor GG using () renaming (F to G; map to mapG) in
let open NatTrans N using () renaming (eta to η) in
(f : I → F I) →
η ∘ modify! FF f ≡ modify! GG (η ∘ f)
modify!-free FF GG N f = fun-ext λ o → begin
η (modify! FF f o) ≡⟨⟩
η (mapF (λ i → set i o) (f (get o))) ≡⟨ app-naturality (flip set) (f ∘ get) o ⟩
mapG (λ i → set i o) (η (f (get o))) ≡⟨⟩
modify! GG (η ∘ f) o ∎
where
open Functor FF using () renaming (F to F; map to mapF; map-∘ to mapF-∘)
open Functor GG using () renaming (F to G; map to mapG; map-∘ to mapG-∘)
open NatTrans N using (app-naturality) renaming (eta to η)
modify!-id : modify! Id id ≡ id
modify!-id = fun-ext λ o → begin
(Functor.map Id) (λ i → set i o) (id (get o)) ≡⟨⟩
(λ i → set i o) (get o) ≡⟨⟩
set (get o) o ≡⟨⟩
flipply set get o ≡⟨ app-≡ o set-get ⟩
id o ≡⟨⟩
o ∎
modify!-∘ : (FF GG : Functor) →
let open Functor FF using () renaming (F to F; map to mapF) in
let open Functor GG using () renaming (F to G; map to mapG) in
{f : I → F I} →
{g : I → G I} →
mapF (modify! GG g) ∘ modify! FF f
≡ modify! (FF • GG) (mapF g ∘ f)
modify!-∘ FF GG {f = f} {g = g} = fun-ext λ o → begin
mapF (modify! GG g) (modify! FF f o) ≡⟨⟩
mapF (λ o → mapG (λ i → set i o) (g (get o)))
(mapF (λ i → set i o) (f (get o))) ≡⟨ app-≡ _ (sym mapF-∘) ⟩
mapF ((λ o → mapG (λ i → set i o) (g (get o)))
∘ (λ i → set i o))(f (get o)) ≡⟨⟩
mapF (λ j → mapG (λ i → set i (set j o)) (g (get (set j o))))
(f (get o)) ≡⟨ {!set-set!} ⟩
mapF (λ j → mapG (λ i → set i o) (g (get (set j o))))
(f (get o)) ≡⟨ {!get-set!} ⟩
mapF (λ j → mapG (λ i → set i o) (g j))
(f (get o)) ≡⟨⟩
mapF (mapG (λ i → set i o) ∘ g) (f (get o)) ≡⟨ app-≡ _ mapF-∘ ⟩
mapF (mapG (λ i → set i o)) (mapF g (f (get o))) ≡⟨⟩
mapFG (λ i → set i o) (mapF g (f (get o))) ≡⟨⟩
modify! (FF • GG) (mapF g ∘ f) o ∎
where
open Functor FF using () renaming (F to F; map to mapF; map-∘ to mapF-∘)
open Functor GG using () renaming (F to G; map to mapG; map-∘ to mapG-∘)
mapFG = Functor.map (FF • GG)
{-
Lens operations:
get : Lens I O → O → I
get l o = l (mapK I) id o
set : Len I O → I → O → O
set l i o = l mapId (const i) o
Lens laws:
a. set-set
set l i ∘ set l j = set l i
Prove from 2.
b. get-set
get l (set l i o) = i
Prove from 0. + 2.
c. set-get
set l o (get l o) = o
This states that set is surjective, it is equivalent to
∀ o → ∃₂ λ i o′ → set l o′ i = o
Independence of 0, 1, 2.
-----------------------
A. 0 does not imply 2. Counterexample:
-- An impossible lens, since ⊤ contains nothing, especially not Bool
l : Lens Bool ⊤
l map f = map (const tt) (f true)
( get l _ = false )
( set l _ _ = tt )
does not satisfy 2. (Lens composition)
mapId (l (mapK Bool) id) ∘ l mapId not
= const ((mapK Bool) (const tt) true)
= const true
l (mapK Bool) (id ∘ not)
= const ((mapK Bool) (const tt) (not true)
= const false
B. 0, 2 are not sufficent to prove c. Counterexample:
-- Lens focusing on nothing.
l : Lens ⊤ Bool
l map f _ = map (const true) (f tt)
( get l _ = tt )
( set l _ _ = true )
so, set l false (get l false) /= false
Proof of 2:
-}
|
-- This module closely follows a section of Martín Escardó's HoTT lecture notes:
-- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#unicharac
{-# OPTIONS --without-K #-}
module Util.HoTT.Univalence.ContrFormulation where
open import Util.Data.Product using (map₂)
open import Util.Prelude
open import Util.HoTT.Equiv
open import Util.HoTT.HLevel.Core
open import Util.HoTT.Singleton
open import Util.HoTT.Univalence.Axiom
open import Util.HoTT.Univalence.Statement
private
variable
α β γ : Level
UnivalenceContr : ∀ α → Set (lsuc α)
UnivalenceContr α = (A : Set α) → IsContr (Σ[ B ∈ Set α ] (A ≃ B))
UnivalenceProp : ∀ α → Set (lsuc α)
UnivalenceProp α = (A : Set α) → IsProp (Σ[ B ∈ Set α ] (A ≃ B))
abstract
IsEquiv→Σ-IsContr : {A : Set α} {B : A → Set β} (x : A)
→ (f : ∀ y → x ≡ y → B y)
→ (∀ y → IsEquiv (f y))
→ IsContr (Σ A B)
IsEquiv→Σ-IsContr {A = A} {B = B} x f f-equiv
= ≃-pres-IsContr Singleton≃ΣB IsContr-Singleton′
where
≡≃B : ∀ y → (x ≡ y) ≃ B y
≡≃B y .forth = f y
≡≃B y .isEquiv = f-equiv y
Singleton≃ΣB : Singleton′ x ≃ Σ A B
Singleton≃ΣB = Σ-≃⁺ ≡≃B
Σ-IsContr→IsEquiv : {A : Set α} {B : A → Set β} (x : A)
→ (f : ∀ y → x ≡ y → B y)
→ IsContr (Σ A B)
→ ∀ y → IsEquiv (f y)
Σ-IsContr→IsEquiv {A = A} {B = B} x f Σ-contr
= IsEquiv-map₂-f→IsEquiv-f f f-equiv
where
f-equiv : IsEquiv (map₂ f)
f-equiv = IsContr→IsEquiv IsContr-Singleton′ Σ-contr (map₂ f)
Univalence→UnivalenceContr : Univalence α → UnivalenceContr α
Univalence→UnivalenceContr ua A = IsEquiv→Σ-IsContr A (λ B → ≡→≃) (λ B → ua)
UnivalenceContr→Univalence : UnivalenceContr α → Univalence α
UnivalenceContr→Univalence ua {A} {B}
= Σ-IsContr→IsEquiv A (λ B → ≡→≃) (ua A) B
univalenceContr : (A : Set α) → IsContr (Σ[ B ∈ Set α ] (A ≃ B))
univalenceContr = Univalence→UnivalenceContr univalence
UnivalenceContr→UnivalenceProp : UnivalenceContr α → UnivalenceProp α
UnivalenceContr→UnivalenceProp ua = IsContr→IsProp ∘ ua
UnivalenceProp→UnivalenceContr : UnivalenceProp α → UnivalenceContr α
UnivalenceProp→UnivalenceContr ua A
= IsProp∧Pointed→IsContr (ua A) (A , ≃-refl)
Univalence→UnivalenceProp : Univalence α → UnivalenceProp α
Univalence→UnivalenceProp
= UnivalenceContr→UnivalenceProp ∘ Univalence→UnivalenceContr
UnivalenceProp→Univalence : UnivalenceProp α → Univalence α
UnivalenceProp→Univalence
= UnivalenceContr→Univalence ∘ UnivalenceProp→UnivalenceContr
univalenceProp : ∀ {α} → UnivalenceProp α
univalenceProp = Univalence→UnivalenceProp univalence
|
{-# OPTIONS --safe --no-sized-types #-}
open import Agda.Builtin.Size
record Stream (A : Set) (i : Size) : Set where
coinductive
field
head : A
tail : {j : Size< i} → Stream A j
open Stream
destroy-guardedness : ∀ {A i} → Stream A i → Stream A i
destroy-guardedness xs .head = xs .head
destroy-guardedness xs .tail = xs .tail
repeat : ∀ {A i} → A → Stream A i
repeat x .head = x
repeat x .tail = destroy-guardedness (repeat x)
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.Notation where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Algebra.Group.Base
module GroupNotationG {ℓ : Level} ((_ , G) : Group {ℓ}) where
0ᴳ = GroupStr.0g G
_+ᴳ_ = GroupStr._+_ G
-ᴳ_ = GroupStr.-_ G
_-ᴳ_ = GroupStr._-_ G
lIdᴳ = GroupStr.lid G
rIdᴳ = GroupStr.rid G
lCancelᴳ = GroupStr.invl G
rCancelᴳ = GroupStr.invr G
assocᴳ = GroupStr.assoc G
setᴳ = GroupStr.is-set G
module GroupNotationᴴ {ℓ : Level} ((_ , G) : Group {ℓ}) where
0ᴴ = GroupStr.0g G
_+ᴴ_ = GroupStr._+_ G
-ᴴ_ = GroupStr.-_ G
_-ᴴ_ = GroupStr._-_ G
lIdᴴ = GroupStr.lid G
rIdᴴ = GroupStr.rid G
lCancelᴴ = GroupStr.invl G
rCancelᴴ = GroupStr.invr G
assocᴴ = GroupStr.assoc G
setᴴ = GroupStr.is-set G
module GroupNotation₀ {ℓ : Level} ((_ , G) : Group {ℓ}) where
0₀ = GroupStr.0g G
_+₀_ = GroupStr._+_ G
-₀_ = GroupStr.-_ G
_-₀_ = GroupStr._-_ G
lId₀ = GroupStr.lid G
rId₀ = GroupStr.rid G
lCancel₀ = GroupStr.invl G
rCancel₀ = GroupStr.invr G
assoc₀ = GroupStr.assoc G
set₀ = GroupStr.is-set G
module GroupNotation₁ {ℓ : Level} ((_ , G) : Group {ℓ}) where
0₁ = GroupStr.0g G
_+₁_ = GroupStr._+_ G
-₁_ = GroupStr.-_ G
_-₁_ = GroupStr._-_ G
lId₁ = GroupStr.lid G
rId₁ = GroupStr.rid G
lCancel₁ = GroupStr.invl G
rCancel₁ = GroupStr.invr G
assoc₁ = GroupStr.assoc G
set₁ = GroupStr.is-set G
|
{-# OPTIONS --without-K --rewriting #-}
module Set where
|
{-# OPTIONS --without-K --safe #-}
-- Enriched category over a Monoidal category V
open import Categories.Category using (module Commutation) renaming (Category to Setoid-Category)
open import Categories.Category.Monoidal using (Monoidal)
module Categories.Enriched.Category {o ℓ e} {V : Setoid-Category o ℓ e}
(M : Monoidal V) where
open import Level
open import Categories.Category.Monoidal.Reasoning M
open import Categories.Category.Monoidal.Utilities M using (module Shorthands)
open import Categories.Morphism.Reasoning V using (pullˡ; pullʳ; pushˡ)
open Setoid-Category V renaming (Obj to ObjV; id to idV)
using (_⇒_; _∘_)
open Commutation V
open Monoidal M using (unit; _⊗₀_; _⊗₁_; module associator; module unitorˡ;
module unitorʳ; assoc-commute-from)
open Shorthands
record Category (v : Level) : Set (o ⊔ ℓ ⊔ e ⊔ suc v) where
field
Obj : Set v
hom : (A B : Obj) → ObjV
id : {A : Obj} → unit ⇒ hom A A
⊚ : {A B C : Obj} → hom B C ⊗₀ hom A B ⇒ hom A C
⊚-assoc : {A B C D : Obj} →
[ (hom C D ⊗₀ hom B C) ⊗₀ hom A B ⇒ hom A D ]⟨
⊚ ⊗₁ idV ⇒⟨ hom B D ⊗₀ hom A B ⟩
⊚
≈ associator.from ⇒⟨ hom C D ⊗₀ (hom B C ⊗₀ hom A B) ⟩
idV ⊗₁ ⊚ ⇒⟨ hom C D ⊗₀ hom A C ⟩
⊚
⟩
unitˡ : {A B : Obj} →
[ unit ⊗₀ hom A B ⇒ hom A B ]⟨
id ⊗₁ idV ⇒⟨ hom B B ⊗₀ hom A B ⟩
⊚
≈ unitorˡ.from
⟩
unitʳ : {A B : Obj} →
[ hom A B ⊗₀ unit ⇒ hom A B ]⟨
idV ⊗₁ id ⇒⟨ hom A B ⊗₀ hom A A ⟩
⊚
≈ unitorʳ.from
⟩
-- A version of ⊚-assoc using generalized hom-variables.
--
-- In this version of associativity, the generalized variables f, g
-- and h represent V-morphisms, or rather, morphism-valued maps,
-- such as V-natural transformations or V-functorial actions. This
-- version is therefore well-suited for proving derived equations,
-- such as functorial laws or commuting diagrams, that involve such
-- maps. For examples, see Underlying.assoc below, or the modules
-- Enriched.Functor and Enriched.NaturalTransformation.
⊚-assoc-var : {X Y Z : ObjV} {A B C D : Obj}
{f : X ⇒ hom C D} {g : Y ⇒ hom B C} {h : Z ⇒ hom A B} →
[ (X ⊗₀ Y) ⊗₀ Z ⇒ hom A D ]⟨
(⊚ ∘ f ⊗₁ g) ⊗₁ h ⇒⟨ hom B D ⊗₀ hom A B ⟩
⊚
≈ associator.from ⇒⟨ X ⊗₀ (Y ⊗₀ Z) ⟩
f ⊗₁ (⊚ ∘ g ⊗₁ h) ⇒⟨ hom C D ⊗₀ hom A C ⟩
⊚
⟩
⊚-assoc-var {f = f} {g} {h} = begin
⊚ ∘ (⊚ ∘ f ⊗₁ g) ⊗₁ h ≈⟨ refl⟩∘⟨ split₁ˡ ⟩
⊚ ∘ ⊚ ⊗₁ idV ∘ (f ⊗₁ g) ⊗₁ h ≈⟨ pullˡ ⊚-assoc ⟩
(⊚ ∘ idV ⊗₁ ⊚ ∘ α⇒) ∘ (f ⊗₁ g) ⊗₁ h ≈⟨ pullʳ (pullʳ assoc-commute-from) ⟩
⊚ ∘ idV ⊗₁ ⊚ ∘ f ⊗₁ (g ⊗₁ h) ∘ α⇒ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩
⊚ ∘ f ⊗₁ (⊚ ∘ g ⊗₁ h) ∘ α⇒ ∎
-- The usual shorthand for hom-objects of an arbitrary category.
infix 15 _[_,_]
_[_,_] : ∀ {c} (C : Category c) (X Y : Category.Obj C) → ObjV
_[_,_] = Category.hom
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Combinatory | CL
type
* : 0-ary
term
app : * * -> * | _$_ l20
i : *
k : *
s : *
theory
(IA) x |> app (i, x) = x
(KA) x y |> app (app(k, x), y) = x
(SA) x y z |> app (app (app (s, x), y), z) = app (app(x, z), app(y, z))
-}
module Combinatory.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Combinatory.Signature
private
variable
Γ Δ Π : Ctx
α : *T
𝔛 : Familyₛ
-- Inductive term declaration
module CL:Terms (𝔛 : Familyₛ) where
data CL : Familyₛ where
var : ℐ ⇾̣ CL
mvar : 𝔛 α Π → Sub CL Π Γ → CL α Γ
_$_ : CL * Γ → CL * Γ → CL * Γ
I : CL * Γ
K : CL * Γ
S : CL * Γ
infixl 20 _$_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
CLᵃ : MetaAlg CL
CLᵃ = record
{ 𝑎𝑙𝑔 = λ where
(appₒ ⋮ a , b) → _$_ a b
(iₒ ⋮ _) → I
(kₒ ⋮ _) → K
(sₒ ⋮ _) → S
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module CLᵃ = MetaAlg CLᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : CL ⇾̣ 𝒜
𝕊 : Sub CL Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 I = 𝑎𝑙𝑔 (iₒ ⋮ tt)
𝕤𝕖𝕞 K = 𝑎𝑙𝑔 (kₒ ⋮ tt)
𝕤𝕖𝕞 S = 𝑎𝑙𝑔 (sₒ ⋮ tt)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ CL α Γ) → 𝕤𝕖𝕞 (CLᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (iₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (kₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (sₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ CL ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : CL ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : CL α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub CL Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! I = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! K = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! S = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
CL:Syn : Syntax
CL:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = CL:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open CL:Terms 𝔛 in record
{ ⊥ = CL ⋉ CLᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax CL:Syn public
open CL:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands CLᵃ public
open import SOAS.Metatheory CL:Syn public
|
{-# OPTIONS --without-K --safe #-}
module Definition.Conversion.Consequences.Completeness where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Conversion
open import Definition.Conversion.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Escape
open import Definition.LogicalRelation.Fundamental
open import Tools.Product
-- Algorithmic equality is derivable from judgemental equality of types.
completeEq : ∀ {A B Γ} → Γ ⊢ A ≡ B → Γ ⊢ A [conv↑] B
completeEq A≡B =
let [Γ] , [A] , [B] , [A≡B] = fundamentalEq A≡B
in escapeEqᵛ [Γ] [A] [A≡B]
-- Algorithmic equality is derivable from judgemental equality of terms.
completeEqTerm : ∀ {t u A Γ} → Γ ⊢ t ≡ u ∷ A → Γ ⊢ t [conv↑] u ∷ A
completeEqTerm t≡u =
let [Γ] , modelsTermEq [A] [t] [u] [t≡u] = fundamentalTermEq t≡u
in escapeEqTermᵛ [Γ] [A] [t≡u]
|
------------------------------------------------------------------------------
-- All the Peano arithmetic modules
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Everything where
open import PA.Axiomatic.Mendelson.Base
open import PA.Axiomatic.Mendelson.Base.Consistency.Axioms
open import PA.Axiomatic.Mendelson.PropertiesATP
open import PA.Axiomatic.Mendelson.PropertiesI
open import PA.Axiomatic.Mendelson.Relation.Binary.EqReasoning
open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityI
open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityATP
open import PA.Axiomatic.Standard.Base
open import PA.Axiomatic.Standard.Base.Consistency.Axioms
open import PA.Axiomatic.Standard.PropertiesATP
open import PA.Axiomatic.Standard.PropertiesI
open import PA.Inductive.Base
open import PA.Inductive.Base.Core
open import PA.Inductive.Existential
open import PA.Inductive.PropertiesATP
open import PA.Inductive.PropertiesI
open import PA.Inductive.PropertiesByInduction
open import PA.Inductive.PropertiesByInductionATP
open import PA.Inductive.PropertiesByInductionI
open import PA.Inductive.Relation.Binary.EqReasoning
open import PA.Inductive.Relation.Binary.PropositionalEquality
open import PA.Inductive2Mendelson
open import PA.Inductive2Standard
|
module Computability.Data.Fin.Opposite where
open import Computability.Prelude
open import Data.Nat using (_≤_; _<_; s≤s; z≤n)
open import Data.Nat.Properties using (≤-step)
open import Data.Fin using (Fin; zero; suc; inject₁; fromℕ; fromℕ<; toℕ; opposite)
opposite-fromℕ : ∀ k → opposite (fromℕ k) ≡ zero
opposite-fromℕ zero = refl
opposite-fromℕ (suc k) rewrite opposite-fromℕ k = refl
opposite-inject₁-suc : ∀{k}(i : Fin k) → opposite (inject₁ i) ≡ suc (opposite i)
opposite-inject₁-suc zero = refl
opposite-inject₁-suc (suc i) rewrite opposite-inject₁-suc i = refl
opposite-opposite : ∀{k}(i : Fin k) → opposite (opposite i) ≡ i
opposite-opposite {suc k} zero rewrite opposite-fromℕ k = refl
opposite-opposite (suc i)
rewrite opposite-inject₁-suc (opposite i)
| opposite-opposite i = refl
opposite-fromℕ< : ∀ a b (lt : a < b) → opposite (fromℕ< (≤-step lt)) ≡ suc (opposite (fromℕ< lt))
opposite-fromℕ< zero .(suc _) (s≤s le) = refl
opposite-fromℕ< (suc a) .(suc _) (s≤s le) rewrite opposite-fromℕ< _ _ le = refl
|
module Type.Properties.Decidable.Proofs where
open import Data
open import Data.Proofs
open import Data.Boolean using (if_then_else_)
open import Data.Boolean.Stmt
open import Data.Either as Either using (_‖_)
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
import Lvl
open import Data.Boolean using (Bool ; 𝑇 ; 𝐹)
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Lang.Inspect
open import Logic
open import Logic.Classical
open import Logic.Predicate
open import Logic.Propositional
open import Numeral.Natural
open import Relator.Equals.Proofs.Equiv
open import Type.Properties.Decidable
open import Type.Properties.Empty
open import Type.Properties.Inhabited
open import Type.Properties.Singleton.Proofs
open import Type
private variable ℓ ℓₚ : Lvl.Level
private variable A B C P Q R T : Type{ℓ}
private variable b b₁ b₂ d : Bool
private variable f : A → B
module _ (P : Stmt{ℓ}) where
decider-classical : ⦃ dec : Decider₀(P)(d) ⦄ → Classical(P)
Classical.excluded-middle (decider-classical ⦃ dec = dec ⦄) = elim(\_ → (P ∨ (¬ P))) [∨]-introₗ [∨]-introᵣ dec
classical-decidable : ⦃ classical : Classical(P) ⦄ → Decidable(0)(P)
∃.witness classical-decidable = Either.isLeft(excluded-middle(P))
∃.proof classical-decidable with excluded-middle(P) | inspect Either.isLeft(excluded-middle(P))
... | Either.Left p | _ = true p
... | Either.Right np | _ = false np
module _ {ℓ₂} {x y : R} {Pred : (P ∨ (¬ P)) → R → Type{ℓ₂}} where
decider-if-intro : ∀{f} ⦃ dec : Decider₀(P)(f) ⦄ → ((p : P) → Pred(Either.Left p)(x)) → ((np : (¬ P)) → Pred(Either.Right np)(y)) → Pred(excluded-middle(P) ⦃ decider-classical ⦄)(if f then x else y)
decider-if-intro {f = 𝑇} ⦃ true p ⦄ fp _ = fp p
decider-if-intro {f = 𝐹} ⦃ false np ⦄ _ fnp = fnp np
decider-to-classical : ⦃ dec : Decider₀(P)(d) ⦄ → Classical(P)
decider-to-classical{P = P} = decider-classical(P)
classical-to-decidable : ⦃ classical : Classical(P) ⦄ → Decidable(0)(P)
classical-to-decidable{P = P} = classical-decidable(P)
classical-to-decider : ⦃ classical : Classical(P) ⦄ → Decider(0)(P)([∃]-witness classical-to-decidable)
classical-to-decider{P = P} = [∃]-proof classical-to-decidable
decider-true : ⦃ dec : Decider₀(P)(b) ⦄ → (P ↔ IsTrue(b))
decider-true ⦃ dec = true p ⦄ = [↔]-intro (const p) (const <>)
decider-true ⦃ dec = false np ⦄ = [↔]-intro empty (empty ∘ np)
decider-false : ⦃ dec : Decider₀(P)(b) ⦄ → ((P → Empty{ℓ}) ↔ IsFalse(b))
decider-false ⦃ dec = true p ⦄ = [↔]-intro empty (empty ∘ apply p)
decider-false ⦃ dec = false np ⦄ = [↔]-intro (const(empty ∘ np)) (const <>)
isempty-decider : ⦃ empty : IsEmpty(P) ⦄ → Decider₀(P)(𝐹)
isempty-decider ⦃ intro p ⦄ = false (empty ∘ p)
inhabited-decider : ⦃ inhab : (◊ P) ⦄ → Decider₀(P)(𝑇)
inhabited-decider ⦃ intro ⦃ p ⦄ ⦄ = true p
empty-decider : Decider₀(Empty{ℓ})(𝐹)
empty-decider = isempty-decider
unit-decider : Decider₀(Unit{ℓ})(𝑇)
unit-decider = inhabited-decider ⦃ unit-is-pos ⦄
instance
tuple-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P ⨯ Q)(b₁ && b₂)
tuple-decider ⦃ true p ⦄ ⦃ true q ⦄ = true(p , q)
tuple-decider ⦃ true p ⦄ ⦃ false nq ⦄ = false(nq ∘ Tuple.right)
tuple-decider ⦃ false np ⦄ ⦃ true q ⦄ = false(np ∘ Tuple.left)
tuple-decider ⦃ false np ⦄ ⦃ false nq ⦄ = false(np ∘ Tuple.left)
instance
either-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P ‖ Q)(b₁ || b₂)
either-decider ⦃ true p ⦄ ⦃ true q ⦄ = true (Either.Left p)
either-decider ⦃ true p ⦄ ⦃ false nq ⦄ = true (Either.Left p)
either-decider ⦃ false np ⦄ ⦃ true q ⦄ = true (Either.Right q)
either-decider ⦃ false np ⦄ ⦃ false nq ⦄ = false (Either.elim np nq)
instance
function-decider : ⦃ dec-P : Decider₀(P)(b₁) ⦄ → ⦃ dec-Q : Decider₀(Q)(b₂) ⦄ → Decider₀(P → Q)((! b₁) || b₂)
function-decider ⦃ true p ⦄ ⦃ true q ⦄ = true (const q)
function-decider ⦃ true p ⦄ ⦃ false nq ⦄ = false (apply p ∘ (nq ∘_))
function-decider ⦃ false np ⦄ ⦃ true q ⦄ = true (const q)
function-decider ⦃ false np ⦄ ⦃ false nq ⦄ = true (empty ∘ np)
instance
not-decider : ⦃ dec : Decider₀(P)(b) ⦄ → Decider₀(¬ P)(! b)
not-decider = function-decider {b₂ = 𝐹} ⦃ dec-Q = empty-decider ⦄
instance
IsTrue-decider : Decider₀(IsTrue(b))(b)
IsTrue-decider {𝑇} = true <>
IsTrue-decider {𝐹} = false id
|
{-# OPTIONS --cubical --safe #-}
module Data.List.Properties where
open import Data.List
open import Prelude
open import Data.Fin
map-length : (f : A → B) (xs : List A)
→ length xs ≡ length (map f xs)
map-length f [] _ = zero
map-length f (x ∷ xs) i = suc (map-length f xs i)
map-ind : (f : A → B) (xs : List A)
→ PathP (λ i → Fin (map-length f xs i) → B) (f ∘ (xs !_)) (map f xs !_)
map-ind f [] i ()
map-ind f (x ∷ xs) i f0 = f x
map-ind f (x ∷ xs) i (fs n) = map-ind f xs i n
tab-length : ∀ n (f : Fin n → A) → length (tabulate n f) ≡ n
tab-length zero f _ = zero
tab-length (suc n) f i = suc (tab-length n (f ∘ fs) i)
tab-distrib : ∀ n (f : Fin n → A) m → ∃[ i ] (f i ≡ tabulate n f ! m)
tab-distrib (suc n) f f0 = f0 , refl
tab-distrib (suc n) f (fs m) = let i , p = tab-distrib n (f ∘ fs) m in fs i , p
tab-id : ∀ n (f : Fin n → A) → PathP (λ i → Fin (tab-length n f i) → A) (_!_ (tabulate n f)) f
tab-id zero f _ ()
tab-id (suc n) f i f0 = f f0
tab-id (suc n) f i (fs m) = tab-id n (f ∘ fs) i m
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Impl.Types.CryptoProxies as CryptoProxies
import LibraBFT.Impl.Types.LedgerInfo as LedgerInfo
import LibraBFT.Impl.Types.LedgerInfoWithSignatures as LedgerInfoWithSignatures
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochIndep
open import Optics.All
open import Util.Prelude
module LibraBFT.Impl.OBM.Genesis where
------------------------------------------------------------------------------
obmMkLedgerInfoWithEpochState : ValidatorSet → Either ErrLog LedgerInfo
------------------------------------------------------------------------------
obmMkGenesisLedgerInfoWithSignatures
: List ValidatorSigner → ValidatorSet → Either ErrLog LedgerInfoWithSignatures
obmMkGenesisLedgerInfoWithSignatures vss0 vs0 = do
liwes ← obmMkLedgerInfoWithEpochState vs0
let sigs = fmap (λ vs → (vs ^∙ vsAuthor , ValidatorSigner.sign vs liwes)) vss0
pure $ foldl' (λ acc (a , sig) → CryptoProxies.addToLi a sig acc)
(LedgerInfoWithSignatures.obmNewNoSigs liwes)
sigs
obmMkLedgerInfoWithEpochState vs = do
li ← LedgerInfo.mockGenesis (just vs)
vv ← ValidatorVerifier.from-e-abs vs
pure (li
& liCommitInfo ∙ biNextEpochState
?~ EpochState∙new (li ^∙ liEpoch) vv)
|
module PreludeInt where
open import AlonzoPrelude
import RTP
int : Nat -> Int
int = RTP.primNatToInt
_+_ : Int -> Int -> Int
_+_ = RTP.primIntAdd
_-_ : Int -> Int -> Int
_-_ = RTP.primIntSub
_*_ : Int -> Int -> Int
_*_ = RTP.primIntMul
div : Int -> Int -> Int
div = RTP.primIntDiv
mod : Int -> Int -> Int
mod = RTP.primIntMod
|
------------------------------------------------------------------------
-- Some theory of equivalences with erased "proofs", defined in terms
-- of partly erased contractible fibres, developed using Cubical Agda
------------------------------------------------------------------------
-- This module instantiates and reexports code from
-- Equivalence.Erased.Contractible-preimages.
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Equivalence.Erased.Contractible-preimages.Cubical
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Erased.Cubical eq
import Equivalence.Erased.Contractible-preimages
open Equivalence.Erased.Contractible-preimages equality-with-J public
hiding (module []-cong)
open Equivalence.Erased.Contractible-preimages.[]-cong
equality-with-J instance-of-[]-cong-axiomatisation
public
|
module Integer.Difference where
open import Data.Product as Σ
open import Data.Product.Relation.Pointwise.NonDependent
open import Data.Unit
open import Equality
open import Natural as ℕ
open import Quotient as /
open import Relation.Binary
open import Syntax
infixl 6 _–_
pattern _–_ a b = _,_ a b
⟦ℤ⟧ = ℕ × ℕ
⟦ℤ²⟧ = ⟦ℤ⟧ × ⟦ℤ⟧
_≈_ : ⟦ℤ⟧ → ⟦ℤ⟧ → Set
(a – b) ≈ (c – d) = a + d ≡ c + b
≈-refl : ∀ {x} → x ≈ x
≈-refl = refl
ℤ = ⟦ℤ⟧ / _≈_
ℤ² = ⟦ℤ²⟧ / Pointwise _≈_ _≈_
instance
⟦ℤ⟧-Number : Number ⟦ℤ⟧
⟦ℤ⟧-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ x → x – 0 }
ℤ-Number : Number ℤ
ℤ-Number = record { Constraint = λ _ → ⊤ ; fromNat = λ x → ⟦ fromNat x ⟧ }
⟦ℤ⟧-Negative : Negative ⟦ℤ⟧
⟦ℤ⟧-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ x → 0 – x }
ℤ-Negative : Negative ℤ
ℤ-Negative = record { Constraint = λ _ → ⊤ ; fromNeg = λ x → ⟦ fromNeg x ⟧ }
suc–suc-injective : ∀ a b → Path ℤ ⟦ suc a – suc b ⟧ ⟦ a – b ⟧
suc–suc-injective a b = equiv (suc a – suc b) (a – b) (sym (+-suc a b ))
⟦negate⟧ : ⟦ℤ⟧ → ⟦ℤ⟧
⟦negate⟧ (a – b) = b – a
negate : ℤ → ℤ
negate =
⟦negate⟧ // λ where
(a – b) (c – d) p →
⟨ +-comm b c ⟩ ≫ sym p ≫ ⟨ +-comm a d ⟩
⟦plus⟧ : ⟦ℤ²⟧ → ⟦ℤ⟧
⟦plus⟧ ((a – b) , (c – d)) = (a + c) – (d + b)
plus : ℤ² → ℤ
plus =
⟦plus⟧ // λ where
((a – b) , (c – d)) ((e – f) , (g – h)) (p , q) →
(a + c) + (h + f)
≡⟨ sym (ℕ.+-assoc a _ _) ⟩
a + (c + (h + f))
≡⟨ cong (a +_) (ℕ.+-assoc c _ _) ⟩
a + ((c + h) + f)
≡⟨ cong (λ z → a + (z + f)) q ⟩
a + ((g + d) + f)
≡⟨ cong (a +_) ⟨ ℕ.+-comm (g + d) _ ⟩ ⟩
a + (f + (g + d))
≡⟨ ℕ.+-assoc a _ _ ⟩
(a + f) + (g + d)
≡⟨ cong (_+ (g + d)) p ⟩
(e + b) + (g + d)
≡⟨ ℕ.+-cross e _ _ _ ⟩
(e + g) + (b + d)
≡⟨ cong ((e + g) +_) ⟨ ℕ.+-comm b _ ⟩ ⟩
(e + g) + (d + b)
∎
instance
⟦ℤ⟧-plus-syntax : plus-syntax-simple ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧
⟦ℤ⟧-plus-syntax = λ where ._+_ x y → ⟦plus⟧ (x , y)
⟦ℤ⟧-minus-syntax : minus-syntax-simple ⟦ℤ⟧ ⟦ℤ⟧ ⟦ℤ⟧
⟦ℤ⟧-minus-syntax = λ where ._-_ x y → ⟦plus⟧ (x , ⟦negate⟧ y)
ℕ-⟦ℤ⟧-minus-syntax : minus-syntax-simple ℕ ℕ ⟦ℤ⟧
ℕ-⟦ℤ⟧-minus-syntax = λ where ._-_ → _–_
ℤ-plus-syntax : plus-syntax-simple ℤ ℤ ℤ
ℤ-plus-syntax = λ where ._+_ → /.uncurry refl refl plus
ℤ-minus-syntax : minus-syntax-simple ℤ ℤ ℤ
ℤ-minus-syntax = λ where ._-_ x y → x + negate y
ℕ-ℤ-minus-syntax : minus-syntax-simple ℕ ℕ ℤ
ℕ-ℤ-minus-syntax = λ where ._-_ x y → ⟦ x – y ⟧
|
module MissingTypeSignature where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
pred zero = zero
pred (suc n) = n
|
module ProofUtilities where
-- open import Data.Nat hiding (_>_)
open import StdLibStuff
open import Syntax
open import FSC
mutual
hn-left-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm m F) ↔ G → Γ ⊢ α ∋ S F ↔ G
hn-left-i m S (app F H) G p = hn-left-i m (λ x → S (app x H)) F G (hn-left-i' m S (headNorm m F) H G p)
hn-left-i _ _ (var _ _) _ p = p
hn-left-i _ _ N _ p = p
hn-left-i _ _ A _ p = p
hn-left-i _ _ Π _ p = p
hn-left-i _ _ i _ p = p
hn-left-i _ _ (lam _ _) _ p = p
hn-left-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm' m F H) ↔ G → Γ ⊢ α ∋ S (app F H) ↔ G
hn-left-i' (suc m) S (lam _ F) H G p with hn-left-i m S (sub H F) G p
hn-left-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-l {_} {_} {_} {_} {_} {_} {S} p'
hn-left-i' 0 _ (lam _ _) _ _ p = p
hn-left-i' zero _ (var _ _) _ _ p = p
hn-left-i' (suc _) _ (var _ _) _ _ p = p
hn-left-i' zero _ N _ _ p = p
hn-left-i' (suc _) _ N _ _ p = p
hn-left-i' zero _ A _ _ p = p
hn-left-i' (suc _) _ A _ _ p = p
hn-left-i' zero _ Π _ _ p = p
hn-left-i' (suc _) _ Π _ _ p = p
hn-left-i' zero _ i _ _ p = p
hn-left-i' (suc _) _ i _ _ p = p
hn-left-i' zero _ (app _ _) _ _ p = p
hn-left-i' (suc _) _ (app _ _) _ _ p = p
hn-left : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ headNorm m F ↔ G → Γ ⊢ α ∋ F ↔ G
hn-left m F G p = hn-left-i m (λ x → x) F G p
mutual
hn-right-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm m F) → Γ ⊢ α ∋ G ↔ S F
hn-right-i m S (app F H) G p = hn-right-i m (λ x → S (app x H)) F G (hn-right-i' m S (headNorm m F) H G p)
hn-right-i _ _ (var _ _) _ p = p
hn-right-i _ _ N _ p = p
hn-right-i _ _ A _ p = p
hn-right-i _ _ Π _ p = p
hn-right-i _ _ i _ p = p
hn-right-i _ _ (lam _ _) _ p = p
hn-right-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm' m F H) → Γ ⊢ α ∋ G ↔ S (app F H)
hn-right-i' (suc m) S (lam _ F) H G p with hn-right-i m S (sub H F) G p
hn-right-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-r {_} {_} {_} {_} {_} {_} {S} p'
hn-right-i' 0 _ (lam _ _) _ _ p = p
hn-right-i' zero _ (var _ _) _ _ p = p
hn-right-i' (suc _) _ (var _ _) _ _ p = p
hn-right-i' zero _ N _ _ p = p
hn-right-i' (suc _) _ N _ _ p = p
hn-right-i' zero _ A _ _ p = p
hn-right-i' (suc _) _ A _ _ p = p
hn-right-i' zero _ Π _ _ p = p
hn-right-i' (suc _) _ Π _ _ p = p
hn-right-i' zero _ i _ _ p = p
hn-right-i' (suc _) _ i _ _ p = p
hn-right-i' zero _ (app _ _) _ _ p = p
hn-right-i' (suc _) _ (app _ _) _ _ p = p
hn-right : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ headNorm m F → Γ ⊢ α ∋ G ↔ F
hn-right m F G p = hn-right-i m (λ x → x) F G p
mutual
hn-succ-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) → Γ ⊢ S (headNorm m F) → Γ ⊢ S F
hn-succ-i m S (app F H) p = hn-succ-i m (λ x → S (app x H)) F (hn-succ-i' m S (headNorm m F) H p)
hn-succ-i _ _ (var _ _) p = p
hn-succ-i _ _ N p = p
hn-succ-i _ _ A p = p
hn-succ-i _ _ Π p = p
hn-succ-i _ _ i p = p
hn-succ-i _ _ (lam _ _) p = p
hn-succ-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) → Γ ⊢ S (headNorm' m F H) → Γ ⊢ S (app F H)
hn-succ-i' (suc m) S (lam _ F) H p with hn-succ-i m S (sub H F) p
hn-succ-i' (suc _) S (lam _ _) _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p'
hn-succ-i' 0 _ (lam _ _) _ p = p
hn-succ-i' zero _ (var _ _) _ p = p
hn-succ-i' (suc _) _ (var _ _) _ p = p
hn-succ-i' zero _ N _ p = p
hn-succ-i' (suc _) _ N _ p = p
hn-succ-i' zero _ A _ p = p
hn-succ-i' (suc _) _ A _ p = p
hn-succ-i' zero _ Π _ p = p
hn-succ-i' (suc _) _ Π _ p = p
hn-succ-i' zero _ i _ p = p
hn-succ-i' (suc _) _ i _ p = p
hn-succ-i' zero _ (app _ _) _ p = p
hn-succ-i' (suc _) _ (app _ _) _ p = p
hn-succ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) → Γ ⊢ headNorm m F → Γ ⊢ F
hn-succ m F p = hn-succ-i m (λ x → x) F p
mutual
hn-ante-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G : Form Γ-t $o) → Γ , S (headNorm m F) ⊢ G → Γ , S F ⊢ G
hn-ante-i m S (app F H) G p = hn-ante-i m (λ x → S (app x H)) F G (hn-ante-i' m S (headNorm m F) H G p)
hn-ante-i _ _ (var _ _) _ p = p
hn-ante-i _ _ N _ p = p
hn-ante-i _ _ A _ p = p
hn-ante-i _ _ Π _ p = p
hn-ante-i _ _ i _ p = p
hn-ante-i _ _ (lam _ _) _ p = p
hn-ante-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t $o) → Γ , S (headNorm' m F H) ⊢ G → Γ , S (app F H) ⊢ G
hn-ante-i' (suc m) S (lam _ F) H G p with hn-ante-i m S (sub H F) G p
hn-ante-i' (suc _) S (lam _ _) _ _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p'
hn-ante-i' 0 _ (lam _ _) _ _ p = p
hn-ante-i' zero _ (var _ _) _ _ p = p
hn-ante-i' (suc _) _ (var _ _) _ _ p = p
hn-ante-i' zero _ N _ _ p = p
hn-ante-i' (suc _) _ N _ _ p = p
hn-ante-i' zero _ A _ _ p = p
hn-ante-i' (suc _) _ A _ _ p = p
hn-ante-i' zero _ Π _ _ p = p
hn-ante-i' (suc _) _ Π _ _ p = p
hn-ante-i' zero _ i _ _ p = p
hn-ante-i' (suc _) _ i _ _ p = p
hn-ante-i' zero _ (app _ _) _ _ p = p
hn-ante-i' (suc _) _ (app _ _) _ _ p = p
hn-ante : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) (G : Form Γ-t $o) → Γ , headNorm m F ⊢ G → Γ , F ⊢ G
hn-ante m F G p = hn-ante-i m (λ x → x) F G p
mutual
hn-ante-eq-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G H : Form Γ-t α) → Γ , S (headNorm m F) ⊢ G == H → Γ , S F ⊢ G == H
hn-ante-eq-i m S (app F I) G H p = hn-ante-eq-i m (λ x → S (app x I)) F G H (hn-ante-eq-i' m S (headNorm m F) I G H p)
hn-ante-eq-i _ _ (var _ _) _ _ p = p
hn-ante-eq-i _ _ N _ _ p = p
hn-ante-eq-i _ _ A _ _ p = p
hn-ante-eq-i _ _ Π _ _ p = p
hn-ante-eq-i _ _ i _ _ p = p
hn-ante-eq-i _ _ (lam _ _) _ _ p = p
hn-ante-eq-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (I : Form Γ-t γ) (G H : Form Γ-t α) → Γ , S (headNorm' m F I) ⊢ G == H → Γ , S (app F I) ⊢ G == H
hn-ante-eq-i' (suc m) S (lam _ F) I G H p with hn-ante-eq-i m S (sub I F) G H p
hn-ante-eq-i' (suc _) S (lam _ _) _ _ _ _ | p' = reduce {_} {_} {_} {_} {_} {_} {S} p'
hn-ante-eq-i' 0 _ (lam _ _) _ _ _ p = p
hn-ante-eq-i' zero _ (var _ _) _ _ _ p = p
hn-ante-eq-i' (suc _) _ (var _ _) _ _ _ p = p
hn-ante-eq-i' zero _ N _ _ _ p = p
hn-ante-eq-i' (suc _) _ N _ _ _ p = p
hn-ante-eq-i' zero _ A _ _ _ p = p
hn-ante-eq-i' (suc _) _ A _ _ _ p = p
hn-ante-eq-i' zero _ Π _ _ _ p = p
hn-ante-eq-i' (suc _) _ Π _ _ _ p = p
hn-ante-eq-i' zero _ i _ _ _ p = p
hn-ante-eq-i' (suc _) _ i _ _ _ p = p
hn-ante-eq-i' zero _ (app _ _) _ _ _ p = p
hn-ante-eq-i' (suc _) _ (app _ _) _ _ _ p = p
hn-ante-eq : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t $o) (G H : Form Γ-t α) → Γ , headNorm m F ⊢ G == H → Γ , F ⊢ G == H
hn-ante-eq m F G H p = hn-ante-eq-i m (λ x → x) F G H p
-- ------------------------------------
head-& : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} →
Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ →
Γ ⊢ $o ∋ (F₁ & G₁) ↔ (F₂ & G₂)
head-& p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-const _ N)) (simp (head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₂))))
head-|| : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} →
Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ →
Γ ⊢ $o ∋ (F₁ || G₁) ↔ (F₂ || G₂)
head-|| p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) p₁)) p₂
head-=> : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} →
Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ →
Γ ⊢ $o ∋ (F₁ => G₁) ↔ (F₂ => G₂)
head-=> p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) p₂
head-~ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ : Form Γ-t $o} →
Γ ⊢ $o ∋ F₁ == F₂ →
Γ ⊢ $o ∋ (~ F₁) ↔ (~ F₂)
head-~ p = head-app _ _ _ _ _ _ (simp (head-const _ N)) p
head-== : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} {F₁ F₂ G₁ G₂ : Form Γ-t α} →
Γ ⊢ α ∋ F₁ == F₂ → Γ ⊢ α ∋ G₁ == G₂ →
Γ ⊢ $o ∋ (F₁ == G₁) ↔ (F₂ == G₂)
head-== p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ _)) p₁)) p₂
|
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Exactness
open import cohomology.Choice
module cohomology.Theory where
record CohomologyTheory i : Type (lsucc i) where
field
C : ℤ → Ptd i → Group i
CEl : ℤ → Ptd i → Type i
CEl n X = Group.El (C n X)
Cid : (n : ℤ) (X : Ptd i) → CEl n X
Cid n X = GroupStructure.ident (Group.group-struct (C n X))
⊙CEl : ℤ → Ptd i → Ptd i
⊙CEl n X = ⊙[ CEl n X , Cid n X ]
field
CF-hom : (n : ℤ) {X Y : Ptd i} → fst (X ⊙→ Y) → (C n Y →ᴳ C n X)
CF-ident : (n : ℤ) {X : Ptd i}
→ CF-hom n {X} {X} (⊙idf X) == idhom (C n X)
CF-comp : (n : ℤ) {X Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))
→ CF-hom n (g ⊙∘ f) == CF-hom n f ∘ᴳ CF-hom n g
CF : (n : ℤ) {X Y : Ptd i} → fst (X ⊙→ Y) → fst (⊙CEl n Y ⊙→ ⊙CEl n X)
CF n f = GroupHom.⊙f (CF-hom n f)
field
C-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X)
C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) == C n X
C-exact : (n : ℤ) {X Y : Ptd i} (f : fst (X ⊙→ Y))
→ is-exact (CF n (⊙cfcod f)) (CF n f)
C-additive : (n : ℤ) {I : Type i} (Z : I → Ptd i)
→ ((W : I → Type i) → has-choice ⟨0⟩ I W)
→ C n (⊙BigWedge Z) == Πᴳ I (C n ∘ Z)
{- A quick useful special case of C-additive:
C n (X ∨ Y) == C n X × C n Y -}
C-binary-additive : (n : ℤ) (X Y : Ptd i)
→ C n (X ⊙∨ Y) == C n X ×ᴳ C n Y
C-binary-additive n X Y =
ap (C n) (! (BigWedge-Bool-⊙path Pick))
∙ C-additive n _ (λ _ → Bool-has-choice)
∙ Πᴳ-Bool-is-×ᴳ (C n ∘ Pick)
where
Pick : Lift {j = i} Bool → Ptd i
Pick (lift true) = X
Pick (lift false) = Y
record OrdinaryTheory i : Type (lsucc i) where
constructor ordinary-theory
field
cohomology-theory : CohomologyTheory i
open CohomologyTheory cohomology-theory public
field
C-dimension : (n : ℤ) → n ≠ O → C n (⊙Sphere O) == 0ᴳ
|
{-# OPTIONS --cubical --safe #-}
module Relation.Nullary.Discrete.FromBoolean where
open import Prelude
open import Relation.Nullary.Discrete
module _ {a} {A : Type a}
(_≡ᴮ_ : A → A → Bool)
(sound : ∀ x y → T (x ≡ᴮ y) → x ≡ y)
(complete : ∀ x → T (x ≡ᴮ x))
where
from-bool-eq : Discrete A
from-bool-eq x y =
iff-dec (sound x y iff flip (subst (λ z → T (x ≡ᴮ z))) (complete x)) (T? (x ≡ᴮ y))
|
module calculus-examples where
open import Data.List using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any using (here ; there ; any)
open import Data.List.Any.Properties
open import Data.OrderedListMap
open import Data.Sum using (inj₁ ; inj₂ ; _⊎_)
open import Data.Maybe.Base
open import Data.Empty using (⊥ ; ⊥-elim)
open import Data.Bool.Base using (true ; false)
open import Relation.Nullary using (Dec ; yes ; no ; ¬_)
open import Agda.Builtin.Equality using (refl ; _≡_)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Relation.Binary.PropositionalEquality
using (subst ; cong ; sym ; trans)
open import calculus
open import utility
open import Esterel.Environment as Env
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ ; unknown ; present ; absent ; _≟ₛₜ_)
open import Esterel.Variable.Shared as SharedVar using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar using (SeqVar)
open import Esterel.Lang
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Properties
open import Esterel.Lang.CanFunction.SetSigMonotonic using (canₛ-set-sig-monotonic)
open import Esterel.Lang.Properties
open import Esterel.Lang.Binding
open import Esterel.Context
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import context-properties
open import Esterel.Lang.CanFunction.Base using (canₛ-⊆-FV)
open import Data.Nat as Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Nat.Properties.Simple
using (+-comm)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_)
open import eval
{-
This example is not true (and not provable under the current calculus)
{- rewriting a present to the true branch -}
{- cannot prove without the `signal` form -}
ex1 : ∀ S p q -> CB p ->
signl S (emit S >> (present S ∣⇒ p ∣⇒ q)) ≡ₑ
signl S (emit S >> p) # []
ex1 S p q CBp = calc where
θS→unk : Env
θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] []
S∈θS→unk : SigMap.∈Dom S (sig θS→unk)
S∈θS→unk = sig-∈-single S Signal.unknown
θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown
θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk
θS→pre : Env
θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present
S∈θS→pre : SigMap.∈Dom S (sig θS→pre)
S∈θS→pre = sig-set-mono' {S} {S} {θS→unk} {Signal.present} {S∈θS→unk} S∈θS→unk
θS→pre[S]≡pre : sig-stats{S = S} θS→pre S∈θS→pre ≡ Signal.present
θS→pre[S]≡pre = sig-putget{S} {θS→unk} {Signal.present} S∈θS→unk S∈θS→pre
θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent
θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where
unknotabs : Signal.unknown ≡ Signal.absent → ⊥
unknotabs ()
CBsignalS[emitS>>p] : CB (signl S (emit S >> p))
CBsignalS[emitS>>p]
= CBsig (CBseq (CBemit{S}) CBp ((λ z → λ ()) , (λ z → λ ()) , (λ z → λ ())))
calc : signl S (emit S >> (present S ∣⇒ p ∣⇒ q)) ≡ₑ
signl S (emit S >> p) # []
calc =
≡ₑtran {r = (ρ θS→unk · (emit S >> (present S ∣⇒ p ∣⇒ q)))}
(≡ₑstep [raise-signal])
(≡ₑtran {r = (ρ θS→pre · (nothin >> (present S ∣⇒ p ∣⇒ q)))}
(≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole)))
(≡ₑtran {r = (ρ θS→pre · (present S ∣⇒ p ∣⇒ q))}
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done]))
(≡ₑtran {r = (ρ θS→pre · p)}
(≡ₑstep ([is-present] S S∈θS→pre θS→pre[S]≡pre dehole))
(≡ₑsymm CBsignalS[emitS>>p]
(≡ₑtran {r = (ρ θS→unk · (emit S >> p))}
(≡ₑstep [raise-signal])
(≡ₑtran {r = (ρ θS→pre · (nothin >> p))}
(≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole)))
(≡ₑtran {r = ρ θS→pre · p}
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done]))
≡ₑrefl)))))))
-}
Canₛpresent-fact : ∀ S p q ->
(Signal.unwrap S) ∈ Canₛ (present S ∣⇒ p ∣⇒ q) (Θ SigMap.[ S ↦ Signal.unknown ] [] []) ->
(Signal.unwrap S ∈ Canₛ p (Θ SigMap.[ S ↦ Signal.unknown ] [] [])) ⊎
(Signal.unwrap S ∈ Canₛ q (Θ SigMap.[ S ↦ Signal.unknown ] [] []))
Canₛpresent-fact S p q S∈Canₛ[presentSpq]
with Env.Sig∈ S (Θ SigMap.[ S ↦ Signal.unknown ] [] [])
Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈
with ⌊ present ≟ₛₜ (Env.sig-stats{S} (Θ SigMap.[ S ↦ Signal.unknown ] [] []) S∈) ⌋
Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | true
= inj₁ S∈Canₛ[presentSpq]
Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false
with ⌊ absent ≟ₛₜ Env.sig-stats{S} (Θ SigMap.[ S ↦ Signal.unknown ] [] []) S∈ ⌋
Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false | true
= inj₂ S∈Canₛ[presentSpq]
Canₛpresent-fact S p q S∈Canₛ[presentSpq] | yes S∈ | false | false
= ++⁻ (Canₛ p (Θ SigMap.[ S ↦ Signal.unknown ] [] [])) S∈Canₛ[presentSpq]
Canₛpresent-fact S p q _ | no ¬p
= ⊥-elim (¬p (SigMap.update-in-keys [] S unknown))
{- rewriting a present to the false branch -}
ex2b : ∀ S p q C -> CB (C ⟦ signl S q ⟧c) ->
Signal.unwrap S ∉ (Canₛ p (Θ SigMap.[ S ↦ unknown ] [] [])) ->
Signal.unwrap S ∉ (Canₛ q (Θ SigMap.[ S ↦ unknown ] [] [])) ->
signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ
signl S q # C
ex2b S p q C CBq s∉Canₛp s∉Canₛq = calc where
θS→unk : Env
θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] []
S∈θS→unk : SigMap.∈Dom S (sig θS→unk)
S∈θS→unk = sig-∈-single S Signal.unknown
θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown
θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk
θS→abs : Env
θS→abs = set-sig{S} θS→unk S∈θS→unk Signal.absent
S∈θS→abs : SigMap.∈Dom S (sig θS→abs)
S∈θS→abs = sig-set-mono' {S} {S} {θS→unk} {Signal.absent} {S∈θS→unk} S∈θS→unk
θS→abs[S]≡abs : sig-stats{S = S} θS→abs S∈θS→abs ≡ Signal.absent
θS→abs[S]≡abs = sig-putget{S} {θS→unk} {Signal.absent} S∈θS→unk S∈θS→abs
S∉Canθₛq : Signal.unwrap S ∉ Canθₛ SigMap.[ S ↦ unknown ] 0 q []env
S∉Canθₛq S∈Canθₛq = s∉Canₛq (Canθₛunknown->Canₛunknown S q S∈Canθₛq)
S∉CanθₛpresentSpq : Signal.unwrap S ∉ Canθₛ SigMap.[ S ↦ unknown ]
0
(present S ∣⇒ p ∣⇒ q)
[]env
S∉CanθₛpresentSpq S∈Canθₛ
with Canθₛunknown->Canₛunknown S (present S ∣⇒ p ∣⇒ q) S∈Canθₛ
... | fact
with Canₛpresent-fact S p q fact
... | inj₁ s∈Canₛp = s∉Canₛp s∈Canₛp
... | inj₂ s∈Canₛq = s∉Canₛq s∈Canₛq
bwd : signl S q ≡ₑ (ρ⟨ θS→abs , WAIT ⟩· q) # C
bwd =
≡ₑtran (≡ₑstep [raise-signal])
(≡ₑtran (≡ₑstep ([absence] S S∈θS→unk θS→unk[S]≡unk S∉Canθₛq))
≡ₑrefl)
fwd : signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ
(ρ⟨ θS→abs , WAIT ⟩· q) # C
fwd =
≡ₑtran (≡ₑstep [raise-signal])
(≡ₑtran (≡ₑstep ([absence] S S∈θS→unk θS→unk[S]≡unk S∉CanθₛpresentSpq))
(≡ₑtran (≡ₑstep ([is-absent] S S∈θS→abs θS→abs[S]≡abs dehole))
≡ₑrefl)) where
calc : signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ
signl S q # C
calc = ≡ₑtran fwd (≡ₑsymm CBq bwd)
ex2 : ∀ S p q C ->
CB (C ⟦ signl S q ⟧c) ->
(∀ status -> Signal.unwrap S ∉ (Canₛ p (Θ SigMap.[ S ↦ status ] [] []))) ->
(∀ status -> Signal.unwrap S ∉ (Canₛ q (Θ SigMap.[ S ↦ status ] [] []))) ->
signl S (present S ∣⇒ p ∣⇒ q) ≡ₑ
signl S q # C
ex2 S p q C CB noSp noSq = ex2b S p q C CB (noSp unknown) (noSq unknown)
{-
Although true, the this example is not provable under the current calculus
{- lifting an emit out of a par -}
ex3 : ∀ S p q -> CB (p ∥ q) ->
signl S ((emit S >> p) ∥ q) ≡ₑ
signl S (emit S >> (p ∥ q)) # []
ex3 S p q CBp∥q = calc where
θS→unk : Env
θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] []
S∈θS→unk : SigMap.∈Dom S (sig θS→unk)
S∈θS→unk = sig-∈-single S Signal.unknown
θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown
θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk
θS→pre : Env
θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present
θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent
θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where
unknotabs : Signal.unknown ≡ Signal.absent → ⊥
unknotabs ()
calc : signl S ((emit S >> p) ∥ q) ≡ₑ
signl S (emit S >> (p ∥ q)) # []
calc =
≡ₑtran {r = ρ⟨ θS→unk · ((emit S >> p) ∥ q)}
(≡ₑstep [raise-signal])
(≡ₑtran {r = ρ θS→pre · (nothin >> p ∥ q)}
(≡ₑstep ([emit]{S = S} S∈θS→unk θS→unk[S]≠absent (depar₁ (deseq dehole))))
(≡ₑtran {r = ρ θS→pre · (p ∥ q)}
(≡ₑctxt (dcenv (dcpar₁ dchole))
(dcenv (dcpar₁ dchole))
(≡ₑstep [seq-done]))
(≡ₑsymm (CBsig (CBseq CBemit CBp∥q
(((λ z → λ ()) ,
(λ z → λ ()) ,
(λ z → λ ())))))
(≡ₑtran {r = ρ θS→unk · (emit S >> (p ∥ q))}
(≡ₑstep [raise-signal])
(≡ₑtran (≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole)))
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [seq-done])))))))
-}
{- pushing a trap across a par -}
ex4 : ∀ n p q -> CB p ->
done q -> p ≡ₑ q # [] ->
(trap (exit (suc n) ∥ p)) ≡ₑ (exit n ∥ trap p) # []
ex4 = ex4-split where
basealwaysdistinct : ∀ x -> distinct base x
basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂})
CBplugrpartrap : ∀ n -> ∀ {r r′ BVp FVp} ->
CorrectBinding r BVp FVp →
r′ ≐ ceval (epar₂ (exit n)) ∷ ceval etrap ∷ [] ⟦ r ⟧c →
CB r′
CBplugrpartrap n {p} {p′} {BVp} {FVp} CBp r′dc
with BVFVcorrect p BVp FVp CBp | unplugc r′dc
... | refl , refl | refl = CBpar CBexit (CBtrap CBp)
(basealwaysdistinct BVp)
(basealwaysdistinct (BVars p))
(basealwaysdistinct (FVars p))
(λ { _ () _ })
CBplugtraprpar : ∀ n -> {r r′ : Term}
{BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} →
CorrectBinding r BVp FVp →
r′ ≐ ceval etrap ∷ ceval (epar₂ (exit (suc n))) ∷ [] ⟦ r ⟧c →
CB r′
CBplugtraprpar n {r} {r′} {BVp} {FVp} CBr r′C
with unplugc r′C
... | refl
with BVFVcorrect r BVp FVp CBr
... | refl , refl
= CBtrap (CBpar CBexit CBr
(basealwaysdistinct BVp)
(basealwaysdistinct (BVars r))
(basealwaysdistinct (FVars r))
(λ { _ () _}))
ex4-split : ∀ n p q -> CB p ->
done q -> p ≡ₑ q # [] ->
(trap (exit (suc n) ∥ p)) ≡ₑ (exit n ∥ trap p) # []
ex4-split n p .nothin CBp (dhalted hnothin) p≡ₑnothin =
≡ₑtran {r = trap (exit (suc n) ∥ nothin)}
(≡ₑctxt (dctrap (dcpar₂ dchole))
(dctrap (dcpar₂ dchole))
(≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑnothin))
(≡ₑtran {r = trap (exit (suc n))}
(≡ₑctxt (dctrap dchole)
(dctrap dchole)
(≡ₑtran (≡ₑstep [par-swap])
(≡ₑstep ([par-nothing] (dhalted (hexit (suc n)))))))
(≡ₑtran {r = exit n}
(≡ₑstep ([trap-done] (hexit (suc n))))
(≡ₑsymm (CBpar CBexit (CBtrap CBp)
(basealwaysdistinct (BVars p))
(basealwaysdistinct (BVars p))
(basealwaysdistinct (FVars p))
(λ { _ () _ }))
(≡ₑtran {r = exit n ∥ trap nothin}
(≡ₑctxt (dcpar₂ (dctrap dchole))
(dcpar₂ (dctrap dchole))
(≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑnothin))
(≡ₑtran {r = exit n ∥ nothin}
(≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole) (≡ₑstep ([trap-done] hnothin)))
(≡ₑtran {r = nothin ∥ exit n}
(≡ₑstep [par-swap])
(≡ₑtran {r = exit n}
(≡ₑstep ([par-nothing] (dhalted (hexit n))))
≡ₑrefl)))))))
ex4-split n p .(exit 0) CBp (dhalted (hexit 0)) p≡ₑexit0 =
≡ₑtran {r = trap (exit (suc n) ∥ exit 0) }
(≡ₑctxt (dctrap (dcpar₂ dchole))
(dctrap (dcpar₂ dchole))
(≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑexit0))
(≡ₑtran {r = trap (exit (suc n))}
(≡ₑctxt (dctrap dchole) (dctrap dchole)
(≡ₑstep ([par-2exit] (suc n) zero)))
(≡ₑtran {r = exit n}
(≡ₑstep ([trap-done] (hexit (suc n))))
(≡ₑsymm (CBpar CBexit (CBtrap CBp)
(basealwaysdistinct (BVars p))
(basealwaysdistinct (BVars p))
(basealwaysdistinct (FVars p))
(λ { _ () _ }))
(≡ₑtran {r = exit n ∥ trap (exit 0)}
(≡ₑctxt (dcpar₂ (dctrap dchole))
(dcpar₂ (dctrap dchole))
(≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑexit0))
(≡ₑtran {r = exit n ∥ nothin }
(≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole)
(≡ₑstep ([trap-done] (hexit zero))))
(≡ₑtran {r = nothin ∥ exit n}
(≡ₑstep [par-swap])
(≡ₑtran {r = exit n}
(≡ₑstep ([par-nothing] (dhalted (hexit n))))
≡ₑrefl)))))))
ex4-split n p .(exit (suc m)) CBp (dhalted (hexit (suc m))) p≡ₑexitm =
≡ₑtran {r = trap (exit (suc n) ∥ exit (suc m)) }
(≡ₑctxt (dctrap (dcpar₂ dchole))
(dctrap (dcpar₂ dchole))
(≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑexitm))
(≡ₑtran {r = trap (exit (suc n ⊔ℕ (suc m)))}
(≡ₑctxt (dctrap dchole) (dctrap dchole)
(≡ₑstep ([par-2exit] (suc n) (suc m))))
(≡ₑtran {r = ↓_ {p = (exit (suc n ⊔ℕ (suc m)))} (hexit (suc n ⊔ℕ (suc m))) }
(≡ₑstep ([trap-done] (hexit (suc (n ⊔ℕ m)))))
(≡ₑsymm (CBpar CBexit (CBtrap CBp)
(basealwaysdistinct (BVars p))
(basealwaysdistinct (BVars p))
(basealwaysdistinct (FVars p))
(λ { _ () _ }))
(≡ₑtran {r = exit n ∥ trap (exit (suc m))}
(≡ₑctxt (dcpar₂ (dctrap dchole))
(dcpar₂ (dctrap dchole))
(≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑexitm))
(≡ₑtran {r = exit n ∥ ↓_ {p = exit (suc m)} (hexit (suc m))}
(≡ₑctxt (dcpar₂ dchole) (dcpar₂ dchole)
(≡ₑstep ([trap-done] (hexit (suc m)))) )
(≡ₑtran {r = ↓_ {p = (exit (suc n ⊔ℕ (suc m)))} (hexit (suc n ⊔ℕ (suc m))) }
(≡ₑstep ([par-2exit] n m))
≡ₑrefl))))))
ex4-split n p q CBp (dpaused pausedq) p≡ₑq =
≡ₑtran {r = trap (exit (suc n) ∥ q)}
(≡ₑctxt (dctrap (dcpar₂ dchole))
(dctrap (dcpar₂ dchole))
(≡ₑ-context [] _ (CBplugtraprpar n) p≡ₑq))
(≡ₑtran {r = trap (exit (suc n))}
(≡ₑctxt (dctrap dchole) (dctrap dchole)
(≡ₑstep ([par-1exit] (suc n) pausedq)))
(≡ₑtran {r = exit n}
(≡ₑstep ([trap-done] (hexit (suc n))))
(≡ₑsymm (CBpar CBexit (CBtrap CBp)
(basealwaysdistinct (BVars p))
(basealwaysdistinct (BVars p))
(basealwaysdistinct (FVars p))
(λ { _ () _ }))
(≡ₑtran {r = exit n ∥ trap q}
(≡ₑctxt (dcpar₂ (dctrap dchole))
(dcpar₂ (dctrap dchole))
(≡ₑ-context [] _ (CBplugrpartrap n) p≡ₑq))
(≡ₑtran {r = exit n}
(≡ₑstep ([par-1exit] n (ptrap pausedq)))
≡ₑrefl)))))
{- lifting a signal out of an evaluation context -}
ex5 : ∀ S p q r E -> CB r ->
q ≐ E ⟦(signl S p)⟧e ->
r ≐ E ⟦ p ⟧e ->
(ρ⟨ []env , WAIT ⟩· q) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S r)) # []
ex5 S p q r E CBr decomp1 decomp2 = calc where
θS→unk : Env
θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] []
replugit : q ≐ Data.List.map ceval E ⟦ signl S p ⟧c ->
E ⟦ ρ⟨ θS→unk , WAIT ⟩· p ⟧e ≐ Data.List.map ceval E ⟦ ρ⟨ θS→unk , WAIT ⟩· p ⟧c
replugit x = ⟦⟧e-to-⟦⟧c Erefl
calc : (ρ⟨ []env , WAIT ⟩· q) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S r)) # []
calc =
≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (E ⟦ (ρ⟨ θS→unk , WAIT ⟩· p) ⟧e)}
(≡ₑctxt (dcenv (⟦⟧e-to-⟦⟧c decomp1))
(dcenv (replugit (⟦⟧e-to-⟦⟧c decomp1)))
(≡ₑstep [raise-signal]))
(≡ₑtran {r = ρ⟨ θS→unk , WAIT ⟩· (E ⟦ p ⟧e)}
(≡ₑstep ([merge]{E = E} Erefl))
(≡ₑsymm (CBρ (CBsig CBr))
(≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ θS→unk , WAIT ⟩· r)}
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal]))
(≡ₑstep ([merge] {E = []}
(subst (\ x ->
ρ⟨ θS→unk , WAIT ⟩· x ≐ [] ⟦
ρ⟨ θS→unk , WAIT ⟩· E ⟦ p ⟧e ⟧e)
(unplug decomp2) dehole))))))
{- two specific examples of lifting a signal out of an evaluation context -}
ex6 : ∀ S p q -> CB (p ∥ q) ->
(ρ⟨ []env , WAIT ⟩· ((signl S p) ∥ q)) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S (p ∥ q))) # []
ex6 S p q CBp∥q =
ex5 S p (signl S p ∥ q) (p ∥ q) ((epar₁ q) ∷ []) CBp∥q (depar₁ dehole) (depar₁ dehole)
ex7 : ∀ S p q -> CB (p >> q) ->
(ρ⟨ []env , WAIT ⟩· ((signl S p) >> q)) ≡ₑ (ρ⟨ []env , WAIT ⟩· (signl S (p >> q))) # []
ex7 S p q CBp>>q =
ex5 S p (signl S p >> q) (p >> q) ((eseq q) ∷ []) CBp>>q (deseq dehole) (deseq dehole)
{- pushing a seq into a binding form (a signal in this case).
this shows the need for the outer environment ρ [} · _
in order to manipulate the environment.
-}
ex8-worker : ∀ {BV FV} S p q ->
CorrectBinding ((signl S p) >> q) BV FV ->
(ρ⟨ []env , WAIT ⟩· (signl S p) >> q) ≡ₑ
(ρ⟨ []env , WAIT ⟩· signl S (p >> q)) # []
ex8-worker S p q (CBseq {BVp = BVsigS·p} {FVq = FVq} (CBsig {BV = BVp} CBp) CBq BVsigS·p≠FVq) =
≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ [S]-env S , WAIT ⟩· p) >> q} {C = []}
(≡ₑctxt {C = []} {C′ = cenv []env WAIT ∷ ceval (eseq q) ∷ []}
Crefl Crefl
(≡ₑstep ([raise-signal] {p} {S})))
(≡ₑtran {r = ρ⟨ [S]-env S , WAIT ⟩· p >> q} {C = []}
(≡ₑstep ([merge] (deseq dehole)))
(≡ₑsymm
(CBρ
(CBsig
(CBseq CBp CBq
(⊆-respect-distinct-left (∪ʳ (+S S base) ⊆-refl) BVsigS·p≠FVq))))
(≡ₑtran {r = ρ⟨ []env , WAIT ⟩· (ρ⟨ [S]-env S , WAIT ⟩· p >> q)} {C = []}
(≡ₑctxt {C = []} {C′ = cenv []env WAIT ∷ []}
Crefl Crefl
(≡ₑstep ([raise-signal] {p >> q} {S})))
(≡ₑstep ([merge] dehole)))))
ex8 : ∀ S p q ->
CB ((signl S p) >> q) ->
(ρ⟨ []env , WAIT ⟩· (signl S p) >> q) ≡ₑ
(ρ⟨ []env , WAIT ⟩· signl S (p >> q)) # []
ex8 S p q cb = ex8-worker S p q cb
{- rearranging signal forms -}
ex9 : ∀ S1 S2 p ->
CB p ->
signl S1 (signl S2 p) ≡ₑ signl S2 (signl S1 p) # []
ex9 S1 S2 p CBp =
≡ₑtran {r = ρ⟨ (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) , WAIT ⟩· (signl S2 p)}
(≡ₑstep [raise-signal])
(≡ₑtran {r = (ρ⟨ Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] , WAIT ⟩·
(ρ⟨ Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] , WAIT ⟩· p))}
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal]))
(≡ₑtran {r = (ρ⟨ (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) ←
(Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) , A-max WAIT WAIT ⟩·
p)}
(≡ₑstep ([merge] dehole))
(≡ₑsymm (CBsig (CBsig CBp))
(≡ₑtran {r = ρ⟨ (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) , WAIT ⟩· (signl S1 p)}
(≡ₑstep [raise-signal])
(≡ₑtran {r = (ρ⟨ Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] , WAIT ⟩·
(ρ⟨ Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] , WAIT ⟩· p))}
(≡ₑctxt (dcenv dchole) (dcenv dchole) (≡ₑstep [raise-signal]))
(≡ₑtran {r = (ρ⟨ (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) ←
(Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) ,
A-max WAIT WAIT ⟩·
p)}
(≡ₑstep ([merge] dehole))
(map-order-irr S1 S2 WAIT p))))))) where
distinct-Ss-env'' : ∀ S1 S2 S3 ->
¬ Signal.unwrap S1 ≡ Signal.unwrap S2 ->
Data.List.Any.Any (_≡_ S3) (Signal.unwrap S1 ∷ []) ->
Data.List.Any.Any (_≡_ S3) (Signal.unwrap S2 ∷ []) ->
⊥
distinct-Ss-env'' S1 S2 S3 S1≠S2 (here S3=S1) (here S3=S2) rewrite S3=S1 = S1≠S2 S3=S2
distinct-Ss-env'' S1 S2 S3 S1≠S2 (here px) (there ())
distinct-Ss-env'' S1 S2 S3 S1≠S2 (there ()) S3∈Domθ2
distinct-Ss-env' : ∀ S1 S2 S3 ->
¬ Signal.unwrap S1 ≡ Signal.unwrap S2 ->
Data.List.Any.Any (_≡_ S3) (Signal.unwrap S1 ∷ []) ->
S3 ∈ proj₁ (Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) ->
⊥
distinct-Ss-env' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2
rewrite SigMap.keys-1map S2 Signal.unknown =
distinct-Ss-env'' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2
distinct-Ss-env : ∀ S1 S2 S3 ->
¬ Signal.unwrap S1 ≡ Signal.unwrap S2 ->
S3 ∈ proj₁ (Dom (Θ SigMap.[ S1 ↦ Signal.unknown ] [] [])) ->
S3 ∈ proj₁ (Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])) ->
⊥
distinct-Ss-env S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2
rewrite SigMap.keys-1map S1 Signal.unknown =
distinct-Ss-env' S1 S2 S3 S1≠S2 S3∈Domθ1 S3∈Domθ2
distinct-doms : ∀ S1 S2 ->
¬ (Signal.unwrap S1 ≡ Signal.unwrap S2) ->
distinct (Env.Dom (Θ SigMap.[ S1 ↦ Signal.unknown ] [] []))
(Env.Dom (Θ SigMap.[ S2 ↦ Signal.unknown ] [] []))
distinct-doms S1 S2 S1≠S2 =
(λ {S3 S3∈θ1 S3∈θ2 -> distinct-Ss-env S1 S2 S3 S1≠S2 S3∈θ1 S3∈θ2})
,
(λ x₁ x₂ → λ ())
,
(λ x₁ x₂ → λ ())
map-order-irr' : ∀ S1 S2 ->
(Θ SigMap.[ S1 ↦ Signal.unknown ] [] []) ←
(Θ SigMap.[ S2 ↦ Signal.unknown ] [] [])
≡
(Θ SigMap.[ S2 ↦ Signal.unknown ] [] []) ←
(Θ SigMap.[ S1 ↦ Signal.unknown ] [] [])
map-order-irr' S1 S2 with (Signal.unwrap S1) Nat.≟ (Signal.unwrap S2)
map-order-irr' S1 S2 | yes S1=S2 rewrite S1=S2 = refl
map-order-irr' S1 S2 | no ¬S1=S2 = Env.←-comm
((Θ SigMap.[ S1 ↦ Signal.unknown ] [] []))
((Θ SigMap.[ S2 ↦ Signal.unknown ] [] []))
(distinct-doms S1 S2 ¬S1=S2)
map-order-irr : ∀ S1 S2 A p ->
(ρ⟨
Θ SigMap.[ S2 ↦ Signal.unknown ] [] [] ←
Θ SigMap.[ S1 ↦ Signal.unknown ] [] []
,
A ⟩· p)
≡ₑ
(ρ⟨
Θ SigMap.[ S1 ↦ Signal.unknown ] [] [] ←
Θ SigMap.[ S2 ↦ Signal.unknown ] [] []
,
A ⟩· p) # []
map-order-irr S1 S2 A p rewrite map-order-irr' S1 S2 = ≡ₑrefl
{- dropping a loop whose body is just `exit` -}
ex10 : ∀ C n -> (loop (exit n)) ≡ₑ (exit n) # C
ex10 C n = ≡ₑtran (≡ₑstep [loop-unroll]) (≡ₑstep [loopˢ-exit])
{- (nothin ∥ p) ≡ₑ p, but only if we know that
p goes to something that's done -}
ex11 : ∀ p q ->
CB p -> done q -> p ≡ₑ q # [] ->
(nothin ∥ p) ≡ₑ p # []
ex11 = calc where
ex11-pq : ∀ q C -> done q -> (nothin ∥ q) ≡ₑ q # C
ex11-pq .nothin C (dhalted hnothin) =
≡ₑtran (≡ₑstep [par-swap]) (≡ₑstep ([par-nothing] (dhalted hnothin)))
ex11-pq .(exit n) C (dhalted (hexit n)) =
≡ₑstep ([par-nothing] (dhalted (hexit n)))
ex11-pq q C (dpaused p/paused) =
≡ₑstep ([par-nothing] (dpaused p/paused))
basealwaysdistinct : ∀ x -> distinct base x
basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂})
CBp->CBnothingp : {r r′ : Term}
{BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} →
CorrectBinding r BVp FVp →
r′ ≐ ceval (epar₂ nothin) ∷ [] ⟦ r ⟧c → CB r′
CBp->CBnothingp {r} CBr r′dc
with sym (unplugc r′dc) | BVFVcorrect _ _ _ CBr
... | refl | refl , refl
= CBpar CBnothing CBr
(basealwaysdistinct (BVars r))
(basealwaysdistinct (BVars r))
(basealwaysdistinct (FVars r))
(λ { _ () _ })
calc : ∀ p q ->
CB p -> done q -> p ≡ₑ q # [] ->
(nothin ∥ p) ≡ₑ p # []
calc p q CBp doneq p≡ₑq =
≡ₑtran {r = (nothin ∥ q)}
(≡ₑctxt (dcpar₂ dchole)
(dcpar₂ dchole)
(≡ₑ-context [] _ CBp->CBnothingp p≡ₑq))
(≡ₑtran {r = q} (ex11-pq q [] doneq) (≡ₑsymm CBp p≡ₑq))
{- although true, can no longer prove
{- an emit (first) in sequence is the same as emit in parallel -}
ex12 : ∀ S p q ->
CB p -> done q -> p ≡ₑ q # [] ->
(signl S ((emit S) ∥ p)) ≡ₑ (signl S ((emit S) >> p)) # []
ex12 S p q CBp doneq p≡ₑq = calc where
θS→unk : Env
θS→unk = Θ SigMap.[ S ↦ Signal.unknown ] [] []
S∈θS→unk : SigMap.∈Dom S (sig θS→unk)
S∈θS→unk = sig-∈-single S Signal.unknown
θS→unk[S]≡unk : sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.unknown
θS→unk[S]≡unk = sig-stats-1map' S Signal.unknown S∈θS→unk
θS→pre : Env
θS→pre = set-sig{S} θS→unk S∈θS→unk Signal.present
θS→unk[S]≠absent : ¬ sig-stats{S = S} θS→unk S∈θS→unk ≡ Signal.absent
θS→unk[S]≠absent is rewrite θS→unk[S]≡unk = unknotabs is where
unknotabs : Signal.unknown ≡ Signal.absent → ⊥
unknotabs ()
CBp->CBρθSp : {r r′ : Term}
{BVp FVp : Σ (List ℕ) (λ x → List ℕ × List ℕ)} →
CorrectBinding r BVp FVp → r′ ≐ cenv θS→pre ∷ [] ⟦ r ⟧c → CB r′
CBp->CBρθSp {r} CBr r′dc
with sym (unplugc r′dc) | BVFVcorrect _ _ _ CBr
... | refl | refl , refl = CBρ CBr
basealwaysdistinct : ∀ x -> distinct base x
basealwaysdistinct x = (λ { z () x₂ }) , (λ { z () x₂ }) , (λ { z () x₂})
CBsiglSemitS>>p : CB (signl S (emit S >> p))
CBsiglSemitS>>p =
CBsig (CBseq CBemit CBp (basealwaysdistinct (FVars p)))
calc : (signl S ((emit S) ∥ p)) ≡ₑ
(signl S ((emit S) >> p)) # []
calc =
≡ₑtran {r = ρ θS→unk · ((emit S) ∥ p)}
(≡ₑstep [raise-signal])
(≡ₑtran {r = ρ θS→pre · (nothin ∥ p)}
(≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (depar₁ dehole)))
(≡ₑtran {r = ρ θS→pre · p}
(≡ₑctxt (dcenv dchole) (dcenv dchole)
(≡ₑ-context [] (cenv _ ∷ [])
CBp->CBρθSp
(ex11 p q CBp doneq p≡ₑq)))
(≡ₑsymm CBsiglSemitS>>p
(≡ₑtran {r = ρ θS→unk · (emit S >> p)}
(≡ₑstep [raise-signal])
(≡ₑtran {r = ρ θS→pre · nothin >> p}
(≡ₑstep ([emit] S∈θS→unk θS→unk[S]≠absent (deseq dehole)))
(≡ₑctxt (dcenv dchole) (dcenv dchole)
(≡ₑstep [seq-done])))))))
-}
|
interleaved mutual
-- we don't do `data A : Set`
data A where
-- you don't have to actually define any constructor to trigger the error, the "where" is enough
data B where
b : B
|
module getline where
-- https://github.com/alhassy/AgdaCheatSheet#interacting-with-the-real-world-compilation-haskell-and-io
open import Data.Nat using (ℕ; suc)
open import Data.Nat.Show using (show)
open import Data.Char using (Char)
open import Data.List as L using (map; sum; upTo)
open import Function using (_$_; const; _∘_)
open import Data.String as S using (String; _++_; fromList)
open import Agda.Builtin.Unit using (⊤)
open import Codata.Musical.Colist using (take)
open import Codata.Musical.Costring using (Costring)
open import Data.Vec.Bounded as B using (toList)
open import Agda.Builtin.Coinduction using (♯_)
open import IO as IO using (run ; putStrLn ; IO)
import IO.Primitive as Primitive
infixr 1 _>>=_ _>>_
_>>=_ : ∀ {ℓ} {α β : Set ℓ} → IO α → (α → IO β) → IO β
this >>= f = ♯ this IO.>>= λ x → ♯ f x
_>>_ : ∀{ℓ} {α β : Set ℓ} → IO α → IO β → IO β
x >> y = x >>= const y
postulate
getLine∞ : Primitive.IO Costring
{-# FOREIGN GHC
toColist :: [a] -> MAlonzo.Code.Codata.Musical.Colist.AgdaColist a
toColist [] = MAlonzo.Code.Codata.Musical.Colist.Nil
toColist (x : xs) =
MAlonzo.Code.Codata.Musical.Colist.Cons x (MAlonzo.RTE.Sharp (toColist xs))
#-}
{- Haskell's prelude is implicitly available; this is for demonstration. -}
{-# FOREIGN GHC import Prelude as Haskell #-}
{-# COMPILE GHC getLine∞ = fmap toColist Haskell.getLine #-}
-- (1)
-- getLine : IO Costring
-- getLine = IO.lift getLine∞
getLine : IO String
getLine = IO.lift
$ getLine∞ Primitive.>>= (Primitive.return ∘ S.fromList ∘ B.toList ∘ take 100)
postulate readInt : L.List Char → ℕ
{-# COMPILE GHC readInt = \x -> read x :: Integer #-}
main : Primitive.IO ⊤
main = run do
putStrLn "Hello, world! I'm a compiled Agda program!"
IO.putStrLn "What is your name?:"
name ← getLine
IO.putStrLn "Please enter a number:"
num ← getLine
let tri = show $ sum $ upTo $ suc $ readInt $ S.toList num
putStrLn $ "The triangle number of " ++ num ++ " is " ++ tri
putStrLn ("Bye, " ++ name)
-- IO.putStrLn∞ ("Bye, " ++ name) {- If using approach (1) above. -}
|
open import Level using () renaming (_⊔_ to _⊔ˡ_)
open import Relation.Binary using (_⇒_; TotalOrder; Reflexive; Symmetric; Transitive; IsEquivalence; IsPreorder; Antisymmetric)
module AKS.Extended {c ℓ₁ ℓ₂} (≤-totalOrder : TotalOrder c ℓ₁ ℓ₂) where
open TotalOrder ≤-totalOrder
using (_≈_; _≤_; total; isEquivalence)
renaming (Carrier to C; refl to ≤-refl; reflexive to ≤-reflexive; trans to ≤-trans )
open IsEquivalence isEquivalence
using ()
renaming (refl to ≈-refl; sym to ≈-sym; trans to ≈-trans)
data Extended : Set c where
-∞ : Extended
⟨_⟩ : C → Extended
infixl 4 _≈ᵉ_
data _≈ᵉ_ : Extended → Extended → Set (c ⊔ˡ ℓ₁) where
-∞≈ : -∞ ≈ᵉ -∞
⟨_⟩ : ∀ {b t} → b ≈ t → ⟨ b ⟩ ≈ᵉ ⟨ t ⟩
≈ᵉ-refl : Reflexive _≈ᵉ_
≈ᵉ-refl { -∞} = -∞≈
≈ᵉ-refl {⟨ _ ⟩} = ⟨ ≈-refl ⟩
≈ᵉ-sym : Symmetric _≈ᵉ_
≈ᵉ-sym -∞≈ = -∞≈
≈ᵉ-sym ⟨ x≈y ⟩ = ⟨ ≈-sym x≈y ⟩
≈ᵉ-trans : Transitive _≈ᵉ_
≈ᵉ-trans -∞≈ -∞≈ = -∞≈
≈ᵉ-trans ⟨ x≈y ⟩ ⟨ y≈z ⟩ = ⟨ ≈-trans x≈y y≈z ⟩
≈ᵉ-isEquivalence : IsEquivalence _≈ᵉ_
≈ᵉ-isEquivalence = record
{ refl = ≈ᵉ-refl
; sym = ≈ᵉ-sym
; trans = ≈ᵉ-trans
}
infixl 4 _≤ᵉ_
data _≤ᵉ_ : Extended → Extended → Set (c ⊔ˡ ℓ₂) where
-∞≤_ : ∀ t → -∞ ≤ᵉ t
⟨_⟩ : ∀ {b t} → b ≤ t → ⟨ b ⟩ ≤ᵉ ⟨ t ⟩
≤ᵉ-refl : Reflexive _≤ᵉ_
≤ᵉ-refl { -∞} = -∞≤ -∞
≤ᵉ-refl {⟨ _ ⟩} = ⟨ ≤-refl ⟩
≤ᵉ-reflexive : _≈ᵉ_ ⇒ _≤ᵉ_
≤ᵉ-reflexive -∞≈ = -∞≤ -∞
≤ᵉ-reflexive ⟨ x≈y ⟩ = ⟨ ≤-reflexive x≈y ⟩
≤ᵉ-trans : Transitive _≤ᵉ_
≤ᵉ-trans {x} {y} {z} (-∞≤ _) (-∞≤ t) = -∞≤ t
≤ᵉ-trans {x} {y} {z} (-∞≤ _) ⟨ _ ⟩ = -∞≤ z
≤ᵉ-trans {x} {y} {z} ⟨ x≤y ⟩ ⟨ y≤z ⟩ = ⟨ (≤-trans x≤y y≤z) ⟩
≤ᵉ-isPreorder : IsPreorder _≈ᵉ_ _≤ᵉ_
≤ᵉ-isPreorder = record { isEquivalence = ≈ᵉ-isEquivalence ; reflexive = ≤ᵉ-reflexive ; trans = ≤ᵉ-trans }
module ≤ᵉ-Reasoning where
open import Relation.Binary.Reasoning.Base.Double ≤ᵉ-isPreorder public
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Empty
open import lib.types.Group
open import lib.types.Int
open import lib.types.List
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Sigma
module lib.types.Word {i} where
module _ (A : Type i) where
PlusMinus : Type i
PlusMinus = Coprod A A
Word : Type i
Word = List PlusMinus
module _ {A : Type i} where
flip : PlusMinus A → PlusMinus A
flip (inl a) = inr a
flip (inr a) = inl a
flip-flip : ∀ x → flip (flip x) == x
flip-flip (inl x) = idp
flip-flip (inr x) = idp
Word-flip : Word A → Word A
Word-flip = map flip
Word-flip-flip : ∀ w → Word-flip (Word-flip w) == w
Word-flip-flip nil = idp
Word-flip-flip (x :: l) = ap2 _::_ (flip-flip x) (Word-flip-flip l)
Word-exp : A → ℤ → Word A
Word-exp a (pos 0) = nil
Word-exp a (pos (S n)) = inl a :: Word-exp a (pos n)
Word-exp a (negsucc 0) = inr a :: nil
Word-exp a (negsucc (S n)) = inr a :: Word-exp a (negsucc n)
module _ {A : Type i} {j} (G : Group j) where
private
module G = Group G
PlusMinus-extendᴳ : (A → G.El) → (PlusMinus A → G.El)
PlusMinus-extendᴳ f (inl a) = f a
PlusMinus-extendᴳ f (inr a) = G.inv (f a)
Word-extendᴳ : (A → G.El) → (Word A → G.El)
Word-extendᴳ f = foldr G.comp G.ident ∘ map (PlusMinus-extendᴳ f)
abstract
Word-extendᴳ-++ : ∀ f l₁ l₂
→ Word-extendᴳ f (l₁ ++ l₂) == G.comp (Word-extendᴳ f l₁) (Word-extendᴳ f l₂)
Word-extendᴳ-++ f nil l₂ = ! $ G.unit-l _
Word-extendᴳ-++ f (x :: l₁) l₂ =
ap (G.comp (PlusMinus-extendᴳ f x)) (Word-extendᴳ-++ f l₁ l₂)
∙ ! (G.assoc (PlusMinus-extendᴳ f x) (Word-extendᴳ f l₁) (Word-extendᴳ f l₂))
module _ {A : Type i} {j} (G : AbGroup j) where
private
module G = AbGroup G
abstract
PlusMinus-extendᴳ-comp : ∀ (f g : A → G.El) x
→ PlusMinus-extendᴳ G.grp (λ a → G.comp (f a) (g a)) x
== G.comp (PlusMinus-extendᴳ G.grp f x) (PlusMinus-extendᴳ G.grp g x)
PlusMinus-extendᴳ-comp f g (inl a) = idp
PlusMinus-extendᴳ-comp f g (inr a) = G.inv-comp (f a) (g a) ∙ G.comm (G.inv (g a)) (G.inv (f a))
Word-extendᴳ-comp : ∀ (f g : A → G.El) l
→ Word-extendᴳ G.grp (λ a → G.comp (f a) (g a)) l
== G.comp (Word-extendᴳ G.grp f l) (Word-extendᴳ G.grp g l)
Word-extendᴳ-comp f g nil = ! (G.unit-l G.ident)
Word-extendᴳ-comp f g (x :: l) =
ap2 G.comp (PlusMinus-extendᴳ-comp f g x) (Word-extendᴳ-comp f g l)
∙ G.interchange (PlusMinus-extendᴳ G.grp f x) (PlusMinus-extendᴳ G.grp g x)
(Word-extendᴳ G.grp f l) (Word-extendᴳ G.grp g l)
|
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
open import Common.Product
{-# TERMINATING #-}
Loop : Set
Loop = Loop
postulate
loop : Loop
data Box (A : Set) : Set where
box : A → Box A
{-# TERMINATING #-}
Boxed-loop : Set
Boxed-loop = Box Boxed-loop
postulate
boxed-loop : Boxed-loop
test₁ : Boxed-loop
test₁ = quoteGoal g in boxed-loop
test₂ : Term
test₂ = quoteTerm Loop
test₃ : Loop → List (Arg Term)
test₃ _ = quoteContext
macro
m₄ : Term → Term → TC ⊤
m₄ _ hole = unify hole (def (quote ⊤) [])
test₄ : Set
test₄ = m₄ Loop
macro
m₅ : Term → TC ⊤
m₅ hole = bindTC (inferType (def (quote loop) [])) λ A →
unify hole A
test₅ : Set
test₅ = m₅
macro
m₆ : Term → TC ⊤
m₆ hole =
bindTC (checkType (def (quote Loop) []) (agda-sort (lit 0))) λ A →
unify hole A
test₆ : Set
test₆ = m₆
macro
m₇ : Term → TC ⊤
m₇ hole =
bindTC (quoteTC Loop) λ A →
unify hole A
test₇ : Set
test₇ = m₇
Vec : Set → Nat → Set
Vec A zero = ⊤
Vec A (suc n) = A × Vec A n
macro
m₈ : Term → TC ⊤
m₈ hole =
bindTC (reduce V) λ V →
unify hole V
where
varg = arg (arg-info visible relevant)
V = def (quote Vec) (varg (def (quote Boxed-loop) []) ∷
varg (lit (nat 1)) ∷
[])
test₈ : Set
test₈ = m₈
|
-- V: letpair (x,y) = (V,W) in E --> E[ V,W / x,y ]
module Properties.StepPair where
open import Data.List
open import Data.List.All
open import Data.Product
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Typing
open import Syntax
open import Global
open import Values
open import Session
open import Properties.Base
-- this will require multiple steps to execute
mklhs : ∀ {Φ t₁ t₂} → Expr (t₁ ∷ t₂ ∷ Φ) TUnit → Expr (t₁ ∷ t₂ ∷ Φ) TUnit
mklhs {Φ} E =
letbind (left (left (split-all-right Φ))) (pair (left (rght [])) (here []) (here []))
(letpair (left (split-all-right Φ)) (here []) E)
reduction : ∀ {t₁ t₂}
→ (E : Expr (t₁ ∷ t₂ ∷ []) TUnit)
→ (v₁ : Val [] t₁)
→ (v₂ : Val [] t₂)
→ let ϱ = vcons ss-[] v₁ (vcons ss-[] v₂ (vnil []-inactive)) in
let lhs = (run (left (left [])) ss-[] (mklhs E) ϱ (halt []-inactive UUnit)) in
let rhs = (run (left (left [])) ss-[] E ϱ (halt []-inactive UUnit)) in
restart lhs ≡
rhs
reduction E v₁ v₂
with split-env (left (left [])) (vcons ss-[] v₁ (vcons ss-[] v₂ (vnil []-inactive)))
... | spe
= refl
reduction-open-type : Set
reduction-open-type = ∀ {Φ t₁ t₂}
(E : Expr (t₁ ∷ t₂ ∷ Φ) TUnit)
(ϱ : VEnv [] (t₁ ∷ t₂ ∷ Φ))
→
let lhs = run (left (left (split-all-left Φ))) ss-[] (mklhs E) ϱ (halt []-inactive UUnit) in
let rhs = run (left (left (split-all-left _))) ss-[] E ϱ (halt []-inactive UUnit) in
restart lhs ≡ rhs
reduction-open : reduction-open-type
reduction-open {Φ} E (vcons ss-[] v (vcons ss-[] v₁ ϱ))
rewrite split-rotate-lemma {Φ}
| split-env-right-lemma0 ϱ
with ssplit-compose3 ss-[] ss-[]
... | ssc3
rewrite split-env-right-lemma0 ϱ
| split-rotate-lemma {Φ}
= refl
|
{-# OPTIONS --without-K #-}
module Explore.README where
-- The core types behind exploration functions
open import Explore.Core
-- The core properties behind exploration functions
open import Explore.Properties
-- Lifting the dependent axiom of choice to sums and products
open import Explore.BigDistr
-- Constructions on top of exploration functions
open import Explore.Explorable
-- Specific constructions on top of summation functions
open import Explore.Summable
-- Exploration of Cartesian products (and Σ-types)
open import Explore.Product
-- Exploration of disjoint sums
open import Explore.Sum
-- Exploration of base types 𝟘, 𝟙, 𝟚, Fin n
open import Explore.Zero
open import Explore.One
open import Explore.Two
open import Explore.Fin
-- A type universe of explorable types
open import Explore.Universe.Type
open import Explore.Universe.Base
open import Explore.Universe
-- Transporting explorations across isomorphisms
open import Explore.Isomorphism
-- From binary trees to explorations and back
open import Explore.BinTree
-- Exploration functions form a monad
open import Explore.Monad
-- Some high-level properties about group homomorphisms and
-- group isomorphisms.
-- For instance the indistinguisability (One-time-pad like) for groups
open import Explore.Group
-- In a (bit) guessing game,
open import Explore.GuessingGameFlipping
-- An example with a specific type: 6 sided dice
open import Explore.Dice
-- TODO unfinished
-- BROKEN open import Explore.Function.Fin
open import Explore.Subset
|
open import Relation.Binary using (IsDecEquivalence)
open import Agda.Builtin.Equality
module UnifyMguCorrectG (FunctionName : Set) ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ (PredicateName VariableName : Set) where
open import UnifyTermF FunctionName
open import UnifyMguF FunctionName
open import UnifyMguCorrectF FunctionName
open import Data.Nat
open import Data.Vec
open import Function
open import Data.Fin renaming (thin to thinF; thick to thickF)
data Formula (n : ℕ) : Set
where
atomic : PredicateName → ∀ {t} → Vec (Term n) t → Formula n
logical : Formula n →
Formula n →
Formula n
quantified : Formula (suc n) → Formula n
open import Relation.Binary.PropositionalEquality
instance ThinFormula : Thin Formula
Thin.thin ThinFormula x (atomic x₁ x₂) = atomic x₁ (thin x x₂)
Thin.thin ThinFormula x (logical x₁ x₂) = logical (thin x x₁) (thin x x₂)
Thin.thin ThinFormula x (quantified x₁) = quantified (thin zero x₁)
Thin.thinfact1 ThinFormula f {atomic pn1 ts1} {atomic pn2 ts2} r = {!!}
Thin.thinfact1 ThinFormula f {atomic x x₁} {logical y y₁} ()
Thin.thinfact1 ThinFormula f {atomic x x₁} {quantified y} ()
Thin.thinfact1 ThinFormula f {logical x x₁} {atomic x₂ x₃} ()
Thin.thinfact1 ThinFormula f {logical x x₁} {logical y y₁} x₂ = {!!}
Thin.thinfact1 ThinFormula f {logical x x₁} {quantified y} ()
Thin.thinfact1 ThinFormula f {quantified x} {atomic x₁ x₂} ()
Thin.thinfact1 ThinFormula f {quantified x} {logical y y₁} ()
Thin.thinfact1 ThinFormula f {quantified x} {quantified y} x₁ = {!!}
foo~ : ∀ {m₁ n₁} →
(Fin m₁ → Term n₁) →
Fin (suc m₁) → Term (suc n₁)
foo~ f = (λ { zero → i zero ; (suc x) → thin zero (f x)})
foo~i≐i : ∀ {m} → foo~ {m} i ≐ i
foo~i≐i zero = refl
foo~i≐i (suc x) = refl
instance SubstitutionFormula : Substitution Formula
Substitution._◃_ SubstitutionFormula = _◃′_ where
_◃′_ : ∀ {m n} -> (f : m ~> n) -> Formula m -> Formula n
f ◃′ atomic 𝑃 τs = atomic 𝑃 (f ◃ τs)
f ◃′ logical φ₁ φ₂ = logical (f ◃ φ₁) (f ◃ φ₂)
f ◃′ quantified φ = quantified (foo~ f ◃ φ)
instance SubstitutionExtensionalityFormula : SubstitutionExtensionality Formula
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (atomic x₁ x₂) = cong (atomic x₁) (◃ext x x₂)
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (logical t t₁) = cong₂ logical (◃ext x t) (◃ext x t₁)
SubstitutionExtensionality.◃ext SubstitutionExtensionalityFormula x (quantified t) = cong quantified ((◃ext (λ { zero → refl ; (suc x₁) → cong (mapTerm suc) (x x₁)}) t)) --
instance SubFact1Formula : Sub.Fact1 Formula
Sub.Fact1.fact1 SubFact1Formula (atomic x x₁) = cong (atomic x) (Sub.fact1 x₁)
Sub.Fact1.fact1 SubFact1Formula (logical t t₁) = cong₂ logical (Sub.fact1 t) (Sub.fact1 t₁)
Sub.Fact1.fact1 SubFact1Formula {n} (quantified φ) = cong quantified (trans (◃ext {Formula} {_} {_} {foo~ {_} i} {i} (foo~i≐i {_}) φ) (Sub.fact1 φ))
Unifies⋆F : ∀ {m} (s t : Formula m) -> Property⋆ m
Unifies⋆F s t f = f ◃ s ≡ f ◃ t
|
module Ordinals where
import Level
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Nat using (ℕ) renaming (zero to z; suc to s)
open import Data.Empty
postulate
ext₀ : Extensionality Level.zero Level.zero
ext₁ : Extensionality Level.zero (Level.suc Level.zero)
data Ord : Set₁ where
zero : Ord
succ : Ord → Ord
sup : (A : Set) → (f : A → Ord) → Ord
infixl 10 _≤_
module CountableOrdinals where
inj-ℕ-Ord : ℕ → Ord
inj-ℕ-Ord z = zero
inj-ℕ-Ord (s n) = succ (inj-ℕ-Ord n)
ω : Ord
ω = sup ℕ inj-ℕ-Ord
_∔_ : Ord → ℕ → Ord
α ∔ z = α
α ∔ (s n) = succ (α ∔ n)
_ẋ_ : Ord → ℕ → Ord
α ẋ z = zero
α ẋ (s n) = sup ℕ (λ k → (α ẋ n) ∔ k)
_^^_ : Ord → ℕ → Ord
α ^^ z = succ zero
α ^^ (s n) = sup ℕ (λ k → (α ^^ n) ẋ k)
ω+ : ℕ → Ord
ω+ n = ω ∔ n
ω× : ℕ → Ord
ω× n = ω ẋ n
ω^ : ℕ → Ord
ω^ n = ω ^^ n
ω+1≢ω : sup ℕ (succ ∘ inj-ℕ-Ord) ≡ ω → ⊥
ω+1≢ω p = {!!}
-- This should not be provable!
-- succ-sup : ∀ A f → sup A (succ ∘ f) ≡ succ (sup A f)
-- succ-sup A f = {!!}
_+_ : Ord → Ord → Ord
α + zero = α
α + succ β = succ (α + β)
α + sup A f = sup A (λ x → α + f x)
zeroₗ : ∀ α → zero + α ≡ α
zeroₗ zero = refl
zeroₗ (succ α) = cong succ (zeroₗ α)
zeroₗ (sup A f) = cong (sup A) (ext₁ (λ x → zeroₗ (f x)))
succₗ : ∀ α β → succ α + β ≡ succ (α + β)
succₗ α zero = refl
succₗ α (succ β) = cong succ (succₗ α β)
succₗ α (sup A f) = {!!}
-- trans (cong (sup A) (ext₁ (λ x → succₗ α (f x))))
-- (succ-sup A (λ x → α + f x))
_≤_ : Ord → Ord → Set₁
α ≤ β = ∃ λ γ → α + γ ≡ β
≤-refl : ∀ α → α ≤ α
≤-refl α = (zero , refl)
zero-min : ∀ α → zero ≤ α
zero-min α = (α , zeroₗ α)
≤-succ : ∀ α β → α ≤ β → succ α ≤ succ β
≤-succ α β (γ , p) = (γ , trans (succₗ α γ) (cong succ p))
≤-step : ∀ α β → α ≤ β → α ≤ succ β
≤-step α β (γ , p) = (succ γ , cong succ p)
≤-sup-step : ∀ α A f → (∀ x → α ≤ f x) → α ≤ sup A f
≤-sup-step α A f p = (sup A (proj₁ ∘ p) , cong (sup A) (ext₁ (proj₂ ∘ p)))
≤-supₗ : ∀ A f β → (∀ x → f x ≤ β) → sup A f ≤ β
≤-supₗ A f β p = (sup A (proj₁ ∘ p) , {!!})
where
q : (x : A) → (f x + proj₁ (p x)) ≡ β
q = proj₂ ∘ p
≤-sup : ∀ A f g → (∀ x → f x ≤ g x) → sup A f ≤ sup A g
≤-sup A f g p = (sup A (proj₁ ∘ p) , {!!}) -- cong (sup A) (ext₁ {!!}))
where
q : (x : A) → (f x + proj₁ (p x)) ≡ g x
q = proj₂ ∘ p
q' : (x : A) → (sup A f + (proj₁ ∘ p) x) ≡ g x
q' = {!!}
lem₁ : ∀ α β → α ≤ α + β
lem₁ α zero = ≤-refl α
lem₁ α (succ β) = ≤-step α (α + β) (lem₁ α β)
lem₁ α (sup A f) = ≤-sup-step α A (λ x → α + f x) (λ x → lem₁ α (f x))
lem₂ : ∀ α β → β ≤ α + β
lem₂ α zero = zero-min (α + zero)
lem₂ α (succ β) = ≤-succ β (α + β) (lem₂ α β)
lem₂ α (sup A f) = ≤-sup A f (λ x → α + f x) (λ x → lem₂ α (f x))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.