src/HOL/Mutabelle/mutabelle.ML
author bulwahn
Mon, 18 Jul 2011 10:34:21 +0200
changeset 44754 aacbe67793c3
parent 43308 7691cc61720a
child 46029 3f1d1ce024cb
permissions -rw-r--r--
adapting mutabelle to latest changes in quickcheck; removing unused code in mutabelle
haftmann@37743
     1
(*  Title:      HOL/Mutabelle/mutabelle.ML
berghofe@34954
     2
    Author:     Veronika Ortner, TU Muenchen
bulwahn@34952
     3
wenzelm@41656
     4
Mutation of theorems.
bulwahn@34952
     5
*)
wenzelm@41656
     6
bulwahn@34952
     7
signature MUTABELLE =
bulwahn@34952
     8
sig
bulwahn@44754
     9
  exception WrongPath of string;
bulwahn@44754
    10
  exception WrongArg of string;
bulwahn@44754
    11
  val freeze : term -> term
bulwahn@44754
    12
  val mutate_exc : term -> string list -> int -> term list 
bulwahn@44754
    13
  val mutate_sign : term -> theory -> (string * string) list -> int -> term list 
bulwahn@44754
    14
  val mutate_mix : term -> theory -> string list -> 
bulwahn@34952
    15
   (string * string) list -> int -> term list
bulwahn@44754
    16
(*  val qc_test : term list -> (typ * typ) list -> theory ->
bulwahn@34952
    17
  int -> int -> int * Thm.cterm list * int * (Thm.cterm * (string * Thm.cterm) list) list
bulwahn@44754
    18
  val qc_test_file : bool -> term list -> (typ * typ) list 
bulwahn@34952
    19
   -> theory -> int -> int -> string -> unit
bulwahn@44754
    20
  val mutqc_file_exc : theory -> string list ->
bulwahn@34952
    21
  int -> Thm.thm -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    22
  val mutqc_file_sign : theory -> (string * string) list ->
bulwahn@34952
    23
  int -> Thm.thm -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    24
  val mutqc_file_mix : theory -> string list -> (string * string) list ->
bulwahn@34952
    25
  int -> Thm.thm -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    26
  val mutqc_file_rec_exc : theory -> string list -> int ->
bulwahn@34952
    27
  Thm.thm list -> (typ * typ) list -> int -> int -> string list -> unit
bulwahn@44754
    28
  val mutqc_file_rec_sign : theory -> (string * string) list -> int ->
bulwahn@34952
    29
  Thm.thm list -> (typ * typ) list -> int -> int -> string list -> unit
bulwahn@44754
    30
  val mutqc_file_rec_mix : theory -> string list -> (string * string) list ->
bulwahn@34952
    31
  int -> Thm.thm list -> (typ * typ) list -> int -> int -> string list -> unit
bulwahn@44754
    32
  val mutqc_thy_exc : theory -> theory ->
bulwahn@34952
    33
  string list -> int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    34
  val mutqc_thy_sign : theory -> theory -> (string * string) list ->
bulwahn@34952
    35
  int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    36
  val mutqc_thy_mix : theory -> theory -> string list -> (string * string) list ->
bulwahn@34952
    37
  int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    38
  val mutqc_file_stat_sign : theory -> (string * string) list ->
bulwahn@34952
    39
  int -> Thm.thm list -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    40
  val mutqc_file_stat_exc : theory -> string list ->
bulwahn@34952
    41
  int -> Thm.thm list -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    42
  val mutqc_file_stat_mix : theory -> string list -> (string * string) list ->
bulwahn@34952
    43
  int -> Thm.thm list -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    44
  val mutqc_thystat_exc : (string -> thm -> bool) -> theory -> theory ->
bulwahn@34952
    45
  string list -> int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    46
  val mutqc_thystat_sign : (string -> thm -> bool) -> theory -> theory -> (string * string) list ->
bulwahn@34952
    47
  int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    48
  val mutqc_thystat_mix : (string -> thm -> bool) -> theory -> theory -> string list -> 
bulwahn@34952
    49
  (string * string) list -> int -> (typ * typ) list -> int -> int -> string -> unit
bulwahn@44754
    50
  val canonize_term: term -> string list -> term
bulwahn@44754
    51
*)  
bulwahn@44754
    52
  val all_unconcealed_thms_of : theory -> (string * thm) list
bulwahn@34952
    53
end;
bulwahn@34952
    54
bulwahn@34952
    55
structure Mutabelle : MUTABELLE = 
bulwahn@34952
    56
struct
bulwahn@34952
    57
bulwahn@34952
    58
fun all_unconcealed_thms_of thy =
bulwahn@34952
    59
  let
wenzelm@39814
    60
    val facts = Global_Theory.facts_of thy
bulwahn@34952
    61
  in
bulwahn@34952
    62
    Facts.fold_static
bulwahn@34952
    63
      (fn (s, ths) =>
bulwahn@34952
    64
        if Facts.is_concealed facts s then I else append (map (`(Thm.get_name_hint)) ths))
bulwahn@34952
    65
      facts []
bulwahn@34952
    66
  end;
bulwahn@34952
    67
bulwahn@34952
    68
fun thms_of thy = filter (fn (_, th) =>
bulwahn@34952
    69
   Context.theory_name (theory_of_thm th) = Context.theory_name thy) (all_unconcealed_thms_of thy);
bulwahn@34952
    70
bulwahn@34952
    71
fun consts_of thy =
bulwahn@34952
    72
 let
bulwahn@34952
    73
   val (namespace, const_table) = #constants (Consts.dest (Sign.consts_of thy))
bulwahn@34952
    74
   val consts = Symtab.dest const_table
bulwahn@34952
    75
 in
wenzelm@43308
    76
   map_filter (fn (s, (T, NONE)) => SOME (s, T) | _ => NONE)
bulwahn@34952
    77
     (filter_out (fn (s, _) => Name_Space.is_concealed namespace s) consts)
bulwahn@34952
    78
 end;
bulwahn@34952
    79
bulwahn@34952
    80
wenzelm@41656
    81
(*possibility to print a given term for debugging purposes*)
bulwahn@34952
    82
wenzelm@38131
    83
fun prt x = Pretty.writeln (Syntax.pretty_term_global @{theory Main} x);
bulwahn@34952
    84
bulwahn@34952
    85
val debug = (Unsynchronized.ref false);
bulwahn@34952
    86
fun debug_msg mutterm = if (!debug) then (prt mutterm) else ();
bulwahn@34952
    87
bulwahn@34952
    88
bulwahn@34952
    89
(*thrown in case the specified path doesn't exist in the specified term*)
bulwahn@34952
    90
bulwahn@34952
    91
exception WrongPath of string;
bulwahn@34952
    92
bulwahn@34952
    93
bulwahn@34952
    94
(*thrown in case the arguments did not fit to the function*)
bulwahn@34952
    95
bulwahn@34952
    96
exception WrongArg of string; 
bulwahn@34952
    97
bulwahn@34952
    98
(*Rename the bound variables in a term with the minimal Index min of 
bulwahn@34952
    99
bound variables. Variable (Bound(min)) will be renamed to Bound(0) etc. 
bulwahn@34952
   100
This is needed in course auf evaluation of contexts.*)
bulwahn@34952
   101
bulwahn@34952
   102
fun rename_bnds curTerm 0 = curTerm
bulwahn@34952
   103
 | rename_bnds (Bound(i)) minInd = 
bulwahn@34952
   104
   let 
bulwahn@34952
   105
     val erg = if (i-minInd < 0) then 0 else (i - minInd)
bulwahn@34952
   106
   in 
bulwahn@34952
   107
     Bound(erg)
bulwahn@34952
   108
   end
bulwahn@34952
   109
 | rename_bnds (Abs(name,t,uTerm)) minInd = 
bulwahn@34952
   110
   Abs(name,t,(rename_bnds uTerm minInd))
bulwahn@34952
   111
 | rename_bnds (fstUTerm $ sndUTerm) minInd =
bulwahn@34952
   112
   (rename_bnds fstUTerm minInd) $ (rename_bnds sndUTerm minInd)
bulwahn@34952
   113
 | rename_bnds elseTerm minInd = elseTerm;
bulwahn@34952
   114
bulwahn@34952
   115
bulwahn@34952
   116
bulwahn@34952
   117
bulwahn@34952
   118
bulwahn@34952
   119
(*Partition a term in its subterms and create an entry 
bulwahn@34952
   120
(term * type * abscontext * mincontext * path) 
bulwahn@34952
   121
for each term in the return list 
bulwahn@34952
   122
e.g: getSubTermList Abs(y, int, Const(f,int->int) $ Const(x,int) $ Bound(0))
bulwahn@34952
   123
will give       [(Const(f,int->int),int->int,[int],[],[00]),
bulwahn@34952
   124
               (Const(x,int),int,[int],[],[010]),
bulwahn@34952
   125
               (Bound(0),int,[int],[int],[110]),
bulwahn@34952
   126
               (Const(x,int) $ Bound(0),type,[int],[int],[10]),
bulwahn@34952
   127
               (Const(f,int->int) $ Const(x,int) $ Bound(0),type,[int],[int],[0],
bulwahn@34952
   128
               (Abs (y,int,Const(f,int->int) $ const(x,int) $ Bound(0)),type,[],[],[])]
bulwahn@34952
   129
                *)
bulwahn@34952
   130
bulwahn@34952
   131
fun getSubTermList (Const(name,t)) abscontext path acc =
bulwahn@34952
   132
   (Const(name,t),t,abscontext,abscontext,path)::acc
bulwahn@34952
   133
 | getSubTermList (Free(name,t)) abscontext path acc =
bulwahn@34952
   134
   (Free(name,t),t,abscontext,abscontext,path)::acc
bulwahn@34952
   135
 | getSubTermList (Var(indname,t)) abscontext path acc =
bulwahn@34952
   136
   (Var(indname,t),t,abscontext,abscontext,path)::acc
bulwahn@34952
   137
 | getSubTermList (Bound(i)) abscontext path acc =
bulwahn@34952
   138
   (Bound(0),nth abscontext i,abscontext, Library.drop i abscontext,path)::acc
bulwahn@34952
   139
 | getSubTermList (Abs(name,t,uTerm)) abscontext path acc = 
bulwahn@34952
   140
   let 
bulwahn@34952
   141
     val curTerm = Abs(name,t,uTerm)
bulwahn@34952
   142
     val bnos = Term.add_loose_bnos (curTerm,0,[])
bulwahn@34952
   143
     val minInd = if (bnos = []) then 0 
bulwahn@34952
   144
       else Library.foldl (fn (n,m) => if (n<m) then n else m) (hd bnos,tl bnos)
bulwahn@34952
   145
     val newTerm = rename_bnds curTerm minInd
bulwahn@34952
   146
     val newContext = Library.drop minInd abscontext
bulwahn@34952
   147
   in 
bulwahn@34952
   148
     getSubTermList uTerm (t::abscontext) (0::path) 
bulwahn@34952
   149
               ((newTerm,(fastype_of1 (abscontext, curTerm)),abscontext,newContext,path)::acc)
bulwahn@34952
   150
   end
bulwahn@34952
   151
 | getSubTermList (fstUTerm $ sndUTerm) abscontext path acc = 
bulwahn@34952
   152
   let 
bulwahn@34952
   153
     val curTerm = (fstUTerm $ sndUTerm)
bulwahn@34952
   154
     val bnos = Term.add_loose_bnos (curTerm, 0, [])
bulwahn@34952
   155
     val minInd = if (bnos = []) then 0
bulwahn@34952
   156
       else Library.foldl (fn (n,m) => if (n<m) then n else m) (hd bnos,tl bnos)
bulwahn@34952
   157
     val newTerm = rename_bnds curTerm minInd
bulwahn@34952
   158
     val newContext = Library.drop minInd abscontext
bulwahn@34952
   159
   in 
bulwahn@34952
   160
     getSubTermList fstUTerm abscontext (0::path) 
bulwahn@34952
   161
       (getSubTermList sndUTerm abscontext (1::path) 
bulwahn@34952
   162
         ((newTerm,(fastype_of1 (abscontext, curTerm)),abscontext,newContext,path)::acc)) 
bulwahn@34952
   163
   end;  
bulwahn@34952
   164
bulwahn@34952
   165
bulwahn@34952
   166
bulwahn@34952
   167
bulwahn@34952
   168
bulwahn@34952
   169
(*tests if the given element ist in the given list*)
bulwahn@34952
   170
bulwahn@34952
   171
fun in_list elem [] = false
bulwahn@34952
   172
 | in_list elem (x::xs) = if (elem = x) then true else in_list elem xs;
bulwahn@34952
   173
bulwahn@34952
   174
bulwahn@34952
   175
(*Evaluate if the longContext is more special as the shortContext. 
bulwahn@34952
   176
If so, a term with shortContext can be substituted in the place of a 
bulwahn@34952
   177
term with longContext*)
bulwahn@34952
   178
bulwahn@34952
   179
fun is_morespecial longContext shortContext = 
bulwahn@34952
   180
 let 
bulwahn@34952
   181
   val revlC = rev longContext
bulwahn@34952
   182
   val revsC = rev shortContext
bulwahn@34952
   183
   fun is_prefix [] longList = true
bulwahn@34952
   184
     | is_prefix shList [] = false
bulwahn@34952
   185
     | is_prefix (x::xs) (y::ys) = if (x=y) then is_prefix xs ys else false
bulwahn@34952
   186
 in 
bulwahn@34952
   187
   is_prefix revsC revlC
bulwahn@34952
   188
 end;
bulwahn@34952
   189
bulwahn@34952
   190
bulwahn@34952
   191
(*takes a (term * type * context * context * path)-tupel and searches in the specified list for 
bulwahn@34952
   192
terms with the same type and appropriate context. Returns a (term * path) list of these terms.
bulwahn@34952
   193
Used in order to generate a list of type-equal subterms of the original term*)
bulwahn@34952
   194
bulwahn@34952
   195
fun searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) [] resultList = 
bulwahn@34952
   196
   resultList
bulwahn@34952
   197
 | searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) 
bulwahn@34952
   198
   ((hdterm,hdtype,hdabsContext,hdminContext,hdpath)::xs) resultList = 
bulwahn@34952
   199
   if ((stype = hdtype) andalso (is_morespecial sabsContext hdminContext) 
bulwahn@34952
   200
     andalso (is_morespecial hdabsContext sminContext)) 
bulwahn@34952
   201
   then searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) xs 
bulwahn@34952
   202
     ((hdterm,hdabsContext,hdminContext,hdpath)::resultList) 
bulwahn@34952
   203
   else searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) xs resultList;
bulwahn@34952
   204
bulwahn@34952
   205
bulwahn@34952
   206
(*evaluates if the given function is in the passed list of forbidden functions*)
bulwahn@34952
   207
bulwahn@34952
   208
fun in_list_forb consSig (consNameStr,consType) [] = false
bulwahn@34952
   209
 | in_list_forb consSig (consNameStr,consType) ((forbNameStr,forbTypeStr)::xs) = 
bulwahn@34952
   210
   let 
bulwahn@34952
   211
     val forbType = Syntax.read_typ_global consSig forbTypeStr
bulwahn@34952
   212
     val typeSignature = #tsig (Sign.rep_sg consSig)
bulwahn@34952
   213
   in
bulwahn@34952
   214
     if ((consNameStr = forbNameStr) 
wenzelm@35845
   215
       andalso (Type.typ_instance typeSignature (consType,(Logic.varifyT_global forbType))))
bulwahn@34952
   216
     then true
bulwahn@34952
   217
     else in_list_forb consSig (consNameStr,consType) xs
bulwahn@34952
   218
   end;
bulwahn@34952
   219
bulwahn@34952
   220
bulwahn@34952
   221
bulwahn@34952
   222
(*searches in the given signature Consts with the same type as sterm and 
bulwahn@34952
   223
returns a list of those terms*)
bulwahn@34952
   224
bulwahn@34952
   225
fun searchForSignatureMutations (sterm,stype) consSig forbidden_funs = 
bulwahn@34952
   226
 let 
bulwahn@34952
   227
   val sigConsTypeList = consts_of consSig;
bulwahn@34952
   228
   val typeSignature = #tsig (Sign.rep_sg consSig)
bulwahn@34952
   229
 in 
bulwahn@34952
   230
   let 
bulwahn@34952
   231
     fun recursiveSearch mutatableTermList [] = mutatableTermList
bulwahn@34952
   232
       | recursiveSearch mutatableTermList ((ConsName,ConsType)::xs) = 
bulwahn@34952
   233
         if (Type.typ_instance typeSignature (stype,ConsType) 
bulwahn@34952
   234
           andalso (not (sterm = Const(ConsName,stype))) 
bulwahn@34952
   235
           andalso (not (in_list_forb consSig (ConsName,ConsType) forbidden_funs))) 
bulwahn@34952
   236
         then recursiveSearch ((Term.Const(ConsName,stype), [], [], [5])::mutatableTermList) xs
bulwahn@34952
   237
         else recursiveSearch mutatableTermList xs
bulwahn@34952
   238
     in
bulwahn@34952
   239
       recursiveSearch [] sigConsTypeList
bulwahn@34952
   240
     end
bulwahn@34952
   241
   end;     
bulwahn@34952
   242
bulwahn@34952
   243
bulwahn@34952
   244
(*generates a list of terms that can be used instead of the passed subterm in the original term. These terms either have
bulwahn@34952
   245
the same type and appropriate context and are generated from the list of subterms either - in case of a Const-term they have been found
bulwahn@34952
   246
in the current signature.
bulwahn@34952
   247
This function has 3 versions:
bulwahn@34952
   248
0: no instertion of signature functions, 
bulwahn@34952
   249
  only terms in the subTermList with the same type and appropriate context as the passed term are returned
bulwahn@34952
   250
1: no exchange of subterms,
bulwahn@34952
   251
  only signature functions are inserted at the place of type-aequivalent Conses
bulwahn@34952
   252
2: mixture of the two other versions. insertion of signature functions and exchange of subterms*)
bulwahn@34952
   253
bulwahn@34952
   254
fun searchForMutatableTerm 0 (sterm,stype,sabscontext,smincontext,spath) 
bulwahn@34952
   255
   subTerms consSig resultList forbidden_funs =
bulwahn@34952
   256
   searchForMutatableSubTerm (sterm,stype,sabscontext,smincontext,spath) subTerms resultList
bulwahn@34952
   257
 | searchForMutatableTerm 1 (Const(constName,constType),stype,sabscontext,smincontext,spath) 
bulwahn@34952
   258
   subTerms consSig resultList forbidden_funs = 
bulwahn@34952
   259
   searchForSignatureMutations (Const(constName,constType),stype) consSig forbidden_funs
bulwahn@34952
   260
 | searchForMutatableTerm 1 _ _ _ _ _ = []
bulwahn@34952
   261
 | searchForMutatableTerm 2 (Const(constName,constType),stype,sabscontext,smincontext,spath) 
bulwahn@34952
   262
   subTerms consSig resultList forbidden_funs = 
bulwahn@34952
   263
     let 
bulwahn@34952
   264
       val subtermMutations = searchForMutatableSubTerm 
bulwahn@34952
   265
         (Const(constName,constType),stype,sabscontext,smincontext,spath) subTerms resultList
bulwahn@34952
   266
       val signatureMutations = searchForSignatureMutations 
bulwahn@34952
   267
         (Const(constName,constType),stype) consSig forbidden_funs
bulwahn@34952
   268
     in
bulwahn@34952
   269
       subtermMutations@signatureMutations
bulwahn@34952
   270
     end
bulwahn@34952
   271
 | searchForMutatableTerm 2 (sterm,stype,sabscontext,smincontext,spath) 
bulwahn@34952
   272
   subTerms consSig resultList forbidden_funs =
bulwahn@34952
   273
   searchForMutatableSubTerm (sterm,stype,sabscontext,smincontext,spath) subTerms resultList
bulwahn@34952
   274
 | searchForMutatableTerm i _ _ _ _ _ = 
bulwahn@34952
   275
   raise WrongArg("Version " ^ string_of_int i ^ 
bulwahn@34952
   276
     " doesn't exist for function searchForMutatableTerm!") ;
bulwahn@34952
   277
bulwahn@34952
   278
bulwahn@34952
   279
bulwahn@34952
   280
bulwahn@34952
   281
(*evaluates if the two terms with paths passed as arguments can be exchanged, i.e. evaluates if one of the terms is a subterm of the other one*)  
bulwahn@34952
   282
bulwahn@34952
   283
fun areReplacable [] [] = false
bulwahn@34952
   284
 | areReplacable fstPath [] = false
bulwahn@34952
   285
 | areReplacable [] sndPath = false
bulwahn@34952
   286
 | areReplacable (x::xs) (y::ys) = if (x=y) then areReplacable xs ys else true; 
bulwahn@34952
   287
bulwahn@34952
   288
bulwahn@34952
   289
bulwahn@34952
   290
bulwahn@34952
   291
(*substitutes the term at the position of the first list in fstTerm by sndTerm. 
bulwahn@34952
   292
The lists represent paths as generated by createSubTermList*)
bulwahn@34952
   293
bulwahn@34952
   294
fun substitute [] fstTerm sndTerm = sndTerm
bulwahn@34952
   295
 | substitute (_::xs) (Abs(s,T,subTerm)) sndTerm = Abs(s,T,(substitute xs subTerm sndTerm))
bulwahn@34952
   296
 | substitute (0::xs) (t $ u) sndTerm = substitute xs t sndTerm $ u 
bulwahn@34952
   297
 | substitute (1::xs) (t $ u) sndTerm = t $ substitute xs u sndTerm
bulwahn@34952
   298
 | substitute (_::xs) _ sndTerm = 
bulwahn@34952
   299
   raise WrongPath ("The Term could not be found at the specified position"); 
bulwahn@34952
   300
bulwahn@34952
   301
bulwahn@34952
   302
(*get the subterm with the specified path in myTerm*)
bulwahn@34952
   303
bulwahn@34952
   304
fun getSubTerm myTerm [] = myTerm
bulwahn@34952
   305
 | getSubTerm (Abs(s,T,subTerm)) (0::xs) = getSubTerm subTerm xs
bulwahn@34952
   306
 | getSubTerm (t $ u) (0::xs) = getSubTerm t xs
bulwahn@34952
   307
 | getSubTerm (t $ u) (1::xs) = getSubTerm u xs
bulwahn@34952
   308
 | getSubTerm _ (_::xs) = 
bulwahn@34952
   309
   raise WrongPath ("The subterm could not be found at the specified position");
bulwahn@34952
   310
bulwahn@34952
   311
bulwahn@34952
   312
(*exchanges two subterms with the given paths in the original Term*)
bulwahn@34952
   313
bulwahn@34952
   314
fun replace origTerm (fstTerm, fstPath) (sndTerm, sndPath) = 
bulwahn@34952
   315
 if (areReplacable (rev fstPath) (rev sndPath))
bulwahn@34952
   316
 then substitute (rev sndPath) (substitute (rev fstPath) origTerm sndTerm) fstTerm
bulwahn@34952
   317
 else origTerm; 
bulwahn@34952
   318
bulwahn@34952
   319
bulwahn@34952
   320
bulwahn@34952
   321
bulwahn@34952
   322
(*tests if the terms with the given pathes in the origTerm are commutative
bulwahn@34952
   323
respecting the list of commutative operators (commutatives)*)
bulwahn@34952
   324
bulwahn@34952
   325
fun areCommutative origTerm fstPath sndPath commutatives =
bulwahn@34952
   326
 if (sndPath = []) 
bulwahn@34952
   327
 then false
bulwahn@34952
   328
 else
bulwahn@34952
   329
   let 
bulwahn@34952
   330
     val base = (tl sndPath)
bulwahn@34952
   331
   in
bulwahn@34952
   332
     let 
bulwahn@34952
   333
       val fstcomm = 1::0::base
bulwahn@34952
   334
       val opcomm = 0::0::base
bulwahn@34952
   335
     in
bulwahn@34952
   336
       if ((fstPath = fstcomm) andalso (is_Const (getSubTerm origTerm (rev opcomm))))
bulwahn@34952
   337
       then
bulwahn@34952
   338
         let 
bulwahn@34952
   339
           val Const(name,_) = (getSubTerm origTerm (rev opcomm))
bulwahn@34952
   340
         in
bulwahn@34952
   341
           if (in_list name commutatives) 
bulwahn@34952
   342
           then true 
bulwahn@34952
   343
           else false
bulwahn@34952
   344
         end
bulwahn@34952
   345
       else false
bulwahn@34952
   346
     end
bulwahn@34952
   347
   end;
bulwahn@34952
   348
bulwahn@34952
   349
bulwahn@34952
   350
(*Canonizes term t with the commutative operators stored in list 
bulwahn@34952
   351
commutatives*)
bulwahn@34952
   352
bulwahn@34952
   353
fun canonize_term (Const (s, T) $ t $ u) comms =
bulwahn@34952
   354
 let
bulwahn@34952
   355
   val t' = canonize_term t comms;
bulwahn@34952
   356
   val u' = canonize_term u comms;
bulwahn@34952
   357
 in 
haftmann@36677
   358
   if member (op =) comms s andalso Term_Ord.termless (u', t')
bulwahn@34952
   359
   then Const (s, T) $ u' $ t'
bulwahn@34952
   360
   else Const (s, T) $ t' $ u'
bulwahn@34952
   361
 end
bulwahn@34952
   362
 | canonize_term (t $ u) comms = canonize_term t comms $ canonize_term u comms
bulwahn@34952
   363
 | canonize_term (Abs (s, T, t)) comms = Abs (s, T, canonize_term t comms)
bulwahn@34952
   364
 | canonize_term t comms = t;
bulwahn@34952
   365
bulwahn@34952
   366
bulwahn@34952
   367
(*inspect the passed list and mutate origTerm following the elements of the list:
bulwahn@34952
   368
if the path of the current element is [5] (dummy path), the term has been found in the signature 
bulwahn@34952
   369
and the subterm will be substituted by it
bulwahn@34952
   370
else the term has been found in the original term and the two subterms have to be exchanged
bulwahn@34952
   371
The additional parameter commutatives indicates the commutative operators  
bulwahn@34952
   372
in the term whose operands won't be exchanged*)
bulwahn@34952
   373
bulwahn@34952
   374
fun createMutatedTerms origTerm _ [] commutatives mutatedTerms = mutatedTerms
bulwahn@34952
   375
 | createMutatedTerms origTerm (hdt as (hdTerm,hdabsContext,hdminContext,hdPath))
bulwahn@34952
   376
   ((sndTerm,sndabsContext,sndminContext,sndPath)::xs) commutatives mutatedTerms = 
bulwahn@34952
   377
   if (sndPath = [5])
bulwahn@34952
   378
   then
bulwahn@34952
   379
     let 
bulwahn@34952
   380
         val canonized = canonize_term (substitute (rev hdPath) origTerm sndTerm) commutatives
bulwahn@34952
   381
       in
bulwahn@34952
   382
         if (canonized = origTerm)  
bulwahn@34952
   383
         then createMutatedTerms origTerm hdt xs commutatives mutatedTerms
bulwahn@34952
   384
         else createMutatedTerms origTerm hdt xs commutatives 
bulwahn@34952
   385
           (insert op aconv canonized mutatedTerms)
bulwahn@34952
   386
       end
bulwahn@34952
   387
     else 
bulwahn@34952
   388
       if ((areCommutative origTerm hdPath sndPath commutatives)
bulwahn@34952
   389
         orelse (areCommutative origTerm sndPath hdPath commutatives)) 
bulwahn@34952
   390
       then createMutatedTerms origTerm hdt xs commutatives mutatedTerms
bulwahn@34952
   391
       else
bulwahn@34952
   392
         let 
bulwahn@34952
   393
           val canonized = canonize_term 
bulwahn@34952
   394
             (replace origTerm
bulwahn@34952
   395
                (incr_boundvars (length sndabsContext - length hdminContext) hdTerm,
bulwahn@34952
   396
                 hdPath)
bulwahn@34952
   397
                (incr_boundvars (length hdabsContext - length sndminContext) sndTerm,
bulwahn@34952
   398
                 sndPath)) commutatives
bulwahn@34952
   399
         in
bulwahn@34952
   400
           if (not(canonized = origTerm)) 
bulwahn@34952
   401
           then createMutatedTerms origTerm hdt xs commutatives 
bulwahn@34952
   402
             (insert op aconv canonized mutatedTerms)
bulwahn@34952
   403
           else createMutatedTerms origTerm hdt xs commutatives mutatedTerms
bulwahn@34952
   404
         end;
bulwahn@34952
   405
bulwahn@34952
   406
bulwahn@34952
   407
bulwahn@34952
   408
(*mutates origTerm by exchanging subterms. The mutated terms are returned in a term list
bulwahn@34952
   409
The parameter commutatives consists of a list of commutative operators. The permutation of their 
bulwahn@34952
   410
operands won't be considered as a new term
bulwahn@34952
   411
!!!Attention!!!: The given origTerm must be canonized. Use function canonize_term!*)
bulwahn@34952
   412
bulwahn@34952
   413
fun mutate_once option origTerm tsig commutatives forbidden_funs= 
bulwahn@34952
   414
 let 
bulwahn@34952
   415
   val subTermList = getSubTermList origTerm [] [] []
bulwahn@34952
   416
 in
bulwahn@34952
   417
   let 
bulwahn@34952
   418
     fun replaceRecursively [] mutatedTerms = mutatedTerms
bulwahn@34952
   419
       | replaceRecursively ((hdTerm,hdType,hdabsContext,hdminContext,hdPath)::tail) 
bulwahn@34952
   420
         mutatedTerms =
bulwahn@34952
   421
         replaceRecursively tail (union op aconv (createMutatedTerms origTerm 
bulwahn@34952
   422
           (hdTerm,hdabsContext,hdminContext,hdPath) 
bulwahn@34952
   423
           (searchForMutatableTerm option (hdTerm,hdType,hdabsContext,hdminContext,hdPath) 
bulwahn@34952
   424
             tail tsig [] forbidden_funs) 
bulwahn@34952
   425
           commutatives []) mutatedTerms)
bulwahn@34952
   426
   in
bulwahn@34952
   427
     replaceRecursively subTermList []
bulwahn@34952
   428
   end
bulwahn@34952
   429
 end;
bulwahn@34952
   430
bulwahn@34952
   431
bulwahn@34952
   432
bulwahn@34952
   433
bulwahn@34952
   434
(*helper function in order to apply recursively the mutate_once function on a whole list of terms
bulwahn@34952
   435
Needed for the mutate function*)
bulwahn@34952
   436
bulwahn@34952
   437
fun mutate_once_rec option [] tsig commutatives forbidden_funs acc = acc
bulwahn@34952
   438
 | mutate_once_rec option (x::xs) tsig commutatives forbidden_funs acc = 
bulwahn@34952
   439
   mutate_once_rec option xs tsig commutatives forbidden_funs 
bulwahn@34952
   440
     (union op aconv (mutate_once option x tsig commutatives forbidden_funs) acc);
bulwahn@34952
   441
bulwahn@34952
   442
bulwahn@34952
   443
bulwahn@34952
   444
(*apply function mutate_once iter times on the given origTerm. *)
bulwahn@34952
   445
(*call of mutiere with canonized form of origTerm. Prevents us of the computation of
bulwahn@34952
   446
canonization in the course of insertion of new terms!*)
bulwahn@34952
   447
bulwahn@34952
   448
fun mutate option origTerm tsig commutatives forbidden_funs 0 = []
bulwahn@34952
   449
 | mutate option origTerm tsig commutatives forbidden_funs 1 = 
bulwahn@34952
   450
   mutate_once option (canonize_term origTerm commutatives) tsig commutatives forbidden_funs
bulwahn@34952
   451
 | mutate option origTerm tsig commutatives forbidden_funs iter = 
bulwahn@34952
   452
   mutate_once_rec option (mutate option origTerm tsig commutatives forbidden_funs (iter-1)) 
bulwahn@34952
   453
     tsig commutatives forbidden_funs []; 
bulwahn@34952
   454
bulwahn@34952
   455
(*mutate origTerm iter times by only exchanging subterms*)
bulwahn@34952
   456
bulwahn@34952
   457
fun mutate_exc origTerm commutatives iter =
wenzelm@38131
   458
 mutate 0 origTerm @{theory Main} commutatives [] iter;
bulwahn@34952
   459
bulwahn@34952
   460
bulwahn@34952
   461
(*mutate origTerm iter times by only inserting signature functions*)
bulwahn@34952
   462
bulwahn@34952
   463
fun mutate_sign origTerm tsig forbidden_funs iter = 
bulwahn@34952
   464
 mutate 1 origTerm tsig [] forbidden_funs iter;
bulwahn@34952
   465
bulwahn@34952
   466
bulwahn@34952
   467
(*mutate origTerm iter times by exchange of subterms and insertion of subterms*)
bulwahn@34952
   468
bulwahn@34952
   469
fun mutate_mix origTerm tsig commutatives forbidden_funs iter =
bulwahn@34952
   470
 mutate 2 origTerm tsig commutatives forbidden_funs iter;  
bulwahn@34952
   471
bulwahn@34952
   472
bulwahn@34952
   473
(*helper function in order to prettily print a list of terms*)
bulwahn@34952
   474
bulwahn@34952
   475
fun pretty xs = map (fn (id, t) => (id, (HOLogic.mk_number HOLogic.natT
bulwahn@34952
   476
 (HOLogic.dest_nat t)) handle TERM _ => t)) xs;
bulwahn@34952
   477
bulwahn@34952
   478
bulwahn@34952
   479
(*helper function for the quickcheck invocation. Evaluates the quickcheck_term function on a whole list of terms
bulwahn@34952
   480
and tries to print the exceptions*)
bulwahn@34952
   481
bulwahn@34952
   482
fun freeze (t $ u) = freeze t $ freeze u
bulwahn@34952
   483
 | freeze (Abs (s, T, t)) = Abs (s, T, freeze t)
bulwahn@34952
   484
 | freeze (Var ((a, i), T)) =
bulwahn@34952
   485
     Free (if i = 0 then a else a ^ "_" ^ string_of_int i, T)
bulwahn@34952
   486
 | freeze t = t;
bulwahn@34952
   487
bulwahn@34952
   488
fun inst_type insts (Type (s, Ts)) = Type (s, map (inst_type insts) Ts)
bulwahn@34952
   489
 | inst_type insts T = the_default HOLogic.intT (AList.lookup op = insts T);
bulwahn@34952
   490
wenzelm@35625
   491
fun preprocess thy insts t = Object_Logic.atomize_term thy
bulwahn@34952
   492
 (map_types (inst_type insts) (freeze t));
bulwahn@34952
   493
bulwahn@34952
   494
fun is_executable thy insts th =
bulwahn@44754
   495
  let
bulwahn@44754
   496
    val ctxt' = Proof_Context.init_global thy
bulwahn@41164
   497
      |> Config.put Quickcheck.size 1
bulwahn@41164
   498
      |> Config.put Quickcheck.iterations 1
bulwahn@44754
   499
    val test = Quickcheck.test_term Exhaustive_Generators.compile_generator_expr ctxt' (true, false)
bulwahn@44754
   500
  in  
bulwahn@44754
   501
    case try test (preprocess thy insts (prop_of th), []) of
bulwahn@44754
   502
      SOME _ => (Output.urgent_message "executable"; true)
bulwahn@44754
   503
    | NONE => (Output.urgent_message ("not executable"); false)
bulwahn@44754
   504
  end;
bulwahn@44754
   505
(*
bulwahn@34952
   506
(*create a string of a list of terms*)
bulwahn@34952
   507
bulwahn@34952
   508
fun string_of_ctermlist thy [] acc = acc
bulwahn@34952
   509
 | string_of_ctermlist thy (x::xs) acc = 
bulwahn@34952
   510
   string_of_ctermlist thy xs ((Syntax.string_of_term_global thy (term_of x)) ^ "\n" ^ acc);
bulwahn@34952
   511
bulwahn@34952
   512
(*helper function in order to decompose the counter examples generated by quickcheck*)
bulwahn@34952
   513
bulwahn@34952
   514
fun decompose_ce thy [] acc = acc
bulwahn@34952
   515
 | decompose_ce thy ((varname,varce)::xs) acc = 
bulwahn@34952
   516
   decompose_ce thy xs ("\t" ^ varname ^ " instanciated to " ^ 
bulwahn@34952
   517
     (Syntax.string_of_term_global thy (term_of varce)) ^ "\n" ^ acc);
bulwahn@34952
   518
bulwahn@34952
   519
(*helper function in order to decompose a list of counter examples*)
bulwahn@34952
   520
bulwahn@34952
   521
fun decompose_celist thy [] acc = acc
bulwahn@34952
   522
 | decompose_celist thy ((mutTerm,varcelist)::xs) acc = decompose_celist thy xs 
bulwahn@34952
   523
   ("mutated term : " ^ 
bulwahn@34952
   524
   (Syntax.string_of_term_global thy (term_of mutTerm)) ^ "\n" ^ 
bulwahn@34952
   525
   "counterexample : \n" ^ 
bulwahn@34952
   526
   (decompose_ce thy (rev varcelist) "") ^ acc); 
bulwahn@34952
   527
bulwahn@34952
   528
bulwahn@34952
   529
(*quickcheck test the list of mutants mutated by applying the type instantiations 
bulwahn@34952
   530
insts and using the quickcheck-theory usedthy. The results of quickcheck are stored
bulwahn@34952
   531
in the file with name filename. If app is true, the output will be appended to the file. 
bulwahn@34952
   532
Else it will be overwritten. *)
bulwahn@34952
   533
bulwahn@34952
   534
fun qc_test_file app mutated insts usedthy sz qciter filename =
bulwahn@34952
   535
 let 
bulwahn@34952
   536
   val statisticList = qc_test mutated insts usedthy sz qciter
bulwahn@34952
   537
   val passed = (string_of_int (#1 statisticList)) ^ 
bulwahn@34952
   538
     " terms passed the quickchecktest: \n\n" ^ 
bulwahn@34952
   539
     (string_of_ctermlist usedthy (rev (#2 statisticList)) "") 
bulwahn@34952
   540
   val counterexps = (string_of_int (#3 statisticList)) ^ 
bulwahn@34952
   541
     " terms produced a counterexample: \n\n" ^
bulwahn@34952
   542
     decompose_celist usedthy (rev (#4 statisticList)) "" 
bulwahn@34952
   543
 in
bulwahn@34952
   544
   if (app = false) 
bulwahn@34952
   545
   then File.write (Path.explode filename) (passed ^ "\n\n" ^ counterexps)
bulwahn@34952
   546
   else File.append (Path.explode filename) (passed ^ "\n\n" ^ counterexps)
bulwahn@34952
   547
 end;
bulwahn@34952
   548
bulwahn@34952
   549
bulwahn@34952
   550
(*mutate sourceThm with the mutate-version given in option and check the resulting mutants. 
bulwahn@34952
   551
The output will be written to the file with name filename*)
bulwahn@34952
   552
bulwahn@34952
   553
fun mutqc_file option usedthy commutatives forbidden_funs iter sourceThm insts sz qciter filename =
bulwahn@34952
   554
 let 
bulwahn@34952
   555
   val mutated = mutate option (prop_of sourceThm) 
bulwahn@34952
   556
     usedthy commutatives forbidden_funs iter 
bulwahn@34952
   557
 in
bulwahn@34952
   558
   qc_test_file false mutated insts usedthy sz qciter filename 
bulwahn@34952
   559
 end;
bulwahn@34952
   560
bulwahn@34952
   561
(*exchange version of function mutqc_file*)
bulwahn@34952
   562
bulwahn@34952
   563
fun mutqc_file_exc usedthy commutatives iter sourceThm insts sz qciter filename =
bulwahn@34952
   564
 mutqc_file 0 usedthy commutatives [] iter sourceThm insts sz qciter filename;
bulwahn@34952
   565
bulwahn@34952
   566
bulwahn@34952
   567
(*sinature version of function mutqc_file*)
bulwahn@34952
   568
fun mutqc_file_sign usedthy forbidden_funs iter sourceThm insts sz qciter filename= 
bulwahn@34952
   569
 mutqc_file 1 usedthy [] forbidden_funs iter sourceThm insts sz qciter filename;
bulwahn@34952
   570
bulwahn@34952
   571
(*mixed version of function mutqc_file*)
bulwahn@34952
   572
bulwahn@34952
   573
fun mutqc_file_mix usedthy commutatives forbidden_funs iter sourceThm insts sz qciter filename =
bulwahn@34952
   574
 mutqc_file 2 usedthy commutatives forbidden_funs iter sourceThm insts sz qciter filename;
bulwahn@34952
   575
bulwahn@34952
   576
bulwahn@34952
   577
bulwahn@34952
   578
(*apply function mutqc_file on a list of theorems. The output for each theorem 
bulwahn@34952
   579
will be stored in a seperated file whose filename must be indicated in a list*)
bulwahn@34952
   580
bulwahn@34952
   581
fun mutqc_file_rec option usedthy commutatives forbFuns iter [] insts sz qciter _ = ()
bulwahn@34952
   582
 | mutqc_file_rec option usedthy commutatives forbFuns iter  sourceThms insts sz qciter [] = 
bulwahn@34952
   583
   raise WrongArg ("Not enough files for the output of qc_test_file_rec!")
bulwahn@34952
   584
 | mutqc_file_rec option usedthy commutatives forbFuns iter (x::xs) insts sz qciter (y::ys) = 
bulwahn@34952
   585
   (mutqc_file option usedthy commutatives forbFuns iter x insts sz qciter y ; 
bulwahn@34952
   586
   mutqc_file_rec option usedthy commutatives forbFuns iter xs insts sz qciter ys);
bulwahn@34952
   587
bulwahn@34952
   588
bulwahn@34952
   589
(*exchange version of function mutqc_file_rec*)
bulwahn@34952
   590
bulwahn@34952
   591
fun mutqc_file_rec_exc usedthy commutatives iter sourceThms insts sz qciter files =
bulwahn@34952
   592
 mutqc_file_rec 0 usedthy commutatives [] iter sourceThms insts sz qciter files;
bulwahn@34952
   593
bulwahn@34952
   594
(*signature version of function mutqc_file_rec*)
bulwahn@34952
   595
bulwahn@34952
   596
fun mutqc_file_rec_sign usedthy forbidden_funs iter sourceThms insts sz qciter files =
bulwahn@34952
   597
 mutqc_file_rec 1 usedthy [] forbidden_funs iter sourceThms insts sz qciter files;
bulwahn@34952
   598
bulwahn@34952
   599
(*mixed version of function mutqc_file_rec*)
bulwahn@34952
   600
bulwahn@34952
   601
fun mutqc_file_rec_mix usedthy commutatives forbidden_funs iter sourceThms insts sz qciter files =
bulwahn@34952
   602
 mutqc_file_rec 2 usedthy commutatives forbidden_funs iter sourceThms insts sz qciter files;
bulwahn@34952
   603
bulwahn@34952
   604
(*create the appropriate number of spaces in order to properly print a table*)
bulwahn@34952
   605
bulwahn@34952
   606
fun create_spaces entry spacenum =
bulwahn@34952
   607
 let 
wenzelm@41315
   608
   val diff = spacenum - (size entry)
wenzelm@41315
   609
 in
wenzelm@41315
   610
   if (diff > 0)
bulwahn@34952
   611
   then implode (replicate diff " ")
bulwahn@34952
   612
   else ""
bulwahn@34952
   613
 end;
bulwahn@34952
   614
bulwahn@34952
   615
bulwahn@34952
   616
(*create a statistic of the output of a quickcheck test on the passed thmlist*)
bulwahn@34952
   617
bulwahn@34952
   618
fun mutqc_file_stat option usedthy commutatives forbidden_funs iter thmlist insts sz qciter filename = 
bulwahn@34952
   619
 let 
bulwahn@34952
   620
   fun mutthmrec [] = ()
bulwahn@34952
   621
   |   mutthmrec (x::xs) =
bulwahn@34952
   622
     let 
bulwahn@34952
   623
       val mutated = mutate option (prop_of x) usedthy
bulwahn@34952
   624
         commutatives forbidden_funs iter
bulwahn@34952
   625
       val (passednum,_,cenum,_) = qc_test mutated insts usedthy sz qciter
wenzelm@36752
   626
       val thmname =  "\ntheorem " ^ Thm.get_name_hint x ^ ":"
bulwahn@34952
   627
       val pnumstring = string_of_int passednum
bulwahn@34952
   628
       val cenumstring = string_of_int cenum
bulwahn@34952
   629
     in
bulwahn@34952
   630
       (File.append (Path.explode filename) 
bulwahn@34952
   631
         (thmname ^ (create_spaces thmname 50) ^ 
bulwahn@34952
   632
         pnumstring ^ (create_spaces pnumstring 20) ^ 
bulwahn@34952
   633
         cenumstring ^ (create_spaces cenumstring 20) ^ "\n");
bulwahn@34952
   634
       mutthmrec xs)
bulwahn@34952
   635
     end;
bulwahn@34952
   636
 in 
bulwahn@34952
   637
   (File.write (Path.explode filename) 
bulwahn@34952
   638
     ("\n\ntheorem name" ^ (create_spaces "theorem name" 50) ^ 
bulwahn@34952
   639
     "passed mutants"  ^ (create_spaces "passed mutants" 20) ^ 
bulwahn@34952
   640
     "counter examples\n\n" );
bulwahn@34952
   641
   mutthmrec thmlist)
bulwahn@34952
   642
 end;
bulwahn@34952
   643
bulwahn@34952
   644
(*signature version of function mutqc_file_stat*)
bulwahn@34952
   645
bulwahn@34952
   646
fun mutqc_file_stat_sign usedthy forbidden_funs iter thmlist insts sz qciter filename =
bulwahn@34952
   647
 mutqc_file_stat 1 usedthy [] forbidden_funs iter thmlist insts sz qciter filename;
bulwahn@34952
   648
bulwahn@34952
   649
(*exchange version of function mutqc_file_stat*)
bulwahn@34952
   650
bulwahn@34952
   651
fun mutqc_file_stat_exc usedthy commutatives iter thmlist insts sz qciter filename =
bulwahn@34952
   652
 mutqc_file_stat 0 usedthy commutatives [] iter thmlist insts sz qciter filename;
bulwahn@34952
   653
bulwahn@34952
   654
(*mixed version of function mutqc_file_stat*)
bulwahn@34952
   655
bulwahn@34952
   656
fun mutqc_file_stat_mix usedthy commutatives forbidden_funs iter thmlist insts sz qciter filename =
bulwahn@34952
   657
 mutqc_file_stat 2 usedthy commutatives forbidden_funs iter thmlist insts sz qciter filename;
bulwahn@34952
   658
bulwahn@34952
   659
(*mutate and quickcheck-test all the theorems contained in the passed theory. 
bulwahn@34952
   660
The output will be stored in a single file*)
bulwahn@34952
   661
bulwahn@34952
   662
fun mutqc_thy option mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   663
 let
bulwahn@34952
   664
   val thmlist = filter (is_executable mutthy insts o snd) (thms_of mutthy);
bulwahn@34952
   665
   fun mutthmrec [] = ()
bulwahn@34952
   666
     | mutthmrec ((name,thm)::xs) = 
bulwahn@34952
   667
         let
bulwahn@34952
   668
           val mutated = mutate option (prop_of thm) 
bulwahn@34952
   669
             usedthy commutatives forbidden_funs iter
bulwahn@34952
   670
         in
bulwahn@34952
   671
           (File.append (Path.explode filename) 
bulwahn@34952
   672
             ("--------------------------\n\nQuickchecktest of theorem " ^ name ^ ":\n\n");
bulwahn@34952
   673
           qc_test_file true mutated insts usedthy sz qciter filename;
bulwahn@34952
   674
           mutthmrec xs)
bulwahn@34952
   675
         end;
bulwahn@34952
   676
   in 
bulwahn@34952
   677
     mutthmrec thmlist
bulwahn@34952
   678
   end;
bulwahn@34952
   679
bulwahn@34952
   680
(*exchange version of function mutqc_thy*)
bulwahn@34952
   681
bulwahn@34952
   682
fun mutqc_thy_exc mutthy usedthy commutatives iter insts sz qciter filename =
bulwahn@34952
   683
 mutqc_thy 0 mutthy usedthy commutatives [] iter insts sz qciter filename;
bulwahn@34952
   684
bulwahn@34952
   685
(*signature version of function mutqc_thy*)
bulwahn@34952
   686
bulwahn@34952
   687
fun mutqc_thy_sign mutthy usedthy forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   688
 mutqc_thy 1 mutthy usedthy [] forbidden_funs iter insts sz qciter filename;
bulwahn@34952
   689
bulwahn@34952
   690
(*mixed version of function mutqc_thy*)
bulwahn@34952
   691
bulwahn@34952
   692
fun mutqc_thy_mix mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   693
 mutqc_thy 2 mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename;
bulwahn@34952
   694
bulwahn@34952
   695
(*create a statistic representation of the call of function mutqc_thy*)
bulwahn@34952
   696
bulwahn@34952
   697
fun mutqc_thystat option p mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   698
 let
bulwahn@34952
   699
   val thmlist = filter
wenzelm@40392
   700
     (fn (s, th) => not (p s th) andalso (Output.urgent_message s; is_executable mutthy insts th)) (thms_of mutthy)
bulwahn@34952
   701
   fun mutthmrec [] = ()
bulwahn@34952
   702
   |   mutthmrec ((name,thm)::xs) =
bulwahn@34952
   703
     let          
wenzelm@40392
   704
       val _ = Output.urgent_message ("mutthmrec: " ^ name);
bulwahn@34952
   705
       val mutated = mutate option (prop_of thm) usedthy
bulwahn@34952
   706
           commutatives forbidden_funs iter
bulwahn@34952
   707
       val (passednum,_,cenum,_) = qc_test mutated insts usedthy sz qciter
bulwahn@34952
   708
       val thmname =  "\ntheorem " ^ name ^ ":"
bulwahn@34952
   709
       val pnumstring = string_of_int passednum
bulwahn@34952
   710
       val cenumstring = string_of_int cenum
bulwahn@34952
   711
     in
bulwahn@34952
   712
       (File.append (Path.explode filename) 
bulwahn@34952
   713
         (thmname ^ (create_spaces thmname 50) ^ 
bulwahn@34952
   714
         pnumstring ^ (create_spaces pnumstring 20) ^ 
bulwahn@34952
   715
         cenumstring ^ (create_spaces cenumstring 20) ^ "\n");
bulwahn@34952
   716
       mutthmrec xs)
bulwahn@34952
   717
     end;
bulwahn@34952
   718
 in 
bulwahn@34952
   719
   (File.write (Path.explode filename) ("Result of the quickcheck-test of theory " ^
bulwahn@34952
   720
     ":\n\ntheorem name" ^ (create_spaces "theorem name" 50) ^ 
bulwahn@34952
   721
     "passed mutants"  ^ (create_spaces "passed mutants" 20) ^ 
bulwahn@34952
   722
     "counter examples\n\n" );
bulwahn@34952
   723
   mutthmrec thmlist)
bulwahn@34952
   724
 end;
bulwahn@34952
   725
bulwahn@34952
   726
(*exchange version of function mutqc_thystat*)
wenzelm@41315
   727
bulwahn@34952
   728
fun mutqc_thystat_exc p mutthy usedthy commutatives iter insts sz qciter filename =
bulwahn@34952
   729
 mutqc_thystat 0 p mutthy usedthy commutatives [] iter insts sz qciter filename;
bulwahn@34952
   730
bulwahn@34952
   731
(*signature version of function mutqc_thystat*)
bulwahn@34952
   732
bulwahn@34952
   733
fun mutqc_thystat_sign p mutthy usedthy forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   734
 mutqc_thystat 1 p mutthy usedthy [] forbidden_funs iter insts sz qciter filename;
bulwahn@34952
   735
bulwahn@34952
   736
(*mixed version of function mutqc_thystat*)
bulwahn@34952
   737
bulwahn@34952
   738
fun mutqc_thystat_mix p mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename =
bulwahn@34952
   739
 mutqc_thystat 2 p mutthy usedthy commutatives forbidden_funs iter insts sz qciter filename;
bulwahn@44754
   740
*)
bulwahn@34952
   741
bulwahn@34952
   742
end