Debian Codegraph @

doc/examples/list.mod

raw
1 -- FILE: /home/diacon/LANG/Cafe/prog/list.mod
2 -- CONTENTS: ADT specification of lists featuring an induction proof
3 -- AUTHOR: Razvan Diaconescu
4 -- DIFFICULTY: *
5
6 -- lists of naturals
7 mod! LIST-NAT {
8 protecting(NAT)
9
10 [ NList < List ]
11
12 op nil : -> List
13 op _._ : Nat List -> NList
14 op car_ : NList -> Nat
15 op cdr_ : NList -> List
16
17 var L : List
18 var N : Nat
19
20 eq car (N . L) = N .
21 eq cdr (N . L) = L .
22 }
23
24 -- lists with append function
25 mod! LISTA {
26 protecting(LIST-NAT)
27
28 op _+_ : List List -> List
29
30 eq nil + L:List = L .
31 eq (N:Nat . L:List) + L':List = (N . (L + L')) .
32 }
33
34 --> proof of associativity of append (_+_)
35 open LISTA .
36 ops l l' l'' : -> List .
37 ops m n p : -> Nat .
38 --> base case
39 red nil + (l + l') == (nil + l) + l' .
40 --> induction hypothesis
41 eq l + (l' + l'') = (l + l') + l'' .
42 --> conclusion
43 red (n . l) + (l' + l'') == ((n . l) + l') + l'' .
44 close
45
46 --
47 eof
48 --
49 $Id: list.mod,v 1.1.1.1 2003-06-19 08:30:10 sawada Exp $