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