src/HOL/Prolog/Func.thy
author wenzelm
Fri Apr 23 23:35:43 2010 +0200 (2010-04-23)
changeset 36319 8feb2c4bef1a
parent 35301 90e42f9ba4d1
child 58889 5b7a9633cfa8
permissions -rw-r--r--
mark schematic statements explicitly;
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@35301
     8
imports HOHH
wenzelm@17311
     9
begin
oheimb@9015
    10
wenzelm@17311
    11
typedecl tm
oheimb@9015
    12
haftmann@35265
    13
axiomatization
haftmann@35265
    14
  abs     :: "(tm \<Rightarrow> tm) \<Rightarrow> tm" and
haftmann@35265
    15
  app     :: "tm \<Rightarrow> tm \<Rightarrow> tm" and
wenzelm@17311
    16
haftmann@35265
    17
  cond    :: "tm \<Rightarrow> tm \<Rightarrow> tm \<Rightarrow> tm" and
haftmann@35265
    18
  "fix"   :: "(tm \<Rightarrow> tm) \<Rightarrow> tm" and
oheimb@9015
    19
haftmann@35265
    20
  true    :: tm and
haftmann@35265
    21
  false   :: tm and
haftmann@35265
    22
  "and"   :: "tm \<Rightarrow> tm \<Rightarrow> tm"       (infixr "and" 999) and
haftmann@35265
    23
  eq      :: "tm \<Rightarrow> tm \<Rightarrow> tm"       (infixr "eq" 999) and
haftmann@35265
    24
haftmann@35265
    25
  Z       :: tm                     ("Z") and
haftmann@35265
    26
  S       :: "tm \<Rightarrow> tm" and
oheimb@9015
    27
haftmann@35265
    28
  plus    :: "tm \<Rightarrow> tm \<Rightarrow> tm"       (infixl "+" 65) and
haftmann@35265
    29
  minus   :: "tm \<Rightarrow> tm \<Rightarrow> tm"       (infixl "-" 65) and
haftmann@35265
    30
  times   :: "tm \<Rightarrow> tm \<Rightarrow> tm"       (infixl "*" 70) and
oheimb@9015
    31
haftmann@35265
    32
  eval    :: "tm \<Rightarrow> tm \<Rightarrow> bool" where
haftmann@35265
    33
haftmann@35265
    34
eval: "
oheimb@9015
    35
oheimb@9015
    36
eval (abs RR) (abs RR)..
oheimb@9015
    37
eval (app F X) V :- eval F (abs R) & eval X U & eval (R U) V..
oheimb@9015
    38
oheimb@9015
    39
eval (cond P L1 R1) D1 :- eval P true  & eval L1 D1..
oheimb@9015
    40
eval (cond P L2 R2) D2 :- eval P false & eval R2 D2..
oheimb@9015
    41
eval (fix G) W   :- eval (G (fix G)) W..
oheimb@9015
    42
oheimb@9015
    43
eval true  true ..
oheimb@9015
    44
eval false false..
oheimb@9015
    45
eval (P and Q) true  :- eval P true  & eval Q true ..
oheimb@9015
    46
eval (P and Q) false :- eval P false | eval Q false..
wenzelm@17311
    47
eval (A1 eq B1) true  :- eval A1 C1 & eval B1 C1..
oheimb@9015
    48
eval (A2 eq B2) false :- True..
oheimb@9015
    49
oheimb@9015
    50
eval Z Z..
oheimb@9015
    51
eval (S N) (S M) :- eval N M..
oheimb@9015
    52
eval ( Z    + M) K     :- eval      M  K..
oheimb@9015
    53
eval ((S N) + M) (S K) :- eval (N + M) K..
oheimb@9015
    54
eval (N     - Z) K     :- eval  N      K..
oheimb@9015
    55
eval ((S N) - (S M)) K :- eval (N- M)  K..
oheimb@9015
    56
eval ( Z    * M) Z..
oheimb@9015
    57
eval ((S N) * M) K :- eval (N * M) L & eval (L + M) K"
oheimb@9015
    58
wenzelm@21425
    59
lemmas prog_Func = eval
wenzelm@21425
    60
wenzelm@36319
    61
schematic_lemma "eval ((S (S Z)) + (S Z)) ?X"
wenzelm@21425
    62
  apply (prolog prog_Func)
wenzelm@21425
    63
  done
wenzelm@21425
    64
wenzelm@36319
    65
schematic_lemma "eval (app (fix (%fact. abs(%n. cond (n eq Z) (S Z)
wenzelm@21425
    66
                        (n * (app fact (n - (S Z))))))) (S (S (S Z)))) ?X"
wenzelm@21425
    67
  apply (prolog prog_Func)
wenzelm@21425
    68
  done
wenzelm@17311
    69
oheimb@9015
    70
end