src/HOL/Codegenerator_Test/Generate_Efficient_Datastructures.thy
author haftmann
Wed, 04 Jan 2017 21:28:29 +0100
changeset 64786 340db65fd2c1
parent 63965 d510b816ea41
child 64850 fc9265882329
permissions -rw-r--r--
reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51161
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     1
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     2
(* Author: Ondrej Kuncar, TU Muenchen *)
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     3
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 63134
diff changeset
     4
section \<open>Pervasive test of code generator\<close>
48624
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
     5
51161
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     6
theory Generate_Efficient_Datastructures
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     7
imports
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
     8
  Candidates
51599
1559e9266280 optionalized very specific code setup for multisets
haftmann
parents: 51161
diff changeset
     9
  "~~/src/HOL/Library/DAList_Multiset"
51161
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
    10
  "~~/src/HOL/Library/RBT_Mapping"
6ed12ae3b3e1 attempt to re-establish conventions which theories are loaded into the grand unified library theory;
haftmann
parents: 51139
diff changeset
    11
  "~~/src/HOL/Library/RBT_Set"
48624
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    12
begin
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    13
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    14
setup \<open>
59842
wenzelm
parents: 59484
diff changeset
    15
fn thy =>
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    16
let
59842
wenzelm
parents: 59484
diff changeset
    17
  val tycos = Sign.logical_types thy;
wenzelm
parents: 59484
diff changeset
    18
  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
    19
    @{const_name "Quickcheck_Narrowing.partial_term_of"})) tycos;
59842
wenzelm
parents: 59484
diff changeset
    20
in fold Code.del_eqns consts thy end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 63134
diff changeset
    21
\<close> \<comment> \<open>drop technical stuff from \<open>Quickcheck_Narrowing\<close> which is tailored towards Haskell\<close>
59484
a130ae7a9398 slightly more standard code setup for String.literal, with explicit special case in predicate compiler
haftmann
parents: 58889
diff changeset
    22
64786
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    23
text \<open>
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    24
  The following code equations have to be deleted because they use 
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    25
  lists to implement sets in the code generetor. 
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    26
\<close>
51116
0dac0158b8d4 implement code generation for finite, card, op = and op <= for sets always via finite_UNIV and card_UNIV, as fragile rewrites based on sorts are hard to find and debug
Andreas Lochbihler
parents: 50996
diff changeset
    27
64786
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    28
declare [[code drop:
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    29
  Sup_pred_inst.Sup_pred
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    30
  Inf_pred_inst.Inf_pred
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    31
  pred_of_set
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    32
  Wellfounded.acc
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    33
  Cardinality.card'
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    34
  Cardinality.finite'
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    35
  Cardinality.subset'
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    36
  Cardinality.eq_set
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    37
  "Gcd :: nat set \<Rightarrow> nat"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    38
  "Lcm :: nat set \<Rightarrow> nat"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    39
  "Gcd :: int set \<Rightarrow> int"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    40
  "Lcm :: int set \<Rightarrow> int"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    41
  "Gcd :: _ poly set \<Rightarrow> _"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    42
  "Lcm :: _ poly set \<Rightarrow> _"
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    43
  Euclidean_Algorithm.Gcd
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    44
  Euclidean_Algorithm.Lcm
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    45
  permutations_of_set
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    46
  permutations_of_multiset
340db65fd2c1 reworked to provide auxiliary operations Euclidean_Algorithm.* to instantiate gcd etc. for euclidean rings
haftmann
parents: 63965
diff changeset
    47
]]
63965
d510b816ea41 Set_Permutations replaced by more general Multiset_Permutations
eberlm <eberlm@in.tum.de>
parents: 63167
diff changeset
    48
48624
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    49
(*
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    50
  If the code generation ends with an exception with the following message:
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    51
  '"List.set" is not a constructor, on left hand side of equation: ...',
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    52
  the code equation in question has to be either deleted (like many others in this file) 
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    53
  or implemented for RBT trees.
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    54
*)
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    55
50996
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    56
export_code _ checking SML OCaml? Haskell?
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    57
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    58
(* Extra setup to make Scala happy *)
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    59
(* If the compilation fails with an error "ambiguous implicit values",
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    60
   read \<section>7.1 in the Code Generation Manual *)
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    61
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    62
lemma [code]:
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    63
  "(gfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Sup {u. u \<le> f u}"
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    64
unfolding gfp_def by blast
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    65
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    66
lemma [code]:
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    67
  "(lfp :: ('a :: complete_linorder \<Rightarrow> 'a) \<Rightarrow> 'a) f = Inf {u. f u \<le> u}"
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    68
unfolding lfp_def by blast
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    69
51ad7b4ac096 restore code equations for List.set in RBT_Set; make Scala happy according to 7.1 in the code generator manual
kuncar
parents: 49948
diff changeset
    70
export_code _ checking Scala?
48624
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    71
9b71daba4ec7 add testing file for RBT_Set
kuncar
parents:
diff changeset
    72
end