| author | wenzelm | 
| Sun, 23 Feb 2014 15:35:19 +0100 | |
| changeset 55688 | 767edb2c1e4e | 
| parent 55563 | a64d49f49ca3 | 
| child 55731 | 66df76dd2640 | 
| permissions | -rw-r--r-- | 
| 47325 | 1 | (* Title: HOL/Tools/transfer.ML | 
| 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 | |
| 52883 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 10 | val bottom_rewr_conv: thm list -> conv | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 11 | val top_rewr_conv: thm list -> conv | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 12 | |
| 47325 | 13 | val prep_conv: 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 | 14 | val get_transfer_raw: Proof.context -> thm list | 
| 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 | 15 | val get_relator_eq_item_net: Proof.context -> thm Item_Net.T | 
| 47503 | 16 | val get_relator_eq: Proof.context -> thm list | 
| 49625 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 17 | val get_sym_relator_eq: Proof.context -> thm list | 
| 51954 | 18 | 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 | 19 | val get_relator_domain: Proof.context -> thm list | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 20 | val get_compound_lhs: Proof.context -> (term * thm) Item_Net.T | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 21 | val get_compound_rhs: Proof.context -> (term * thm) Item_Net.T | 
| 47325 | 22 | val transfer_add: attribute | 
| 23 | val transfer_del: attribute | |
| 53649 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 24 | val transfer_raw_add: thm -> Context.generic -> Context.generic | 
| 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 25 | 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 | 26 | 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 | 27 | val untransferred_attribute: thm list -> attribute | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 28 | 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 | 29 | val transfer_domain_del: attribute | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 30 | 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 | 31 | val transfer_rule_of_lhs: Proof.context -> term -> thm | 
| 47658 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 32 | val transfer_tac: bool -> Proof.context -> int -> tactic | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 33 | 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 | 34 | val gen_frees_tac: (string * typ) list -> Proof.context -> int -> tactic | 
| 47325 | 35 | val setup: theory -> theory | 
| 36 | end | |
| 37 | ||
| 38 | structure Transfer : TRANSFER = | |
| 39 | struct | |
| 40 | ||
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 41 | (** Theory Data **) | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 42 | |
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 43 | val compound_xhs_empty_net = Item_Net.init (Thm.eq_thm_prop o pairself snd) (single o fst); | 
| 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 | 44 | val rewr_rules = Item_Net.init Thm.eq_thm_prop (single o fst o HOLogic.dest_eq | 
| 
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 | 45 | 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 | 46 | |
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 47 | structure Data = Generic_Data | 
| 47325 | 48 | ( | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 49 | type T = | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 50 |     { 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 | 51 | known_frees : (string * typ) list, | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 52 | 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 | 53 | compound_rhs : (term * thm) Item_Net.T, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 54 | 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 | 55 | relator_eq_raw : thm Item_Net.T, | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 56 | relator_domain : thm Item_Net.T } | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 57 | val empty = | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 58 |     { transfer_raw = Thm.intro_rules,
 | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 59 | known_frees = [], | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 60 | compound_lhs = compound_xhs_empty_net, | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 61 | 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 | 62 | relator_eq = rewr_rules, | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 63 | relator_eq_raw = Thm.full_rules, | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 64 | relator_domain = Thm.full_rules } | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 65 | val extend = I | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 66 | fun merge | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 67 |     ( { transfer_raw = t1, known_frees = k1,
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 68 | compound_lhs = l1, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 69 | compound_rhs = c1, relator_eq = r1, | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 70 | relator_eq_raw = rw1, relator_domain = rd1 }, | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 71 |       { transfer_raw = t2, known_frees = k2,
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 72 | compound_lhs = l2, | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 73 | compound_rhs = c2, relator_eq = 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 | 74 | relator_eq_raw = rw2, relator_domain = rd2 } ) = | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 75 |     { 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 | 76 | 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 | 77 | 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 | 78 | compound_rhs = Item_Net.merge (c1, c2), | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 79 | 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 | 80 | relator_eq_raw = Item_Net.merge (rw1, rw2), | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 81 | relator_domain = Item_Net.merge (rd1, rd2) } | 
| 47325 | 82 | ) | 
| 83 | ||
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 84 | fun get_transfer_raw ctxt = ctxt | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 85 | |> (Item_Net.content o #transfer_raw o Data.get o Context.Proof) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 86 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 87 | fun get_known_frees ctxt = ctxt | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 88 | |> (#known_frees o Data.get o Context.Proof) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 89 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 90 | fun get_compound_lhs ctxt = ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 91 | |> (#compound_lhs o Data.get o Context.Proof) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 92 | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 93 | fun get_compound_rhs ctxt = ctxt | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 94 | |> (#compound_rhs o Data.get o Context.Proof) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 95 | |
| 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 | 96 | fun get_relator_eq_item_net ctxt = (#relator_eq o Data.get o Context.Proof) ctxt | 
| 
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 | 97 | |
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 98 | fun get_relator_eq ctxt = ctxt | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 99 | |> (Item_Net.content o #relator_eq o Data.get o Context.Proof) | 
| 49625 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 100 | |> map safe_mk_meta_eq | 
| 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 101 | |
| 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 102 | fun get_sym_relator_eq ctxt = ctxt | 
| 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 103 | |> (Item_Net.content o #relator_eq o Data.get o Context.Proof) | 
| 
06cf80661e7a
new get function for non-symmetric relator_eq & tuned
 kuncar parents: 
48066diff
changeset | 104 | |> map (Thm.symmetric o safe_mk_meta_eq) | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 105 | |
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 106 | fun get_relator_eq_raw ctxt = ctxt | 
| 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 107 | |> (Item_Net.content o #relator_eq_raw o Data.get o Context.Proof) | 
| 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 108 | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 109 | fun get_relator_domain ctxt = ctxt | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 110 | |> (Item_Net.content o #relator_domain o Data.get o Context.Proof) | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 111 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 112 | fun map_data f1 f2 f3 f4 f5 f6 f7 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 113 |   { transfer_raw, known_frees, compound_lhs, compound_rhs,
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 114 | relator_eq, relator_eq_raw, 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 | 115 |   { 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 | 116 | known_frees = f2 known_frees, | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 117 | compound_lhs = f3 compound_lhs, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 118 | compound_rhs = f4 compound_rhs, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 119 | relator_eq = f5 relator_eq, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 120 | relator_eq_raw = f6 relator_eq_raw, | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 121 | relator_domain = f7 relator_domain } | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 122 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 123 | fun map_transfer_raw f = map_data f I I I I I I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 124 | fun map_known_frees f = map_data I f I I I I I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 125 | fun map_compound_lhs f = map_data I I f I I I I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 126 | fun map_compound_rhs f = map_data I I I f I I I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 127 | fun map_relator_eq f = map_data I I I I f I I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 128 | fun map_relator_eq_raw f = map_data I I I I I f I | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 129 | fun map_relator_domain f = map_data I I I I I I f | 
| 47503 | 130 | |
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 131 | fun add_transfer_thm thm = Data.map | 
| 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 132 | (map_transfer_raw (Item_Net.update thm) o | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 133 | map_compound_lhs | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 134 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 135 |         Const (@{const_name Rel}, _) $ _ $ (lhs as (_ $ _)) $ _ =>
 | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 136 | Item_Net.update (lhs, thm) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 137 | | _ => I) o | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 138 | map_compound_rhs | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 139 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 140 |         Const (@{const_name Rel}, _) $ _ $ _ $ (rhs as (_ $ _)) =>
 | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 141 | Item_Net.update (rhs, thm) | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 142 | | _ => I) o | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 143 | map_known_frees (Term.add_frees (Thm.concl_of thm))) | 
| 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 144 | |
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 145 | fun del_transfer_thm thm = Data.map | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 146 | (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 | 147 | map_compound_lhs | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 148 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 149 |         Const (@{const_name Rel}, _) $ _ $ (lhs as (_ $ _)) $ _ =>
 | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 150 | Item_Net.remove (lhs, thm) | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 151 | | _ => I) o | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 152 | map_compound_rhs | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 153 | (case HOLogic.dest_Trueprop (Thm.concl_of thm) of | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 154 |         Const (@{const_name Rel}, _) $ _ $ _ $ (rhs as (_ $ _)) =>
 | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 155 | Item_Net.remove (rhs, thm) | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 156 | | _ => I)) | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 157 | |
| 53649 
96814d676c49
public access to the raw transfer rules - for restoring transferring
 kuncar parents: 
53145diff
changeset | 158 | 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 | 159 | 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 | 160 | |
| 47325 | 161 | (** Conversions **) | 
| 162 | ||
| 52883 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 163 | fun bottom_rewr_conv rewrs = Conv.bottom_conv (K (Conv.try_conv (Conv.rewrs_conv rewrs))) @{context}
 | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 164 | fun top_rewr_conv rewrs = Conv.top_conv (K (Conv.try_conv (Conv.rewrs_conv rewrs))) @{context}
 | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 165 | |
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 166 | fun transfer_rel_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 | 167 | 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 | 168 | |
| 47325 | 169 | val Rel_rule = Thm.symmetric @{thm Rel_def}
 | 
| 170 | ||
| 171 | fun dest_funcT cT = | |
| 172 | (case Thm.dest_ctyp cT of [T, U] => (T, U) | |
| 173 |     | _ => raise TYPE ("dest_funcT", [Thm.typ_of cT], []))
 | |
| 174 | ||
| 175 | fun Rel_conv ct = | |
| 176 | let val (cT, cT') = dest_funcT (Thm.ctyp_of_term ct) | |
| 177 | val (cU, _) = dest_funcT cT' | |
| 178 | in Drule.instantiate' [SOME cT, SOME cU] [SOME ct] Rel_rule end | |
| 179 | ||
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 180 | (* 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 | 181 | 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 | 182 | 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 | 183 | |
| 47325 | 184 | 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 | 185 | Conv.implies_conv safe_Rel_conv prep_conv | 
| 47325 | 186 | else_conv | 
| 51955 
04d9381bebff
try to detect assumptions of transfer rules that are in a shape of a transfer rule
 kuncar parents: 
51954diff
changeset | 187 | safe_Rel_conv | 
| 47325 | 188 | else_conv | 
| 189 | Conv.all_conv) ct | |
| 190 | ||
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 191 | (** Replacing explicit equalities with is_equality premises **) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 192 | |
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 193 | fun mk_is_equality t = | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 194 |   Const (@{const_name is_equality}, Term.fastype_of t --> HOLogic.boolT) $ t
 | 
| 47325 | 195 | |
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 196 | val is_equality_lemma = | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 197 |   @{lemma "(!!R. is_equality R ==> PROP (P R)) == PROP (P (op =))"
 | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 198 | by (unfold is_equality_def, rule, drule meta_spec, | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 199 | erule meta_mp, rule refl, simp)} | 
| 47325 | 200 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 201 | fun gen_abstract_equalities ctxt (dest : term -> term * (term -> term)) thm = | 
| 47325 | 202 | let | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 203 | val thy = Thm.theory_of_thm thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 204 | val prop = Thm.prop_of thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 205 | val (t, mk_prop') = dest prop | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 206 | (* Only consider "op =" at non-base types *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 207 |     fun is_eq (Const (@{const_name HOL.eq}, Type ("fun", [T, _]))) =
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 208 | (case T of Type (_, []) => false | _ => true) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 209 | | is_eq _ = false | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 210 | 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 | 211 | val eq_consts = rev (add_eqs t []) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 212 | 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 | 213 | val used = Term.add_free_names prop [] | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 214 | 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 | 215 | val frees = map Free (names ~~ eqTs) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 216 | 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 | 217 | 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 | 218 | val prop2 = fold Logic.all frees (Logic.list_implies (prems, prop1)) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 219 | val cprop = Thm.cterm_of thy prop2 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 220 | val equal_thm = Raw_Simplifier.rewrite ctxt false [is_equality_lemma] cprop | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 221 | fun forall_elim thm = Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm | 
| 47325 | 222 | in | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 223 |     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 | 224 | end | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 225 | handle TERM _ => thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 226 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 227 | fun abstract_equalities_transfer ctxt thm = | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 228 | let | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 229 | fun dest prop = | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 230 | let | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 231 | val prems = Logic.strip_imp_prems prop | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 232 | 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 | 233 | 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 | 234 | in | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 235 | (rel, fn rel' => | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 236 | 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 | 237 | end | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 238 | val contracted_eq_thm = | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 239 | Conv.fconv_rule (transfer_rel_conv (bottom_rewr_conv (get_relator_eq ctxt))) thm | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 240 | handle CTERM _ => thm | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 241 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 242 | 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 | 243 | end | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 244 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 245 | 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 | 246 | 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 | 247 |     (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 | 248 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 249 | 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 | 250 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 251 | 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 | 252 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 253 | 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 | 254 | 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 | 255 | 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 | 256 | in | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 257 | (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 | 258 | end | 
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 259 | fun transfer_rel_conv conv = | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 260 | Conv.concl_conv ~1 (HOLogic.Trueprop_conv (Conv.arg1_conv (Conv.arg_conv conv))) | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 261 | val contracted_eq_thm = | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 262 | Conv.fconv_rule (transfer_rel_conv (bottom_rewr_conv (get_relator_eq 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 | 263 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 264 | gen_abstract_equalities ctxt dest contracted_eq_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 | 265 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 266 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 267 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 268 | (** 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 | 269 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 270 | fun mk_Domainp_assm (T, R) = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 271 |   HOLogic.mk_eq ((Const (@{const_name Domainp}, Term.fastype_of T --> Term.fastype_of R) $ T), R)
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 272 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 273 | val Domainp_lemma = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 274 |   @{lemma "(!!R. Domainp T = R ==> PROP (P R)) == PROP (P (Domainp T))"
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 275 | by (rule, drule meta_spec, | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 276 | erule meta_mp, rule refl, simp)} | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 277 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 278 | fun fold_Domainp f (t as Const (@{const_name Domainp},_) $ (Var (_,_))) = 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 | 279 | | 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 | 280 | | 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 | 281 | | 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 | 282 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 283 | fun 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 | 284 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 285 | 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 | 286 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 287 | 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 | 288 | SOME 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 | 289 | | NONE => | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 290 | (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 | 291 | 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 | 292 | | 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 | 293 | | 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 | 294 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 295 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 296 | 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 | 297 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 298 | val thy = Thm.theory_of_thm thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 299 | 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 | 300 | 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 | 301 | 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 | 302 | 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 | 303 | 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 | 304 | 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 | 305 | 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 | 306 |     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 | 307 | 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 | 308 | 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 | 309 | 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 | 310 | 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 | 311 | val prop2 = Logic.list_rename_params (rev names) prop1 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 312 | val cprop = Thm.cterm_of thy prop2 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 313 | val equal_thm = Raw_Simplifier.rewrite ctxt false [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 | 314 | 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 | 315 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 316 |     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 | 317 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 318 | handle TERM _ => thm | 
| 
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 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 | 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 | 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 | 323 | let | 
| 
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 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 | 325 | 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 | 326 | 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 | 327 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 328 | (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 | 329 | 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 | 330 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 331 | in | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 332 | 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 | 333 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 334 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 335 | 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 | 336 | let | 
| 
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 is_transfer_rule tm = case (HOLogic.dest_Trueprop tm) of | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 338 |       (Const (@{const_name HOL.eq}, _)) $ ((Const (@{const_name Domainp}, _)) $ _) $ _ => false
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 339 | | _ $ _ $ _ => true | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 340 | | _ => false | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 341 | fun safe_transfer_rule_conv ctm = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 342 | if is_transfer_rule (term_of ctm) then safe_Rel_conv ctm else Conv.all_conv ctm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 343 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 344 | 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 | 345 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 346 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 347 | (** 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 | 348 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 349 | fun add_transfer_domain_thm thm ctxt = | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 350 | (add_transfer_thm o abstract_equalities_domain (Context.proof_of ctxt) o detect_transfer_rules) thm 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 | 351 | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 352 | fun del_transfer_domain_thm thm ctxt = | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 353 | (del_transfer_thm o abstract_equalities_domain (Context.proof_of ctxt) o detect_transfer_rules) thm ctxt | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 354 | |
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 355 | (** Transfer proof method **) | 
| 47325 | 356 | |
| 47355 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 357 | val post_simps = | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 358 |   @{thms transfer_forall_eq [symmetric]
 | 
| 47355 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 359 | transfer_implies_eq [symmetric] transfer_bforall_unfold} | 
| 
3d9d98e0f1a4
add bounded quantifier constant transfer_bforall, whose definition is unfolded after transfer
 huffman parents: 
47327diff
changeset | 360 | |
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 361 | fun gen_frees_tac keepers ctxt = SUBGOAL (fn (t, i) => | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 362 | let | 
| 48065 
8aa05d38299a
transfer method now avoids generalizing over free variables that are known to appear in registered transfer rules
 huffman parents: 
48064diff
changeset | 363 | val keepers = keepers @ get_known_frees ctxt | 
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 364 | 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 | 365 | val vs' = filter_out (member (op =) keepers) vs | 
| 47356 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 366 | in | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 367 | Induct.arbitrary_tac ctxt 0 vs' i | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 368 | end) | 
| 
19fb95255ec9
transfer method generalizes over free variables in goal
 huffman parents: 
47355diff
changeset | 369 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 370 | fun mk_relT (T, U) = T --> U --> HOLogic.boolT | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 371 | |
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 372 | fun mk_Rel t = | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 373 | let val T = fastype_of t | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 374 |   in Const (@{const_name Transfer.Rel}, T --> T) $ t end
 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 375 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 376 | 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 | 377 | let | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 378 | val thy = Proof_Context.theory_of ctxt | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 379 | (* 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 | 380 |     fun rel (T as Type ("fun", [T1, T2])) (U as Type ("fun", [U1, U2])) =
 | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 381 | let | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 382 | val r1 = rel T1 U1 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 383 | val r2 = rel T2 U2 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 384 | val rT = fastype_of r1 --> fastype_of r2 --> mk_relT (T, U) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 385 | in | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 386 |           Const (@{const_name fun_rel}, rT) $ r1 $ r2
 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 387 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 388 | | rel T U = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 389 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 390 | val (a, _) = dest_TFree (prj (T, U)) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 391 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 392 | Free (the (AList.lookup (op =) tab a), mk_relT (T, U)) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 393 | end | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 394 | fun zip _ thms (Bound i) (Bound _) = (nth thms i, []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 395 | | zip ctxt thms (Abs (x, T, t)) (Abs (y, U, u)) = | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 396 | let | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 397 | val ([x', y'], ctxt') = Variable.variant_fixes [x, y] ctxt | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 398 | val prop = mk_Rel (rel T U) $ Free (x', T) $ Free (y', U) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 399 | val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 400 | val thm0 = Thm.assume cprop | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 401 | val (thm1, hyps) = zip ctxt' (thm0 :: thms) t u | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 402 | val ((r1, x), y) = apfst Thm.dest_comb (Thm.dest_comb (Thm.dest_arg cprop)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 403 | val r2 = Thm.dest_fun2 (Thm.dest_arg (cprop_of thm1)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 404 | val (a1, (b1, _)) = apsnd dest_funcT (dest_funcT (ctyp_of_term r1)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 405 | val (a2, (b2, _)) = apsnd dest_funcT (dest_funcT (ctyp_of_term r2)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 406 | val tinsts = [SOME a1, SOME b1, SOME a2, SOME b2] | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 407 | val insts = [SOME (Thm.dest_arg r1), SOME (Thm.dest_arg r2)] | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 408 |           val rule = Drule.instantiate' tinsts insts @{thm Rel_abs}
 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 409 | val thm2 = Thm.forall_intr x (Thm.forall_intr y (Thm.implies_intr cprop thm1)) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 410 | in | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 411 | (thm2 COMP rule, hyps) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 412 | end | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 413 | | zip ctxt thms (f $ t) (g $ u) = | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 414 | let | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 415 | val (thm1, hyps1) = zip ctxt thms f g | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 416 | val (thm2, hyps2) = zip ctxt thms t u | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 417 | in | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 418 |           (thm2 RS (thm1 RS @{thm Rel_app}), hyps1 @ hyps2)
 | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 419 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 420 | | zip _ _ t u = | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 421 | let | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 422 | val T = fastype_of t | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 423 | val U = fastype_of u | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 424 | val prop = mk_Rel (rel T U) $ t $ u | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 425 | val cprop = Thm.cterm_of thy (HOLogic.mk_Trueprop prop) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 426 | in | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 427 | (Thm.assume cprop, [cprop]) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 428 | end | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 429 | 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 | 430 | val goal = HOLogic.mk_Trueprop (r $ t $ u) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 431 | val rename = Thm.trivial (cterm_of thy goal) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 432 | val (thm, hyps) = zip ctxt [] t u | 
| 47580 
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
 huffman parents: 
47568diff
changeset | 433 | in | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 434 | Drule.implies_intr_list hyps (thm RS rename) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 435 | end | 
| 47580 
d99c883cdf2c
use simpler method for preserving bound variable names in transfer tactic
 huffman parents: 
47568diff
changeset | 436 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 437 | (* create a lambda term of the same shape as the given term *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 438 | fun skeleton (is_atom : term -> bool) ctxt t = | 
| 47325 | 439 | let | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 440 | fun dummy ctxt = | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 441 | let | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 442 | val (c, ctxt) = yield_singleton Variable.variant_fixes "a" ctxt | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 443 | in | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 444 | (Free (c, dummyT), ctxt) | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 445 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 446 | fun go (Bound i) ctxt = (Bound i, ctxt) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 447 | | go (Abs (x, _, t)) ctxt = | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 448 | let | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 449 | val (t', ctxt) = go t ctxt | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 450 | in | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 451 | (Abs (x, dummyT, t'), ctxt) | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 452 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 453 | | go (tu as (t $ u)) ctxt = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 454 | if is_atom tu andalso not (Term.is_open tu) then dummy ctxt else | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 455 | let | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 456 | val (t', ctxt) = go t ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 457 | val (u', ctxt) = go u ctxt | 
| 48066 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 458 | in | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 459 | (t' $ u', ctxt) | 
| 
c6783c9b87bf
transfer method now handles transfer rules for compound terms, e.g. locale-defined constants with hidden parameters
 huffman parents: 
48065diff
changeset | 460 | end | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 461 | | go _ ctxt = dummy ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 462 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 463 | go t ctxt |> fst |> Syntax.check_term ctxt |> | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 464 | map_types (map_type_tfree (fn (a, _) => TFree (a, HOLogic.typeS))) | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 465 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 466 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 467 | (** Monotonicity analysis **) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 468 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 469 | (* TODO: Put extensible table in theory data *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 470 | val monotab = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 471 | Symtab.make | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 472 |     [(@{const_name transfer_implies}, [~1, 1]),
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 473 |      (@{const_name transfer_forall}, [1])(*,
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 474 |      (@{const_name implies}, [~1, 1]),
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 475 |      (@{const_name All}, [1])*)]
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 476 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 477 | (* | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 478 | 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 | 479 | 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 | 480 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 481 | Invariants: bool_insts p (t, u) requires that | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 482 | u :: _ => _ => ... => bool, and | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 483 | t is a skeleton of u | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 484 | *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 485 | fun bool_insts p (t, u) = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 486 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 487 | fun strip2 (t1 $ t2, u1 $ u2, tus) = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 488 | strip2 (t1, u1, (t2, u2) :: tus) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 489 | | strip2 x = x | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 490 | 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 | 491 | 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 | 492 | | go Ts p (t, u) tab = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 493 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 494 | 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 | 495 | val (_, tf, tus) = strip2 (t, u, []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 496 | 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 | 497 | val tab1 = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 498 | case ps_opt of | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 499 | SOME ps => | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 500 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 501 | 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 | 502 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 503 | fold I (map2 (go Ts) ps' tus) tab | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 504 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 505 | | NONE => tab | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 506 | 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 | 507 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 508 | Symtab.join (K or3) (tab1, tab2) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 509 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 510 | val tab = go [] p (t, u) Symtab.empty | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 511 |     fun f (a, (true, false, false)) = SOME (a, @{const implies})
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 512 |       | f (a, (false, true, false)) = SOME (a, @{const rev_implies})
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 513 | | 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 | 514 | | f _ = NONE | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 515 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 516 | map_filter f (Symtab.dest tab) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 517 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 518 | |
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 519 | fun retrieve_terms t net = map fst (Item_Net.retrieve net t) | 
| 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 520 | |
| 53131 
701360318565
double check that lhs or rhs really matches a subterm in a goal when creating a hole in a skeleton (Net.net does only rough matching)
 kuncar parents: 
53042diff
changeset | 521 | fun matches_list ctxt term = | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 522 | is_some o find_first (fn pat => Pattern.matches (Proof_Context.theory_of ctxt) (pat, term)) | 
| 53131 
701360318565
double check that lhs or rhs really matches a subterm in a goal when creating a hole in a skeleton (Net.net does only rough matching)
 kuncar parents: 
53042diff
changeset | 523 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 524 | fun transfer_rule_of_term ctxt equiv t : thm = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 525 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 526 | val compound_rhs = get_compound_rhs ctxt | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 527 | fun is_rhs t = compound_rhs |> retrieve_terms t |> matches_list ctxt t | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 528 | val s = skeleton is_rhs ctxt t | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 529 | val frees = map fst (Term.add_frees s []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 530 | val tfrees = map fst (Term.add_tfrees s []) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 531 | fun prep a = "R" ^ Library.unprefix "'" a | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 532 | 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 | 533 | val tab = tfrees ~~ rnames | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 534 | 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 | 535 | 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 | 536 | 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 | 537 |     val cbool = @{ctyp bool}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 538 |     val relT = @{typ "bool => bool => bool"}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 539 | val idx = Thm.maxidx_of thm + 1 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 540 | val thy = Proof_Context.theory_of ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 541 | fun tinst (a, _) = (ctyp_of thy (TVar ((a, idx), HOLogic.typeS)), cbool) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 542 | fun inst (a, t) = (cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), cterm_of thy t) | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 543 | in | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 544 | thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 545 | |> Thm.generalize (tfrees, rnames @ frees) idx | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 546 | |> Thm.instantiate (map tinst binsts, map inst binsts) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 547 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 548 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 549 | fun transfer_rule_of_lhs ctxt t : thm = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 550 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 551 | val compound_lhs = get_compound_lhs ctxt | 
| 53145 
2fb458aceb78
delete corresponding compound lhs and rhs when a transfer rule is deleted; tuned
 kuncar parents: 
53144diff
changeset | 552 | fun is_lhs t = compound_lhs |> retrieve_terms t |> matches_list ctxt t | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 553 | val s = skeleton is_lhs ctxt t | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 554 | val frees = map fst (Term.add_frees s []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 555 | val tfrees = map fst (Term.add_tfrees s []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 556 | fun prep a = "R" ^ Library.unprefix "'" a | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 557 | 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 | 558 | val tab = tfrees ~~ rnames | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 559 | 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 | 560 | 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 | 561 | val binsts = bool_insts 1 (s, t) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 562 |     val cbool = @{ctyp bool}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 563 |     val relT = @{typ "bool => bool => bool"}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 564 | val idx = Thm.maxidx_of thm + 1 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 565 | val thy = Proof_Context.theory_of ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 566 | fun tinst (a, _) = (ctyp_of thy (TVar ((a, idx), HOLogic.typeS)), cbool) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 567 | fun inst (a, t) = (cterm_of thy (Var (Name.clean_index (prep a, idx), relT)), cterm_of thy t) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 568 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 569 | thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 570 | |> Thm.generalize (tfrees, rnames @ frees) idx | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 571 | |> Thm.instantiate (map tinst binsts, map inst binsts) | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 572 | end | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 573 | |
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 574 | fun eq_tac eq_rules = TRY o REPEAT_ALL_NEW (resolve_tac eq_rules) THEN_ALL_NEW rtac @{thm is_equality_eq}
 | 
| 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 575 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 576 | fun transfer_tac equiv ctxt i = | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 577 | let | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 578 |     val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 579 | val start_rule = | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 580 |       if equiv then @{thm transfer_start} else @{thm transfer_start'}
 | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 581 | val rules = get_transfer_raw ctxt | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 582 | val eq_rules = get_relator_eq_raw ctxt | 
| 47803 
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
 huffman parents: 
47789diff
changeset | 583 | (* allow unsolved subgoals only for standard transfer method, not for transfer' *) | 
| 
2e3821e13d67
allow transfer tactic to leave extra unsolved subgoals if transfer rules are missing
 huffman parents: 
47789diff
changeset | 584 | val end_tac = if equiv then K all_tac else K no_tac | 
| 49977 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 585 | val err_msg = "Transfer failed to convert goal to an object-logic formula" | 
| 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 586 | fun main_tac (t, i) = | 
| 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 587 | rtac start_rule i THEN | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 588 | (rtac (transfer_rule_of_term ctxt equiv (HOLogic.dest_Trueprop t)) | 
| 49977 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 589 | THEN_ALL_NEW | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 590 | (SOLVED' (REPEAT_ALL_NEW (resolve_tac rules) THEN_ALL_NEW (DETERM o eq_tac eq_rules)) | 
| 49977 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 591 | ORELSE' end_tac)) (i + 1) | 
| 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 592 | handle TERM (_, ts) => raise TERM (err_msg, ts) | 
| 47325 | 593 | in | 
| 594 | EVERY | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 595 | [rewrite_goal_tac ctxt pre_simps i THEN | 
| 49977 
3259ea7a52af
transfer package: error message if preprocessing goal to object-logic formula fails
 huffman parents: 
49976diff
changeset | 596 | SUBGOAL main_tac i, | 
| 47325 | 597 | (* FIXME: rewrite_goal_tac does unwanted eta-contraction *) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 598 | rewrite_goal_tac ctxt post_simps i, | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 599 | Goal.norm_hhf_tac ctxt i] | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 600 | end | 
| 47325 | 601 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 602 | fun transfer_prover_tac ctxt = SUBGOAL (fn (t, i) => | 
| 47325 | 603 | let | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 604 | 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 | 605 | val rule1 = transfer_rule_of_term ctxt false rhs | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 606 | val rules = get_transfer_raw ctxt | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 607 | val eq_rules = get_relator_eq_raw ctxt | 
| 52883 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 608 |     val expand_eq_in_rel = transfer_rel_conv (top_rewr_conv [@{thm fun_rel_eq[symmetric,THEN eq_reflection]}])
 | 
| 47325 | 609 | in | 
| 610 | EVERY | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 611 | [CONVERSION prep_conv i, | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 612 |        rtac @{thm transfer_prover_start} i,
 | 
| 52883 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 613 | ((rtac rule1 ORELSE' (CONVERSION expand_eq_in_rel THEN' rtac rule1)) | 
| 
0a7c97c76f46
expand equalities in the transfer relation in transfer_prover if the relation doesn't follow the functional structure
 kuncar parents: 
52358diff
changeset | 614 | THEN_ALL_NEW | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 615 | (REPEAT_ALL_NEW (resolve_tac rules) THEN_ALL_NEW (DETERM o eq_tac eq_rules))) (i+1), | 
| 47618 
1568dadd598a
make correspondence tactic more robust by replacing lhs with schematic variable before applying intro rules
 huffman parents: 
47580diff
changeset | 616 |        rtac @{thm refl} i]
 | 
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 617 | end) | 
| 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 618 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 619 | (** Transfer attribute **) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 620 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 621 | fun transferred ctxt extra_rules thm = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 622 | let | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 623 |     val start_rule = @{thm transfer_start}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 624 |     val start_rule' = @{thm transfer_start'}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 625 | val rules = extra_rules @ get_transfer_raw ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 626 | val eq_rules = get_relator_eq_raw ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 627 | val err_msg = "Transfer failed to convert goal to an object-logic formula" | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 628 |     val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 629 | val thm1 = Drule.forall_intr_vars thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 630 | val instT = rev (Term.add_tvars (Thm.full_prop_of thm1) []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 631 | |> map (fn v as ((a, _), S) => (v, TFree (a, S))) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 632 | val thm2 = thm1 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 633 | |> Thm.certify_instantiate (instT, []) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 634 | |> Raw_Simplifier.rewrite_rule ctxt pre_simps | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 635 | val ctxt' = Variable.declare_names (Thm.full_prop_of thm2) ctxt | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 636 | val t = HOLogic.dest_Trueprop (Thm.concl_of thm2) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 637 | val rule = transfer_rule_of_lhs ctxt' t | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 638 | val tac = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 639 | resolve_tac [thm2 RS start_rule', thm2 RS start_rule] 1 THEN | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 640 | (rtac rule | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 641 | THEN_ALL_NEW | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 642 | (SOLVED' (REPEAT_ALL_NEW (resolve_tac rules) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 643 | THEN_ALL_NEW (DETERM o eq_tac eq_rules)))) 1 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 644 | handle TERM (_, ts) => raise TERM (err_msg, ts) | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 645 |     val thm3 = Goal.prove_internal ctxt' [] @{cpat "Trueprop ?P"} (K tac)
 | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 646 | val tnames = map (fst o dest_TFree o snd) instT | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 647 | in | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 648 | thm3 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 649 | |> Raw_Simplifier.rewrite_rule ctxt' post_simps | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 650 | |> Simplifier.norm_hhf ctxt' | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 651 | |> Drule.generalize (tnames, []) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 652 | |> Drule.zero_var_indexes | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 653 | end | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 654 | (* | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 655 | handle THM _ => thm | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 656 | *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 657 | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 658 | fun untransferred ctxt extra_rules thm = | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 659 | let | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 660 |     val start_rule = @{thm untransfer_start}
 | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 661 | 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 | 662 | 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 | 663 | val err_msg = "Transfer failed to convert goal to an object-logic formula" | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 664 |     val pre_simps = @{thms transfer_forall_eq transfer_implies_eq}
 | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 665 | val thm1 = Drule.forall_intr_vars thm | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 666 | val instT = rev (Term.add_tvars (Thm.full_prop_of thm1) []) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 667 | |> map (fn v as ((a, _), S) => (v, TFree (a, S))) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 668 | val thm2 = thm1 | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 669 | |> Thm.certify_instantiate (instT, []) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 670 | |> 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 | 671 | 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 | 672 | 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 | 673 | 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 | 674 | val tac = | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 675 | rtac (thm2 RS start_rule) 1 THEN | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 676 | (rtac rule | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 677 | THEN_ALL_NEW | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 678 | (SOLVED' (REPEAT_ALL_NEW (resolve_tac rules) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 679 | THEN_ALL_NEW (DETERM o eq_tac eq_rules)))) 1 | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 680 | handle TERM (_, ts) => raise TERM (err_msg, ts) | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 681 |     val thm3 = Goal.prove_internal ctxt' [] @{cpat "Trueprop ?P"} (K tac)
 | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 682 | val tnames = map (fst o dest_TFree o snd) instT | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 683 | in | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 684 | thm3 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 685 | |> Raw_Simplifier.rewrite_rule ctxt' post_simps | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 686 | |> Simplifier.norm_hhf ctxt' | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 687 | |> Drule.generalize (tnames, []) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 688 | |> Drule.zero_var_indexes | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 689 | end | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 690 | |
| 47789 
71a526ee569a
implement transfer tactic with more scalable forward proof methods
 huffman parents: 
47658diff
changeset | 691 | (** Methods and attributes **) | 
| 47325 | 692 | |
| 47568 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 693 | 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 | 694 |   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 | 695 | |
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 696 | 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 | 697 | |-- Scan.repeat free) [] | 
| 
98c8b7542b72
add option to transfer method for specifying variables not to generalize over
 huffman parents: 
47523diff
changeset | 698 | |
| 53042 | 699 | 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 | 700 | fixing >> (fn vs => fn ctxt => | 
| 47658 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 701 | SIMPLE_METHOD' (gen_frees_tac vs ctxt THEN' transfer_tac equiv ctxt)) | 
| 47325 | 702 | |
| 53042 | 703 | val transfer_prover_method : (Proof.context -> Proof.method) context_parser = | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 704 | Scan.succeed (fn ctxt => SIMPLE_METHOD' (transfer_prover_tac ctxt)) | 
| 47325 | 705 | |
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 706 | (* Attribute for transfer rules *) | 
| 47325 | 707 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 708 | fun prep_rule ctxt = | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 709 | abstract_domains_transfer ctxt o abstract_equalities_transfer ctxt o Conv.fconv_rule prep_conv | 
| 47325 | 710 | |
| 711 | val transfer_add = | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 712 | Thm.declaration_attribute (fn thm => fn ctxt => | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 713 | (add_transfer_thm o prep_rule (Context.proof_of ctxt)) thm ctxt) | 
| 47325 | 714 | |
| 715 | val transfer_del = | |
| 52884 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 716 | Thm.declaration_attribute (fn thm => fn ctxt => | 
| 
34c47bc771f2
contract equalities in transfer and transfer domain rules when they are registered
 kuncar parents: 
52883diff
changeset | 717 | (del_transfer_thm o prep_rule (Context.proof_of ctxt)) thm ctxt) | 
| 47325 | 718 | |
| 719 | val transfer_attribute = | |
| 720 | Attrib.add_del transfer_add transfer_del | |
| 721 | ||
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 722 | (* 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 | 723 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 724 | 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 | 725 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 726 | 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 | 727 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 728 | 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 | 729 | 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 | 730 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 731 | (* Attributes for transferred rules *) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 732 | |
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 733 | fun transferred_attribute thms = Thm.rule_attribute | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 734 | (fn context => transferred (Context.proof_of context) thms) | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 735 | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 736 | fun untransferred_attribute thms = Thm.rule_attribute | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 737 | (fn context => untransferred (Context.proof_of context) thms) | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 738 | |
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 739 | val transferred_attribute_parser = | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 740 | Attrib.thms >> transferred_attribute | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 741 | |
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 742 | val untransferred_attribute_parser = | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 743 | Attrib.thms >> untransferred_attribute | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 744 | |
| 47325 | 745 | (* Theory setup *) | 
| 746 | ||
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 747 | val relator_eq_setup = | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 748 | let | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 749 |     val name = @{binding relator_eq}
 | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 750 | fun add_thm thm context = context | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 751 | |> Data.map (map_relator_eq (Item_Net.update thm)) | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 752 | |> Data.map (map_relator_eq_raw | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 753 | (Item_Net.update (abstract_equalities_relator_eq (Context.proof_of context) thm))) | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 754 | fun del_thm thm context = context | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 755 | |> Data.map (map_relator_eq (Item_Net.remove thm)) | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 756 | |> Data.map (map_relator_eq_raw | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
53649diff
changeset | 757 | (Item_Net.remove (abstract_equalities_relator_eq (Context.proof_of context) thm))) | 
| 49975 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 758 | val add = Thm.declaration_attribute add_thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 759 | val del = Thm.declaration_attribute del_thm | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 760 | val text = "declaration of relator equality rule (used by transfer method)" | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 761 | val content = Item_Net.content o #relator_eq o Data.get | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 762 | in | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 763 | Attrib.setup name (Attrib.add_del add del) text | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 764 | #> Global_Theory.add_thms_dynamic (name, content) | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 765 | end | 
| 
faf4afed009f
transfer package: more flexible handling of equality relations using is_equality predicate
 huffman parents: 
49625diff
changeset | 766 | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 767 | val relator_domain_setup = | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 768 | let | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 769 |     val name = @{binding relator_domain}
 | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 770 | fun add_thm thm = Data.map (map_relator_domain (Item_Net.update thm)) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 771 | #> add_transfer_domain_thm thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 772 | fun del_thm thm = Data.map (map_relator_domain (Item_Net.remove thm)) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 773 | #> del_transfer_domain_thm thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 774 | val add = Thm.declaration_attribute add_thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 775 | val del = Thm.declaration_attribute del_thm | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 776 | val text = "declaration of relator domain rule (used by transfer method)" | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 777 | val content = Item_Net.content o #relator_domain o Data.get | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 778 | in | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 779 | Attrib.setup name (Attrib.add_del add del) text | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 780 | #> Global_Theory.add_thms_dynamic (name, content) | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 781 | end | 
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 782 | |
| 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 783 | |
| 47325 | 784 | val setup = | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 785 | relator_eq_setup | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 786 | #> relator_domain_setup | 
| 47325 | 787 |   #> Attrib.setup @{binding transfer_rule} transfer_attribute
 | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 788 | "transfer rule for transfer method" | 
| 48064 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 789 | #> Global_Theory.add_thms_dynamic | 
| 
7bd9e18ce058
unify theory-data structures for transfer package
 huffman parents: 
47803diff
changeset | 790 |      (@{binding transfer_raw}, Item_Net.content o #transfer_raw o Data.get)
 | 
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51955diff
changeset | 791 |   #> Attrib.setup @{binding transfer_domain_rule} 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 | 792 | "transfer domain rule for transfer method" | 
| 52354 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 793 |   #> Attrib.setup @{binding transferred} transferred_attribute_parser
 | 
| 
acb4f932dd24
implement 'transferred' attribute for transfer package, with support for monotonicity of !!/==>
 huffman parents: 
51996diff
changeset | 794 | "raw theorem transferred to abstract theorem using transfer rules" | 
| 52358 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 795 |   #> Attrib.setup @{binding untransferred} untransferred_attribute_parser
 | 
| 
f4c4bcb0d564
implement 'untransferred' attribute, which is like 'transferred' but works in the opposite direction
 huffman parents: 
52354diff
changeset | 796 | "abstract theorem transferred to raw theorem using transfer rules" | 
| 51437 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 797 | #> Global_Theory.add_thms_dynamic | 
| 
8739f8abbecb
fixing transfer tactic - unfold fully identity relation by using relator_eq
 kuncar parents: 
51374diff
changeset | 798 |      (@{binding relator_eq_raw}, Item_Net.content o #relator_eq_raw o Data.get)
 | 
| 47658 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 799 |   #> Method.setup @{binding transfer} (transfer_method true)
 | 
| 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 800 | "generic theorem transfer method" | 
| 
7631f6f7873d
enable variant of transfer method that proves an implication instead of an equivalence
 huffman parents: 
47635diff
changeset | 801 |   #> Method.setup @{binding transfer'} (transfer_method false)
 | 
| 47325 | 802 | "generic theorem transfer method" | 
| 47635 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 803 |   #> Method.setup @{binding transfer_prover} transfer_prover_method
 | 
| 
ebb79474262c
rename 'correspondence' method to 'transfer_prover'
 huffman parents: 
47618diff
changeset | 804 | "for proving transfer rules" | 
| 47325 | 805 | |
| 806 | end |