src/HOL/Prolog/Func.thy
author haftmann
Fri Apr 20 11:21:42 2007 +0200 (2007-04-20)
changeset 22744 5cbe966d67a2
parent 21425 c11ab38b78a7
child 34974 18b41bba42b5
permissions -rw-r--r--
Isar definitions are now added explicitly to code theorem table
     1 (*  Title:    HOL/Prolog/Func.thy
     2     ID:       $Id$
     3     Author:   David von Oheimb (based on a lecture on Lambda Prolog by Nadathur)
     4 *)
     5 
     6 header {* Untyped functional language, with call by value semantics *}
     7 
     8 theory Func
     9 imports HOHH
    10 begin
    11 
    12 typedecl tm
    13 
    14 consts
    15   abs     :: "(tm => tm) => tm"
    16   app     :: "tm => tm => tm"
    17 
    18   cond    :: "tm => tm => tm => tm"
    19   "fix"   :: "(tm => tm) => tm"
    20 
    21   true    :: tm
    22   false   :: tm
    23   "and"   :: "tm => tm => tm"       (infixr "and" 999)
    24   eq      :: "tm => tm => tm"       (infixr "eq" 999)
    25 
    26   Z       :: tm                     ("Z")
    27   S       :: "tm => tm"
    28 (*
    29         "++", "--",
    30         "**"    :: tm => tm => tm       (infixr 999)
    31 *)
    32         eval    :: "[tm, tm] => bool"
    33 
    34 instance tm :: plus ..
    35 instance tm :: minus ..
    36 instance tm :: times ..
    37 
    38 axioms   eval: "
    39 
    40 eval (abs RR) (abs RR)..
    41 eval (app F X) V :- eval F (abs R) & eval X U & eval (R U) V..
    42 
    43 eval (cond P L1 R1) D1 :- eval P true  & eval L1 D1..
    44 eval (cond P L2 R2) D2 :- eval P false & eval R2 D2..
    45 eval (fix G) W   :- eval (G (fix G)) W..
    46 
    47 eval true  true ..
    48 eval false false..
    49 eval (P and Q) true  :- eval P true  & eval Q true ..
    50 eval (P and Q) false :- eval P false | eval Q false..
    51 eval (A1 eq B1) true  :- eval A1 C1 & eval B1 C1..
    52 eval (A2 eq B2) false :- True..
    53 
    54 eval Z Z..
    55 eval (S N) (S M) :- eval N M..
    56 eval ( Z    + M) K     :- eval      M  K..
    57 eval ((S N) + M) (S K) :- eval (N + M) K..
    58 eval (N     - Z) K     :- eval  N      K..
    59 eval ((S N) - (S M)) K :- eval (N- M)  K..
    60 eval ( Z    * M) Z..
    61 eval ((S N) * M) K :- eval (N * M) L & eval (L + M) K"
    62 
    63 
    64 lemmas prog_Func = eval
    65 
    66 lemma "eval ((S (S Z)) + (S Z)) ?X"
    67   apply (prolog prog_Func)
    68   done
    69 
    70 lemma "eval (app (fix (%fact. abs(%n. cond (n eq Z) (S Z)
    71                         (n * (app fact (n - (S Z))))))) (S (S (S Z)))) ?X"
    72   apply (prolog prog_Func)
    73   done
    74 
    75 end