| 1 | %% predefined universe containing all types, |
|---|
| 2 | %% superclass of all other classes |
|---|
| 3 | |
|---|
| 4 | class Type |
|---|
| 5 | |
|---|
| 6 | var s,t : Type |
|---|
| 7 | |
|---|
| 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 9 | %% invisible type "Unit" for formulae |
|---|
| 10 | |
|---|
| 11 | type Unit: Type %% flat cpo with bottom |
|---|
| 12 | |
|---|
| 13 | %% type aliases |
|---|
| 14 | type Pred __ : Type -> Type := \ t: -Type . t ->? Unit |
|---|
| 15 | type ? __ := \ t:Type . Unit ->? t |
|---|
| 16 | |
|---|
| 17 | pred true, false : Unit |
|---|
| 18 | |
|---|
| 19 | preds __/\__, __\/__, __=>__, __if__,__<=>__ : Unit * Unit |
|---|
| 20 | pred not : Unit |
|---|
| 21 | |
|---|
| 22 | pred __=__ : s * s %% =e= |
|---|
| 23 | |
|---|
| 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 25 | %% (builtin) type (constructors) |
|---|
| 26 | |
|---|
| 27 | type __->?__ : -Type -> +Type -> Type |
|---|
| 28 | |
|---|
| 29 | %% nested pairs are different from n-tupels (n > 2) |
|---|
| 30 | type __*__ : +Type -> +Type -> Type |
|---|
| 31 | type __*__*__ : +Type -> +Type -> +Type -> Type |
|---|
| 32 | |
|---|
| 33 | %% ... |
|---|
| 34 | |
|---|
| 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 36 | %% "pred p args = e" abbreviates "op p args :? unit = e" |
|---|
| 37 | %% CASL requires "<=>" for pred-defn and disallows "()" as result |
|---|
| 38 | |
|---|
| 39 | op def, tt : Pred s |
|---|
| 40 | var x : s |
|---|
| 41 | |
|---|
| 42 | program def = \x: s . () %% def is also total (identical to tt) |
|---|
| 43 | |
|---|
| 44 | program tt = \x: s . () %% tt is total "op tt(x: s): unit = ()" |
|---|
| 45 | |
|---|
| 46 | program __und__ (x, y: Unit) : Unit = () |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | %% total function type |
|---|
| 50 | type __->__ : -Type -> +Type -> Type |
|---|
| 51 | |
|---|
| 52 | type __->__ < __ ->? __ |
|---|
| 53 | |
|---|
| 54 | . __ in s -> t = \f: s ->? t . all(\x:s. def f(x)) |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | %% total functions |
|---|
| 58 | op __res__ (x: s; y: t) : s = x |
|---|
| 59 | op fst (x: s; y: t) : s = x |
|---|
| 60 | program snd (x: s, y: t) : t = y |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | %% trivial because its the strict function property |
|---|
| 64 | |
|---|
| 65 | . (\ (x:s, y:t). def (x res y)) = (\ (x:s, y:t). (def y) und (def x)) |
|---|
| 66 | . fst = (__ res__) |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 70 | %% Internal Logic |
|---|
| 71 | |
|---|
| 72 | pred eq : s * s |
|---|
| 73 | |
|---|
| 74 | . (\x: s. eq(x, x)) = tt |
|---|
| 75 | . (\(x, y:s). x res eq(x,y)) = (\(x, y:s). y res eq(x,y)) |
|---|
| 76 | |
|---|
| 77 | %% then %def |
|---|
| 78 | |
|---|
| 79 | %% notation "\ ." abbreviates "\bla:unit." |
|---|
| 80 | %% where "bla" is never used, but only "()" instead |
|---|
| 81 | |
|---|
| 82 | %% for type inference |
|---|
| 83 | %% an implicit cast from s to ?s of a term "e" yields the term "\ . e" |
|---|
| 84 | |
|---|
| 85 | type s < ?s |
|---|
| 86 | |
|---|
| 87 | program all (p: Pred(s)) : Pred Unit = eq(p, tt) |
|---|
| 88 | |
|---|
| 89 | %% the cast from ?s to s is still done manually here (for the strict "und") |
|---|
| 90 | program And (x, y: Pred Unit) : Pred Unit = t1() und t2() |
|---|
| 91 | |
|---|
| 92 | %% use "And" instead of "und" to avoid cast from "?unit" to "unit" |
|---|
| 93 | program __impl__ (x, y: Pred Unit) : Pred Unit = eq(x, x And y) |
|---|
| 94 | |
|---|
| 95 | program __or__ (x, y: Pred Unit) : Pred Unit = all(\r: Pred Unit. |
|---|
| 96 | ((x impl r) und (y impl r)) impl r) |
|---|
| 97 | |
|---|
| 98 | program ex (p: Pred(s)) : Pred Unit = all(\r: Pred Unit. |
|---|
| 99 | all(\x:s. p(x) impl r) impl r) |
|---|
| 100 | |
|---|
| 101 | program ff () : Pred Unit = all(\r: Pred Unit. r()) |
|---|
| 102 | |
|---|
| 103 | program neg (r: Pred Unit) : Pred Unit = r impl ff |
|---|
| 104 | |
|---|
| 105 | %% the type instance for the first "eq" should be "?t" |
|---|
| 106 | %% this is explicitely enforced by "\ .f(x)" |
|---|
| 107 | |
|---|
| 108 | . all(\(f,g): s->?t. all(\x:s. eq(\ . f(x), g(x)) impl eq(f, g))) |
|---|
| 109 | |
|---|
| 110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 111 | %% Recursion (requires "free type nat ::= 0 | Suc(nat)" and "+" |
|---|
| 112 | |
|---|
| 113 | type nat |
|---|
| 114 | |
|---|
| 115 | class Cpo < Type |
|---|
| 116 | { |
|---|
| 117 | var c : Cpo |
|---|
| 118 | |
|---|
| 119 | pred __<<=__ : c * c |
|---|
| 120 | |
|---|
| 121 | . all(\x: c. x <<= x) %(reflexive)% |
|---|
| 122 | . all(\(x,y,z: c). ((x <<= y) und (y <<= z)) impl x <<= z) %(transitive)% |
|---|
| 123 | . all(\(x,y,z: c). ((x <<= y) und (y <<= x)) impl eq(x,y)) %(antisymmetric)% |
|---|
| 124 | |
|---|
| 125 | pred isChain (s: nat -> c) <=> all(\n:nat. s(n) <<= s(Suc(n))) |
|---|
| 126 | pred isBound (x: c; s: nat -> c) <=> all(\n:nat. s(n) <<= x) |
|---|
| 127 | |
|---|
| 128 | op sup : (nat -> c) ->? c |
|---|
| 129 | |
|---|
| 130 | . all(\s: nat -> c. def(sup s) impl |
|---|
| 131 | (isBound(sup s, s) und all(\x:c. isBound(x, s) impl sup(s) <<= x))) |
|---|
| 132 | %(sup is minimally bound)% |
|---|
| 133 | |
|---|
| 134 | . all(\s:nat -> c. isChain(s) impl def(sup(s))) %(sup exists)% |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | class Pcpo < Cpo |
|---|
| 138 | { |
|---|
| 139 | var p : Pcpo |
|---|
| 140 | |
|---|
| 141 | op bottom : p |
|---|
| 142 | |
|---|
| 143 | . all(\x : p. bottom <<= x) |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | class instance Flatcpo < Cpo |
|---|
| 147 | { |
|---|
| 148 | var f : Flatcpo |
|---|
| 149 | |
|---|
| 150 | program __<<=[f]__ = eq |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | var c, d: Cpo |
|---|
| 154 | |
|---|
| 155 | type instance __*__ : +Cpo -> +Cpo -> Cpo |
|---|
| 156 | |
|---|
| 157 | var x1,x2 : c; y1, y2 : d |
|---|
| 158 | |
|---|
| 159 | program (x1, y1) <<= (x2, y2) = (x1 <<= x2) und (y1 <<= y2) |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | type instance __*__ : +Pcpo -> +Pcpo -> Pcpo |
|---|
| 163 | |
|---|
| 164 | type Unit : Pcpo |
|---|
| 165 | |
|---|
| 166 | %% Pcont |
|---|
| 167 | type instance __-->?__ : -Cpo -> +Cpo -> Pcpo |
|---|
| 168 | |
|---|
| 169 | type __-->?__ < __->?__ |
|---|
| 170 | . __ in c -->? d = \f : c ->? d . |
|---|
| 171 | all(\(x,y: c). (def (f x) und x <<= y) impl def (f y)) und |
|---|
| 172 | all(\s: nat -> c. (isChain(s) und def f(sup(s))) impl |
|---|
| 173 | ex(\m:nat. def f(s(m)) und |
|---|
| 174 | eq(sup(\n:nat.!f(s(n+m))), f(sup(s))))) |
|---|
| 175 | |
|---|
| 176 | program f <<=[c -->? d] g = all(\x:c. def (f x) impl f(x) <<= g(x)) |
|---|
| 177 | |
|---|
| 178 | %% Tcont |
|---|
| 179 | type instance __-->__ : -Cpo -> +Cpo -> Cpo |
|---|
| 180 | |
|---|
| 181 | type __-->__ < __-->?__ |
|---|
| 182 | . __ in c --> d = \f : c -->? d . all(\x:c. def f(x)) |
|---|
| 183 | |
|---|
| 184 | var f, g : c --> d |
|---|
| 185 | |
|---|
| 186 | program f <<= g = f <<=[c -->? d] g |
|---|
| 187 | |
|---|
| 188 | type instance __-->__ : -Cpo -> +Pcpo -> Pcpo |
|---|
| 189 | |
|---|
| 190 | fun Y : (p --> p) --> p |
|---|
| 191 | |
|---|
| 192 | . all(\f: p -->? p . eq(f(Y(f)), Y(f)) und |
|---|
| 193 | all(\x:p . eq(f(x), x) impl Y(f) <<= x)) |
|---|
| 194 | |
|---|
| 195 | var f : p --> p; x : p |
|---|
| 196 | . f(Y(f)) = Y(f) |
|---|
| 197 | . f(x) = x => Y(f) <<= x |
|---|
| 198 | |
|---|
| 199 | op undefined : c --> p = Y((\x': c --> p . x') as (c --> p) --> c --> p) |
|---|
| 200 | |
|---|
| 201 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 202 | %% user stuff |
|---|
| 203 | |
|---|
| 204 | free type bool ::= true | false |
|---|
| 205 | |
|---|
| 206 | type bool : Flatcpo |
|---|
| 207 | type nat : Flatcpo |
|---|
| 208 | |
|---|