small changes
This commit is contained in:
parent
cd5f1dd2d4
commit
90ce509af6
3 changed files with 60 additions and 5 deletions
48
extra/iso-exercise.lagda
Normal file
48
extra/iso-exercise.lagda
Normal file
|
@ -0,0 +1,48 @@
|
|||
\begin{code}
|
||||
module iso-exercise where
|
||||
|
||||
import Relation.Binary.PropositionalEquality as Eq
|
||||
open Eq using (_≡_; refl; cong₂)
|
||||
open Eq.≡-Reasoning
|
||||
open import plfa.Isomorphism using (_≃_)
|
||||
open import Data.List using (List; []; _∷_)
|
||||
open import Data.List.All using (All; []; _∷_)
|
||||
open import Data.List.Any using (Any; here; there)
|
||||
open import Data.List.Membership.Propositional using (_∈_)
|
||||
open import Function using (_∘_)
|
||||
|
||||
postulate
|
||||
extensionality : ∀ {A : Set} {B : A → Set} {C : A → Set} {f g : {x : A} → B x → C x}
|
||||
→ (∀ {x : A} (bx : B x) → f {x} bx ≡ g {x} bx)
|
||||
--------------------------------------------
|
||||
→ (λ {x} → f {x}) ≡ (λ {x} → g {x})
|
||||
|
||||
f : ∀ {A : Set} {P : A → Set} {xs : List A} → All P xs → (∀ {x} -> x ∈ xs -> P x)
|
||||
f [] ()
|
||||
f (px ∷ pxs) (here refl) = px
|
||||
f (px ∷ pxs) (there x∈xs) = f pxs x∈xs
|
||||
|
||||
g : ∀ {A : Set} {P : A → Set} {xs : List A} → (∀ {x} -> x ∈ xs -> P x) → All P xs
|
||||
g {xs = []} h = []
|
||||
g {xs = x ∷ xs} h = h {x} (here refl) ∷ g (h ∘ there)
|
||||
|
||||
gf : ∀ {A : Set} {P : A → Set} {xs : List A} → ∀ (pxs : All P xs) → g (f pxs) ≡ pxs
|
||||
gf [] = refl
|
||||
gf (px ∷ pxs) = Eq.cong₂ _∷_ refl (gf pxs)
|
||||
|
||||
fg : ∀ {A : Set} {P : A → Set} {xs : List A}
|
||||
→ ∀ (h : ∀ {x} -> x ∈ xs -> P x) → ∀ {x} (x∈ : x ∈ xs) → f (g h) {x} x∈ ≡ h {x} x∈
|
||||
fg {xs = []} h ()
|
||||
fg {xs = x ∷ xs} h (here refl) = refl
|
||||
fg {xs = x ∷ xs} h (there x∈xs) = fg (h ∘ there) x∈xs
|
||||
|
||||
lemma : ∀ {A : Set} {P : A → Set} {xs : List A} → All P xs ≃ (∀ {x} -> x ∈ xs -> P x)
|
||||
lemma =
|
||||
record
|
||||
{ to = f
|
||||
; from = g
|
||||
; from∘to = gf
|
||||
; to∘from = extensionality ∘ fg
|
||||
}
|
||||
|
||||
\end{code}
|
|
@ -541,7 +541,7 @@ Show that erasure relates corresponding boolean and decidable operations:
|
|||
\begin{code}
|
||||
postulate
|
||||
∧-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∧ ⌊ y ⌋ ≡ ⌊ x ×-dec y ⌋
|
||||
∨-× : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∨ ⌊ y ⌋ ≡ ⌊ x ⊎-dec y ⌋
|
||||
∨-⊎ : ∀ {A B : Set} (x : Dec A) (y : Dec B) → ⌊ x ⌋ ∨ ⌊ y ⌋ ≡ ⌊ x ⊎-dec y ⌋
|
||||
not-¬ : ∀ {A : Set} (x : Dec A) → not ⌊ x ⌋ ≡ ⌊ ¬? x ⌋
|
||||
\end{code}
|
||||
|
||||
|
|
|
@ -569,9 +569,9 @@ replaces the formal parameter by the actual parameter.
|
|||
|
||||
If a term is a value, then no reduction applies; conversely,
|
||||
if a reduction applies to a term then it is not a value.
|
||||
We will show in the next chapter that for well-typed terms
|
||||
this exhausts the possibilities: for every well-typed term
|
||||
either a reduction applies or it is a value.
|
||||
We will show in the next chapter that
|
||||
this exhausts the possibilities: every well-typed term
|
||||
either reduces or is a value.
|
||||
|
||||
For numbers, zero does not reduce and successor reduces the subterm.
|
||||
A case expression reduces its argument to a number, and then chooses
|
||||
|
@ -628,13 +628,20 @@ data _—→_ : Term → Term → Set where
|
|||
|
||||
The reduction rules are carefully designed to ensure that subterms
|
||||
of a term are reduced to values before the whole term is reduced.
|
||||
This is referred to as _call by value_ reduction.
|
||||
This is referred to as _call-by-value_ reduction.
|
||||
|
||||
Further, we have arranged that subterms are reduced in a
|
||||
left-to-right order. This means that reduction is _deterministic_:
|
||||
for any term, there is at most one other term to which it reduces.
|
||||
Put another way, our reduction relation `—→` is in fact a function.
|
||||
|
||||
This style of explaining the meaning of terms is called
|
||||
a _small-step operational semantics_. If `M —→ N`, we say that
|
||||
term `M` _reduces_ to term `N`, or equivalently,
|
||||
term `M` _steps_ to term `N`. Each compatibility rule has
|
||||
another reduction rule in its premise; so a step always consists
|
||||
of a beta rule, possibly adjusted by zero or more compatibility rules.
|
||||
|
||||
|
||||
#### Quiz
|
||||
|
||||
|
|
Loading…
Reference in a new issue