39 set_unfoldss: thm list list, |
39 set_unfoldss: thm list list, |
40 pred_unfolds: thm list, |
40 pred_unfolds: thm list, |
41 rel_unfolds: thm list |
41 rel_unfolds: thm list |
42 }; |
42 }; |
43 |
43 |
44 fun add_to_thms thms NONE = thms |
|
45 | add_to_thms thms (SOME new) = thms |> not (Thm.is_reflexive new) ? insert Thm.eq_thm new; |
|
46 fun adds_to_thms thms NONE = thms |
|
47 | adds_to_thms thms (SOME news) = insert (eq_set Thm.eq_thm) (no_reflexive news) thms; |
|
48 |
|
49 val empty_unfolds = {map_unfolds = [], set_unfoldss = [], pred_unfolds = [], rel_unfolds = []}; |
44 val empty_unfolds = {map_unfolds = [], set_unfoldss = [], pred_unfolds = [], rel_unfolds = []}; |
50 |
45 |
51 fun add_to_unfolds_opt map_opt sets_opt pred_opt rel_opt |
46 fun add_to_thms thms new = thms |> not (Thm.is_reflexive new) ? insert Thm.eq_thm new; |
|
47 fun adds_to_thms thms news = insert (eq_set Thm.eq_thm) (no_reflexive news) thms; |
|
48 |
|
49 fun add_to_unfolds map sets pred rel |
52 {map_unfolds, set_unfoldss, pred_unfolds, rel_unfolds} = |
50 {map_unfolds, set_unfoldss, pred_unfolds, rel_unfolds} = |
53 {map_unfolds = add_to_thms map_unfolds map_opt, |
51 {map_unfolds = add_to_thms map_unfolds map, |
54 set_unfoldss = adds_to_thms set_unfoldss sets_opt, |
52 set_unfoldss = adds_to_thms set_unfoldss sets, |
55 pred_unfolds = add_to_thms pred_unfolds pred_opt, |
53 pred_unfolds = add_to_thms pred_unfolds pred, |
56 rel_unfolds = add_to_thms rel_unfolds rel_opt}; |
54 rel_unfolds = add_to_thms rel_unfolds rel}; |
57 |
55 |
58 fun add_to_unfolds map sets pred rel = |
56 fun add_bnf_to_unfolds bnf = |
59 add_to_unfolds_opt (SOME map) (SOME sets) (SOME pred) (SOME rel); |
57 add_to_unfolds (map_def_of_bnf bnf) (set_defs_of_bnf bnf) (pred_def_of_bnf bnf) |
|
58 (rel_def_of_bnf bnf); |
60 |
59 |
61 val map_unfolds_of = #map_unfolds; |
60 val map_unfolds_of = #map_unfolds; |
62 val set_unfoldss_of = #set_unfoldss; |
61 val set_unfoldss_of = #set_unfoldss; |
63 val pred_unfolds_of = #pred_unfolds; |
62 val pred_unfolds_of = #pred_unfolds; |
64 val rel_unfolds_of = #rel_unfolds; |
63 val rel_unfolds_of = #rel_unfolds; |
271 (maps wit_thms_of_bnf inners); |
270 (maps wit_thms_of_bnf inners); |
272 |
271 |
273 val (bnf', lthy') = |
272 val (bnf', lthy') = |
274 bnf_def const_policy (K Derive_Few_Facts) qualify tacs wit_tac (SOME (oDs @ flat Dss)) |
273 bnf_def const_policy (K Derive_Few_Facts) qualify tacs wit_tac (SOME (oDs @ flat Dss)) |
275 (((((b, mapx), sets), bd), wits), SOME pred) lthy; |
274 (((((b, mapx), sets), bd), wits), SOME pred) lthy; |
276 |
|
277 val unfold_set' = |
|
278 add_to_unfolds (map_def_of_bnf bnf') (set_defs_of_bnf bnf') (pred_def_of_bnf bnf') |
|
279 (rel_def_of_bnf bnf') unfold_set; |
|
280 in |
275 in |
281 (bnf', (unfold_set', lthy')) |
276 (bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
282 end; |
277 end; |
283 |
278 |
284 (* Killing live variables *) |
279 (* Killing live variables *) |
285 |
280 |
286 fun kill_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
281 fun kill_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
373 fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
368 fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
374 |
369 |
375 val (bnf', lthy') = |
370 val (bnf', lthy') = |
376 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME (killedAs @ Ds)) |
371 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME (killedAs @ Ds)) |
377 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
372 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
378 |
|
379 val unfold_set' = |
|
380 add_to_unfolds (map_def_of_bnf bnf') (set_defs_of_bnf bnf') (pred_def_of_bnf bnf') |
|
381 (rel_def_of_bnf bnf') unfold_set; |
|
382 in |
373 in |
383 (bnf', (unfold_set', lthy')) |
374 (bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
384 end; |
375 end; |
385 |
376 |
386 (* Adding dummy live variables *) |
377 (* Adding dummy live variables *) |
387 |
378 |
388 fun lift_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
379 fun lift_bnf qualify n bnf (unfold_set, lthy) = if n = 0 then (bnf, (unfold_set, lthy)) else |
462 |
453 |
463 val (bnf', lthy') = |
454 val (bnf', lthy') = |
464 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME Ds) |
455 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME Ds) |
465 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
456 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
466 |
457 |
467 val unfold_set' = |
|
468 add_to_unfolds (map_def_of_bnf bnf') (set_defs_of_bnf bnf') (pred_def_of_bnf bnf') |
|
469 (pred_def_of_bnf bnf') unfold_set; |
|
470 in |
458 in |
471 (bnf', (unfold_set', lthy')) |
459 (bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
472 end; |
460 end; |
473 |
461 |
474 (* Changing the order of live variables *) |
462 (* Changing the order of live variables *) |
475 |
463 |
476 fun permute_bnf qualify src dest bnf (unfold_set, lthy) = |
464 fun permute_bnf qualify src dest bnf (unfold_set, lthy) = |
541 fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
529 fun wit_tac _ = mk_simple_wit_tac (wit_thms_of_bnf bnf); |
542 |
530 |
543 val (bnf', lthy') = |
531 val (bnf', lthy') = |
544 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME Ds) |
532 bnf_def Smart_Inline (K Derive_Few_Facts) qualify tacs wit_tac (SOME Ds) |
545 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
533 (((((b, mapx), sets), Term.absdummy T bd), wits), SOME pred) lthy; |
546 |
|
547 val unfold_set' = |
|
548 add_to_unfolds (map_def_of_bnf bnf') (set_defs_of_bnf bnf') (pred_def_of_bnf bnf') |
|
549 (pred_def_of_bnf bnf') unfold_set; |
|
550 in |
534 in |
551 (bnf', (unfold_set', lthy')) |
535 (bnf', (add_bnf_to_unfolds bnf' unfold_set, lthy')) |
552 end; |
536 end; |
553 |
537 |
554 (* Composition pipeline *) |
538 (* Composition pipeline *) |
555 |
539 |
556 fun permute_and_kill qualify n src dest bnf = |
540 fun permute_and_kill qualify n src dest bnf = |