src/HOL/Prolog/Func.thy
author wenzelm
Sat Dec 01 18:52:32 2001 +0100 (2001-12-01)
changeset 12338 de0f4a63baa5
parent 9015 8006e9009621
child 13208 965f95a3abd9
permissions -rw-r--r--
renamed class "term" to "type" (actually "HOL.type");
     1 (* untyped functional language, with call by value semantics *)
     2 
     3 Func = HOHH +
     4 
     5 types tm
     6 
     7 arities tm :: type
     8 
     9 consts	abs	:: (tm => tm) => tm
    10 	app	:: tm => tm => tm
    11 
    12 	cond	:: tm => tm => tm => tm
    13 	fix	:: (tm => tm) => tm
    14 
    15 	true,
    16 	false	:: tm
    17 	"and"	:: tm => tm => tm	(infixr 999)
    18 	"eq"	:: tm => tm => tm	(infixr 999)
    19 
    20 	"0"	:: tm			("Z")
    21 	S	:: tm => tm
    22 (*
    23 	"++", "--",
    24 	"**"	:: tm => tm => tm	(infixr 999)
    25 *)
    26 	eval	:: [tm, tm] => bool
    27 
    28 arities tm :: plus
    29 arities tm :: minus
    30 arities tm :: times
    31 
    32 rules	eval "
    33 
    34 eval (abs RR) (abs RR)..
    35 eval (app F X) V :- eval F (abs R) & eval X U & eval (R U) V..
    36 
    37 eval (cond P L1 R1) D1 :- eval P true  & eval L1 D1..
    38 eval (cond P L2 R2) D2 :- eval P false & eval R2 D2..
    39 eval (fix G) W   :- eval (G (fix G)) W..
    40 
    41 eval true  true ..
    42 eval false false..
    43 eval (P and Q) true  :- eval P true  & eval Q true ..
    44 eval (P and Q) false :- eval P false | eval Q false..
    45 eval (A1 eq B1) true  :- eval A1 C1 & eval B1 C1.. 
    46 eval (A2 eq B2) false :- True..
    47 
    48 eval Z Z..
    49 eval (S N) (S M) :- eval N M..
    50 eval ( Z    + M) K     :- eval      M  K..
    51 eval ((S N) + M) (S K) :- eval (N + M) K..
    52 eval (N     - Z) K     :- eval  N      K..
    53 eval ((S N) - (S M)) K :- eval (N- M)  K..
    54 eval ( Z    * M) Z..
    55 eval ((S N) * M) K :- eval (N * M) L & eval (L + M) K"
    56 
    57 end