| author | nipkow | 
| Mon, 15 Jan 2024 22:50:13 +0100 | |
| changeset 79490 | b287510a4202 | 
| parent 79274 | fb8ed7fbb537 | 
| child 80636 | 4041e7c8059d | 
| permissions | -rw-r--r-- | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 1 | (* Title: HOL/Tools/Transfer/transfer.ML | 
| 47325 | 2 | Author: Brian Huffman, TU Muenchen | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 3 | Author: Ondrej Kuncar, TU Muenchen | 
| 47325 | 4 | |
| 5 | Generic theorem transfer method. | |
| 6 | *) | |
| 7 | ||
| 8 | signature TRANSFER = | |
| 9 | sig | |
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 10 | type pred_data | 
| 60220 | 11 | val mk_pred_data: thm -> thm -> thm list -> pred_data | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 12 | val rel_eq_onp: pred_data -> thm | 
| 60216 | 13 | val pred_def: pred_data -> thm | 
| 60220 | 14 | val pred_simps: pred_data -> thm list | 
| 15 | val update_pred_simps: thm list -> pred_data -> pred_data | |
| 47325 | 16 | val prep_conv: conv | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 17 | val fold_relator_eqs_conv: Proof.context -> conv | 
| 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 18 | val unfold_relator_eqs_conv: Proof.context -> conv | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 19 | val get_transfer_raw: Proof.context -> thm list | 
| 47503 | 20 | val get_relator_eq: Proof.context -> thm list | 
| 70473 | 21 | val retrieve_relator_eq: Proof.context -> term -> thm list | 
| 49625 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 22 | val get_sym_relator_eq: Proof.context -> thm list | 
| 51954 | 23 | val get_relator_eq_raw: Proof.context -> thm list | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 24 | val get_relator_domain: Proof.context -> thm list | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 25 | val morph_pred_data: morphism -> pred_data -> pred_data | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 26 | val lookup_pred_data: Proof.context -> string -> pred_data option | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 27 | val update_pred_data: string -> pred_data -> Context.generic -> Context.generic | 
| 70473 | 28 | val is_compound_lhs: Proof.context -> term -> bool | 
| 29 | val is_compound_rhs: Proof.context -> term -> bool | |
| 47325 | 30 | val transfer_add: attribute | 
| 31 | val transfer_del: attribute | |
| 53649 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 32 | val transfer_raw_add: thm -> Context.generic -> Context.generic | 
| 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 33 | val transfer_raw_del: thm -> Context.generic -> Context.generic | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 34 | val transferred_attribute: thm list -> attribute | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 35 | val untransferred_attribute: thm list -> attribute | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 36 | val prep_transfer_domain_thm: Proof.context -> thm -> thm | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 37 | val transfer_domain_add: attribute | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 38 | val transfer_domain_del: attribute | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 39 | val transfer_rule_of_term: Proof.context -> bool -> term -> thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 40 | val transfer_rule_of_lhs: Proof.context -> term -> thm | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 41 | val eq_tac: Proof.context -> int -> tactic | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 42 | val transfer_start_tac: bool -> Proof.context -> int -> tactic | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 43 | val transfer_prover_start_tac: Proof.context -> int -> tactic | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 44 | val transfer_step_tac: Proof.context -> int -> tactic | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 45 | val transfer_end_tac: Proof.context -> int -> tactic | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 46 | val transfer_prover_end_tac: Proof.context -> int -> tactic | 
| 47658 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 47 | val transfer_tac: bool -> Proof.context -> int -> tactic | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 48 | val transfer_prover_tac: Proof.context -> int -> tactic | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 49 | val gen_frees_tac: (string * typ) list -> Proof.context -> int -> tactic | 
| 47325 | 50 | end | 
| 51 | ||
| 52 | structure Transfer : TRANSFER = | |
| 53 | struct | |
| 54 | ||
| 60216 | 55 | |
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 56 | (** Theory Data **) | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 57 | |
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58821diff
changeset | 58 | val compound_xhs_empty_net = Item_Net.init (Thm.eq_thm_prop o apply2 snd) (single o fst); | 
| 58821 | 59 | val rewr_rules = Item_Net.init Thm.eq_thm_prop (single o fst o HOLogic.dest_eq | 
| 55563 
a64d49f49ca3
implement the reflexivity prover as a monotonicity prover that proves R >= op=; derive "reflexivity" rules for relators from mono rules and eq rules
 kuncar parents: 
54883diff
changeset | 60 | o HOLogic.dest_Trueprop o Thm.concl_of); | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 61 | |
| 70473 | 62 | datatype pred_data = PRED_DATA of {pred_def: thm, rel_eq_onp: thm, pred_simps: thm list}
 | 
| 60220 | 63 | |
| 64 | fun mk_pred_data pred_def rel_eq_onp pred_simps = PRED_DATA {pred_def = pred_def, 
 | |
| 65 | rel_eq_onp = rel_eq_onp, pred_simps = pred_simps} | |
| 66 | ||
| 67 | fun map_pred_data' f1 f2 f3 (PRED_DATA {pred_def, rel_eq_onp, pred_simps}) =
 | |
| 68 |   PRED_DATA {pred_def = f1 pred_def, rel_eq_onp = f2 rel_eq_onp, pred_simps = f3 pred_simps}
 | |
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 69 | |
| 60220 | 70 | fun rep_pred_data (PRED_DATA p) = p | 
| 71 | val rel_eq_onp = #rel_eq_onp o rep_pred_data | |
| 72 | val pred_def = #pred_def o rep_pred_data | |
| 73 | val pred_simps = #pred_simps o rep_pred_data | |
| 74 | fun update_pred_simps new_pred_data = map_pred_data' I I (K new_pred_data) | |
| 75 | ||
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 76 | |
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 77 | structure Data = Generic_Data | 
| 47325 | 78 | ( | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 79 | type T = | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 80 |     { transfer_raw : thm Item_Net.T,
 | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 81 | known_frees : (string * typ) list, | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 82 | compound_lhs : (term * thm) Item_Net.T, | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 83 | compound_rhs : (term * thm) Item_Net.T, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 84 | relator_eq : thm Item_Net.T, | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 85 | relator_eq_raw : thm Item_Net.T, | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 86 | relator_domain : thm Item_Net.T, | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 87 | pred_data : pred_data Symtab.table } | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 88 | val empty = | 
| 74152 | 89 |     { transfer_raw = Thm.item_net_intro,
 | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 90 | known_frees = [], | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 91 | compound_lhs = compound_xhs_empty_net, | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 92 | compound_rhs = compound_xhs_empty_net, | 
| 55563 
a64d49f49ca3
implement the reflexivity prover as a monotonicity prover that proves R >= op=; derive "reflexivity" rules for relators from mono rules and eq rules
 kuncar parents: 
54883diff
changeset | 93 | relator_eq = rewr_rules, | 
| 74152 | 94 | relator_eq_raw = Thm.item_net, | 
| 95 | relator_domain = Thm.item_net, | |
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 96 | pred_data = Symtab.empty } | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 97 | fun merge | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 98 |     ( { transfer_raw = t1, known_frees = k1,
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 99 | compound_lhs = l1, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 100 | compound_rhs = c1, relator_eq = r1, | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 101 | relator_eq_raw = rw1, relator_domain = rd1, | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 102 | pred_data = pd1 }, | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 103 |       { transfer_raw = t2, known_frees = k2,
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 104 | compound_lhs = l2, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 105 | compound_rhs = c2, relator_eq = r2, | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 106 | relator_eq_raw = rw2, relator_domain = rd2, | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 107 | pred_data = pd2 } ) = | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 108 |     { transfer_raw = Item_Net.merge (t1, t2),
 | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 109 | known_frees = Library.merge (op =) (k1, k2), | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 110 | compound_lhs = Item_Net.merge (l1, l2), | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 111 | compound_rhs = Item_Net.merge (c1, c2), | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 112 | relator_eq = Item_Net.merge (r1, r2), | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 113 | relator_eq_raw = Item_Net.merge (rw1, rw2), | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 114 | relator_domain = Item_Net.merge (rd1, rd2), | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 115 | pred_data = Symtab.merge (K true) (pd1, pd2) } | 
| 47325 | 116 | ) | 
| 117 | ||
| 70473 | 118 | fun get_net_content f ctxt = | 
| 119 | Item_Net.content (f (Data.get (Context.Proof ctxt))) | |
| 120 | |> map (Thm.transfer' ctxt) | |
| 121 | ||
| 122 | val get_transfer_raw = get_net_content #transfer_raw | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 123 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 124 | val get_known_frees = #known_frees o Data.get o Context.Proof | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 125 | |
| 70473 | 126 | fun is_compound f ctxt t = | 
| 127 | Item_Net.retrieve (f (Data.get (Context.Proof ctxt))) t | |
| 128 | |> exists (fn (pat, _) => Pattern.matches (Proof_Context.theory_of ctxt) (pat, t)); | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 129 | |
| 70473 | 130 | val is_compound_lhs = is_compound #compound_lhs | 
| 131 | val is_compound_rhs = is_compound #compound_rhs | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 132 | |
| 70473 | 133 | val get_relator_eq = get_net_content #relator_eq #> map safe_mk_meta_eq | 
| 55563 
a64d49f49ca3
implement the reflexivity prover as a monotonicity prover that proves R >= op=; derive "reflexivity" rules for relators from mono rules and eq rules
 kuncar parents: 
54883diff
changeset | 134 | |
| 70473 | 135 | fun retrieve_relator_eq ctxt t = | 
| 136 | Item_Net.retrieve (#relator_eq (Data.get (Context.Proof ctxt))) t | |
| 137 | |> map (Thm.transfer' ctxt) | |
| 49625 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 138 | |
| 70473 | 139 | val get_sym_relator_eq = get_net_content #relator_eq #> map (safe_mk_meta_eq #> Thm.symmetric) | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 140 | |
| 70473 | 141 | val get_relator_eq_raw = get_net_content #relator_eq_raw | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 142 | |
| 70473 | 143 | val get_relator_domain = get_net_content #relator_domain | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 144 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 145 | val get_pred_data = #pred_data o Data.get o Context.Proof | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 146 | |
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 147 | fun map_data f1 f2 f3 f4 f5 f6 f7 f8 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 148 |   { transfer_raw, known_frees, compound_lhs, compound_rhs,
 | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 149 | relator_eq, relator_eq_raw, relator_domain, pred_data } = | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 150 |   { transfer_raw = f1 transfer_raw,
 | 
| 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 151 | known_frees = f2 known_frees, | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 152 | compound_lhs = f3 compound_lhs, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 153 | compound_rhs = f4 compound_rhs, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 154 | relator_eq = f5 relator_eq, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 155 | relator_eq_raw = f6 relator_eq_raw, | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 156 | relator_domain = f7 relator_domain, | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 157 | pred_data = f8 pred_data } | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 158 | |
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 159 | fun map_transfer_raw f = map_data f I I I I I I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 160 | fun map_known_frees f = map_data I f I I I I I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 161 | fun map_compound_lhs f = map_data I I f I I I I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 162 | fun map_compound_rhs f = map_data I I I f I I I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 163 | fun map_relator_eq f = map_data I I I I f I I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 164 | fun map_relator_eq_raw f = map_data I I I I I f I I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 165 | fun map_relator_domain f = map_data I I I I I I f I | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 166 | fun map_pred_data f = map_data I I I I I I I f | 
| 47503 | 167 | |
| 70473 | 168 | val add_transfer_thm = | 
| 169 | Thm.trim_context #> (fn thm => Data.map | |
| 170 | (map_transfer_raw (Item_Net.update thm) o | |
| 171 | map_compound_lhs | |
| 172 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | |
| 173 | Const (\<^const_name>\<open>Rel\<close>, _) $ _ $ (lhs as (_ $ _)) $ _ => | |
| 174 | Item_Net.update (lhs, thm) | |
| 175 | | _ => I) o | |
| 176 | map_compound_rhs | |
| 177 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | |
| 178 | Const (\<^const_name>\<open>Rel\<close>, _) $ _ $ _ $ (rhs as (_ $ _)) => | |
| 179 | Item_Net.update (rhs, thm) | |
| 180 | | _ => I) o | |
| 181 | map_known_frees (Term.add_frees (Thm.concl_of thm)))) | |
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 182 | |
| 58821 | 183 | fun del_transfer_thm thm = Data.map | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 184 | (map_transfer_raw (Item_Net.remove thm) o | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 185 | map_compound_lhs | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 186 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 69593 | 187 | Const (\<^const_name>\<open>Rel\<close>, _) $ _ $ (lhs as (_ $ _)) $ _ => | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 188 | Item_Net.remove (lhs, thm) | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 189 | | _ => I) o | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 190 | map_compound_rhs | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 191 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 69593 | 192 | Const (\<^const_name>\<open>Rel\<close>, _) $ _ $ _ $ (rhs as (_ $ _)) => | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 193 | Item_Net.remove (rhs, thm) | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 194 | | _ => I)) | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 195 | |
| 53649 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 196 | fun transfer_raw_add thm ctxt = add_transfer_thm thm ctxt | 
| 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 197 | fun transfer_raw_del thm ctxt = del_transfer_thm thm ctxt | 
| 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 198 | |
| 47325 | 199 | (** Conversions **) | 
| 200 | ||
| 58821 | 201 | fun transfer_rel_conv conv = | 
| 52883 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 202 | Conv.concl_conv ~1 (HOLogic.Trueprop_conv (Conv.fun2_conv (Conv.arg_conv conv))) | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 203 | |
| 47325 | 204 | val Rel_rule = Thm.symmetric @{thm Rel_def}
 | 
| 205 | ||
| 206 | fun Rel_conv ct = | |
| 70159 | 207 | let val (cT, cT') = Thm.dest_funT (Thm.ctyp_of_cterm ct) | 
| 208 | val (cU, _) = Thm.dest_funT cT' | |
| 60801 | 209 | in Thm.instantiate' [SOME cT, SOME cU] [SOME ct] Rel_rule end | 
| 47325 | 210 | |
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 211 | (* Conversion to preprocess a transfer rule *) | 
| 51955 
04d9381bebff
try to detect assumptions of transfer rules that are in a shape of a transfer rule
 kuncar parents: 
51954diff
changeset | 212 | fun safe_Rel_conv ct = | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 213 | Conv.try_conv (HOLogic.Trueprop_conv (Conv.fun_conv (Conv.fun_conv Rel_conv))) ct | 
| 51955 
04d9381bebff
try to detect assumptions of transfer rules that are in a shape of a transfer rule
 kuncar parents: 
51954diff
changeset | 214 | |
| 47325 | 215 | fun prep_conv ct = ( | 
| 51955 
04d9381bebff
try to detect assumptions of transfer rules that are in a shape of a transfer rule
 kuncar parents: 
51954diff
changeset | 216 | Conv.implies_conv safe_Rel_conv prep_conv | 
| 47325 | 217 | else_conv | 
| 51955 
04d9381bebff
try to detect assumptions of transfer rules that are in a shape of a transfer rule
 kuncar parents: 
51954diff
changeset | 218 | safe_Rel_conv | 
| 47325 | 219 | else_conv | 
| 220 | Conv.all_conv) ct | |
| 221 | ||
| 74545 | 222 | fun fold_relator_eqs_conv ctxt = Conv.bottom_rewrs_conv (get_relator_eq ctxt) ctxt | 
| 223 | fun unfold_relator_eqs_conv ctxt = Conv.top_rewrs_conv (get_sym_relator_eq ctxt) ctxt | |
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 224 | |
| 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 225 | |
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 226 | (** Replacing explicit equalities with is_equality premises **) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 227 | |
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 228 | fun mk_is_equality t = | 
| 69593 | 229 | Const (\<^const_name>\<open>is_equality\<close>, Term.fastype_of t --> HOLogic.boolT) $ t | 
| 47325 | 230 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 231 | fun gen_abstract_equalities ctxt (dest : term -> term * (term -> term)) thm = | 
| 47325 | 232 | let | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 233 | val prop = Thm.prop_of thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 234 | val (t, mk_prop') = dest prop | 
| 67399 | 235 | (* Only consider "(=)" at non-base types *) | 
| 69593 | 236 |     fun is_eq (Const (\<^const_name>\<open>HOL.eq\<close>, Type ("fun", [T, _]))) =
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 237 | (case T of Type (_, []) => false | _ => true) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 238 | | is_eq _ = false | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 239 | val add_eqs = Term.fold_aterms (fn t => if is_eq t then insert (op =) t else I) | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 240 | val eq_consts = rev (add_eqs t []) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 241 | val eqTs = map (snd o dest_Const) eq_consts | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 242 | val used = Term.add_free_names prop [] | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 243 | val names = map (K "") eqTs |> Name.variant_list used | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 244 | val frees = map Free (names ~~ eqTs) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 245 | val prems = map (HOLogic.mk_Trueprop o mk_is_equality) frees | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 246 | val prop1 = mk_prop' (Term.subst_atomic (eq_consts ~~ frees) t) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 247 | val prop2 = fold Logic.all frees (Logic.list_implies (prems, prop1)) | 
| 59642 | 248 | val cprop = Thm.cterm_of ctxt prop2 | 
| 70491 | 249 |     val equal_thm = Raw_Simplifier.rewrite ctxt false @{thms is_equality_lemma} cprop
 | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 250 | fun forall_elim thm = Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm | 
| 47325 | 251 | in | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 252 |     forall_elim (thm COMP (equal_thm COMP @{thm equal_elim_rule2}))
 | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 253 | end | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 254 | handle TERM _ => thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 255 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 256 | fun abstract_equalities_transfer ctxt thm = | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 257 | let | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 258 | fun dest prop = | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 259 | let | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 260 | val prems = Logic.strip_imp_prems prop | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 261 | val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 262 | val ((rel, x), y) = apfst Term.dest_comb (Term.dest_comb concl) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 263 | in | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 264 | (rel, fn rel' => | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 265 | Logic.list_implies (prems, HOLogic.mk_Trueprop (rel' $ x $ y))) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 266 | end | 
| 58821 | 267 | val contracted_eq_thm = | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 268 | Conv.fconv_rule (transfer_rel_conv (fold_relator_eqs_conv ctxt)) thm | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 269 | handle CTERM _ => thm | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 270 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 271 | gen_abstract_equalities ctxt dest contracted_eq_thm | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 272 | end | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 273 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 274 | fun abstract_equalities_relator_eq ctxt rel_eq_thm = | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 275 | gen_abstract_equalities ctxt (fn x => (x, I)) | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 276 |     (rel_eq_thm RS @{thm is_equality_def [THEN iffD2]})
 | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 277 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 278 | fun abstract_equalities_domain ctxt thm = | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 279 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 280 | fun dest prop = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 281 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 282 | val prems = Logic.strip_imp_prems prop | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 283 | val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop) | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 284 | val ((eq, dom), y) = apfst Term.dest_comb (Term.dest_comb concl) | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 285 | in | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 286 | (dom, fn dom' => Logic.list_implies (prems, HOLogic.mk_Trueprop (eq $ dom' $ y))) | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 287 | end | 
| 58821 | 288 | fun transfer_rel_conv conv = | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 289 | Conv.concl_conv ~1 (HOLogic.Trueprop_conv (Conv.arg1_conv (Conv.arg_conv conv))) | 
| 58821 | 290 | val contracted_eq_thm = | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 291 | Conv.fconv_rule (transfer_rel_conv (fold_relator_eqs_conv ctxt)) thm | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 292 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 293 | gen_abstract_equalities ctxt dest contracted_eq_thm | 
| 58821 | 294 | end | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 295 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 296 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 297 | (** Replacing explicit Domainp predicates with Domainp assumptions **) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 298 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 299 | fun mk_Domainp_assm (T, R) = | 
| 69593 | 300 | HOLogic.mk_eq ((Const (\<^const_name>\<open>Domainp\<close>, Term.fastype_of T --> Term.fastype_of R) $ T), R) | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 301 | |
| 69593 | 302 | fun fold_Domainp f (t as Const (\<^const_name>\<open>Domainp\<close>,_) $ (Var (_,_))) = f t | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 303 | | fold_Domainp f (t $ u) = fold_Domainp f t #> fold_Domainp f u | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 304 | | fold_Domainp f (Abs (_, _, t)) = fold_Domainp f t | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 305 | | fold_Domainp _ _ = I | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 306 | |
| 58821 | 307 | fun subst_terms tab t = | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 308 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 309 | val t' = Termtab.lookup tab t | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 310 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 311 | case t' of | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 312 | SOME t' => t' | 
| 58821 | 313 | | NONE => | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 314 | (case t of | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 315 | u $ v => (subst_terms tab u) $ (subst_terms tab v) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 316 | | Abs (a, T, t) => Abs (a, T, subst_terms tab t) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 317 | | t => t) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 318 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 319 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 320 | fun gen_abstract_domains ctxt (dest : term -> term * (term -> term)) thm = | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 321 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 322 | val prop = Thm.prop_of thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 323 | val (t, mk_prop') = dest prop | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 324 | val Domainp_tms = rev (fold_Domainp (fn t => insert op= t) t []) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 325 | val Domainp_Ts = map (snd o dest_funT o snd o dest_Const o fst o dest_comb) Domainp_tms | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 326 | val used = Term.add_free_names t [] | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 327 | val rels = map (snd o dest_comb) Domainp_tms | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 328 | val rel_names = map (fst o fst o dest_Var) rels | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 329 |     val names = map (fn name => ("D" ^ name)) rel_names |> Name.variant_list used
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 330 | val frees = map Free (names ~~ Domainp_Ts) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 331 | val prems = map (HOLogic.mk_Trueprop o mk_Domainp_assm) (rels ~~ frees); | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 332 | val t' = subst_terms (fold Termtab.update (Domainp_tms ~~ frees) Termtab.empty) t | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 333 | val prop1 = fold Logic.all frees (Logic.list_implies (prems, mk_prop' t')) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 334 | val prop2 = Logic.list_rename_params (rev names) prop1 | 
| 59642 | 335 | val cprop = Thm.cterm_of ctxt prop2 | 
| 70491 | 336 |     val equal_thm = Raw_Simplifier.rewrite ctxt false @{thms Domainp_lemma} cprop
 | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 337 | fun forall_elim thm = Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm; | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 338 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 339 |     forall_elim (thm COMP (equal_thm COMP @{thm equal_elim_rule2}))
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 340 | end | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 341 | handle TERM _ => thm | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 342 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 343 | fun abstract_domains_transfer ctxt thm = | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 344 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 345 | fun dest prop = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 346 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 347 | val prems = Logic.strip_imp_prems prop | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 348 | val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 349 | val ((rel, x), y) = apfst Term.dest_comb (Term.dest_comb concl) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 350 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 351 | (x, fn x' => | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 352 | Logic.list_implies (prems, HOLogic.mk_Trueprop (rel $ x' $ y))) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 353 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 354 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 355 | gen_abstract_domains ctxt dest thm | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 356 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 357 | |
| 56520 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 358 | fun abstract_domains_relator_domain ctxt thm = | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 359 | let | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 360 | fun dest prop = | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 361 | let | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 362 | val prems = Logic.strip_imp_prems prop | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 363 | val concl = HOLogic.dest_Trueprop (Logic.strip_imp_concl prop) | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 364 | val ((rel, x), y) = apfst Term.dest_comb (Term.dest_comb concl) | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 365 | in | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 366 | (y, fn y' => | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 367 | Logic.list_implies (prems, HOLogic.mk_Trueprop (rel $ x $ y'))) | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 368 | end | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 369 | in | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 370 | gen_abstract_domains ctxt dest thm | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 371 | end | 
| 
3373f5d1e074
abstract Domainp in relator_domain rules => more natural statement of the rule
 kuncar parents: 
56254diff
changeset | 372 | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 373 | fun detect_transfer_rules thm = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 374 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 375 | fun is_transfer_rule tm = case (HOLogic.dest_Trueprop tm) of | 
| 69593 | 376 | (Const (\<^const_name>\<open>HOL.eq\<close>, _)) $ ((Const (\<^const_name>\<open>Domainp\<close>, _)) $ _) $ _ => false | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 377 | | _ $ _ $ _ => true | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 378 | | _ => false | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 379 | fun safe_transfer_rule_conv ctm = | 
| 59582 | 380 | if is_transfer_rule (Thm.term_of ctm) then safe_Rel_conv ctm else Conv.all_conv ctm | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 381 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 382 | Conv.fconv_rule (Conv.prems_conv ~1 safe_transfer_rule_conv) thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 383 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 384 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 385 | (** Adding transfer domain rules **) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 386 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 387 | fun prep_transfer_domain_thm ctxt = | 
| 79274 | 388 | abstract_equalities_domain ctxt o detect_transfer_rules o Thm.transfer' ctxt | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 389 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 390 | fun add_transfer_domain_thm thm ctxt = | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 391 | (add_transfer_thm o prep_transfer_domain_thm (Context.proof_of ctxt)) thm ctxt | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 392 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 393 | fun del_transfer_domain_thm thm ctxt = | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 394 | (del_transfer_thm o prep_transfer_domain_thm (Context.proof_of ctxt)) thm ctxt | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 395 | |
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 396 | (** Transfer proof method **) | 
| 47325 | 397 | |
| 47355 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 398 | val post_simps = | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 399 |   @{thms transfer_forall_eq [symmetric]
 | 
| 47355 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 400 | transfer_implies_eq [symmetric] transfer_bforall_unfold} | 
| 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 401 | |
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 402 | fun gen_frees_tac keepers ctxt = SUBGOAL (fn (t, i) => | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 403 | let | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 404 | val keepers = keepers @ get_known_frees ctxt | 
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 405 | val vs = rev (Term.add_frees t []) | 
| 47568 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 406 | val vs' = filter_out (member (op =) keepers) vs | 
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 407 | in | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 408 | Induct.arbitrary_tac ctxt 0 vs' i | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 409 | end) | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 410 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 411 | fun mk_relT (T, U) = T --> U --> HOLogic.boolT | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 412 | |
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 413 | fun mk_Rel t = | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 414 | let val T = fastype_of t | 
| 69593 | 415 | in Const (\<^const_name>\<open>Transfer.Rel\<close>, T --> T) $ t end | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 416 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 417 | fun transfer_rule_of_terms (prj : typ * typ -> typ) ctxt tab t u = | 
| 47580 
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
 huffman parents: 
47568diff
changeset | 418 | let | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 419 | (* precondition: prj(T,U) must consist of only TFrees and type "fun" *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 420 |     fun rel (T as Type ("fun", [T1, T2])) (U as Type ("fun", [U1, U2])) =
 | 
| 59642 | 421 | let | 
| 422 | val r1 = rel T1 U1 | |
| 423 | val r2 = rel T2 U2 | |
| 424 | val rT = fastype_of r1 --> fastype_of r2 --> mk_relT (T, U) | |
| 425 | in | |
| 69593 | 426 | Const (\<^const_name>\<open>rel_fun\<close>, rT) $ r1 $ r2 | 
| 59642 | 427 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 428 | | rel T U = | 
| 59642 | 429 | let | 
| 430 | val (a, _) = dest_TFree (prj (T, U)) | |
| 431 | in | |
| 432 | Free (the (AList.lookup (op =) tab a), mk_relT (T, U)) | |
| 433 | end | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 434 | fun zip _ thms (Bound i) (Bound _) = (nth thms i, []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 435 | | zip ctxt thms (Abs (x, T, t)) (Abs (y, U, u)) = | 
| 59642 | 436 | let | 
| 437 | val ([x', y'], ctxt') = Variable.variant_fixes [x, y] ctxt | |
| 438 | val prop = mk_Rel (rel T U) $ Free (x', T) $ Free (y', U) | |
| 439 | val cprop = Thm.cterm_of ctxt' (HOLogic.mk_Trueprop prop) | |
| 440 | val thm0 = Thm.assume cprop | |
| 441 | val (thm1, hyps) = zip ctxt' (thm0 :: thms) t u | |
| 442 | val ((r1, x), y) = apfst Thm.dest_comb (Thm.dest_comb (Thm.dest_arg cprop)) | |
| 443 | val r2 = Thm.dest_fun2 (Thm.dest_arg (Thm.cprop_of thm1)) | |
| 70159 | 444 | val (a1, (b1, _)) = apsnd Thm.dest_funT (Thm.dest_funT (Thm.ctyp_of_cterm r1)) | 
| 445 | val (a2, (b2, _)) = apsnd Thm.dest_funT (Thm.dest_funT (Thm.ctyp_of_cterm r2)) | |
| 59642 | 446 | val tinsts = [SOME a1, SOME b1, SOME a2, SOME b2] | 
| 447 | val insts = [SOME (Thm.dest_arg r1), SOME (Thm.dest_arg r2)] | |
| 60801 | 448 |             val rule = Thm.instantiate' tinsts insts @{thm Rel_abs}
 | 
| 59642 | 449 | val thm2 = Thm.forall_intr x (Thm.forall_intr y (Thm.implies_intr cprop thm1)) | 
| 450 | in | |
| 451 | (thm2 COMP rule, hyps) | |
| 452 | end | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 453 | | zip ctxt thms (f $ t) (g $ u) = | 
| 59642 | 454 | let | 
| 455 | val (thm1, hyps1) = zip ctxt thms f g | |
| 456 | val (thm2, hyps2) = zip ctxt thms t u | |
| 457 | in | |
| 458 |             (thm2 RS (thm1 RS @{thm Rel_app}), hyps1 @ hyps2)
 | |
| 459 | end | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 460 | | zip _ _ t u = | 
| 59642 | 461 | let | 
| 462 | val T = fastype_of t | |
| 463 | val U = fastype_of u | |
| 464 | val prop = mk_Rel (rel T U) $ t $ u | |
| 465 | val cprop = Thm.cterm_of ctxt (HOLogic.mk_Trueprop prop) | |
| 466 | in | |
| 467 | (Thm.assume cprop, [cprop]) | |
| 468 | end | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 469 | val r = mk_Rel (rel (fastype_of t) (fastype_of u)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 470 | val goal = HOLogic.mk_Trueprop (r $ t $ u) | 
| 59642 | 471 | val rename = Thm.trivial (Thm.cterm_of ctxt goal) | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 472 | val (thm, hyps) = zip ctxt [] t u | 
| 47580 
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
 huffman parents: 
47568diff
changeset | 473 | in | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 474 | Drule.implies_intr_list hyps (thm RS rename) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 475 | end | 
| 47580 
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
 huffman parents: 
47568diff
changeset | 476 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 477 | (* create a lambda term of the same shape as the given term *) | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 478 | fun skeleton is_atom = | 
| 47325 | 479 | let | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 480 | fun dummy ctxt = | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 481 | let val (c, ctxt') = yield_singleton Variable.variant_fixes "a" ctxt | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 482 | in (Free (c, dummyT), ctxt') end | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 483 | fun skel (Bound i) ctxt = (Bound i, ctxt) | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 484 | | skel (Abs (x, _, t)) ctxt = | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 485 | let val (t', ctxt) = skel t ctxt | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 486 | in (Abs (x, dummyT, t'), ctxt) end | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 487 | | skel (tu as t $ u) ctxt = | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 488 | if is_atom tu andalso not (Term.is_open tu) then dummy ctxt | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 489 | else | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 490 | let | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 491 | val (t', ctxt) = skel t ctxt | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 492 | val (u', ctxt) = skel u ctxt | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 493 | in (t' $ u', ctxt) end | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 494 | | skel _ ctxt = dummy ctxt | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 495 | in | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 496 | fn ctxt => fn t => | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 497 | fst (skel t ctxt) |> Syntax.check_term ctxt (* FIXME avoid syntax operation!? *) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 498 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 499 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 500 | (** Monotonicity analysis **) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 501 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 502 | (* TODO: Put extensible table in theory data *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 503 | val monotab = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 504 | Symtab.make | 
| 69593 | 505 | [(\<^const_name>\<open>transfer_implies\<close>, [~1, 1]), | 
| 506 | (\<^const_name>\<open>transfer_forall\<close>, [1])(*, | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 507 |      (@{const_name implies}, [~1, 1]),
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 508 |      (@{const_name All}, [1])*)]
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 509 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 510 | (* | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 511 | Function bool_insts determines the set of boolean-relation variables | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 512 | that can be instantiated to implies, rev_implies, or iff. | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 513 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 514 | Invariants: bool_insts p (t, u) requires that | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 515 | u :: _ => _ => ... => bool, and | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 516 | t is a skeleton of u | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 517 | *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 518 | fun bool_insts p (t, u) = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 519 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 520 | fun strip2 (t1 $ t2, u1 $ u2, tus) = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 521 | strip2 (t1, u1, (t2, u2) :: tus) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 522 | | strip2 x = x | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 523 | fun or3 ((a, b, c), (x, y, z)) = (a orelse x, b orelse y, c orelse z) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 524 | fun go Ts p (Abs (_, T, t), Abs (_, _, u)) tab = go (T :: Ts) p (t, u) tab | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 525 | | go Ts p (t, u) tab = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 526 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 527 | val (a, _) = dest_TFree (Term.body_type (Term.fastype_of1 (Ts, t))) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 528 | val (_, tf, tus) = strip2 (t, u, []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 529 | val ps_opt = case tf of Const (c, _) => Symtab.lookup monotab c | _ => NONE | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 530 | val tab1 = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 531 | case ps_opt of | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 532 | SOME ps => | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 533 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 534 | val ps' = map (fn x => p * x) (take (length tus) ps) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 535 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 536 | fold I (map2 (go Ts) ps' tus) tab | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 537 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 538 | | NONE => tab | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 539 | val tab2 = Symtab.make [(a, (p >= 0, p <= 0, is_none ps_opt))] | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 540 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 541 | Symtab.join (K or3) (tab1, tab2) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 542 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 543 | val tab = go [] p (t, u) Symtab.empty | 
| 74383 | 544 | fun f (a, (true, false, false)) = SOME (a, \<^Const>\<open>implies\<close>) | 
| 545 | | f (a, (false, true, false)) = SOME (a, \<^Const>\<open>rev_implies\<close>) | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 546 | | f (a, (true, true, _)) = SOME (a, HOLogic.eq_const HOLogic.boolT) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 547 | | f _ = NONE | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 548 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 549 | map_filter f (Symtab.dest tab) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 550 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 551 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 552 | fun transfer_rule_of_term ctxt equiv t = | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 553 | let | 
| 70473 | 554 | val s = skeleton (is_compound_rhs ctxt) ctxt t | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 555 | val frees = map fst (Term.add_frees s []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 556 | val tfrees = map fst (Term.add_tfrees s []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 557 | fun prep a = "R" ^ Library.unprefix "'" a | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 558 | val (rnames, ctxt') = Variable.variant_fixes (map prep tfrees) ctxt | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 559 | val tab = tfrees ~~ rnames | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 560 | fun prep a = the (AList.lookup (op =) tab a) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 561 | val thm = transfer_rule_of_terms fst ctxt' tab s t | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 562 | val binsts = bool_insts (if equiv then 0 else 1) (s, t) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 563 | val idx = Thm.maxidx_of thm + 1 | 
| 69593 | 564 | fun tinst (a, _) = (((a, idx), \<^sort>\<open>type\<close>), \<^ctyp>\<open>bool\<close>) | 
| 60642 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60367diff
changeset | 565 | fun inst (a, t) = | 
| 69593 | 566 | ((Name.clean_index (prep a, idx), \<^typ>\<open>bool \<Rightarrow> bool \<Rightarrow> bool\<close>), Thm.cterm_of ctxt' t) | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 567 | in | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 568 | thm | 
| 74266 | 569 | |> Thm.generalize (Names.make_set tfrees, Names.make_set (rnames @ frees)) idx | 
| 74282 | 570 | |> Thm.instantiate (TVars.make (map tinst binsts), Vars.make (map inst binsts)) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 571 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 572 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 573 | fun transfer_rule_of_lhs ctxt t = | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 574 | let | 
| 70473 | 575 | val s = skeleton (is_compound_lhs ctxt) ctxt t | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 576 | val frees = map fst (Term.add_frees s []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 577 | val tfrees = map fst (Term.add_tfrees s []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 578 | fun prep a = "R" ^ Library.unprefix "'" a | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 579 | val (rnames, ctxt') = Variable.variant_fixes (map prep tfrees) ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 580 | val tab = tfrees ~~ rnames | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 581 | fun prep a = the (AList.lookup (op =) tab a) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 582 | val thm = transfer_rule_of_terms snd ctxt' tab t s | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 583 | val binsts = bool_insts 1 (s, t) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 584 | val idx = Thm.maxidx_of thm + 1 | 
| 69593 | 585 | fun tinst (a, _) = (((a, idx), \<^sort>\<open>type\<close>), \<^ctyp>\<open>bool\<close>) | 
| 60642 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60367diff
changeset | 586 | fun inst (a, t) = | 
| 69593 | 587 | ((Name.clean_index (prep a, idx), \<^typ>\<open>bool \<Rightarrow> bool \<Rightarrow> bool\<close>), Thm.cterm_of ctxt' t) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 588 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 589 | thm | 
| 74266 | 590 | |> Thm.generalize (Names.make_set tfrees, Names.make_set (rnames @ frees)) idx | 
| 74282 | 591 | |> Thm.instantiate (TVars.make (map tinst binsts), Vars.make (map inst binsts)) | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 592 | end | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 593 | |
| 59531 | 594 | fun eq_rules_tac ctxt eq_rules = | 
| 595 | TRY o REPEAT_ALL_NEW (resolve_tac ctxt eq_rules) | |
| 60752 | 596 |   THEN_ALL_NEW resolve_tac ctxt @{thms is_equality_eq}
 | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 597 | |
| 59531 | 598 | fun eq_tac ctxt = eq_rules_tac ctxt (get_relator_eq_raw ctxt) | 
| 55731 
66df76dd2640
rewrite composition of quotients to a more readable form in a respectfulness goal that is presented to a user
 kuncar parents: 
55563diff
changeset | 599 | |
| 59531 | 600 | fun transfer_step_tac ctxt = | 
| 61366 | 601 | REPEAT_ALL_NEW (resolve_tac ctxt (get_transfer_raw ctxt)) | 
| 602 | THEN_ALL_NEW (DETERM o eq_rules_tac ctxt (get_relator_eq_raw ctxt)) | |
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 603 | |
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 604 | fun transfer_start_tac equiv ctxt i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 605 | let | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 606 |       val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 607 | val start_rule = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 608 |         if equiv then @{thm transfer_start} else @{thm transfer_start'}
 | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 609 | val err_msg = "Transfer failed to convert goal to an object-logic formula" | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 610 | fun main_tac (t, i) = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 611 | resolve_tac ctxt [start_rule] i THEN | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 612 | (resolve_tac ctxt [transfer_rule_of_term ctxt equiv (HOLogic.dest_Trueprop t)]) (i + 1) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 613 | handle TERM (_, ts) => raise TERM (err_msg, ts) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 614 | in | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 615 | EVERY | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 616 | [rewrite_goal_tac ctxt pre_simps i THEN | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 617 | SUBGOAL main_tac i] | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 618 | end; | 
| 47325 | 619 | |
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 620 | fun transfer_prover_start_tac ctxt = SUBGOAL (fn (t, i) => | 
| 47325 | 621 | let | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 622 | val rhs = (snd o Term.dest_comb o HOLogic.dest_Trueprop) t | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 623 | val rule1 = transfer_rule_of_term ctxt false rhs | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 624 | val expand_eqs_in_rel_conv = transfer_rel_conv (unfold_relator_eqs_conv ctxt) | 
| 47325 | 625 | in | 
| 626 | EVERY | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 627 | [CONVERSION prep_conv i, | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 628 | CONVERSION expand_eqs_in_rel_conv i, | 
| 60752 | 629 |        resolve_tac ctxt @{thms transfer_prover_start} i,
 | 
| 64434 
af5235830c16
always expand equalities in the transfer relation in transfer_prover (cf. 0a7c97c76f46)
 kuncar parents: 
62958diff
changeset | 630 | resolve_tac ctxt [rule1] (i + 1)] | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 631 | end); | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 632 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 633 | fun transfer_end_tac ctxt i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 634 | let | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 635 |     val post_simps = @{thms transfer_forall_eq [symmetric]
 | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 636 | transfer_implies_eq [symmetric] transfer_bforall_unfold} | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 637 | in | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 638 | EVERY [rewrite_goal_tac ctxt post_simps i, | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 639 | Goal.norm_hhf_tac ctxt i] | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 640 | end; | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 641 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 642 | fun transfer_prover_end_tac ctxt i = resolve_tac ctxt @{thms refl} i
 | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 643 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 644 | local | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 645 | infix 1 THEN_ALL_BUT_FIRST_NEW | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 646 | fun (tac1 THEN_ALL_BUT_FIRST_NEW tac2) i st = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 647 | st |> (tac1 i THEN (fn st' => | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 648 | Seq.INTERVAL tac2 (i + 1) (i + Thm.nprems_of st' - Thm.nprems_of st) st')); | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 649 | in | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 650 | fun transfer_tac equiv ctxt i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 651 | let | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 652 | val rules = get_transfer_raw ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 653 | val eq_rules = get_relator_eq_raw ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 654 | (* allow unsolved subgoals only for standard transfer method, not for transfer' *) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 655 | val end_tac = if equiv then K all_tac else K no_tac | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 656 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 657 | fun transfer_search_tac i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 658 | (SOLVED' | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 659 | (REPEAT_ALL_NEW (resolve_tac ctxt rules) THEN_ALL_NEW | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 660 | (DETERM o eq_rules_tac ctxt eq_rules)) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 661 | ORELSE' end_tac) i | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 662 | in | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 663 | (transfer_start_tac equiv ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 664 | THEN_ALL_BUT_FIRST_NEW transfer_search_tac | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 665 | THEN' transfer_end_tac ctxt) i | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 666 | end | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 667 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 668 | fun transfer_prover_tac ctxt i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 669 | let | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 670 | val rules = get_transfer_raw ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 671 | val eq_rules = get_relator_eq_raw ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 672 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 673 | fun transfer_prover_search_tac i = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 674 | (REPEAT_ALL_NEW (resolve_tac ctxt rules) THEN_ALL_NEW | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 675 | (DETERM o eq_rules_tac ctxt eq_rules)) i | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 676 | in | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 677 | (transfer_prover_start_tac ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 678 | THEN_ALL_BUT_FIRST_NEW transfer_prover_search_tac | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 679 | THEN' transfer_prover_end_tac ctxt) i | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 680 | end | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 681 | end; | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 682 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 683 | (** Transfer attribute **) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 684 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 685 | fun transferred ctxt extra_rules thm = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 686 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 687 | val rules = extra_rules @ get_transfer_raw ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 688 | val eq_rules = get_relator_eq_raw ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 689 |     val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 74245 | 690 | val thm1 = Thm.forall_intr_vars thm | 
| 60805 | 691 | val instT = | 
| 692 | rev (Term.add_tvars (Thm.full_prop_of thm1) []) | |
| 693 | |> map (fn v as ((a, _), S) => (v, Thm.ctyp_of ctxt (TFree (a, S)))) | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 694 | val thm2 = thm1 | 
| 74282 | 695 | |> Thm.instantiate (TVars.make instT, Vars.empty) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 696 | |> Raw_Simplifier.rewrite_rule ctxt pre_simps | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 697 | val ctxt' = Variable.declare_names (Thm.full_prop_of thm2) ctxt | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 698 | val rule = transfer_rule_of_lhs ctxt' (HOLogic.dest_Trueprop (Thm.concl_of thm2)) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 699 | in | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 700 | Goal.prove_internal ctxt' [] | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 701 |       (Thm.cterm_of ctxt' (HOLogic.mk_Trueprop (Var (("P", 0), \<^typ>\<open>bool\<close>))))
 | 
| 74530 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 702 | (fn _ => | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 703 |         resolve_tac ctxt' [thm2 RS @{thm transfer_start'}, thm2 RS @{thm transfer_start}] 1 THEN
 | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 704 | (resolve_tac ctxt' [rule] | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 705 | THEN_ALL_NEW | 
| 74530 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 706 | (SOLVED' (REPEAT_ALL_NEW (resolve_tac ctxt' rules) | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 707 | THEN_ALL_NEW (DETERM o eq_rules_tac ctxt' eq_rules)))) 1 | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 708 | handle TERM (_, ts) => | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 709 |             raise TERM ("Transfer failed to convert goal to an object-logic formula", ts))
 | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 710 | |> Raw_Simplifier.rewrite_rule ctxt' post_simps | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 711 | |> Simplifier.norm_hhf ctxt' | 
| 74200 
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
 wenzelm parents: 
74152diff
changeset | 712 | |> Drule.generalize | 
| 74266 | 713 | (Names.make_set (map (fst o dest_TFree o Thm.typ_of o snd) instT), Names.empty) | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 714 | |> Drule.zero_var_indexes | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 715 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 716 | (* | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 717 | handle THM _ => thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 718 | *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 719 | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 720 | fun untransferred ctxt extra_rules thm = | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 721 | let | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 722 | val rules = extra_rules @ get_transfer_raw ctxt | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 723 | val eq_rules = get_relator_eq_raw ctxt | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 724 |     val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 74245 | 725 | val thm1 = Thm.forall_intr_vars thm | 
| 60805 | 726 | val instT = | 
| 727 | rev (Term.add_tvars (Thm.full_prop_of thm1) []) | |
| 728 | |> map (fn v as ((a, _), S) => (v, Thm.ctyp_of ctxt (TFree (a, S)))) | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 729 | val thm2 = thm1 | 
| 74282 | 730 | |> Thm.instantiate (TVars.make instT, Vars.empty) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 731 | |> Raw_Simplifier.rewrite_rule ctxt pre_simps | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 732 | val ctxt' = Variable.declare_names (Thm.full_prop_of thm2) ctxt | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 733 | val t = HOLogic.dest_Trueprop (Thm.concl_of thm2) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 734 | val rule = transfer_rule_of_term ctxt' true t | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 735 | in | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 736 | Goal.prove_internal ctxt' [] | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 737 |       (Thm.cterm_of ctxt' (HOLogic.mk_Trueprop (Var (("P", 0), \<^typ>\<open>bool\<close>))))
 | 
| 74530 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 738 | (fn _ => | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 739 |         resolve_tac ctxt' [thm2 RS @{thm untransfer_start}] 1 THEN
 | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 740 | (resolve_tac ctxt' [rule] | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 741 | THEN_ALL_NEW | 
| 74530 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 742 | (SOLVED' (REPEAT_ALL_NEW (resolve_tac ctxt' rules) | 
| 
823ccd84b879
revert bbfed17243af, breaks HOL-Proofs extraction;
 wenzelm parents: 
74526diff
changeset | 743 | THEN_ALL_NEW (DETERM o eq_rules_tac ctxt' eq_rules)))) 1 | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 744 | handle TERM (_, ts) => | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 745 |             raise TERM ("Transfer failed to convert goal to an object-logic formula", ts))
 | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 746 | |> Raw_Simplifier.rewrite_rule ctxt' post_simps | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 747 | |> Simplifier.norm_hhf ctxt' | 
| 74200 
17090e27aae9
more scalable data structure (but: rarely used with > 5 arguments);
 wenzelm parents: 
74152diff
changeset | 748 | |> Drule.generalize | 
| 74266 | 749 | (Names.make_set (map (fst o dest_TFree o Thm.typ_of o snd) instT), Names.empty) | 
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 750 | |> Drule.zero_var_indexes | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 751 | end | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 752 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 753 | (** Methods and attributes **) | 
| 47325 | 754 | |
| 47568 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 755 | val free = Args.context -- Args.term >> (fn (_, Free v) => v | (ctxt, t) => | 
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 756 |   error ("Bad free variable: " ^ Syntax.string_of_term ctxt t))
 | 
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 757 | |
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 758 | val fixing = Scan.optional (Scan.lift (Args.$$$ "fixing" -- Args.colon) | 
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 759 | |-- Scan.repeat free) [] | 
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 760 | |
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 761 | val reverse_prems = fn _ => PRIMITIVE (fn thm => fold_rev (fn i => Thm.permute_prems i 1) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 762 | (0 upto Thm.nprems_of thm - 1) thm); | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 763 | |
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 764 | fun transfer_start_method equiv : (Proof.context -> Proof.method) context_parser = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 765 | fixing >> (fn vs => fn ctxt => | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 766 | SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_start_tac equiv ctxt | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 767 | THEN' reverse_prems)); | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 768 | |
| 53042 | 769 | fun transfer_method equiv : (Proof.context -> Proof.method) context_parser = | 
| 47568 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 770 | fixing >> (fn vs => fn ctxt => | 
| 47658 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 771 | SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_tac equiv ctxt)) | 
| 47325 | 772 | |
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 773 | val transfer_prover_start_method : (Proof.context -> Proof.method) context_parser = | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 774 | Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_start_tac ctxt THEN' reverse_prems)) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 775 | |
| 53042 | 776 | val transfer_prover_method : (Proof.context -> Proof.method) context_parser = | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 777 | Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_tac ctxt)) | 
| 47325 | 778 | |
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 779 | (* Attribute for transfer rules *) | 
| 47325 | 780 | |
| 58821 | 781 | fun prep_rule ctxt = | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 782 | abstract_domains_transfer ctxt o abstract_equalities_transfer ctxt o Conv.fconv_rule prep_conv | 
| 47325 | 783 | |
| 784 | val transfer_add = | |
| 58821 | 785 | Thm.declaration_attribute (fn thm => fn ctxt => | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 786 | (add_transfer_thm o prep_rule (Context.proof_of ctxt)) thm ctxt) | 
| 47325 | 787 | |
| 788 | val transfer_del = | |
| 58821 | 789 | Thm.declaration_attribute (fn thm => fn ctxt => | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 790 | (del_transfer_thm o prep_rule (Context.proof_of ctxt)) thm ctxt) | 
| 47325 | 791 | |
| 792 | val transfer_attribute = | |
| 793 | Attrib.add_del transfer_add transfer_del | |
| 794 | ||
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 795 | (* Attributes for transfer domain rules *) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 796 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 797 | val transfer_domain_add = Thm.declaration_attribute add_transfer_domain_thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 798 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 799 | val transfer_domain_del = Thm.declaration_attribute del_transfer_domain_thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 800 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 801 | val transfer_domain_attribute = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 802 | Attrib.add_del transfer_domain_add transfer_domain_del | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 803 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 804 | (* Attributes for transferred rules *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 805 | |
| 61853 
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
 wenzelm parents: 
61367diff
changeset | 806 | fun transferred_attribute thms = | 
| 
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
 wenzelm parents: 
61367diff
changeset | 807 | Thm.rule_attribute thms (fn context => transferred (Context.proof_of context) thms) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 808 | |
| 61853 
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
 wenzelm parents: 
61367diff
changeset | 809 | fun untransferred_attribute thms = | 
| 
fb7756087101
rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
 wenzelm parents: 
61367diff
changeset | 810 | Thm.rule_attribute thms (fn context => untransferred (Context.proof_of context) thms) | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 811 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 812 | val transferred_attribute_parser = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 813 | Attrib.thms >> transferred_attribute | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 814 | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 815 | val untransferred_attribute_parser = | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 816 | Attrib.thms >> untransferred_attribute | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 817 | |
| 60220 | 818 | fun morph_pred_data phi = | 
| 819 | let | |
| 820 | val morph_thm = Morphism.thm phi | |
| 821 | in | |
| 822 | map_pred_data' morph_thm morph_thm (map morph_thm) | |
| 823 | end | |
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 824 | |
| 70316 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 825 | fun lookup_pred_data ctxt type_name = | 
| 
c61b7af108a6
misc tuning and clarification, notably wrt. flow of context;
 wenzelm parents: 
70159diff
changeset | 826 | Symtab.lookup (get_pred_data ctxt) type_name | 
| 67664 | 827 | |> Option.map (morph_pred_data (Morphism.transfer_morphism' ctxt)) | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 828 | |
| 58821 | 829 | fun update_pred_data type_name qinfo ctxt = | 
| 56524 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 830 | Data.map (map_pred_data (Symtab.update (type_name, qinfo))) ctxt | 
| 
f4ba736040fa
setup for Transfer and Lifting from BNF; tuned thm names
 kuncar parents: 
56520diff
changeset | 831 | |
| 47325 | 832 | (* Theory setup *) | 
| 833 | ||
| 58821 | 834 | val _ = | 
| 835 | Theory.setup | |
| 836 | let | |
| 69593 | 837 | val name = \<^binding>\<open>relator_eq\<close> | 
| 70473 | 838 | fun add_thm thm context = | 
| 839 | context | |
| 840 | |> Data.map (map_relator_eq (Item_Net.update (Thm.trim_context thm))) | |
| 58821 | 841 | |> Data.map (map_relator_eq_raw | 
| 70473 | 842 | (Item_Net.update | 
| 843 | (Thm.trim_context (abstract_equalities_relator_eq (Context.proof_of context) thm)))) | |
| 58821 | 844 | fun del_thm thm context = context | 
| 845 | |> Data.map (map_relator_eq (Item_Net.remove thm)) | |
| 846 | |> Data.map (map_relator_eq_raw | |
| 847 | (Item_Net.remove (abstract_equalities_relator_eq (Context.proof_of context) thm))) | |
| 848 | val add = Thm.declaration_attribute add_thm | |
| 849 | val del = Thm.declaration_attribute del_thm | |
| 850 | val text = "declaration of relator equality rule (used by transfer method)" | |
| 851 | val content = Item_Net.content o #relator_eq o Data.get | |
| 852 | in | |
| 853 | Attrib.setup name (Attrib.add_del add del) text | |
| 854 | #> Global_Theory.add_thms_dynamic (name, content) | |
| 855 | end | |
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 856 | |
| 58821 | 857 | val _ = | 
| 858 | Theory.setup | |
| 859 | let | |
| 69593 | 860 | val name = \<^binding>\<open>relator_domain\<close> | 
| 58821 | 861 | fun add_thm thm context = | 
| 862 | let | |
| 70473 | 863 | val thm' = thm | 
| 864 | |> abstract_domains_relator_domain (Context.proof_of context) | |
| 865 | |> Thm.trim_context | |
| 58821 | 866 | in | 
| 70473 | 867 | context | 
| 868 | |> Data.map (map_relator_domain (Item_Net.update thm')) | |
| 869 | |> add_transfer_domain_thm thm' | |
| 58821 | 870 | end | 
| 871 | fun del_thm thm context = | |
| 872 | let | |
| 70473 | 873 | val thm' = abstract_domains_relator_domain (Context.proof_of context) thm | 
| 58821 | 874 | in | 
| 70473 | 875 | context | 
| 876 | |> Data.map (map_relator_domain (Item_Net.remove thm')) | |
| 877 | |> del_transfer_domain_thm thm' | |
| 58821 | 878 | end | 
| 879 | val add = Thm.declaration_attribute add_thm | |
| 880 | val del = Thm.declaration_attribute del_thm | |
| 881 | val text = "declaration of relator domain rule (used by transfer method)" | |
| 882 | val content = Item_Net.content o #relator_domain o Data.get | |
| 883 | in | |
| 884 | Attrib.setup name (Attrib.add_del add del) text | |
| 885 | #> Global_Theory.add_thms_dynamic (name, content) | |
| 886 | end | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 887 | |
| 58821 | 888 | val _ = | 
| 889 | Theory.setup | |
| 69593 | 890 | (Attrib.setup \<^binding>\<open>transfer_rule\<close> transfer_attribute | 
| 58821 | 891 | "transfer rule for transfer method" | 
| 892 | #> Global_Theory.add_thms_dynamic | |
| 69593 | 893 | (\<^binding>\<open>transfer_raw\<close>, Item_Net.content o #transfer_raw o Data.get) | 
| 894 | #> Attrib.setup \<^binding>\<open>transfer_domain_rule\<close> transfer_domain_attribute | |
| 58821 | 895 | "transfer domain rule for transfer method" | 
| 69593 | 896 | #> Attrib.setup \<^binding>\<open>transferred\<close> transferred_attribute_parser | 
| 58821 | 897 | "raw theorem transferred to abstract theorem using transfer rules" | 
| 69593 | 898 | #> Attrib.setup \<^binding>\<open>untransferred\<close> untransferred_attribute_parser | 
| 58821 | 899 | "abstract theorem transferred to raw theorem using transfer rules" | 
| 900 | #> Global_Theory.add_thms_dynamic | |
| 69593 | 901 | (\<^binding>\<open>relator_eq_raw\<close>, Item_Net.content o #relator_eq_raw o Data.get) | 
| 902 | #> Method.setup \<^binding>\<open>transfer_start\<close> (transfer_start_method true) | |
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 903 | "firtst step in the transfer algorithm (for debugging transfer)" | 
| 69593 | 904 | #> Method.setup \<^binding>\<open>transfer_start'\<close> (transfer_start_method false) | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 905 | "firtst step in the transfer algorithm (for debugging transfer)" | 
| 69593 | 906 | #> Method.setup \<^binding>\<open>transfer_prover_start\<close> transfer_prover_start_method | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 907 | "firtst step in the transfer_prover algorithm (for debugging transfer_prover)" | 
| 69593 | 908 | #> Method.setup \<^binding>\<open>transfer_step\<close> | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 909 | (Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_step_tac ctxt))) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 910 | "step in the search for transfer rules (for debugging transfer and transfer_prover)" | 
| 69593 | 911 | #> Method.setup \<^binding>\<open>transfer_end\<close> | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 912 | (Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_end_tac ctxt))) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 913 | "last step in the transfer algorithm (for debugging transfer)" | 
| 69593 | 914 | #> Method.setup \<^binding>\<open>transfer_prover_end\<close> | 
| 61367 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 915 | (Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_end_tac ctxt))) | 
| 
46af4f577c7e
new methods for debugging transfer and transfer_prover
 kuncar parents: 
61366diff
changeset | 916 | "last step in the transfer_prover algorithm (for debugging transfer_prover)" | 
| 69593 | 917 | #> Method.setup \<^binding>\<open>transfer\<close> (transfer_method true) | 
| 58821 | 918 | "generic theorem transfer method" | 
| 69593 | 919 | #> Method.setup \<^binding>\<open>transfer'\<close> (transfer_method false) | 
| 58821 | 920 | "generic theorem transfer method" | 
| 69593 | 921 | #> Method.setup \<^binding>\<open>transfer_prover\<close> transfer_prover_method | 
| 58821 | 922 | "for proving transfer rules") | 
| 47325 | 923 | end |