src/HOL/Codegenerator_Test/Generate_Efficient_Datastructures.thy
author haftmann
Thu Feb 05 19:44:14 2015 +0100 (2015-02-05)
changeset 59484 a130ae7a9398
parent 58889 5b7a9633cfa8
child 59842 9fda99b3d5ee
permissions -rw-r--r--
slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann@51161
     1
haftmann@51161
     2
(* Author: Ondrej Kuncar, TU Muenchen *)
haftmann@51161
     3
wenzelm@58889
     4
section {* Pervasive test of code generator *}
kuncar@48624
     5
haftmann@51161
     6
theory Generate_Efficient_Datastructures
haftmann@51161
     7
imports
haftmann@51161
     8
  Candidates
haftmann@51599
     9
  "~~/src/HOL/Library/DAList_Multiset"
haftmann@51161
    10
  "~~/src/HOL/Library/RBT_Mapping"
haftmann@51161
    11
  "~~/src/HOL/Library/RBT_Set"
kuncar@48624
    12
begin
kuncar@48624
    13
haftmann@59484
    14
setup \<open>
haftmann@59484
    15
let
haftmann@59484
    16
  val tycos = (#log_types o Type.rep_tsig o Sign.tsig_of) @{theory};
haftmann@59484
    17
  val consts = map_filter (try (curry (Axclass.param_of_inst @{theory})
haftmann@59484
    18
    @{const_name "Quickcheck_Narrowing.partial_term_of"})) tycos;
haftmann@59484
    19
in fold Code.del_eqns consts end
haftmann@59484
    20
\<close> -- \<open>drop technical stuff from @{text Quickcheck_Narrowing} which is tailored towards Haskell\<close>
haftmann@59484
    21
kuncar@48624
    22
(* 
kuncar@48624
    23
   The following code equations have to be deleted because they use 
kuncar@48624
    24
   lists to implement sets in the code generetor. 
kuncar@48624
    25
*)
kuncar@48624
    26
kuncar@48624
    27
lemma [code, code del]:
kuncar@48624
    28
  "Sup_pred_inst.Sup_pred = Sup_pred_inst.Sup_pred" ..
kuncar@48624
    29
kuncar@48624
    30
lemma [code, code del]:
kuncar@48624
    31
  "Inf_pred_inst.Inf_pred = Inf_pred_inst.Inf_pred" ..
kuncar@48624
    32
kuncar@48624
    33
lemma [code, code del]:
kuncar@48624
    34
  "pred_of_set = pred_of_set" ..
kuncar@48624
    35
kuncar@48624
    36
lemma [code, code del]:
haftmann@54295
    37
  "Wellfounded.acc = Wellfounded.acc" ..
kuncar@48624
    38
Andreas@51139
    39
lemma [code, code del]:
Andreas@51139
    40
  "Cardinality.card' = Cardinality.card'" ..
Andreas@51139
    41
Andreas@51139
    42
lemma [code, code del]:
Andreas@51139
    43
  "Cardinality.finite' = Cardinality.finite'" ..
Andreas@51139
    44
Andreas@51139
    45
lemma [code, code del]:
Andreas@51139
    46
  "Cardinality.subset' = Cardinality.subset'" ..
Andreas@51139
    47
Andreas@51139
    48
lemma [code, code del]:
Andreas@51139
    49
  "Cardinality.eq_set = Cardinality.eq_set" ..
Andreas@51116
    50
haftmann@54437
    51
lemma [code, code del]:
haftmann@54437
    52
  "(Gcd :: nat set \<Rightarrow> nat) = Gcd" ..
haftmann@54437
    53
haftmann@54437
    54
lemma [code, code del]:
haftmann@54437
    55
  "(Lcm :: nat set \<Rightarrow> nat) = Lcm" ..
haftmann@54437
    56
haftmann@54437
    57
lemma [code, code del]:
haftmann@54437
    58
  "(Gcd :: int set \<Rightarrow> int) = Gcd" ..
haftmann@54437
    59
haftmann@54437
    60
lemma [code, code del]:
haftmann@54437
    61
  "(Lcm :: int set \<Rightarrow> int) = Lcm" ..
haftmann@54437
    62
  
kuncar@48624
    63
(*
kuncar@48624
    64
  If the code generation ends with an exception with the following message:
kuncar@48624
    65
  '"List.set" is not a constructor, on left hand side of equation: ...',
kuncar@48624
    66
  the code equation in question has to be either deleted (like many others in this file) 
kuncar@48624
    67
  or implemented for RBT trees.
kuncar@48624
    68
*)
kuncar@48624
    69
kuncar@50996
    70
export_code _ checking SML OCaml? Haskell?
kuncar@50996
    71
kuncar@50996
    72
(* Extra setup to make Scala happy *)
kuncar@50996
    73
(* If the compilation fails with an error "ambiguous implicit values",
kuncar@50996
    74
   read \<section>7.1 in the Code Generation Manual *)
kuncar@50996
    75
kuncar@50996
    76
lemma [code]:
kuncar@50996
    77
  "(gfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Sup {u. u \<le> f u}"
kuncar@50996
    78
unfolding gfp_def by blast
kuncar@50996
    79
kuncar@50996
    80
lemma [code]:
kuncar@50996
    81
  "(lfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Inf {u. f u \<le> u}"
kuncar@50996
    82
unfolding lfp_def by blast
kuncar@50996
    83
kuncar@50996
    84
export_code _ checking Scala?
kuncar@48624
    85
kuncar@48624
    86
end