src/HOL/ex/Eval_Examples.thy
author wenzelm
Fri, 23 Nov 2018 16:43:11 +0100
changeset 69334 6b49700da068
parent 61343 5b5656a63bd6
permissions -rw-r--r--
clarified font_domain: strict excludes e.g. space character;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30021
19c06d4763e0 stripped Id
haftmann
parents: 28952
diff changeset
     1
(* Author: Florian Haftmann, TU Muenchen *)
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     2
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 61076
diff changeset
     3
section \<open>Small examples for evaluation mechanisms\<close>
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     4
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     5
theory Eval_Examples
32067
e425fe0ff24a more canonical import
haftmann
parents: 30021
diff changeset
     6
imports Complex_Main
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     7
begin
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
     8
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 61076
diff changeset
     9
text \<open>evaluation oracle\<close>
25099
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    10
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    11
lemma "True \<or> False" by eval
40760
haftmann
parents: 40757
diff changeset
    12
lemma "Suc 0 \<noteq> Suc 1" by eval
haftmann
parents: 40757
diff changeset
    13
lemma "[] = ([] :: int list)" by eval
25099
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    14
lemma "[()] = [()]" by eval
40760
haftmann
parents: 40757
diff changeset
    15
lemma "fst ([] :: nat list, Suc 0) = []" by eval
25099
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    16
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 61076
diff changeset
    17
text \<open>normalization\<close>
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    18
25099
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    19
lemma "True \<or> False" by normalization
40760
haftmann
parents: 40757
diff changeset
    20
lemma "Suc 0 \<noteq> Suc 1" by normalization
haftmann
parents: 40757
diff changeset
    21
lemma "[] = ([] :: int list)" by normalization
25099
b2c19b9964db lemmas with normalization
haftmann
parents: 24916
diff changeset
    22
lemma "[()] = [()]" by normalization
40760
haftmann
parents: 40757
diff changeset
    23
lemma "fst ([] :: nat list, Suc 0) = []" by normalization
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    24
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 61076
diff changeset
    25
text \<open>term evaluation\<close>
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    26
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    27
value "(Suc 2 + 1) * 4"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    28
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    29
value "(Suc 2 + Suc 0) * Suc 3"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    30
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    31
value "nat 100"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    32
40760
haftmann
parents: 40757
diff changeset
    33
value "(10::int) \<le> 12"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    34
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    35
value "max (2::int) 4"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    36
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    37
value "of_int 2 / of_int 4 * (1::rat)"
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    38
40760
haftmann
parents: 40757
diff changeset
    39
value "[] :: nat list"
24835
8c26128f8997 clarified relationship of code generator conversions and evaluations
haftmann
parents: 24659
diff changeset
    40
24587
4f2cbf6e563f multi-functional value keyword
haftmann
parents: 24423
diff changeset
    41
value "[(nat 100, ())]"
24659
6b7ac2a43df8 more permissive
haftmann
parents: 24587
diff changeset
    42
61343
5b5656a63bd6 isabelle update_cartouches;
wenzelm
parents: 61076
diff changeset
    43
text \<open>a fancy datatype\<close>
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    44
58310
91ea607a34d8 updated news
blanchet
parents: 58249
diff changeset
    45
datatype ('a, 'b) foo =
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 58889
diff changeset
    46
    Foo "'a::order" 'b
40757
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    47
  | Bla "('a, 'b) bar"
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    48
  | Dummy nat
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    49
and ('a, 'b) bar =
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    50
    Bar 'a 'b
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    51
  | Blubb "('a, 'b) foo"
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    52
40757
b469a373df31 tuned example
haftmann
parents: 32067
diff changeset
    53
value "Bla (Bar (4::nat) [Suc 0])"
23268
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    54
572a483de1b0 renamed ex/Eval_Examples.thy;
wenzelm
parents:
diff changeset
    55
end