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