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