src/HOL/Prolog/Func.thy
author haftmann
Thu, 28 Jan 2010 11:48:49 +0100
changeset 34974 18b41bba42b5
parent 21425 c11ab38b78a7
child 35265 3fd8c3edf639
permissions -rw-r--r--
new theory Algebras.thy for generic algebraic structures
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13208
965f95a3abd9 added the usual file headers
oheimb
parents: 12338
diff changeset
     1
(*  Title:    HOL/Prolog/Func.thy
965f95a3abd9 added the usual file headers
oheimb
parents: 12338
diff changeset
     2
    Author:   David von Oheimb (based on a lecture on Lambda Prolog by Nadathur)
965f95a3abd9 added the usual file headers
oheimb
parents: 12338
diff changeset
     3
*)
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
     4
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     5
header {* Untyped functional language, with call by value semantics *}
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
     6
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     7
theory Func
34974
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 21425
diff changeset
     8
imports HOHH Algebras
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
     9
begin
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    10
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    11
typedecl tm
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    12
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    13
consts
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    14
  abs     :: "(tm => tm) => tm"
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    15
  app     :: "tm => tm => tm"
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    16
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    17
  cond    :: "tm => tm => tm => tm"
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    18
  "fix"   :: "(tm => tm) => tm"
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    19
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    20
  true    :: tm
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    21
  false   :: tm
21425
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    22
  "and"   :: "tm => tm => tm"       (infixr "and" 999)
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    23
  eq      :: "tm => tm => tm"       (infixr "eq" 999)
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    24
20713
823967ef47f1 renamed 0 and 1 to HOL.zero and HOL.one respectivly; introduced corresponding syntactic classes
haftmann
parents: 17311
diff changeset
    25
  Z       :: tm                     ("Z")
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    26
  S       :: "tm => tm"
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    27
(*
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    28
        "++", "--",
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    29
        "**"    :: tm => tm => tm       (infixr 999)
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    30
*)
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    31
        eval    :: "[tm, tm] => bool"
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    32
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    33
instance tm :: plus ..
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    34
instance tm :: minus ..
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    35
instance tm :: times ..
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    36
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    37
axioms   eval: "
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    38
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    39
eval (abs RR) (abs RR)..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    40
eval (app F X) V :- eval F (abs R) & eval X U & eval (R U) V..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    41
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    42
eval (cond P L1 R1) D1 :- eval P true  & eval L1 D1..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    43
eval (cond P L2 R2) D2 :- eval P false & eval R2 D2..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    44
eval (fix G) W   :- eval (G (fix G)) W..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    45
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    46
eval true  true ..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    47
eval false false..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    48
eval (P and Q) true  :- eval P true  & eval Q true ..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    49
eval (P and Q) false :- eval P false | eval Q false..
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    50
eval (A1 eq B1) true  :- eval A1 C1 & eval B1 C1..
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    51
eval (A2 eq B2) false :- True..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    52
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    53
eval Z Z..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    54
eval (S N) (S M) :- eval N M..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    55
eval ( Z    + M) K     :- eval      M  K..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    56
eval ((S N) + M) (S K) :- eval (N + M) K..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    57
eval (N     - Z) K     :- eval  N      K..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    58
eval ((S N) - (S M)) K :- eval (N- M)  K..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    59
eval ( Z    * M) Z..
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    60
eval ((S N) * M) K :- eval (N * M) L & eval (L + M) K"
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    61
21425
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    62
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    63
lemmas prog_Func = eval
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    64
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    65
lemma "eval ((S (S Z)) + (S Z)) ?X"
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    66
  apply (prolog prog_Func)
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    67
  done
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    68
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    69
lemma "eval (app (fix (%fact. abs(%n. cond (n eq Z) (S Z)
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    70
                        (n * (app fact (n - (S Z))))))) (S (S (S Z)))) ?X"
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    71
  apply (prolog prog_Func)
c11ab38b78a7 HOL-Prolog: converted legacy ML scripts;
wenzelm
parents: 20713
diff changeset
    72
  done
17311
5b1d47d920ce converted to Isar theory format;
wenzelm
parents: 14981
diff changeset
    73
9015
8006e9009621 added HOL/Prolog
oheimb
parents:
diff changeset
    74
end