src/HOL/Mutabelle/mutabelle.ML
author wenzelm
Tue, 03 Sep 2013 01:12:40 +0200
changeset 53374 a14d2a854c02
parent 51092 5e6398b48030
child 56025 d74fed45fa8b
permissions -rw-r--r--
tuned proofs -- clarified flow of facts wrt. calculation;
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
46332
f62f5f1fda3b removing dead code from Mutabelle; tuned
bulwahn
parents: 45428
diff changeset
    16
43883
aacbe67793c3 adapting mutabelle to latest changes in quickcheck; removing unused code in mutabelle
bulwahn
parents: 42429
diff changeset
    17
  val all_unconcealed_thms_of : theory -> (string * thm) list
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    18
end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    19
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    20
structure Mutabelle : MUTABELLE = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    21
struct
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    22
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    23
fun all_unconcealed_thms_of thy =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    24
  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
    25
    val facts = Global_Theory.facts_of thy
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    26
  in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    27
    Facts.fold_static
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    28
      (fn (s, ths) =>
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    29
        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
    30
      facts []
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    31
  end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    32
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    33
fun consts_of thy =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    34
 let
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    35
   val (namespace, const_table) = #constants (Consts.dest (Sign.consts_of thy))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    36
   val consts = Symtab.dest const_table
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    37
 in
42429
7691cc61720a standardized some ML aliases;
wenzelm
parents: 42361
diff changeset
    38
   map_filter (fn (s, (T, NONE)) => SOME (s, T) | _ => NONE)
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    39
     (filter_out (fn (s, _) => Name_Space.is_concealed namespace s) consts)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    40
 end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    41
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    42
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    43
(*thrown in case the specified path doesn't exist in the specified term*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    44
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    45
exception WrongPath of string;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    46
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    47
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    48
(*thrown in case the arguments did not fit to the function*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    49
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    50
exception WrongArg of string; 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    51
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    52
(*Rename the bound variables in a term with the minimal Index min of 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    53
bound variables. Variable (Bound(min)) will be renamed to Bound(0) etc. 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    54
This is needed in course auf evaluation of contexts.*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    55
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    56
fun rename_bnds curTerm 0 = curTerm
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    57
 | rename_bnds (Bound(i)) minInd = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    58
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    59
     val erg = if (i-minInd < 0) then 0 else (i - minInd)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    60
   in 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    61
     Bound(erg)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    62
   end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    63
 | rename_bnds (Abs(name,t,uTerm)) minInd = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    64
   Abs(name,t,(rename_bnds uTerm minInd))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    65
 | rename_bnds (fstUTerm $ sndUTerm) minInd =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    66
   (rename_bnds fstUTerm minInd) $ (rename_bnds sndUTerm minInd)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    67
 | rename_bnds elseTerm minInd = elseTerm;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    68
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    69
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    70
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    71
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    72
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    73
(*Partition a term in its subterms and create an entry 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    74
(term * type * abscontext * mincontext * path) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    75
for each term in the return list 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    76
e.g: getSubTermList Abs(y, int, Const(f,int->int) $ Const(x,int) $ Bound(0))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    77
will give       [(Const(f,int->int),int->int,[int],[],[00]),
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    78
               (Const(x,int),int,[int],[],[010]),
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    79
               (Bound(0),int,[int],[int],[110]),
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    80
               (Const(x,int) $ Bound(0),type,[int],[int],[10]),
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    81
               (Const(f,int->int) $ Const(x,int) $ Bound(0),type,[int],[int],[0],
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    82
               (Abs (y,int,Const(f,int->int) $ const(x,int) $ Bound(0)),type,[],[],[])]
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    83
                *)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    84
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    85
fun getSubTermList (Const(name,t)) abscontext path acc =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    86
   (Const(name,t),t,abscontext,abscontext,path)::acc
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    87
 | getSubTermList (Free(name,t)) abscontext path acc =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    88
   (Free(name,t),t,abscontext,abscontext,path)::acc
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    89
 | getSubTermList (Var(indname,t)) abscontext path acc =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    90
   (Var(indname,t),t,abscontext,abscontext,path)::acc
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    91
 | getSubTermList (Bound(i)) abscontext path acc =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    92
   (Bound(0),nth abscontext i,abscontext, Library.drop i abscontext,path)::acc
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    93
 | getSubTermList (Abs(name,t,uTerm)) abscontext path acc = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    94
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    95
     val curTerm = Abs(name,t,uTerm)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    96
     val bnos = Term.add_loose_bnos (curTerm,0,[])
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    97
     val minInd = if (bnos = []) then 0 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
    98
       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
    99
     val newTerm = rename_bnds curTerm minInd
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   100
     val newContext = Library.drop minInd abscontext
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   101
   in 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   102
     getSubTermList uTerm (t::abscontext) (0::path) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   103
               ((newTerm,(fastype_of1 (abscontext, curTerm)),abscontext,newContext,path)::acc)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   104
   end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   105
 | getSubTermList (fstUTerm $ sndUTerm) abscontext path acc = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   106
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   107
     val curTerm = (fstUTerm $ sndUTerm)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   108
     val bnos = Term.add_loose_bnos (curTerm, 0, [])
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   109
     val minInd = if (bnos = []) then 0
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   110
       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
   111
     val newTerm = rename_bnds curTerm minInd
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   112
     val newContext = Library.drop minInd abscontext
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   113
   in 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   114
     getSubTermList fstUTerm abscontext (0::path) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   115
       (getSubTermList sndUTerm abscontext (1::path) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   116
         ((newTerm,(fastype_of1 (abscontext, curTerm)),abscontext,newContext,path)::acc)) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   117
   end;  
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   118
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   119
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   120
(*Evaluate if the longContext is more special as the shortContext. 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   121
If so, a term with shortContext can be substituted in the place of a 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   122
term with longContext*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   123
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   124
fun is_morespecial longContext shortContext = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   125
 let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   126
   val revlC = rev longContext
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   127
   val revsC = rev shortContext
51092
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   128
   fun is_prefix [] _ = true
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   129
     | is_prefix _ [] = false
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   130
     | 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
   131
 in 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   132
   is_prefix revsC revlC
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   133
 end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   134
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   135
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   136
(*takes a (term * type * context * context * path)-tupel and searches in the specified list for 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   137
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
   138
Used in order to generate a list of type-equal subterms of the original term*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   139
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   140
fun searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) [] resultList = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   141
   resultList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   142
 | searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   143
   ((hdterm,hdtype,hdabsContext,hdminContext,hdpath)::xs) resultList = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   144
   if ((stype = hdtype) andalso (is_morespecial sabsContext hdminContext) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   145
     andalso (is_morespecial hdabsContext sminContext)) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   146
   then searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) xs 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   147
     ((hdterm,hdabsContext,hdminContext,hdpath)::resultList) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   148
   else searchForMutatableSubTerm (sterm,stype,sabsContext,sminContext,spath) xs resultList;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   149
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   150
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   151
(*evaluates if the given function is in the passed list of forbidden functions*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   152
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   153
fun in_list_forb consSig (consNameStr,consType) [] = false
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   154
 | in_list_forb consSig (consNameStr,consType) ((forbNameStr,forbTypeStr)::xs) = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   155
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   156
     val forbType = Syntax.read_typ_global consSig forbTypeStr
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   157
   in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   158
     if ((consNameStr = forbNameStr) 
47004
wenzelm
parents: 46479
diff changeset
   159
       andalso (Sign.typ_instance consSig (consType,(Logic.varifyT_global forbType))))
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   160
     then true
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   161
     else in_list_forb consSig (consNameStr,consType) xs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   162
   end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   163
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
(*searches in the given signature Consts with the same type as sterm and 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   167
returns a list of those terms*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   168
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   169
fun searchForSignatureMutations (sterm,stype) consSig forbidden_funs = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   170
 let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   171
   val sigConsTypeList = consts_of consSig;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   172
 in 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   173
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   174
     fun recursiveSearch mutatableTermList [] = mutatableTermList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   175
       | recursiveSearch mutatableTermList ((ConsName,ConsType)::xs) = 
47004
wenzelm
parents: 46479
diff changeset
   176
         if (Sign.typ_instance consSig (stype,ConsType) 
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   177
           andalso (not (sterm = Const(ConsName,stype))) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   178
           andalso (not (in_list_forb consSig (ConsName,ConsType) forbidden_funs))) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   179
         then recursiveSearch ((Term.Const(ConsName,stype), [], [], [5])::mutatableTermList) xs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   180
         else recursiveSearch mutatableTermList xs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   181
     in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   182
       recursiveSearch [] sigConsTypeList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   183
     end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   184
   end;     
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   185
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   186
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   187
(*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
   188
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
   189
in the current signature.
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   190
This function has 3 versions:
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   191
0: no instertion of signature functions, 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   192
  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
   193
1: no exchange of subterms,
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   194
  only signature functions are inserted at the place of type-aequivalent Conses
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   195
2: mixture of the two other versions. insertion of signature functions and exchange of subterms*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   196
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   197
fun searchForMutatableTerm 0 (sterm,stype,sabscontext,smincontext,spath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   198
   subTerms consSig resultList forbidden_funs =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   199
   searchForMutatableSubTerm (sterm,stype,sabscontext,smincontext,spath) subTerms resultList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   200
 | searchForMutatableTerm 1 (Const(constName,constType),stype,sabscontext,smincontext,spath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   201
   subTerms consSig resultList forbidden_funs = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   202
   searchForSignatureMutations (Const(constName,constType),stype) consSig forbidden_funs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   203
 | searchForMutatableTerm 1 _ _ _ _ _ = []
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   204
 | searchForMutatableTerm 2 (Const(constName,constType),stype,sabscontext,smincontext,spath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   205
   subTerms consSig resultList forbidden_funs = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   206
     let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   207
       val subtermMutations = searchForMutatableSubTerm 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   208
         (Const(constName,constType),stype,sabscontext,smincontext,spath) subTerms resultList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   209
       val signatureMutations = searchForSignatureMutations 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   210
         (Const(constName,constType),stype) consSig forbidden_funs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   211
     in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   212
       subtermMutations@signatureMutations
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   213
     end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   214
 | searchForMutatableTerm 2 (sterm,stype,sabscontext,smincontext,spath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   215
   subTerms consSig resultList forbidden_funs =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   216
   searchForMutatableSubTerm (sterm,stype,sabscontext,smincontext,spath) subTerms resultList
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   217
 | searchForMutatableTerm i _ _ _ _ _ = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   218
   raise WrongArg("Version " ^ string_of_int i ^ 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   219
     " doesn't exist for function searchForMutatableTerm!") ;
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
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   223
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   224
(*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
   225
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   226
fun areReplacable [] [] = false
51092
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   227
 | areReplacable _ [] = false
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   228
 | areReplacable [] _ = false
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   229
 | areReplacable (x::xs) (y::ys) = if (x=y) then areReplacable xs ys else true; 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   230
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   231
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   232
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   233
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   234
(*substitutes the term at the position of the first list in fstTerm by sndTerm. 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   235
The lists represent paths as generated by createSubTermList*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   236
51092
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   237
fun substitute [] _ sndTerm = sndTerm
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   238
 | substitute (_::xs) (Abs(s,T,subTerm)) sndTerm = Abs(s,T,(substitute xs subTerm sndTerm))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   239
 | substitute (0::xs) (t $ u) sndTerm = substitute xs t sndTerm $ u 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   240
 | substitute (1::xs) (t $ u) sndTerm = t $ substitute xs u sndTerm
51092
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   241
 | substitute (_::_) _ sndTerm = 
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   242
   raise WrongPath ("The Term could not be found at the specified position"); 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   243
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   244
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   245
(*get the subterm with the specified path in myTerm*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   246
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   247
fun getSubTerm myTerm [] = myTerm
51092
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   248
 | getSubTerm (Abs(_,_,subTerm)) (0::xs) = getSubTerm subTerm xs
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   249
 | getSubTerm (t $ _) (0::xs) = getSubTerm t xs
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   250
 | getSubTerm (_ $ u) (1::xs) = getSubTerm u xs
5e6398b48030 formal cleanup of sources
haftmann
parents: 47004
diff changeset
   251
 | getSubTerm _ (_::_) = 
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   252
   raise WrongPath ("The subterm could not be found at the specified position");
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   253
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   254
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   255
(*exchanges two subterms with the given paths in the original Term*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   256
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   257
fun replace origTerm (fstTerm, fstPath) (sndTerm, sndPath) = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   258
 if (areReplacable (rev fstPath) (rev sndPath))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   259
 then substitute (rev sndPath) (substitute (rev fstPath) origTerm sndTerm) fstTerm
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   260
 else origTerm; 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   261
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   262
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   263
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   264
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   265
(*tests if the terms with the given pathes in the origTerm are commutative
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   266
respecting the list of commutative operators (commutatives)*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   267
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   268
fun areCommutative origTerm fstPath sndPath commutatives =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   269
 if (sndPath = []) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   270
 then false
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   271
 else
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   272
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   273
     val base = (tl sndPath)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   274
   in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   275
     let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   276
       val fstcomm = 1::0::base
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   277
       val opcomm = 0::0::base
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   278
     in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   279
       if ((fstPath = fstcomm) andalso (is_Const (getSubTerm origTerm (rev opcomm))))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   280
       then
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   281
         let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   282
           val Const(name,_) = (getSubTerm origTerm (rev opcomm))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   283
         in
46332
f62f5f1fda3b removing dead code from Mutabelle; tuned
bulwahn
parents: 45428
diff changeset
   284
           member (op =) commutatives name
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   285
         end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   286
       else false
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   287
     end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   288
   end;
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
(*Canonizes term t with the commutative operators stored in list 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   292
commutatives*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   293
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   294
fun canonize_term (Const (s, T) $ t $ u) comms =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   295
 let
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   296
   val t' = canonize_term t comms;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   297
   val u' = canonize_term u comms;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   298
 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
   299
   if member (op =) comms s andalso Term_Ord.termless (u', t')
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   300
   then Const (s, T) $ u' $ t'
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   301
   else Const (s, T) $ t' $ u'
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   302
 end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   303
 | canonize_term (t $ u) comms = canonize_term t comms $ canonize_term u comms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   304
 | canonize_term (Abs (s, T, t)) comms = Abs (s, T, canonize_term t comms)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   305
 | canonize_term t comms = t;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   306
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   307
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   308
(*inspect the passed list and mutate origTerm following the elements of the list:
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   309
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
   310
and the subterm will be substituted by it
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   311
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
   312
The additional parameter commutatives indicates the commutative operators  
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   313
in the term whose operands won't be exchanged*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   314
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   315
fun createMutatedTerms origTerm _ [] commutatives mutatedTerms = mutatedTerms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   316
 | createMutatedTerms origTerm (hdt as (hdTerm,hdabsContext,hdminContext,hdPath))
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   317
   ((sndTerm,sndabsContext,sndminContext,sndPath)::xs) commutatives mutatedTerms = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   318
   if (sndPath = [5])
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   319
   then
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   320
     let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   321
         val canonized = canonize_term (substitute (rev hdPath) origTerm sndTerm) commutatives
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   322
       in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   323
         if (canonized = origTerm)  
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   324
         then createMutatedTerms origTerm hdt xs commutatives mutatedTerms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   325
         else createMutatedTerms origTerm hdt xs commutatives 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   326
           (insert op aconv canonized mutatedTerms)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   327
       end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   328
     else 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   329
       if ((areCommutative origTerm hdPath sndPath commutatives)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   330
         orelse (areCommutative origTerm sndPath hdPath commutatives)) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   331
       then createMutatedTerms origTerm hdt xs commutatives mutatedTerms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   332
       else
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   333
         let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   334
           val canonized = canonize_term 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   335
             (replace origTerm
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   336
                (incr_boundvars (length sndabsContext - length hdminContext) hdTerm,
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   337
                 hdPath)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   338
                (incr_boundvars (length hdabsContext - length sndminContext) sndTerm,
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   339
                 sndPath)) commutatives
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   340
         in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   341
           if (not(canonized = origTerm)) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   342
           then createMutatedTerms origTerm hdt xs commutatives 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   343
             (insert op aconv canonized mutatedTerms)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   344
           else createMutatedTerms origTerm hdt xs commutatives mutatedTerms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   345
         end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   346
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   347
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   348
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   349
(*mutates origTerm by exchanging subterms. The mutated terms are returned in a term list
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   350
The parameter commutatives consists of a list of commutative operators. The permutation of their 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   351
operands won't be considered as a new term
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   352
!!!Attention!!!: The given origTerm must be canonized. Use function canonize_term!*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   353
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   354
fun mutate_once option origTerm tsig commutatives forbidden_funs= 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   355
 let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   356
   val subTermList = getSubTermList origTerm [] [] []
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   357
 in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   358
   let 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   359
     fun replaceRecursively [] mutatedTerms = mutatedTerms
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   360
       | replaceRecursively ((hdTerm,hdType,hdabsContext,hdminContext,hdPath)::tail) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   361
         mutatedTerms =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   362
         replaceRecursively tail (union op aconv (createMutatedTerms origTerm 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   363
           (hdTerm,hdabsContext,hdminContext,hdPath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   364
           (searchForMutatableTerm option (hdTerm,hdType,hdabsContext,hdminContext,hdPath) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   365
             tail tsig [] forbidden_funs) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   366
           commutatives []) mutatedTerms)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   367
   in
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   368
     replaceRecursively subTermList []
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   369
   end
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   370
 end;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   371
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   372
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   373
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   374
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   375
(*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
   376
Needed for the mutate function*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   377
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   378
fun mutate_once_rec option [] tsig commutatives forbidden_funs acc = acc
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   379
 | mutate_once_rec option (x::xs) tsig commutatives forbidden_funs acc = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   380
   mutate_once_rec option xs tsig commutatives forbidden_funs 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   381
     (union op aconv (mutate_once option x tsig commutatives forbidden_funs) acc);
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   382
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   383
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   384
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   385
(*apply function mutate_once iter times on the given origTerm. *)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   386
(*call of mutiere with canonized form of origTerm. Prevents us of the computation of
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   387
canonization in the course of insertion of new terms!*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   388
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   389
fun mutate option origTerm tsig commutatives forbidden_funs 0 = []
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   390
 | mutate option origTerm tsig commutatives forbidden_funs 1 = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   391
   mutate_once option (canonize_term origTerm commutatives) tsig commutatives forbidden_funs
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   392
 | mutate option origTerm tsig commutatives forbidden_funs iter = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   393
   mutate_once_rec option (mutate option origTerm tsig commutatives forbidden_funs (iter-1)) 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   394
     tsig commutatives forbidden_funs []; 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   395
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   396
(*mutate origTerm iter times by only exchanging subterms*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   397
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   398
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
   399
 mutate 0 origTerm @{theory Main} commutatives [] iter;
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   400
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   401
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   402
(*mutate origTerm iter times by only inserting signature functions*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   403
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   404
fun mutate_sign origTerm tsig forbidden_funs iter = 
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   405
 mutate 1 origTerm tsig [] forbidden_funs iter;
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
(*mutate origTerm iter times by exchange of subterms and insertion of subterms*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   409
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   410
fun mutate_mix origTerm tsig commutatives forbidden_funs iter =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   411
 mutate 2 origTerm tsig commutatives forbidden_funs iter;  
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   412
46332
f62f5f1fda3b removing dead code from Mutabelle; tuned
bulwahn
parents: 45428
diff changeset
   413
 
34965
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   414
(*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
   415
and tries to print the exceptions*)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   416
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   417
fun freeze (t $ u) = freeze t $ freeze u
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   418
 | freeze (Abs (s, T, t)) = Abs (s, T, freeze t)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   419
 | freeze (Var ((a, i), T)) =
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   420
     Free (if i = 0 then a else a ^ "_" ^ string_of_int i, T)
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   421
 | freeze t = t;
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   422
3b4762c1052c adding Mutabelle to repository
bulwahn
parents:
diff changeset
   423
end