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