theory Unit_Interval_Group imports Fractional_Part_Arithmetic "HOL-Algebra.Ring" begin section \Unit interval as Abelian group\ definition unit_interval_set :: "'a::floor_ceiling set" ("\") where "unit_interval_set = {x. 0 \ x \ x < 1}" definition ui_plus :: "'a \ 'a \ 'a::floor_ceiling" where "ui_plus a b = frac (a + b)" definition ui_minus :: "'a \ 'a \ 'a::floor_ceiling" where "ui_minus a b = frac (a - b)" definition ui_uminus :: "'a \ 'a::floor_ceiling" where "ui_uminus a = 1 - frac a" abbreviation unit_interval :: "'a::floor_ceiling ring" ("\") where "unit_interval \ \carrier = \, mult = (*), one = 1, zero = 0, add = ui_plus \" interpretation fracs: abelian_group "\ :: 'a::floor_ceiling ring" proof- have all_units: "Units (add_monoid \) = (\ :: 'a :: floor_ceiling set)" proof show "\ \ Units (add_monoid (\ :: 'a::floor_ceiling ring))" proof fix x :: "'a :: floor_ceiling" assume "x \ \" show "x \ Units (add_monoid \)" proof (cases "x = 0") assume "x = 0" show "x \ Units (add_monoid \)" unfolding \x = 0\ Units_def ui_plus_def unit_interval_set_def by force next assume "x \ 0" show "x \ Units (add_monoid \)" unfolding Units_def ui_plus_def unit_interval_set_def partial_object.select_convs monoid.select_convs ring.select_convs proof (rule CollectI, rule conjI) show "\xa\{x. 0 \ x \ x < 1}. frac (xa + x) = 0 \ frac (x + xa) = 0" proof show "1 - x \ {x. 0 \ x \ x < 1}" using \x \ \\ \x \ 0\ unfolding unit_interval_set_def by auto show "frac (1 - x + x) = 0 \ frac (x + (1 - x)) = 0" using \x \ \\ unfolding unit_interval_set_def by auto qed qed (use \x \ \\[unfolded unit_interval_set_def] in blast) qed qed show "Units (add_monoid \) \ \" unfolding partial_object.select_convs Units_def by blast qed show "abelian_group (\ :: 'a::floor_ceiling ring)" by (standard, unfold all_units, unfold ui_plus_def unit_interval_set_def) (simp_all add: frac_eq frac_lt_1 add.assoc, simp add: add.commute) qed end