src/HOL/Codegenerator_Test/Generate_Efficient_Datastructures.thy
author wenzelm
Sun Nov 02 18:21:45 2014 +0100 (2014-11-02)
changeset 58889 5b7a9633cfa8
parent 54437 0060957404c7
child 59484 a130ae7a9398
permissions -rw-r--r--
modernized header uniformly as section;
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
kuncar@48624
    14
(* 
kuncar@48624
    15
   The following code equations have to be deleted because they use 
kuncar@48624
    16
   lists to implement sets in the code generetor. 
kuncar@48624
    17
*)
kuncar@48624
    18
kuncar@48624
    19
lemma [code, code del]:
kuncar@48624
    20
  "Sup_pred_inst.Sup_pred = Sup_pred_inst.Sup_pred" ..
kuncar@48624
    21
kuncar@48624
    22
lemma [code, code del]:
kuncar@48624
    23
  "Inf_pred_inst.Inf_pred = Inf_pred_inst.Inf_pred" ..
kuncar@48624
    24
kuncar@48624
    25
lemma [code, code del]:
kuncar@48624
    26
  "pred_of_set = pred_of_set" ..
kuncar@48624
    27
kuncar@48624
    28
lemma [code, code del]:
haftmann@54295
    29
  "Wellfounded.acc = Wellfounded.acc" ..
kuncar@48624
    30
Andreas@51139
    31
lemma [code, code del]:
Andreas@51139
    32
  "Cardinality.card' = Cardinality.card'" ..
Andreas@51139
    33
Andreas@51139
    34
lemma [code, code del]:
Andreas@51139
    35
  "Cardinality.finite' = Cardinality.finite'" ..
Andreas@51139
    36
Andreas@51139
    37
lemma [code, code del]:
Andreas@51139
    38
  "Cardinality.subset' = Cardinality.subset'" ..
Andreas@51139
    39
Andreas@51139
    40
lemma [code, code del]:
Andreas@51139
    41
  "Cardinality.eq_set = Cardinality.eq_set" ..
Andreas@51116
    42
haftmann@54437
    43
lemma [code, code del]:
haftmann@54437
    44
  "(Gcd :: nat set \<Rightarrow> nat) = Gcd" ..
haftmann@54437
    45
haftmann@54437
    46
lemma [code, code del]:
haftmann@54437
    47
  "(Lcm :: nat set \<Rightarrow> nat) = Lcm" ..
haftmann@54437
    48
haftmann@54437
    49
lemma [code, code del]:
haftmann@54437
    50
  "(Gcd :: int set \<Rightarrow> int) = Gcd" ..
haftmann@54437
    51
haftmann@54437
    52
lemma [code, code del]:
haftmann@54437
    53
  "(Lcm :: int set \<Rightarrow> int) = Lcm" ..
haftmann@54437
    54
  
kuncar@48624
    55
(*
kuncar@48624
    56
  If the code generation ends with an exception with the following message:
kuncar@48624
    57
  '"List.set" is not a constructor, on left hand side of equation: ...',
kuncar@48624
    58
  the code equation in question has to be either deleted (like many others in this file) 
kuncar@48624
    59
  or implemented for RBT trees.
kuncar@48624
    60
*)
kuncar@48624
    61
kuncar@50996
    62
export_code _ checking SML OCaml? Haskell?
kuncar@50996
    63
kuncar@50996
    64
(* Extra setup to make Scala happy *)
kuncar@50996
    65
(* If the compilation fails with an error "ambiguous implicit values",
kuncar@50996
    66
   read \<section>7.1 in the Code Generation Manual *)
kuncar@50996
    67
kuncar@50996
    68
lemma [code]:
kuncar@50996
    69
  "(gfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Sup {u. u \<le> f u}"
kuncar@50996
    70
unfolding gfp_def by blast
kuncar@50996
    71
kuncar@50996
    72
lemma [code]:
kuncar@50996
    73
  "(lfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Inf {u. f u \<le> u}"
kuncar@50996
    74
unfolding lfp_def by blast
kuncar@50996
    75
kuncar@50996
    76
export_code _ checking Scala?
kuncar@48624
    77
kuncar@48624
    78
end