src/HOL/Prolog/Func.thy
author wenzelm
Wed Sep 07 21:07:09 2005 +0200 (2005-09-07)
changeset 17311 5b1d47d920ce
parent 14981 e73f8140af78
child 20713 823967ef47f1
permissions -rw-r--r--
converted to Isar theory format;
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@17311
    23
  "and"   :: "tm => tm => tm"       (infixr 999)
wenzelm@17311
    24
  "eq"    :: "tm => tm => tm"       (infixr 999)
oheimb@9015
    25
wenzelm@17311
    26
  "0"     :: 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@17311
    63
ML {* use_legacy_bindings (the_context ()) *}
wenzelm@17311
    64
oheimb@9015
    65
end