Mercurial > hg > Members > atton > agda-proofs
annotate cbc/stack-product.agda @ 27:892f8b3aa57e
ReWrite stack.agda using product type definition
author | atton <atton@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 23 Dec 2016 10:20:05 +0000 |
parents | |
children | 67978ba63a6f |
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 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 open import Relation.Binary.PropositionalEquality |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 -- 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
|
8 goto = executeCS |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 data Bool : Set where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 True : Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 False : Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 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
|
15 Nothing : Maybe a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 Just : a -> Maybe a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
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 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
|
20 field |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 stack : stackImpl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 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
|
23 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
|
24 |
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 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
|
27 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
|
28 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 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
|
30 datum (cons a _) = a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 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
|
33 next (cons _ n) = n |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 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
|
36 field |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 top : Maybe (Element a) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 open SingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 emptySingleLinkedStack : {a : Set} -> SingleLinkedStack a |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 emptySingleLinkedStack = record {top = Nothing} |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 |
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 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
|
47 pushSingleLinkedStack = cs push |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 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
|
50 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
|
51 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 element = cons datum (top stack) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 stack1 = record {top = Just element} |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 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
|
56 popSingleLinkedStack = cs pop |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 datum1 = datum x |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63 stack1 = record { top = (next x) } |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 |
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 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
|
70 createSingleLinkedStack = record { stack = emptySingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 ; push = pushSingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 ; pop = popSingleLinkedStack |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } |
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 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
|
79 test01 = cs test01' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 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
|
82 test01' (record { top = Nothing } , _) = False |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 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
|
84 |
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 test02 : {a : Set} -> CodeSegment (SingleLinkedStack a) Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 test02 = cs test02' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 test02' : {a : Set} -> SingleLinkedStack a -> Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 test02' stack = goto popSingleLinkedStack (stack , test01) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 |
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 test03 : {a : Set} -> CodeSegment a Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 test03 = cs test03' |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 where |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 test03' : {a : Set} -> a -> Bool |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 test03' a = goto pushSingleLinkedStack (emptySingleLinkedStack , a , test02) |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 |
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 lemma : {A : Set} {a : A} -> goto test03 a ≡ False |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 lemma = refl |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 id : {A : Set} -> A -> A |
892f8b3aa57e
ReWrite stack.agda using product type definition
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 id a = a |
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 |