src/HOL/Codegenerator_Test/Candidates.thy
author haftmann
Sun, 06 Sep 2015 22:14:52 +0200
changeset 61130 8e736ce4c6f4
parent 61129 774752af4a1f
child 61227 19ee25fe9737
permissions -rw-r--r--
unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31378
d1cbf6393964 tuned code generator test theories
haftmann
parents: 30446
diff changeset
     1
d1cbf6393964 tuned code generator test theories
haftmann
parents: 30446
diff changeset
     2
(* Author: Florian Haftmann, TU Muenchen *)
21917
haftmann
parents:
diff changeset
     3
58889
5b7a9633cfa8 modernized header uniformly as section;
wenzelm
parents: 58740
diff changeset
     4
section {* A huge collection of equations to generate code from *}
21917
haftmann
parents:
diff changeset
     5
37695
71e84a203c19 introduced distinct session HOL-Codegenerator_Test
haftmann
parents: 37407
diff changeset
     6
theory Candidates
21917
haftmann
parents:
diff changeset
     7
imports
27421
7e458bd56860 HOL += HOL-Complex
haftmann
parents: 27103
diff changeset
     8
  Complex_Main
51160
599ff65b85e2 systematic conversions between nat and nibble/char;
haftmann
parents: 49077
diff changeset
     9
  "~~/src/HOL/Library/Library"
51161
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    10
  "~~/src/HOL/Library/Sublist_Order"
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 51161
diff changeset
    11
  "~~/src/HOL/Number_Theory/Eratosthenes"
35303
816e48d60b13 added Dlist
haftmann
parents: 33500
diff changeset
    12
  "~~/src/HOL/ex/Records"
21917
haftmann
parents:
diff changeset
    13
begin
haftmann
parents:
diff changeset
    14
61129
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    15
text \<open>Drop technical stuff from @{theory Quickcheck_Narrowing} which is tailored towards Haskell\<close>
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    16
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    17
setup \<open>
59842
wenzelm
parents: 59733
diff changeset
    18
fn thy =>
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    19
let
59842
wenzelm
parents: 59733
diff changeset
    20
  val tycos = Sign.logical_types thy;
wenzelm
parents: 59733
diff changeset
    21
  val consts = map_filter (try (curry (Axclass.param_of_inst thy)
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    22
    @{const_name "Quickcheck_Narrowing.partial_term_of"})) tycos;
59842
wenzelm
parents: 59733
diff changeset
    23
in fold Code.del_eqns consts thy end
61129
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    24
\<close>
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    25
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    26
text \<open>Simple example for the predicate compiler.\<close>
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    27
51161
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    28
inductive sublist :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    29
where
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    30
  empty: "sublist [] xs"
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    31
| drop: "sublist ys xs \<Longrightarrow> sublist ys (x # xs)"
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51160
diff changeset
    32
| take: "sublist ys xs \<Longrightarrow> sublist (x # ys) (x # xs)"
33500
22e5725be1f3 added predicate example
haftmann
parents: 33356
diff changeset
    33
22e5725be1f3 added predicate example
haftmann
parents: 33356
diff changeset
    34
code_pred sublist .
22e5725be1f3 added predicate example
haftmann
parents: 33356
diff changeset
    35
61129
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    36
text \<open>Avoid popular infix.\<close>
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    37
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    38
code_reserved SML upto
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    39
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    40
text \<open>Explicit check in @{text OCaml} for correct precedence of let expressions in list expressions\<close>
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    41
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    42
definition funny_list :: "bool list"
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    43
where
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    44
  "funny_list = [let b = True in b, False]"
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    45
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    46
definition funny_list' :: "bool list"
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    47
where
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    48
  "funny_list' = funny_list"
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    49
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    50
lemma [code]:
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    51
  "funny_list' = [True, False]"
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    52
  by (simp add: funny_list_def funny_list'_def)
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    53
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    54
definition check_list :: unit
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    55
where
774752af4a1f parenthesing let-expressions in OCaml similar to case expressions avoids precendence problems due to ambiguous scope;
haftmann
parents: 59842
diff changeset
    56
  "check_list = (if funny_list = funny_list' then () else undefined)"
31378
d1cbf6393964 tuned code generator test theories
haftmann
parents: 30446
diff changeset
    57
61130
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    58
text \<open>Explicit check in @{text Scala} for correct bracketing of abstractions\<close>
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    59
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    60
definition funny_funs :: "(bool \<Rightarrow> bool) list \<Rightarrow> (bool \<Rightarrow> bool) list"
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    61
where
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    62
  "funny_funs fs = (\<lambda>x. x \<or> True) # (\<lambda>x. x \<or> False) # fs"
8e736ce4c6f4 unconditional parenthesing of (chained) abstractions in Scala, with explicit regression setup
haftmann
parents: 61129
diff changeset
    63
21917
haftmann
parents:
diff changeset
    64
end