src/HOL/ex/Eval_Examples.thy
author haftmann
Mon, 08 Oct 2007 22:03:28 +0200
changeset 24916 dc56dd1b3cda
parent 24835 8c26128f8997
child 25099 b2c19b9964db
permissions -rw-r--r--
simplified evaluation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     1
(*  ID:         $Id$
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     3
*)
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     4
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     5
header {* Small examples for evaluation mechanisms *}
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     6
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     7
theory Eval_Examples
24659
6b7ac2a43df8 more permissive
haftmann
parents: 24587
diff changeset
     8
imports Eval "~~/src/HOL/Real/Rational"
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     9
begin
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    10
24292
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    11
text {* SML evaluation oracle *}
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    12
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    13
lemma "True \<or> False" by evaluation
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    14
lemma "\<not> (Suc 0 = Suc 1)" by evaluation
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    15
lemma "[] = ([]\<Colon> int list)" by evaluation
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    16
lemma "[()] = [()]" by evaluation
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    17
lemma "fst ([]::nat list, Suc 0) = []" by evaluation
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    18
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    19
text {* evaluation oracle *}
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    20
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    21
lemma "True \<or> False" by eval
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    22
lemma "\<not> (Suc 0 = Suc 1)" by eval
24280
c9867bdf2424 updated code generator setup
haftmann
parents: 23268
diff changeset
    23
lemma "[] = ([]\<Colon> int list)" by eval
c9867bdf2424 updated code generator setup
haftmann
parents: 23268
diff changeset
    24
lemma "[()] = [()]" by eval
24292
26ac9fe0e80e added evaluation examples
haftmann
parents: 24280
diff changeset
    25
lemma "fst ([]::nat list, Suc 0) = []" by eval
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    26
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    27
text {* term evaluation *}
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    28
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    29
value "(Suc 2 + 1) * 4"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    30
value (code) "(Suc 2 + 1) * 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    31
value (SML) "(Suc 2 + 1) * 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    32
value ("normal_form") "(Suc 2 + 1) * 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    33
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    34
value "(Suc 2 + Suc 0) * Suc 3"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    35
value (code) "(Suc 2 + Suc 0) * Suc 3"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    36
value (SML) "(Suc 2 + Suc 0) * Suc 3"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    37
value ("normal_form") "(Suc 2 + Suc 0) * Suc 3"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    38
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    39
value "nat 100"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    40
value (code) "nat 100"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    41
value (SML) "nat 100"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    42
value ("normal_form") "nat 100"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    43
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    44
value "(10\<Colon>int) \<le> 12"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    45
value (code) "(10\<Colon>int) \<le> 12"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    46
value (SML) "(10\<Colon>int) \<le> 12"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    47
value ("normal_form") "(10\<Colon>int) \<le> 12"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    48
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    49
value "max (2::int) 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    50
value (code) "max (2::int) 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    51
value (SML) "max (2::int) 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    52
value ("normal_form") "max (2::int) 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    53
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    54
value "of_int 2 / of_int 4 * (1::rat)"
24916
dc56dd1b3cda simplified evaluation
haftmann
parents: 24835
diff changeset
    55
(*value (code) "of_int 2 / of_int 4 * (1::rat)"*)
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    56
value (SML) "of_int 2 / of_int 4 * (1::rat)"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    57
value ("normal_form") "of_int 2 / of_int 4 * (1::rat)"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    58
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    59
value "[]::nat list"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    60
value (code) "[]::nat list"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    61
(*value (SML) "[]::nat list" FIXME*)
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    62
value ("normal_form") "[]::nat list"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    63
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    64
value "[(nat 100, ())]"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    65
value (code) "[(nat 100, ())]"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    66
(*value (SML) "[(nat 100, ())]" FIXME*)
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    67
value ("normal_form") "[(nat 100, ())]"
24659
6b7ac2a43df8 more permissive
haftmann
parents: 24587
diff changeset
    68
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    69
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    70
text {* a fancy datatype *}
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    71
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    72
datatype ('a, 'b) bair =
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    73
    Bair "'a\<Colon>order" 'b
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    74
  | Shift "('a, 'b) cair"
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    75
  | Dummy unit
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    76
and ('a, 'b) cair =
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    77
    Cair 'a 'b
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    78
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    79
value "Shift (Cair (4::nat) [Suc 0])"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    80
value (code) "Shift (Cair (4::nat) [Suc 0])"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    81
value (SML) "Shift (Cair (4::nat) [Suc 0])"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    82
value ("normal_form") "Shift (Cair (4::nat) [Suc 0])"
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    83
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    84
end