Skip to content

Commit 6e1fb64

Browse files
committed
added inthe interpretation functions
1 parent 9c15e24 commit 6e1fb64

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

README/Data/Fin/Relation/Ternary/PunchOut.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-- precisely mirrored in the constructors of the view type
99
--
1010
-- Using this view, we can exhibit the corresponding properties of
11-
-- the function `punchIn` defined in `Data.Fin.Properties`
11+
-- the function `punchOut` defined in `Data.Fin.Properties`
1212
------------------------------------------------------------------------
1313

1414
{-# OPTIONS --without-K --safe #-}

src/Data/Fin/Relation/Ternary/Pinch.agda

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ private
2929
------------------------------------------------------------------------
3030
-- The View, considered as a ternary relation
3131

32+
-- Each constructor corresponds to a particular call-pattern in the original
33+
-- function definition; recursive calls are represented by inductive premises
34+
3235
data View : {n} (i : Fin n) (j : Fin (suc n)) (k : Fin n) Set where
3336

3437
any-zero : {n} (i : Fin (suc n)) View i zero zero
@@ -37,14 +40,24 @@ data View : ∀ {n} (i : Fin n) (j : Fin (suc n)) (k : Fin n) → Set where
3740

3841
-- The View is sound, ie covers all telescopes (satisfying the always-true precondition)
3942

43+
-- The recursion/pattern analysis of the original definition of `pinch`
44+
-- (which is responsible for showing termination in the first place)
45+
-- is then exactly replicated in the definition of the covering function `view`;
46+
-- thus that definitional pattern analysis is encapsulated once and for all
47+
4048
view : {n} i j View {n} i j (pinch i j)
4149
view {suc _} i zero = any-zero i
4250
view zero (suc j) = zero-suc j
4351
view (suc i) (suc j) = suc-suc (view i j)
4452

53+
-- Interpretation of the view: the original function itself
54+
55+
⟦_⟧ : {i j} {k} .(v : View {n} i j k) Fin n
56+
⟦_⟧ {n = n} {i} {j} {k} _ = pinch i j
57+
4558
-- The View is complete
4659

47-
view-complete : {n} {i j} {k} (v : View {n} i j k) pinch i j ≡ k
60+
view-complete : {n} {i j} {k} (v : View {n} i j k) ⟦ v ⟧ ≡ k
4861
view-complete (any-zero i) = refl
4962
view-complete (zero-suc j) = refl
5063
view-complete (suc-suc v) = cong suc (view-complete v)

src/Data/Fin/Relation/Ternary/PunchIn.agda

+14-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ private
2727
------------------------------------------------------------------------
2828
-- The View, considered as a ternary relation
2929

30+
-- Each constructor corresponds to a particular call-pattern in the original
31+
-- function definition; recursive calls are represented by inductive premises
32+
3033
data View : {n} (i : Fin (suc n)) (j : Fin n) (k : Fin (suc n)) Set where
3134

3235
zero-suc : {n} (j : Fin n) View zero j (suc j)
@@ -43,14 +46,24 @@ view-codomain (suc-suc v) = (view-codomain v) ∘ suc-injective
4346

4447
-- The View is sound, ie covers all telescopes (satisfying the always-true precondition)
4548

49+
-- The recursion/pattern analysis of the original definition of `punchIn`
50+
-- (which is responsible for showing termination in the first place)
51+
-- is then exactly replicated in the definition of the covering function `view`;
52+
-- thus that definitional pattern analysis is encapsulated once and for all
53+
4654
view : i j View {n} i j (punchIn i j)
4755
view zero j = zero-suc j
4856
view (suc i) zero = suc-zero i
4957
view (suc i) (suc j) = suc-suc (view i j)
5058

59+
-- Interpretation of the view: the original function itself
60+
61+
⟦_⟧ : {i} {j} {k} .(v : View {n} i j k) Fin (suc n)
62+
⟦_⟧ {n = n} {i} {j} {k} _ = punchIn i j
63+
5164
-- The View is complete
5265

53-
view-complete : {i j} {k} (v : View {n} i j k) punchIn i j ≡ k
66+
view-complete : {i j} {k} (v : View {n} i j k) ⟦ v ⟧ ≡ k
5467
view-complete (zero-suc j) = refl
5568
view-complete (suc-zero i) = refl
5669
view-complete (suc-suc v) = cong suc (view-complete v)

src/Data/Fin/Relation/Ternary/PunchOut.agda

+14-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ private
2828
------------------------------------------------------------------------
2929
-- The View, considered as a ternary relation
3030

31+
-- Each constructor corresponds to a particular call-pattern in the original
32+
-- function definition; recursive calls are represented by inductive premises
33+
3134
data View : {n} (i j : Fin (suc n)) (k : Fin n) Set where
3235

3336
zero-suc : {n} (j : Fin n) View zero (suc j) j
@@ -44,15 +47,25 @@ view-domain (suc-suc v) = (view-domain v) ∘ suc-injective
4447

4548
-- The View is sound, ie covers all telescopes satisfying that precondition
4649

50+
-- The recursion/pattern analysis of the original definition of `punchOut`
51+
-- (which is responsible for showing termination in the first place)
52+
-- is then exactly replicated in the definition of the covering function `view`;
53+
-- thus that definitional pattern analysis is encapsulated once and for all
54+
4755
view : {n} {i j} (d : Domain i j) View {n} i j (punchOut d)
4856
view {i = zero} {j = zero} d with () d refl
4957
view {i = zero} {j = suc j} d = zero-suc j
5058
view {n = suc _} {i = suc i} {j = zero} d = suc-zero i
5159
view {n = suc _} {i = suc i} {j = suc j} d = suc-suc (view (d ∘ (cong suc)))
5260

61+
-- Interpretation of the view: the original function itself
62+
63+
⟦_⟧ : {i j} {k} (v : View {n} i j k) Fin n
64+
⟦ v ⟧ = punchOut (view-domain v)
65+
5366
-- The View is complete
5467

55-
view-complete : {i j} {k} (v : View {n} i j k) punchOut (view-domain v) ≡ k
68+
view-complete : {i j} {k} (v : View {n} i j k) ⟦ v ⟧ ≡ k
5669
view-complete (zero-suc j) = refl
5770
view-complete (suc-zero i) = refl
5871
view-complete (suc-suc v) = cong suc (view-complete v)

0 commit comments

Comments
 (0)