| author | blanchet | 
| Fri, 01 Jul 2011 15:53:37 +0200 | |
| changeset 43625 | c3e28c869499 | 
| parent 43554 | 9bece8cbb5be | 
| child 43829 | fba9754b827e | 
| permissions | -rw-r--r-- | 
| 36898 | 1 | (* Title: HOL/Tools/SMT/smt_translate.ML | 
| 2 | Author: Sascha Boehme, TU Muenchen | |
| 3 | ||
| 4 | Translate theorems into an SMT intermediate format and serialize them. | |
| 5 | *) | |
| 6 | ||
| 7 | signature SMT_TRANSLATE = | |
| 8 | sig | |
| 41123 | 9 | (*intermediate term structure*) | 
| 36898 | 10 | datatype squant = SForall | SExists | 
| 11 | datatype 'a spattern = SPat of 'a list | SNoPat of 'a list | |
| 12 | datatype sterm = | |
| 13 | SVar of int | | |
| 14 | SApp of string * sterm list | | |
| 15 | SLet of string * sterm * sterm | | |
| 40664 | 16 | SQua of squant * string list * sterm spattern list * int option * sterm | 
| 36898 | 17 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 18 | (*translation configuration*) | 
| 36898 | 19 |   type prefixes = {sort_prefix: string, func_prefix: string}
 | 
| 20 |   type sign = {
 | |
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 21 | header: string list, | 
| 36898 | 22 | sorts: string list, | 
| 39298 
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
 boehmes parents: 
37124diff
changeset | 23 | dtyps: (string * (string * (string * string) list) list) list list, | 
| 36898 | 24 | funcs: (string * (string list * string)) list } | 
| 25 |   type config = {
 | |
| 26 | prefixes: prefixes, | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 27 | header: term list -> string list, | 
| 41059 
d2b1fc1b8e19
centralized handling of built-in types and constants;
 boehmes parents: 
41057diff
changeset | 28 | is_fol: bool, | 
| 
d2b1fc1b8e19
centralized handling of built-in types and constants;
 boehmes parents: 
41057diff
changeset | 29 | has_datatypes: bool, | 
| 36898 | 30 | serialize: string list -> sign -> sterm list -> string } | 
| 31 |   type recon = {
 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 32 | context: Proof.context, | 
| 36898 | 33 | typs: typ Symtab.table, | 
| 34 | terms: term Symtab.table, | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 35 | rewrite_rules: thm list, | 
| 40161 
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
 boehmes parents: 
39535diff
changeset | 36 | assms: (int * thm) list } | 
| 36898 | 37 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 38 | (*translation*) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 39 | val add_config: SMT_Utils.class * (Proof.context -> config) -> | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 40 | Context.generic -> Context.generic | 
| 43507 
d566714a9ce1
export lambda-lifting code as there is potential use for it within Sledgehammer
 boehmes parents: 
43385diff
changeset | 41 | val lift_lambdas: Proof.context -> term list -> | 
| 
d566714a9ce1
export lambda-lifting code as there is potential use for it within Sledgehammer
 boehmes parents: 
43385diff
changeset | 42 | Proof.context * (term list * term list) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 43 | val translate: Proof.context -> string list -> (int * thm) list -> | 
| 36898 | 44 | string * recon | 
| 45 | end | |
| 46 | ||
| 47 | structure SMT_Translate: SMT_TRANSLATE = | |
| 48 | struct | |
| 49 | ||
| 40663 | 50 | |
| 36898 | 51 | (* intermediate term structure *) | 
| 52 | ||
| 53 | datatype squant = SForall | SExists | |
| 54 | ||
| 55 | datatype 'a spattern = SPat of 'a list | SNoPat of 'a list | |
| 56 | ||
| 57 | datatype sterm = | |
| 58 | SVar of int | | |
| 59 | SApp of string * sterm list | | |
| 60 | SLet of string * sterm * sterm | | |
| 40664 | 61 | SQua of squant * string list * sterm spattern list * int option * sterm | 
| 36898 | 62 | |
| 63 | ||
| 64 | ||
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 65 | (* translation configuration *) | 
| 36898 | 66 | |
| 67 | type prefixes = {sort_prefix: string, func_prefix: string}
 | |
| 68 | ||
| 69 | type sign = {
 | |
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 70 | header: string list, | 
| 36898 | 71 | sorts: string list, | 
| 39298 
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
 boehmes parents: 
37124diff
changeset | 72 | dtyps: (string * (string * (string * string) list) list) list list, | 
| 36898 | 73 | funcs: (string * (string list * string)) list } | 
| 74 | ||
| 75 | type config = {
 | |
| 76 | prefixes: prefixes, | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 77 | header: term list -> string list, | 
| 41059 
d2b1fc1b8e19
centralized handling of built-in types and constants;
 boehmes parents: 
41057diff
changeset | 78 | is_fol: bool, | 
| 
d2b1fc1b8e19
centralized handling of built-in types and constants;
 boehmes parents: 
41057diff
changeset | 79 | has_datatypes: bool, | 
| 36898 | 80 | serialize: string list -> sign -> sterm list -> string } | 
| 81 | ||
| 82 | type recon = {
 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 83 | context: Proof.context, | 
| 36898 | 84 | typs: typ Symtab.table, | 
| 85 | terms: term Symtab.table, | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 86 | rewrite_rules: thm list, | 
| 40161 
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
 boehmes parents: 
39535diff
changeset | 87 | assms: (int * thm) list } | 
| 36898 | 88 | |
| 89 | ||
| 90 | ||
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 91 | (* translation context *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 92 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 93 | fun make_tr_context {sort_prefix, func_prefix} =
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 94 | (sort_prefix, 1, Typtab.empty, func_prefix, 1, Termtab.empty) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 95 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 96 | fun string_of_index pre i = pre ^ string_of_int i | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 97 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 98 | fun add_typ T proper (cx as (sp, Tidx, typs, fp, idx, terms)) = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 99 | (case Typtab.lookup typs T of | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 100 | SOME (n, _) => (n, cx) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 101 | | NONE => | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 102 | let | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 103 | val n = string_of_index sp Tidx | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 104 | val typs' = Typtab.update (T, (n, proper)) typs | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 105 | in (n, (sp, Tidx+1, typs', fp, idx, terms)) end) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 106 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 107 | fun add_fun t sort (cx as (sp, Tidx, typs, fp, idx, terms)) = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 108 | (case Termtab.lookup terms t of | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 109 | SOME (n, _) => (n, cx) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 110 | | NONE => | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 111 | let | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 112 | val n = string_of_index fp idx | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 113 | val terms' = Termtab.update (t, (n, sort)) terms | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 114 | in (n, (sp, Tidx, typs, fp, idx+1, terms')) end) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 115 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 116 | fun sign_of header dtyps (_, _, typs, _, _, terms) = {
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 117 | header = header, | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 118 | sorts = Typtab.fold (fn (_, (n, true)) => cons n | _ => I) typs [], | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 119 | dtyps = dtyps, | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 120 | funcs = Termtab.fold (fn (_, (n, SOME ss)) => cons (n,ss) | _ => I) terms []} | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 121 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 122 | fun recon_of ctxt rules thms ithms (_, _, typs, _, _, terms) = | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 123 | let | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 124 | fun add_typ (T, (n, _)) = Symtab.update (n, T) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 125 | val typs' = Typtab.fold add_typ typs Symtab.empty | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 126 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 127 | fun add_fun (t, (n, _)) = Symtab.update (n, t) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 128 | val terms' = Termtab.fold add_fun terms Symtab.empty | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 129 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 130 | val assms = map (pair ~1) thms @ ithms | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 131 | in | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 132 |     {context=ctxt, typs=typs', terms=terms', rewrite_rules=rules, assms=assms}
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 133 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 134 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 135 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 136 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 137 | (* preprocessing *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 138 | |
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 139 | (** datatype declarations **) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 140 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 141 | fun collect_datatypes_and_records (tr_context, ctxt) ts = | 
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 142 | let | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 143 | val (declss, ctxt') = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 144 | fold (Term.fold_types SMT_Datatypes.add_decls) ts ([], ctxt) | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 145 | |
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 146 | fun is_decl_typ T = exists (exists (equal T o fst)) declss | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 147 | |
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 148 | fun add_typ' T proper = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 149 | (case SMT_Builtin.dest_builtin_typ ctxt' T of | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 150 | SOME n => pair n | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 151 | | NONE => add_typ T proper) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 152 | |
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 153 | fun tr_select sel = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 154 | let val T = Term.range_type (Term.fastype_of sel) | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 155 | in add_fun sel NONE ##>> add_typ' T (not (is_decl_typ T)) end | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 156 | fun tr_constr (constr, selects) = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 157 | add_fun constr NONE ##>> fold_map tr_select selects | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 158 | fun tr_typ (T, cases) = add_typ' T false ##>> fold_map tr_constr cases | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 159 | val (declss', tr_context') = fold_map (fold_map tr_typ) declss tr_context | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 160 | |
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 161 | fun add (constr, selects) = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 162 | Termtab.update (constr, length selects) #> | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 163 | fold (Termtab.update o rpair 1) selects | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 164 | val funcs = fold (fold (fold add o snd)) declss Termtab.empty | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 165 | in ((funcs, declss', tr_context', ctxt'), ts) end | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 166 | (* FIXME: also return necessary datatype and record theorems *) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 167 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 168 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 169 | (** eta-expand quantifiers, let expressions and built-ins *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 170 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 171 | local | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 172 | fun eta f T t = Abs (Name.uu, T, f (Term.incr_boundvars 1 t $ Bound 0)) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 173 | |
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 174 | fun exp f T = eta f (Term.domain_type (Term.domain_type T)) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 175 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 176 | fun exp2 T q = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 177 | let val U = Term.domain_type T | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 178 | in Abs (Name.uu, U, q $ eta I (Term.domain_type U) (Bound 0)) end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 179 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 180 | fun exp2' T l = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 181 | let val (U1, U2) = Term.dest_funT T ||> Term.domain_type | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 182 | in Abs (Name.uu, U1, eta I U2 (l $ Bound 0)) end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 183 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 184 | fun expf k i T t = | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 185 | let val Ts = drop i (fst (SMT_Utils.dest_funT k T)) | 
| 41195 
f59491d56327
fixed eta-expansion: introduce a couple of abstractions at once
 boehmes parents: 
41173diff
changeset | 186 | in | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 187 | Term.incr_boundvars (length Ts) t | 
| 42321 
ce83c1654b86
fixed eta-expansion: use correct order to apply new bound variables
 boehmes parents: 
42319diff
changeset | 188 | |> fold_rev (fn i => fn u => u $ Bound i) (0 upto length Ts - 1) | 
| 41195 
f59491d56327
fixed eta-expansion: introduce a couple of abstractions at once
 boehmes parents: 
41173diff
changeset | 189 | |> fold_rev (fn T => fn u => Abs (Name.uu, T, u)) Ts | 
| 
f59491d56327
fixed eta-expansion: introduce a couple of abstractions at once
 boehmes parents: 
41173diff
changeset | 190 | end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 191 | in | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 192 | |
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 193 | fun eta_expand ctxt is_fol funcs = | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 194 | let | 
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 195 | fun exp_func t T ts = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 196 | (case Termtab.lookup funcs t of | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 197 | SOME k => | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 198 | Term.list_comb (t, ts) | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 199 | |> k <> length ts ? expf k (length ts) T | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 200 | | NONE => Term.list_comb (t, ts)) | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 201 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 202 |     fun expand ((q as Const (@{const_name All}, _)) $ Abs a) = q $ abs_expand a
 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 203 |       | expand ((q as Const (@{const_name All}, T)) $ t) = q $ exp expand T t
 | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 204 |       | expand (q as Const (@{const_name All}, T)) = exp2 T q
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 205 |       | expand ((q as Const (@{const_name Ex}, _)) $ Abs a) = q $ abs_expand a
 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 206 |       | expand ((q as Const (@{const_name Ex}, T)) $ t) = q $ exp expand T t
 | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 207 |       | expand (q as Const (@{const_name Ex}, T)) = exp2 T q
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 208 |       | expand ((l as Const (@{const_name Let}, _)) $ t $ Abs a) =
 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 209 | if is_fol then expand (Term.betapply (Abs a, t)) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 210 | else l $ expand t $ abs_expand a | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 211 |       | expand ((l as Const (@{const_name Let}, T)) $ t $ u) =
 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 212 | if is_fol then expand (u $ t) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 213 | else l $ expand t $ exp expand (Term.range_type T) u | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 214 |       | expand ((l as Const (@{const_name Let}, T)) $ t) =
 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 215 | if is_fol then | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 216 | let val U = Term.domain_type (Term.range_type T) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 217 | in Abs (Name.uu, U, Bound 0 $ Term.incr_boundvars 1 t) end | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 218 | else exp2 T (l $ expand t) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 219 |       | expand (l as Const (@{const_name Let}, T)) =
 | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 220 | if is_fol then | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 221 | let val U = Term.domain_type (Term.range_type T) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 222 | in | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 223 | Abs (Name.uu, Term.domain_type T, Abs (Name.uu, U, | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 224 | Bound 0 $ Bound 1)) | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 225 | end | 
| 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 226 | else exp2' T l | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 227 | | expand t = | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 228 | (case Term.strip_comb t of | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 229 | (u as Const (c as (_, T)), ts) => | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 230 | (case SMT_Builtin.dest_builtin ctxt c ts of | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 231 | SOME (_, k, us, mk) => | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 232 | if k = length us then mk (map expand us) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 233 | else expf k (length ts) T (mk (map expand us)) | 
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 234 | | NONE => exp_func u T (map expand ts)) | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 235 | | (u as Free (_, T), ts) => exp_func u T (map expand ts) | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 236 | | (Abs a, ts) => Term.list_comb (abs_expand a, map expand ts) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 237 | | (u, ts) => Term.list_comb (u, map expand ts)) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 238 | |
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 239 | and abs_expand (n, T, t) = Abs (n, T, expand t) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 240 | |
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 241 | in map expand end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 242 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 243 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 244 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 245 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 246 | (** lambda-lifting **) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 247 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 248 | local | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 249 | fun mk_def Ts T lhs rhs = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 250 | let | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 251 | val eq = HOLogic.eq_const T $ lhs $ rhs | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 252 | val trigger = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 253 |         [[Const (@{const_name SMT.pat}, T --> @{typ SMT.pattern}) $ lhs]]
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 254 |         |> map (HOLogic.mk_list @{typ SMT.pattern})
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 255 |         |> HOLogic.mk_list @{typ "SMT.pattern list"}
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 256 | fun mk_all T t = HOLogic.all_const T $ Abs (Name.uu, T, t) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 257 |     in fold mk_all Ts (@{const SMT.trigger} $ trigger $ eq) end
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 258 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 259 | fun mk_abs Ts = fold (fn T => fn t => Abs (Name.uu, T, t)) Ts | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 260 | |
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 261 | fun dest_abs Ts (Abs (_, T, t)) = dest_abs (T :: Ts) t | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 262 | | dest_abs Ts t = (Ts, t) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 263 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 264 | fun replace_lambda Us Ts t (cx as (defs, ctxt)) = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 265 | let | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 266 | val t1 = mk_abs Us t | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 267 | val bs = sort int_ord (Term.add_loose_bnos (t1, 0, [])) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 268 | fun rep i k = if member (op =) bs i then (Bound k, k+1) else (Bound i, k) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 269 | val (rs, _) = fold_map rep (0 upto length Ts - 1) 0 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 270 | val t2 = Term.subst_bounds (rs, t1) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 271 | val Ts' = map (nth Ts) bs | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 272 | val (_, t3) = dest_abs [] t2 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 273 | val t4 = mk_abs Ts' t2 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 274 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 275 | val T = Term.fastype_of1 (Us @ Ts, t) | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 276 | fun app f = Term.list_comb (f, map Bound (rev bs)) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 277 | in | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 278 | (case Termtab.lookup defs t4 of | 
| 41197 
edab1efe0a70
fix lambda-lifting: take level of bound variables into account and also apply bound variables from outer scope
 boehmes parents: 
41196diff
changeset | 279 | SOME (f, _) => (app f, cx) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 280 | | NONE => | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 281 | let | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 282 | val (n, ctxt') = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 283 | yield_singleton Variable.variant_fixes Name.uu ctxt | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 284 | val (is, UTs) = split_list (map_index I (Us @ Ts')) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 285 | val f = Free (n, rev UTs ---> T) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 286 | val lhs = Term.list_comb (f, map Bound (rev is)) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 287 | val def = mk_def UTs (Term.fastype_of1 (Us @ Ts, t)) lhs t3 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 288 | in (app f, (Termtab.update (t4, (f, def)) defs, ctxt')) end) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 289 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 290 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 291 | fun traverse Ts t = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 292 | (case t of | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 293 |       (q as Const (@{const_name All}, _)) $ Abs a =>
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 294 | abs_traverse Ts a #>> (fn a' => q $ Abs a') | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 295 |     | (q as Const (@{const_name Ex}, _)) $ Abs a =>
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 296 | abs_traverse Ts a #>> (fn a' => q $ Abs a') | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 297 |     | (l as Const (@{const_name Let}, _)) $ u $ Abs a =>
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 298 | traverse Ts u ##>> abs_traverse Ts a #>> | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 299 | (fn (u', a') => l $ u' $ Abs a') | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 300 | | Abs _ => | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 301 | let val (Us, u) = dest_abs [] t | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 302 | in traverse (Us @ Ts) u #-> replace_lambda Us Ts end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 303 | | u1 $ u2 => traverse Ts u1 ##>> traverse Ts u2 #>> (op $) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 304 | | _ => pair t) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 305 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 306 | and abs_traverse Ts (n, T, t) = traverse (T::Ts) t #>> (fn t' => (n, T, t')) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 307 | in | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 308 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 309 | fun lift_lambdas ctxt ts = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 310 | (Termtab.empty, ctxt) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 311 | |> fold_map (traverse []) ts | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 312 | |> (fn (us, (defs, ctxt')) => | 
| 43507 
d566714a9ce1
export lambda-lifting code as there is potential use for it within Sledgehammer
 boehmes parents: 
43385diff
changeset | 313 | (ctxt', (Termtab.fold (cons o snd o snd) defs [], us))) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 314 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 315 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 316 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 317 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 318 | (** introduce explicit applications **) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 319 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 320 | local | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 321 | (* | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 322 | Make application explicit for functions with varying number of arguments. | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 323 | *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 324 | |
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 325 | fun add t i = apfst (Termtab.map_default (t, i) (Integer.min i)) | 
| 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 326 | fun add_type T = apsnd (Typtab.update (T, ())) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 327 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 328 | fun min_arities t = | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 329 | (case Term.strip_comb t of | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 330 | (u as Const _, ts) => add u (length ts) #> fold min_arities ts | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 331 | | (u as Free _, ts) => add u (length ts) #> fold min_arities ts | 
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 332 | | (Abs (_, T, u), ts) => add_type T #> min_arities u #> fold min_arities ts | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 333 | | (_, ts) => fold min_arities ts) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 334 | |
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 335 | fun minimize types t i = | 
| 43554 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 336 | let | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 337 | fun find_min j [] _ = j | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 338 | | find_min j (U :: Us) T = | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 339 | if Typtab.defined types T then j | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 340 | else find_min (j + 1) Us (U --> T) | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 341 | |
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 342 | val (Ts, T) = Term.strip_type (Term.type_of t) | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 343 | in find_min 0 (take i (rev Ts)) T end | 
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 344 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 345 | fun app u (t, T) = | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 346 |     (Const (@{const_name SMT.fun_app}, T --> T) $ t $ u, Term.range_type T)
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 347 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 348 | fun apply i t T ts = | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 349 | let | 
| 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 350 | val (ts1, ts2) = chop i ts | 
| 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 351 | val (_, U) = SMT_Utils.dest_funT i T | 
| 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 352 | in fst (fold app ts2 (Term.list_comb (t, ts1), U)) end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 353 | in | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 354 | |
| 43385 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 355 | fun intro_explicit_application ctxt funcs ts = | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 356 | let | 
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 357 | val (arities, types) = fold min_arities ts (Termtab.empty, Typtab.empty) | 
| 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 358 | val arities' = Termtab.map (minimize types) arities | 
| 43385 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 359 | |
| 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 360 | fun app_func t T ts = | 
| 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 361 | if is_some (Termtab.lookup funcs t) then Term.list_comb (t, ts) | 
| 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 362 | else apply (the (Termtab.lookup arities' t)) t T ts | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 363 | |
| 43554 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 364 | fun in_list T f t = HOLogic.mk_list T (map f (HOLogic.dest_list t)) | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 365 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 366 | fun traverse Ts t = | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 367 | (case Term.strip_comb t of | 
| 43554 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 368 |         (q as Const (@{const_name All}, _), [Abs (x, T, u)]) =>
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 369 | q $ Abs (x, T, in_trigger (T :: Ts) u) | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 370 |       | (q as Const (@{const_name Ex}, _), [Abs (x, T, u)]) =>
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 371 | q $ Abs (x, T, in_trigger (T :: Ts) u) | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 372 |       | (q as Const (@{const_name Let}, _), [u1 as Abs _, u2]) =>
 | 
| 43154 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 373 | q $ traverse Ts u1 $ traverse Ts u2 | 
| 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 374 | | (u as Const (c as (_, T)), ts) => | 
| 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 375 | (case SMT_Builtin.dest_builtin ctxt c ts of | 
| 
72e4753a6677
made introduction of explicit application stable under removal of vacuous facts (which only lower the rank of constants but do not participate in the proof)
 boehmes parents: 
42321diff
changeset | 376 | SOME (_, _, us, mk) => mk (map (traverse Ts) us) | 
| 43385 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 377 | | NONE => app_func u T (map (traverse Ts) ts)) | 
| 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 378 | | (u as Free (_, T), ts) => app_func u T (map (traverse Ts) ts) | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 379 | | (u as Bound i, ts) => apply 0 u (nth Ts i) (map (traverse Ts) ts) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 380 | | (Abs (n, T, u), ts) => traverses Ts (Abs (n, T, traverse (T::Ts) u)) ts | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 381 | | (u, ts) => traverses Ts u ts) | 
| 43554 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 382 |     and in_trigger Ts ((c as @{const SMT.trigger}) $ p $ t) =
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 383 | c $ in_pats Ts p $ in_weight Ts t | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 384 | | in_trigger Ts t = in_weight Ts t | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 385 | and in_pats Ts ps = | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 386 |       in_list @{typ "SMT.pattern list"}
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 387 |         (in_list @{typ SMT.pattern} (in_pat Ts)) ps
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 388 |     and in_pat Ts ((p as Const (@{const_name SMT.pat}, _)) $ t) =
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 389 | p $ traverse Ts t | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 390 |       | in_pat Ts ((p as Const (@{const_name SMT.nopat}, _)) $ t) =
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 391 | p $ traverse Ts t | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 392 |       | in_pat _ t = raise TERM ("bad pattern", [t])
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 393 |     and in_weight Ts ((c as @{const SMT.weight}) $ w $ t) =
 | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 394 | c $ w $ traverse Ts t | 
| 
9bece8cbb5be
generalized introduction of explicit application constant: consider more functions as possible witness/instance of quantifiers than before (a constant of type T1 -> T2 -> T3 should be considered to have a rank less or equal to 1 if variables of type T2 -> T3 occur bound in a problem);
 boehmes parents: 
43507diff
changeset | 395 | | in_weight Ts t = traverse Ts t | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 396 | and traverses Ts t ts = Term.list_comb (t, map (traverse Ts) ts) | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 397 | in map (traverse []) ts end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 398 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 399 | val fun_app_eq = mk_meta_eq @{thm SMT.fun_app_def}
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 400 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 401 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 402 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 403 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 404 | (** map HOL formulas to FOL formulas (i.e., separate formulas froms terms) **) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 405 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 406 | local | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 407 |   val term_bool = @{lemma "SMT.term_true ~= SMT.term_false"
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 408 | by (simp add: SMT.term_true_def SMT.term_false_def)} | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 409 | |
| 41785 
77dcc197df9a
wrap occurrences of quantifiers in first-order terms (i.e., outside first-order formulas) in If-expressions
 boehmes parents: 
41426diff
changeset | 410 |   val is_quant = member (op =) [@{const_name All}, @{const_name Ex}]
 | 
| 
77dcc197df9a
wrap occurrences of quantifiers in first-order terms (i.e., outside first-order formulas) in If-expressions
 boehmes parents: 
41426diff
changeset | 411 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 412 | val fol_rules = [ | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 413 | Let_def, | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 414 |     mk_meta_eq @{thm SMT.term_true_def},
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 415 |     mk_meta_eq @{thm SMT.term_false_def},
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 416 |     @{lemma "P = True == P" by (rule eq_reflection) simp},
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 417 |     @{lemma "if P then True else False == P" by (rule eq_reflection) simp}]
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 418 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 419 |   fun as_term t = @{const HOL.eq (bool)} $ t $ @{const SMT.term_true}
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 420 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 421 | fun wrap_in_if t = | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 422 |     @{const If (bool)} $ t $ @{const SMT.term_true} $ @{const SMT.term_false}
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 423 | |
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 424 | fun is_builtin_conn_or_pred ctxt c ts = | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 425 | is_some (SMT_Builtin.dest_builtin_conn ctxt c ts) orelse | 
| 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 426 | is_some (SMT_Builtin.dest_builtin_pred ctxt c ts) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 427 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 428 | fun builtin b ctxt c ts = | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 429 | (case (Const c, ts) of | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 430 |       (@{const HOL.eq (bool)}, [t, u]) =>
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 431 |         if t = @{const SMT.term_true} orelse u = @{const SMT.term_true} then
 | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 432 | SMT_Builtin.dest_builtin_eq ctxt t u | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 433 | else b ctxt c ts | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 434 | | _ => b ctxt c ts) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 435 | in | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 436 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 437 | fun folify ctxt = | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 438 | let | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 439 | fun in_list T f t = HOLogic.mk_list T (map f (HOLogic.dest_list t)) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 440 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 441 | fun in_term t = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 442 | (case Term.strip_comb t of | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 443 |         (@{const True}, []) => @{const SMT.term_true}
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 444 |       | (@{const False}, []) => @{const SMT.term_false}
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 445 |       | (u as Const (@{const_name If}, _), [t1, t2, t3]) =>
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 446 | u $ in_form t1 $ in_term t2 $ in_term t3 | 
| 41785 
77dcc197df9a
wrap occurrences of quantifiers in first-order terms (i.e., outside first-order formulas) in If-expressions
 boehmes parents: 
41426diff
changeset | 447 | | (Const (c as (n, _)), ts) => | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 448 | if is_builtin_conn_or_pred ctxt c ts then wrap_in_if (in_form t) | 
| 41785 
77dcc197df9a
wrap occurrences of quantifiers in first-order terms (i.e., outside first-order formulas) in If-expressions
 boehmes parents: 
41426diff
changeset | 449 | else if is_quant n then wrap_in_if (in_form t) | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 450 | else Term.list_comb (Const c, map in_term ts) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 451 | | (Free c, ts) => Term.list_comb (Free c, map in_term ts) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 452 | | _ => t) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 453 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 454 |     and in_weight ((c as @{const SMT.weight}) $ w $ t) = c $ w $ in_form t
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 455 | | in_weight t = in_form t | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 456 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 457 |     and in_pat ((p as Const (@{const_name SMT.pat}, _)) $ t) = p $ in_term t
 | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 458 |       | in_pat ((p as Const (@{const_name SMT.nopat}, _)) $ t) = p $ in_term t
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 459 |       | in_pat t = raise TERM ("bad pattern", [t])
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 460 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 461 | and in_pats ps = | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 462 |       in_list @{typ "SMT.pattern list"} (in_list @{typ SMT.pattern} in_pat) ps
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 463 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 464 |     and in_trigger ((c as @{const SMT.trigger}) $ p $ t) =
 | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 465 | c $ in_pats p $ in_weight t | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 466 | | in_trigger t = in_weight t | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 467 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 468 | and in_form t = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 469 | (case Term.strip_comb t of | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 470 | (q as Const (qn, _), [Abs (n, T, u)]) => | 
| 41785 
77dcc197df9a
wrap occurrences of quantifiers in first-order terms (i.e., outside first-order formulas) in If-expressions
 boehmes parents: 
41426diff
changeset | 471 | if is_quant qn then q $ Abs (n, T, in_trigger u) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 472 | else as_term (in_term t) | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 473 | | (Const c, ts) => | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 474 | (case SMT_Builtin.dest_builtin_conn ctxt c ts of | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 475 | SOME (_, _, us, mk) => mk (map in_form us) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 476 | | NONE => | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 477 | (case SMT_Builtin.dest_builtin_pred ctxt c ts of | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 478 | SOME (_, _, us, mk) => mk (map in_term us) | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 479 | | NONE => as_term (in_term t))) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 480 | | _ => as_term (in_term t)) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 481 | in | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 482 | map in_form #> | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 483 | cons (SMT_Utils.prop_of term_bool) #> | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 484 | pair (fol_rules, [term_bool], builtin) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 485 | end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 486 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 487 | end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 488 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 489 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 490 | (* translation into intermediate format *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 491 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 492 | (** utility functions **) | 
| 36898 | 493 | |
| 494 | val quantifier = (fn | |
| 495 |     @{const_name All} => SOME SForall
 | |
| 496 |   | @{const_name Ex} => SOME SExists
 | |
| 497 | | _ => NONE) | |
| 498 | ||
| 499 | fun group_quant qname Ts (t as Const (q, _) $ Abs (_, T, u)) = | |
| 500 | if q = qname then group_quant qname (T :: Ts) u else (Ts, t) | |
| 501 | | group_quant _ Ts t = (Ts, t) | |
| 502 | ||
| 40664 | 503 | fun dest_weight (@{const SMT.weight} $ w $ t) =
 | 
| 41173 
7c6178d45cc8
fixed checking and translation of weights (previously, weights occurring in terms were rejected, and weight numbers were unintended translated into Vars)
 boehmes parents: 
41172diff
changeset | 504 | (SOME (snd (HOLogic.dest_number w)), t) | 
| 40664 | 505 | | dest_weight t = (NONE, t) | 
| 506 | ||
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 507 | fun dest_pat (Const (@{const_name SMT.pat}, _) $ t) = (t, true)
 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 508 |   | dest_pat (Const (@{const_name SMT.nopat}, _) $ t) = (t, false)
 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 509 |   | dest_pat t = raise TERM ("bad pattern", [t])
 | 
| 37124 | 510 | |
| 511 | fun dest_pats [] = I | |
| 512 | | dest_pats ts = | |
| 513 | (case map dest_pat ts |> split_list ||> distinct (op =) of | |
| 514 | (ps, [true]) => cons (SPat ps) | |
| 515 | | (ps, [false]) => cons (SNoPat ps) | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 516 |       | _ => raise TERM ("bad multi-pattern", ts))
 | 
| 36898 | 517 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 518 | fun dest_trigger (@{const SMT.trigger} $ tl $ t) =
 | 
| 37124 | 519 | (rev (fold (dest_pats o HOLogic.dest_list) (HOLogic.dest_list tl) []), t) | 
| 36898 | 520 | | dest_trigger t = ([], t) | 
| 521 | ||
| 522 | fun dest_quant qn T t = quantifier qn |> Option.map (fn q => | |
| 523 | let | |
| 524 | val (Ts, u) = group_quant qn [T] t | |
| 40664 | 525 | val (ps, p) = dest_trigger u | 
| 526 | val (w, b) = dest_weight p | |
| 527 | in (q, rev Ts, ps, w, b) end) | |
| 36898 | 528 | |
| 529 | fun fold_map_pat f (SPat ts) = fold_map f ts #>> SPat | |
| 530 | | fold_map_pat f (SNoPat ts) = fold_map f ts #>> SNoPat | |
| 531 | ||
| 532 | ||
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 533 | (** translation from Isabelle terms into SMT intermediate terms **) | 
| 36898 | 534 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 535 | fun intermediate header dtyps builtin ctxt ts trx = | 
| 41059 
d2b1fc1b8e19
centralized handling of built-in types and constants;
 boehmes parents: 
41057diff
changeset | 536 | let | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 537 | fun transT (T as TFree _) = add_typ T true | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 538 |       | transT (T as TVar _) = (fn _ => raise TYPE ("bad SMT type", [T], []))
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 539 | | transT (T as Type _) = | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 540 | (case SMT_Builtin.dest_builtin_typ ctxt T of | 
| 39298 
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
 boehmes parents: 
37124diff
changeset | 541 | SOME n => pair n | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 542 | | NONE => add_typ T true) | 
| 36898 | 543 | |
| 544 | fun app n ts = SApp (n, ts) | |
| 545 | ||
| 546 | fun trans t = | |
| 547 | (case Term.strip_comb t of | |
| 548 | (Const (qn, _), [Abs (_, T, t1)]) => | |
| 549 | (case dest_quant qn T t1 of | |
| 40664 | 550 | SOME (q, Ts, ps, w, b) => | 
| 36898 | 551 | fold_map transT Ts ##>> fold_map (fold_map_pat trans) ps ##>> | 
| 40664 | 552 | trans b #>> (fn ((Ts', ps'), b') => SQua (q, Ts', ps', w, b')) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 553 |           | NONE => raise TERM ("unsupported quantifier", [t]))
 | 
| 36898 | 554 |       | (Const (@{const_name Let}, _), [t1, Abs (_, T, t2)]) =>
 | 
| 555 | transT T ##>> trans t1 ##>> trans t2 #>> | |
| 556 | (fn ((U, u1), u2) => SLet (U, u1, u2)) | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 557 | | (u as Const (c as (_, T)), ts) => | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 558 | (case builtin ctxt c ts of | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 559 | SOME (n, _, us, _) => fold_map trans us #>> app n | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 560 | | NONE => transs u T ts) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 561 | | (u as Free (_, T), ts) => transs u T ts | 
| 36898 | 562 | | (Bound i, []) => pair (SVar i) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 563 |       | _ => raise TERM ("bad SMT term", [t]))
 | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 564 | |
| 36898 | 565 | and transs t T ts = | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 566 | let val (Us, U) = SMT_Utils.dest_funT (length ts) T | 
| 36898 | 567 | in | 
| 568 | fold_map transT Us ##>> transT U #-> (fn Up => | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 569 | add_fun t (SOME Up) ##>> fold_map trans ts #>> SApp) | 
| 36898 | 570 | end | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 571 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 572 | val (us, trx') = fold_map trans ts trx | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 573 | in ((sign_of (header ts) dtyps trx', us), trx') end | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 574 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 575 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 576 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 577 | (* translation *) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 578 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 579 | structure Configs = Generic_Data | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 580 | ( | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 581 | type T = (Proof.context -> config) SMT_Utils.dict | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 582 | val empty = [] | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 583 | val extend = I | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 584 | fun merge data = SMT_Utils.dict_merge fst data | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 585 | ) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 586 | |
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 587 | fun add_config (cs, cfg) = Configs.map (SMT_Utils.dict_update (cs, cfg)) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 588 | |
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 589 | fun get_config ctxt = | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 590 | let val cs = SMT_Config.solver_class_of ctxt | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 591 | in | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 592 | (case SMT_Utils.dict_get (Configs.get (Context.Proof ctxt)) cs of | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 593 | SOME cfg => cfg ctxt | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 594 |     | NONE => error ("SMT: no translation configuration found " ^
 | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 595 | "for solver class " ^ quote (SMT_Utils.string_of_class cs))) | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 596 | end | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 597 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 598 | fun translate ctxt comments ithms = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 599 | let | 
| 41232 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 600 |     val {prefixes, is_fol, header, has_datatypes, serialize} = get_config ctxt
 | 
| 
4ea9f2a8c093
fixed lambda-lifting: shift indices of bound variables correctly (after locking the required bound variables) and apply bound variables to the new function symbol in the right order;
 boehmes parents: 
41198diff
changeset | 601 | |
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 602 | val with_datatypes = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 603 | has_datatypes andalso Config.get ctxt SMT_Config.datatypes | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 604 | |
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 605 | fun no_dtyps (tr_context, ctxt) ts = | 
| 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 606 | ((Termtab.empty, [], tr_context, ctxt), ts) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 607 | |
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 608 | val ts1 = map (Envir.beta_eta_contract o SMT_Utils.prop_of o snd) ithms | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 609 | |
| 41426 
09615ed31f04
re-implemented support for datatypes (including records and typedefs);
 boehmes parents: 
41328diff
changeset | 610 | val ((funcs, dtyps, tr_context, ctxt1), ts2) = | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 611 | ((make_tr_context prefixes, ctxt), ts1) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 612 | |-> (if with_datatypes then collect_datatypes_and_records else no_dtyps) | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 613 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 614 | val (ctxt2, ts3) = | 
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 615 | ts2 | 
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
41785diff
changeset | 616 | |> eta_expand ctxt1 is_fol funcs | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 617 | |> lift_lambdas ctxt1 | 
| 43507 
d566714a9ce1
export lambda-lifting code as there is potential use for it within Sledgehammer
 boehmes parents: 
43385diff
changeset | 618 | ||> (op @) | 
| 43385 
9cd4b4ecb4dd
slightly more general treatment of mutually recursive datatypes;
 boehmes parents: 
43154diff
changeset | 619 | |-> (fn ctxt1' => pair ctxt1' o intro_explicit_application ctxt1 funcs) | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 620 | |
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 621 | val ((rewrite_rules, extra_thms, builtin), ts4) = | 
| 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 622 | (if is_fol then folify ctxt2 else pair ([], [], I)) ts3 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 623 | |
| 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 624 | val rewrite_rules' = fun_app_eq :: rewrite_rules | 
| 36898 | 625 | in | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 626 | (ts4, tr_context) | 
| 41328 
6792a5c92a58
avoid ML structure aliases (especially single-letter abbreviations)
 boehmes parents: 
41281diff
changeset | 627 | |-> intermediate header dtyps (builtin SMT_Builtin.dest_builtin) ctxt2 | 
| 41127 
2ea84c8535c6
re-implemented eta-expansion, lambda-lifting, and explicit application on terms (exploiting the control over the term structure);
 boehmes parents: 
41123diff
changeset | 628 | |>> uncurry (serialize comments) | 
| 41281 
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
 boehmes parents: 
41250diff
changeset | 629 | ||> recon_of ctxt2 rewrite_rules' extra_thms ithms | 
| 36898 | 630 | end | 
| 631 | ||
| 632 | end |