src/HOL/Code_Setup.thy
author haftmann
Thu, 09 Oct 2008 08:47:27 +0200
changeset 28537 1e84256d1a8a
parent 28512 f29fecd6ddaa
child 28562 4e74209f113e
permissions -rw-r--r--
established canonical argument order in SML code generators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Code_Setup.thy
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     2
    ID:         $Id$
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     4
*)
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     5
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
     6
header {* Setup of code generators and related tools *}
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     7
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     8
theory Code_Setup
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
     9
imports HOL
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    10
begin
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    11
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    12
subsection {* Generic code generator foundation *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    13
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    14
text {* Datatypes *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    15
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    16
code_datatype True False
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    17
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    18
code_datatype "TYPE('a\<Colon>{})"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    19
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    20
code_datatype Trueprop "prop"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    21
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    22
text {* Code equations *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    23
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    24
lemma [code func]:
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    25
  shows "False \<and> x \<longleftrightarrow> False"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    26
    and "True \<and> x \<longleftrightarrow> x"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    27
    and "x \<and> False \<longleftrightarrow> False"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    28
    and "x \<and> True \<longleftrightarrow> x" by simp_all
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    29
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    30
lemma [code func]:
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    31
  shows "False \<or> x \<longleftrightarrow> x"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    32
    and "True \<or> x \<longleftrightarrow> True"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    33
    and "x \<or> False \<longleftrightarrow> x"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    34
    and "x \<or> True \<longleftrightarrow> True" by simp_all
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    35
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    36
lemma [code func]:
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    37
  shows "\<not> True \<longleftrightarrow> False"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    38
    and "\<not> False \<longleftrightarrow> True" by (rule HOL.simp_thms)+
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    39
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    40
lemmas [code func] = Let_def if_True if_False
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    41
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    42
lemmas [code func, code unfold, symmetric, code post] = imp_conv_disj
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    43
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    44
text {* Equality *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    45
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    46
context eq
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
    47
begin
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
    48
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    49
lemma equals_eq [code inline, code func]: "op = \<equiv> eq"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    50
  by (rule eq_reflection) (rule ext, rule ext, rule sym, rule eq_equals)
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    51
28512
f29fecd6ddaa corrected SML undefined
haftmann
parents: 28400
diff changeset
    52
declare eq [code unfold, code inline del]
f29fecd6ddaa corrected SML undefined
haftmann
parents: 28400
diff changeset
    53
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    54
declare equals_eq [symmetric, code post]
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    55
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    56
end
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    57
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    58
declare simp_thms(6) [code nbe]
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    59
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    60
hide (open) const eq
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    61
hide const eq
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    62
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    63
setup {*
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    64
  Code_Unit.add_const_alias @{thm equals_eq}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    65
*}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    66
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    67
text {* Cases *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    68
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    69
lemma Let_case_cert:
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    70
  assumes "CASE \<equiv> (\<lambda>x. Let x f)"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    71
  shows "CASE x \<equiv> f x"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    72
  using assms by simp_all
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    73
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    74
lemma If_case_cert:
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    75
  includes meta_conjunction_syntax
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    76
  assumes "CASE \<equiv> (\<lambda>b. If b f g)"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    77
  shows "(CASE True \<equiv> f) && (CASE False \<equiv> g)"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    78
  using assms by simp_all
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    79
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    80
setup {*
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    81
  Code.add_case @{thm Let_case_cert}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    82
  #> Code.add_case @{thm If_case_cert}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    83
  #> Code.add_undefined @{const_name undefined}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    84
*}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    85
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    86
code_abort undefined
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    87
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    88
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    89
subsection {* Generic code generator preprocessor *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    90
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    91
setup {*
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    92
  Code.map_pre (K HOL_basic_ss)
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    93
  #> Code.map_post (K HOL_basic_ss)
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    94
*}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    95
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
    96
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    97
subsection {* Generic code generator target languages *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    98
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
    99
text {* type bool *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   100
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   101
code_type bool
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   102
  (SML "bool")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   103
  (OCaml "bool")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   104
  (Haskell "Bool")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   105
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   106
code_const True and False and Not and "op &" and "op |" and If
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   107
  (SML "true" and "false" and "not"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   108
    and infixl 1 "andalso" and infixl 0 "orelse"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   109
    and "!(if (_)/ then (_)/ else (_))")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   110
  (OCaml "true" and "false" and "not"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   111
    and infixl 4 "&&" and infixl 2 "||"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   112
    and "!(if (_)/ then (_)/ else (_))")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   113
  (Haskell "True" and "False" and "not"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   114
    and infixl 3 "&&" and infixl 2 "||"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   115
    and "!(if (_)/ then (_)/ else (_))")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   116
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   117
code_reserved SML
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   118
  bool true false not
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   119
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   120
code_reserved OCaml
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   121
  bool not
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   122
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   123
text {* using built-in Haskell equality *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   124
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   125
code_class eq
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   126
  (Haskell "Eq" where "eq_class.eq" \<equiv> "(==)")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   127
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   128
code_const "eq_class.eq"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   129
  (Haskell infixl 4 "==")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   130
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   131
code_const "op ="
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   132
  (Haskell infixl 4 "==")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   133
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   134
text {* undefined *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   135
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   136
code_const undefined
28512
f29fecd6ddaa corrected SML undefined
haftmann
parents: 28400
diff changeset
   137
  (SML "!(raise/ Fail/ \"undefined\")")
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   138
  (OCaml "failwith/ \"undefined\"")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   139
  (Haskell "error/ \"undefined\"")
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   140
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   141
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   142
subsection {* SML code generator setup *}
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   143
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   144
types_code
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   145
  "bool"  ("bool")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   146
attach (term_of) {*
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   147
fun term_of_bool b = if b then HOLogic.true_const else HOLogic.false_const;
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   148
*}
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   149
attach (test) {*
25885
6fbc3f54f819 New interface for test data generators.
berghofe
parents: 25866
diff changeset
   150
fun gen_bool i =
6fbc3f54f819 New interface for test data generators.
berghofe
parents: 25866
diff changeset
   151
  let val b = one_of [false, true]
6fbc3f54f819 New interface for test data generators.
berghofe
parents: 25866
diff changeset
   152
  in (b, fn () => term_of_bool b) end;
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   153
*}
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   154
  "prop"  ("bool")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   155
attach (term_of) {*
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   156
fun term_of_prop b =
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   157
  HOLogic.mk_Trueprop (if b then HOLogic.true_const else HOLogic.false_const);
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   158
*}
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   159
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   160
consts_code
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   161
  "Trueprop" ("(_)")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   162
  "True"    ("true")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   163
  "False"   ("false")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   164
  "Not"     ("Bool.not")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   165
  "op |"    ("(_ orelse/ _)")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   166
  "op &"    ("(_ andalso/ _)")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   167
  "If"      ("(if _/ then _/ else _)")
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   168
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   169
setup {*
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   170
let
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   171
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   172
fun eq_codegen thy defs dep thyname b t gr =
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   173
    (case strip_comb t of
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   174
       (Const ("op =", Type (_, [Type ("fun", _), _])), _) => NONE
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   175
     | (Const ("op =", _), [t, u]) =>
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   176
          let
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   177
            val (pt, gr') = Codegen.invoke_codegen thy defs dep thyname false t gr;
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   178
            val (pu, gr'') = Codegen.invoke_codegen thy defs dep thyname false u gr';
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   179
            val (_, gr''') = Codegen.invoke_tycodegen thy defs dep thyname false HOLogic.boolT gr'';
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   180
          in
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   181
            SOME (Codegen.parens
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   182
              (Pretty.block [pt, Codegen.str " =", Pretty.brk 1, pu]), gr''')
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   183
          end
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   184
     | (t as Const ("op =", _), ts) => SOME (Codegen.invoke_codegen
28537
1e84256d1a8a established canonical argument order in SML code generators
haftmann
parents: 28512
diff changeset
   185
         thy defs dep thyname b (Codegen.eta_expand t ts 2) gr)
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   186
     | _ => NONE);
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   187
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   188
in
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   189
  Codegen.add_codegen "eq_codegen" eq_codegen
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   190
end
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   191
*}
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   192
24463
841c2e24761f Smaller size and fewer iterations for quickcheck.
berghofe
parents: 24293
diff changeset
   193
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   194
subsection {* Evaluation and normalization by evaluation *}
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   195
27103
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   196
ML {*
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   197
structure Eval_Method =
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   198
struct
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   199
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   200
val eval_ref : (unit -> bool) option ref = ref NONE;
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   201
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   202
end;
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   203
*}
d8549f4d900b major refactorings in code generator modules
haftmann
parents: 26975
diff changeset
   204
28290
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   205
oracle eval_oracle = {* fn ct =>
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   206
  let
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   207
    val thy = Thm.theory_of_cterm ct;
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   208
    val t = Thm.term_of ct;
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   209
  in
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   210
    if Code_ML.eval_term ("Eval_Method.eval_ref", Eval_Method.eval_ref) thy
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   211
      (HOLogic.dest_Trueprop t) [] 
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   212
    then ct
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   213
    else @{cprop True} (*dummy*)
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   214
  end
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   215
*}
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   216
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   217
method_setup eval = {*
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   218
let
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   219
  fun eval_tac thy = 
28290
4cc2b6046258 simplified oracle interface;
wenzelm
parents: 28054
diff changeset
   220
    CSUBGOAL (fn (ct, i) => rtac (eval_oracle ct) i)
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   221
in 
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   222
  Method.ctxt_args (fn ctxt => 
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   223
    Method.SIMPLE_METHOD' (eval_tac (ProofContext.theory_of ctxt)))
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   224
end
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   225
*} "solve goal by evaluation"
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   226
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   227
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   228
method_setup evaluation = {*
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   229
  Method.no_args (Method.SIMPLE_METHOD' (CONVERSION Codegen.evaluation_conv THEN' rtac TrueI))
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   230
*} "solve goal by evaluation"
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   231
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   232
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   233
method_setup normalization = {*
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   234
  Method.no_args (Method.SIMPLE_METHOD'
25962
13b6c0b31005 clarified setup of method "normalization"
haftmann
parents: 25916
diff changeset
   235
    (CONVERSION (ObjectLogic.judgment_conv Nbe.norm_conv)
13b6c0b31005 clarified setup of method "normalization"
haftmann
parents: 25916
diff changeset
   236
    THEN' (fn k => TRY (rtac TrueI k))
25866
263aaf988d44 normalization conversion
haftmann
parents: 25860
diff changeset
   237
  ))
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   238
*} "solve goal by normalization"
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   239
28400
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   240
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   241
subsection {* Quickcheck *}
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   242
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   243
quickcheck_params [size = 5, iterations = 50]
89904cfd41c3 polished code generator setup
haftmann
parents: 28346
diff changeset
   244
24285
066bb557570f added Code_Setup
haftmann
parents:
diff changeset
   245
end