26 val add_transfer_rules_in_restore_data: string -> thm Item_Net.T -> Context.generic -> Context.generic |
26 val add_transfer_rules_in_restore_data: string -> thm Item_Net.T -> Context.generic -> Context.generic |
27 |
27 |
28 val get_invariant_commute_rules: Proof.context -> thm list |
28 val get_invariant_commute_rules: Proof.context -> thm list |
29 |
29 |
30 val get_reflexivity_rules: Proof.context -> thm list |
30 val get_reflexivity_rules: Proof.context -> thm list |
31 val add_reflexivity_rule_raw_attribute: attribute |
|
32 val add_reflexivity_rule_attribute: attribute |
31 val add_reflexivity_rule_attribute: attribute |
33 |
32 |
34 type relator_distr_data = {pos_mono_rule: thm, neg_mono_rule: thm, |
33 type relator_distr_data = {pos_mono_rule: thm, neg_mono_rule: thm, |
35 pos_distr_rules: thm list, neg_distr_rules: thm list} |
34 pos_distr_rules: thm list, neg_distr_rules: thm list} |
36 val lookup_relator_distr_data: Proof.context -> string -> relator_distr_data option |
35 val lookup_relator_distr_data: Proof.context -> string -> relator_distr_data option |
274 fun get_invariant_commute_rules ctxt = map safe_mk_meta_eq (Invariant_Commute.get ctxt) |
273 fun get_invariant_commute_rules ctxt = map safe_mk_meta_eq (Invariant_Commute.get ctxt) |
275 |
274 |
276 (* info about reflexivity rules *) |
275 (* info about reflexivity rules *) |
277 |
276 |
278 fun get_reflexivity_rules ctxt = Item_Net.content (get_reflexivity_rules' (Context.Proof ctxt)) |
277 fun get_reflexivity_rules ctxt = Item_Net.content (get_reflexivity_rules' (Context.Proof ctxt)) |
279 |
278 |
280 |
279 fun add_reflexivity_rule thm = Data.map (map_reflexivity_rules (Item_Net.update thm)) |
281 (* Conversion to create a reflp' variant of a reflexivity rule *) |
|
282 fun safe_reflp_conv ct = |
|
283 Conv.try_conv (HOLogic.Trueprop_conv (Conv.rewr_conv (Thm.symmetric @{thm reflp'_def}))) ct |
|
284 |
|
285 fun prep_reflp_conv ct = ( |
|
286 Conv.implies_conv safe_reflp_conv prep_reflp_conv |
|
287 else_conv |
|
288 safe_reflp_conv |
|
289 else_conv |
|
290 Conv.all_conv) ct |
|
291 |
|
292 fun add_reflexivity_rule_raw thm = Data.map (map_reflexivity_rules (Item_Net.update thm)) |
|
293 val add_reflexivity_rule_raw_attribute = Thm.declaration_attribute add_reflexivity_rule_raw |
|
294 |
|
295 fun add_reflexivity_rule thm = add_reflexivity_rule_raw thm #> |
|
296 add_reflexivity_rule_raw (Conv.fconv_rule prep_reflp_conv thm) |
|
297 val add_reflexivity_rule_attribute = Thm.declaration_attribute add_reflexivity_rule |
280 val add_reflexivity_rule_attribute = Thm.declaration_attribute add_reflexivity_rule |
298 |
281 |
299 |
|
300 val relfexivity_rule_setup = |
282 val relfexivity_rule_setup = |
301 let |
283 let |
302 val name = @{binding reflexivity_rule} |
284 val name = @{binding reflexivity_rule} |
303 fun del_thm_raw thm = Data.map (map_reflexivity_rules (Item_Net.remove thm)) |
285 fun del_thm thm = Data.map (map_reflexivity_rules (Item_Net.remove thm)) |
304 fun del_thm thm = del_thm_raw thm #> |
|
305 del_thm_raw (Conv.fconv_rule prep_reflp_conv thm) |
|
306 val del = Thm.declaration_attribute del_thm |
286 val del = Thm.declaration_attribute del_thm |
307 val text = "rules that are used to prove that a relation is reflexive" |
287 val text = "rules that are used to prove that a relation is reflexive" |
308 val content = Item_Net.content o get_reflexivity_rules' |
288 val content = Item_Net.content o get_reflexivity_rules' |
309 in |
289 in |
310 Attrib.setup name (Attrib.add_del add_reflexivity_rule_attribute del) text |
290 Attrib.setup name (Attrib.add_del add_reflexivity_rule_attribute del) text |
368 val rewr_conv = HOLogic.Trueprop_conv (Conv.rewrs_conv [@{thm POS_NEG}, @{thm NEG_POS}]) |
348 val rewr_conv = HOLogic.Trueprop_conv (Conv.rewrs_conv [@{thm POS_NEG}, @{thm NEG_POS}]) |
369 in |
349 in |
370 Conv.fconv_rule (Conv.prems_conv ~1 rewr_conv then_conv Conv.concl_conv ~1 rewr_conv) mono_rule |
350 Conv.fconv_rule (Conv.prems_conv ~1 rewr_conv then_conv Conv.concl_conv ~1 rewr_conv) mono_rule |
371 end; |
351 end; |
372 |
352 |
|
353 fun add_reflexivity_rules mono_rule ctxt = |
|
354 let |
|
355 fun find_eq_rule thm ctxt = |
|
356 let |
|
357 val concl_rhs = (hd o get_args 1 o HOLogic.dest_Trueprop o concl_of) thm; |
|
358 val rules = Item_Net.retrieve (Transfer.get_relator_eq_item_net ctxt) concl_rhs; |
|
359 in |
|
360 find_first (fn thm => Pattern.matches (Proof_Context.theory_of ctxt) (concl_rhs, |
|
361 (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o Thm.concl_of) thm)) rules |
|
362 end |
|
363 |
|
364 val eq_rule = find_eq_rule mono_rule (Context.proof_of ctxt); |
|
365 val eq_rule = if is_some eq_rule then the eq_rule else error |
|
366 "No corresponding rule that the relator preserves equality was found." |
|
367 in |
|
368 ctxt |
|
369 |> add_reflexivity_rule (Drule.zero_var_indexes (@{thm ord_le_eq_trans} OF [mono_rule, eq_rule])) |
|
370 |> add_reflexivity_rule |
|
371 (Drule.zero_var_indexes (@{thm ord_eq_le_trans} OF [sym OF [eq_rule], mono_rule])) |
|
372 end |
|
373 |
373 fun add_mono_rule mono_rule ctxt = |
374 fun add_mono_rule mono_rule ctxt = |
374 let |
375 let |
375 val mono_rule = introduce_polarities mono_rule |
376 val pol_mono_rule = introduce_polarities mono_rule |
376 val mono_ruleT_name = (fst o dest_Type o fst o relation_types o fst o relation_types o snd o |
377 val mono_ruleT_name = (fst o dest_Type o fst o relation_types o fst o relation_types o snd o |
377 dest_Const o head_of o HOLogic.dest_Trueprop o concl_of) mono_rule |
378 dest_Const o head_of o HOLogic.dest_Trueprop o concl_of) pol_mono_rule |
378 val _ = if Symtab.defined (get_relator_distr_data' ctxt) mono_ruleT_name |
379 val _ = if Symtab.defined (get_relator_distr_data' ctxt) mono_ruleT_name |
379 then error ("Monotocity rule for type " ^ quote mono_ruleT_name ^ " is already_defined.") |
380 then error ("Monotocity rule for type " ^ quote mono_ruleT_name ^ " is already_defined.") |
380 else () |
381 else () |
381 val neg_mono_rule = negate_mono_rule mono_rule |
382 val neg_mono_rule = negate_mono_rule pol_mono_rule |
382 val relator_distr_data = {pos_mono_rule = mono_rule, neg_mono_rule = neg_mono_rule, |
383 val relator_distr_data = {pos_mono_rule = pol_mono_rule, neg_mono_rule = neg_mono_rule, |
383 pos_distr_rules = [], neg_distr_rules = []} |
384 pos_distr_rules = [], neg_distr_rules = []} |
384 in |
385 in |
385 Data.map (map_relator_distr_data (Symtab.update (mono_ruleT_name, relator_distr_data))) ctxt |
386 ctxt |
|
387 |> Data.map (map_relator_distr_data (Symtab.update (mono_ruleT_name, relator_distr_data))) |
|
388 |> add_reflexivity_rules mono_rule |
386 end; |
389 end; |
387 |
390 |
388 local |
391 local |
389 fun add_distr_rule update_entry distr_rule ctxt = |
392 fun add_distr_rule update_entry distr_rule ctxt = |
390 let |
393 let |