Mercurial > hg > Members > atton > agda-proofs
annotate cbc/stack-product.agda @ 28:67978ba63a6f
Rewrite cs composition style
author | atton <atton@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 23 Dec 2016 10:43:23 +0000 |
parents | 892f8b3aa57e |
children | b8e606ab3a0b |
rev | line source |
---|---|
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 module stack-product where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 open import product |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 open import Data.Product |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
5 open import Function using (id) |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 open import Relation.Binary.PropositionalEquality |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 -- definition based from Gears(209:5708390a9d88) src/parallel_execution |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 goto = executeCS |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 data Bool : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 True : Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 False : Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 data Maybe (a : Set) : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 Nothing : Maybe a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 Just : a -> Maybe a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 record Stack {a t : Set} (stackImpl : Set) : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 field |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 stack : stackImpl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 push : CodeSegment (stackImpl × a × (CodeSegment stackImpl t)) t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 pop : CodeSegment (stackImpl × (CodeSegment (stackImpl × Maybe a) t)) t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 data Element (a : Set) : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 cons : a -> Maybe (Element a) -> Element a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 datum : {a : Set} -> Element a -> a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 datum (cons a _) = a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 next : {a : Set} -> Element a -> Maybe (Element a) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 next (cons _ n) = n |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 record SingleLinkedStack (a : Set) : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 field |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 top : Maybe (Element a) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 open SingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 emptySingleLinkedStack : {a : Set} -> SingleLinkedStack a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 emptySingleLinkedStack = record {top = Nothing} |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 pushSingleLinkedStack : {a t : Set} -> CodeSegment ((SingleLinkedStack a) × a × (CodeSegment (SingleLinkedStack a) t)) t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 pushSingleLinkedStack = cs push |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 push : {a t : Set} -> ((SingleLinkedStack a) × a × (CodeSegment (SingleLinkedStack a) t)) -> t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 push (stack , datum , next) = goto next stack1 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 element = cons datum (top stack) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 stack1 = record {top = Just element} |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 popSingleLinkedStack : {a t : Set} -> CodeSegment (SingleLinkedStack a × (CodeSegment (SingleLinkedStack a × Maybe a) t)) t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 popSingleLinkedStack = cs pop |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 pop : {a t : Set} -> (SingleLinkedStack a × (CodeSegment (SingleLinkedStack a × Maybe a) t)) -> t |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 pop (record { top = Nothing } , nextCS) = goto nextCS (emptySingleLinkedStack , Nothing) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61 pop (record { top = Just x } , nextCS) = goto nextCS (stack1 , (Just datum1)) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 datum1 = datum x |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 stack1 = record { top = (next x) } |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 createSingleLinkedStack : {a b : Set} -> Stack {a} {b} (SingleLinkedStack a) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 createSingleLinkedStack = record { stack = emptySingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 ; push = pushSingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 ; pop = popSingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 } |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 test01 : {a : Set} -> CodeSegment (SingleLinkedStack a × Maybe a) Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 test01 = cs test01' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 test01' : {a : Set} -> (SingleLinkedStack a × Maybe a) -> Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 test01' (record { top = Nothing } , _) = False |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 test01' (record { top = Just x } , _) = True |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
87 test02 : {a : Set} -> CodeSegment (SingleLinkedStack a) (SingleLinkedStack a × Maybe a) |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 test02 = cs test02' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 where |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
90 test02' : {a : Set} -> SingleLinkedStack a -> (SingleLinkedStack a × Maybe a) |
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
91 test02' stack = goto popSingleLinkedStack (stack , (cs id)) |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
94 test03 : {a : Set} -> CodeSegment a (SingleLinkedStack a) |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 test03 = cs test03' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 where |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
97 test03' : {a : Set} -> a -> SingleLinkedStack a |
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
98 test03' a = goto pushSingleLinkedStack (emptySingleLinkedStack , a , (cs id)) |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
101 lemma : {A : Set} {a : A} -> goto (test03 ◎ test02 ◎ test01) a ≡ False |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 lemma = refl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 |
28
67978ba63a6f
Rewrite cs composition style
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
104 |
27
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 {- |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 n-push : {A : Set} {a : A} -> Nat -> SingleLinkedStack A -> SingleLinkedStack A |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 n-push zero s = s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 n-push {A} {a} (suc n) s = pushSingleLinkedStack (n-push {A} {a} n s) a (\s -> s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 n-pop : {A : Set} {a : A} -> Nat -> SingleLinkedStack A -> SingleLinkedStack A |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 n-pop zero s = s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 n-pop {A} {a} (suc n) s = popSingleLinkedStack (n-pop {A} {a} n s) (\s _ -> s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 open ≡-Reasoning |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 push-pop-equiv : {A : Set} {a : A} (s : SingleLinkedStack A) -> popSingleLinkedStack (pushSingleLinkedStack s a (\s -> s)) (\s _ -> s) ≡ s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 push-pop-equiv s = refl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 push-and-n-pop : {A : Set} {a : A} (n : Nat) (s : SingleLinkedStack A) -> n-pop {A} {a} (suc n) (pushSingleLinkedStack s a id) ≡ n-pop {A} {a} n s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 push-and-n-pop zero s = refl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 push-and-n-pop {A} {a} (suc n) s = begin |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 n-pop (suc (suc n)) (pushSingleLinkedStack s a id) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 ≡⟨ refl ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 popSingleLinkedStack (n-pop (suc n) (pushSingleLinkedStack s a id)) (\s _ -> s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 ≡⟨ cong (\s -> popSingleLinkedStack s (\s _ -> s)) (push-and-n-pop n s) ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 popSingleLinkedStack (n-pop n s) (\s _ -> s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 ≡⟨ refl ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 n-pop (suc n) s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 ∎ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 n-push-pop-equiv : {A : Set} {a : A} (n : Nat) (s : SingleLinkedStack A) -> (n-pop {A} {a} n (n-push {A} {a} n s)) ≡ s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 n-push-pop-equiv zero s = refl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 n-push-pop-equiv {A} {a} (suc n) s = begin |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 n-pop (suc n) (n-push (suc n) s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 ≡⟨ refl ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 n-pop (suc n) (pushSingleLinkedStack (n-push n s) a (\s -> s)) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 ≡⟨ push-and-n-pop n (n-push n s) ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 n-pop n (n-push n s) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 ≡⟨ n-push-pop-equiv n s ⟩ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 s |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 ∎ |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 n-push-pop-equiv-empty : {A : Set} {a : A} -> (n : Nat) -> n-pop {A} {a} n (n-push {A} {a} n emptySingleLinkedStack) ≡ emptySingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 n-push-pop-equiv-empty n = n-push-pop-equiv n emptySingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 -} |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 |