31 infinity. |
31 infinity. |
32 \<close> |
32 \<close> |
33 |
33 |
34 typedef enat = "UNIV :: nat option set" .. |
34 typedef enat = "UNIV :: nat option set" .. |
35 |
35 |
36 text \<open>TODO: introduce enat as coinductive datatype, enat is just @{const of_nat}\<close> |
36 text \<open>TODO: introduce enat as coinductive datatype, enat is just \<^const>\<open>of_nat\<close>\<close> |
37 |
37 |
38 definition enat :: "nat \<Rightarrow> enat" where |
38 definition enat :: "nat \<Rightarrow> enat" where |
39 "enat n = Abs_enat (Some n)" |
39 "enat n = Abs_enat (Some n)" |
40 |
40 |
41 instantiation enat :: infinity |
41 instantiation enat :: infinity |
535 fun find_first_t _ _ [] = raise TERM("find_first_t", []) |
535 fun find_first_t _ _ [] = raise TERM("find_first_t", []) |
536 | find_first_t past u (t::terms) = |
536 | find_first_t past u (t::terms) = |
537 if u aconv t then (rev past @ terms) |
537 if u aconv t then (rev past @ terms) |
538 else find_first_t (t::past) u terms |
538 else find_first_t (t::past) u terms |
539 |
539 |
540 fun dest_summing (Const (@{const_name Groups.plus}, _) $ t $ u, ts) = |
540 fun dest_summing (Const (\<^const_name>\<open>Groups.plus\<close>, _) $ t $ u, ts) = |
541 dest_summing (t, dest_summing (u, ts)) |
541 dest_summing (t, dest_summing (u, ts)) |
542 | dest_summing (t, ts) = t :: ts |
542 | dest_summing (t, ts) = t :: ts |
543 |
543 |
544 val mk_sum = Arith_Data.long_mk_sum |
544 val mk_sum = Arith_Data.long_mk_sum |
545 fun dest_sum t = dest_summing (t, []) |
545 fun dest_sum t = dest_summing (t, []) |
546 val find_first = find_first_t [] |
546 val find_first = find_first_t [] |
547 val trans_tac = Numeral_Simprocs.trans_tac |
547 val trans_tac = Numeral_Simprocs.trans_tac |
548 val norm_ss = |
548 val norm_ss = |
549 simpset_of (put_simpset HOL_basic_ss @{context} |
549 simpset_of (put_simpset HOL_basic_ss \<^context> |
550 addsimps @{thms ac_simps add_0_left add_0_right}) |
550 addsimps @{thms ac_simps add_0_left add_0_right}) |
551 fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt)) |
551 fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset norm_ss ctxt)) |
552 fun simplify_meta_eq ctxt cancel_th th = |
552 fun simplify_meta_eq ctxt cancel_th th = |
553 Arith_Data.simplify_meta_eq [] ctxt |
553 Arith_Data.simplify_meta_eq [] ctxt |
554 ([th, cancel_th] MRS trans) |
554 ([th, cancel_th] MRS trans) |
556 end |
556 end |
557 |
557 |
558 structure Eq_Enat_Cancel = ExtractCommonTermFun |
558 structure Eq_Enat_Cancel = ExtractCommonTermFun |
559 (open Cancel_Enat_Common |
559 (open Cancel_Enat_Common |
560 val mk_bal = HOLogic.mk_eq |
560 val mk_bal = HOLogic.mk_eq |
561 val dest_bal = HOLogic.dest_bin @{const_name HOL.eq} @{typ enat} |
561 val dest_bal = HOLogic.dest_bin \<^const_name>\<open>HOL.eq\<close> \<^typ>\<open>enat\<close> |
562 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel} |
562 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel} |
563 ) |
563 ) |
564 |
564 |
565 structure Le_Enat_Cancel = ExtractCommonTermFun |
565 structure Le_Enat_Cancel = ExtractCommonTermFun |
566 (open Cancel_Enat_Common |
566 (open Cancel_Enat_Common |
567 val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less_eq} |
567 val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less_eq\<close> |
568 val dest_bal = HOLogic.dest_bin @{const_name Orderings.less_eq} @{typ enat} |
568 val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less_eq\<close> \<^typ>\<open>enat\<close> |
569 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le} |
569 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_le} |
570 ) |
570 ) |
571 |
571 |
572 structure Less_Enat_Cancel = ExtractCommonTermFun |
572 structure Less_Enat_Cancel = ExtractCommonTermFun |
573 (open Cancel_Enat_Common |
573 (open Cancel_Enat_Common |
574 val mk_bal = HOLogic.mk_binrel @{const_name Orderings.less} |
574 val mk_bal = HOLogic.mk_binrel \<^const_name>\<open>Orderings.less\<close> |
575 val dest_bal = HOLogic.dest_bin @{const_name Orderings.less} @{typ enat} |
575 val dest_bal = HOLogic.dest_bin \<^const_name>\<open>Orderings.less\<close> \<^typ>\<open>enat\<close> |
576 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less} |
576 fun simp_conv _ _ = SOME @{thm enat_add_left_cancel_less} |
577 ) |
577 ) |
578 \<close> |
578 \<close> |
579 |
579 |
580 simproc_setup enat_eq_cancel |
580 simproc_setup enat_eq_cancel |