src/HOL/Mutabelle/Mutabelle.thy
author haftmann
Sat, 28 Aug 2010 16:14:32 +0200
changeset 38864 4abe644fcea5
parent 38795 848be46708dc
child 39557 fe5722fce758
permissions -rw-r--r--
formerly unnamed infix equality now named HOL.eq
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     1
theory Mutabelle
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     2
imports Main
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     3
uses "mutabelle.ML"
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     4
begin
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     5
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     6
ML {*
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
     7
val comms = [@{const_name HOL.eq}, @{const_name HOL.disj}, @{const_name HOL.conj}];
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     8
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
     9
val forbidden =
34974
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    10
 [(@{const_name Power.power}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    11
  (@{const_name HOL.induct_equal}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    12
  (@{const_name HOL.induct_implies}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    13
  (@{const_name HOL.induct_conj}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    14
  (@{const_name HOL.undefined}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    15
  (@{const_name HOL.default}, "'a"),
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    16
  (@{const_name dummy_pattern}, "'a::{}"),
35267
8dfd816713c6 moved remaning class operations from Algebras.thy to Groups.thy
haftmann
parents: 35092
diff changeset
    17
  (@{const_name Groups.uminus}, "'a"),
34974
18b41bba42b5 new theory Algebras.thy for generic algebraic structures
haftmann
parents: 34965
diff changeset
    18
  (@{const_name Nat.size}, "'a"),
35092
cfe605c54e50 moved less_eq, less to Orderings.thy; moved abs, sgn to Groups.thy
haftmann
parents: 34974
diff changeset
    19
  (@{const_name Groups.abs}, "'a")];
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    20
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    21
val forbidden_thms =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    22
 ["finite_intvl_succ_class",
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    23
  "nibble"];
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    24
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    25
val forbidden_consts =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    26
 [@{const_name nibble_pair_of_char}];
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    27
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    28
fun is_forbidden s th =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    29
 exists (fn s' => s' mem space_explode "." s) forbidden_thms orelse
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    30
 exists (fn s' => s' mem (Term.add_const_names (prop_of th) [])) forbidden_consts;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    31
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    32
fun test j = List.app (fn i =>
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    33
 Mutabelle.mutqc_thystat_mix is_forbidden
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    34
   @{theory List} @{theory Main} comms forbidden 1 [] i j ("list_" ^ string_of_int i ^ ".txt"))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    35
 (1 upto 10);
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    36
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    37
fun get_numbers xs =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    38
 let
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    39
   val (_, xs1) = take_prefix (not o equal ":") xs;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    40
   val (_, xs2) = take_prefix (fn ":" => true | " " => true | _ => false) xs1;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    41
   val (xs3, xs4) = take_prefix Symbol.is_digit xs2;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    42
   val (_, xs5) = take_prefix (equal " ") xs4;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    43
   val (xs6, xs7) = take_prefix Symbol.is_digit xs5
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    44
 in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    45
   case (xs3, xs6) of
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    46
     ([], _) => NONE
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    47
   | (_, []) => NONE
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    48
   | (ys, zs) => SOME (fst (read_int ys), fst (read_int zs), xs7)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    49
 end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    50
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    51
fun add_numbers s =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    52
 let
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    53
   fun strip ("\n" :: "\n" :: "\n" :: xs) = xs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    54
     | strip (_ :: xs) = strip xs;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    55
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    56
   fun add (i, j) xs = (case get_numbers xs of
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    57
         NONE => (i, j)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    58
       | SOME (i', j', xs') => add (i+i', j+j') xs')
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    59
 in add (0,0) (strip (explode s)) end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    60
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    61
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    62
(*
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    63
ML {*
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35267
diff changeset
    64
Quickcheck.test_term (ProofContext.init_global @{theory})
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    65
 false (SOME "SML") 1 1 (prop_of (hd @{thms nibble_pair_of_char_simps}))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    66
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    67
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    68
ML {*
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    69
fun is_executable thy th = can (Quickcheck.test_term
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35267
diff changeset
    70
 (ProofContext.init_global thy) false (SOME "SML") 1 1) (prop_of th);
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    71
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    72
fun is_executable_term thy t = can (Quickcheck.test_term
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35267
diff changeset
    73
 (ProofContext.init_global thy) false (SOME "SML") 1 1) t;
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    74
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    75
fun thms_of thy = filter (fn (_, th) => not (Thm.is_internal th) andalso
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    76
   Context.theory_name (theory_of_thm th) = Context.theory_name thy andalso
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    77
   is_executable thy th)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    78
 (PureThy.all_thms_of thy);
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    79
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    80
fun find_thm thy = find_first (fn (_, th) => not (Thm.is_internal th) andalso
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    81
   Context.theory_name (theory_of_thm th) = Context.theory_name thy andalso
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    82
   is_executable thy th)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    83
 (PureThy.all_thms_of thy);
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    84
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    85
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    86
ML {*
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    87
is_executable @{theory} (hd @{thms nibble_pair_of_char_simps})
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    88
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    89
*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    90
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    91
ML {*
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    92
Mutabelle.mutate_mix @{term "Suc x \<noteq> 0"} @{theory} comms forbidden 1
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    93
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    94
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    95
ML {*
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    96
Mutabelle.mutqc_thystat_mix is_forbidden @{theory Nat} @{theory} comms forbidden 1 [] 10 5 "/tmp/muta.out"
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    97
*}
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    98
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    99
end