diff -r 3e79279c10ca -r 0b7bdb75f451 src/HOL/Option.thy --- a/src/HOL/Option.thy Tue May 31 12:24:43 2016 +0200 +++ b/src/HOL/Option.thy Tue May 31 13:02:44 2016 +0200 @@ -136,6 +136,43 @@ | _ \ False)" by (auto split: prod.split option.split) + +definition combine_options :: "('a \ 'a \ 'a) \ 'a option \ 'a option \ 'a option" + where "combine_options f x y = + (case x of None \ y | Some x \ (case y of None \ Some x | Some y \ Some (f x y)))" + +lemma combine_options_simps [simp]: + "combine_options f None y = y" + "combine_options f x None = x" + "combine_options f (Some a) (Some b) = Some (f a b)" + by (simp_all add: combine_options_def split: option.splits) + +lemma combine_options_cases [case_names None1 None2 Some]: + "(x = None \ P x y) \ (y = None \ P x y) \ + (\a b. x = Some a \ y = Some b \ P x y) \ P x y" + by (cases x; cases y) simp_all + +lemma combine_options_commute: + "(\x y. f x y = f y x) \ combine_options f x y = combine_options f y x" + using combine_options_cases[of x ] + by (induction x y rule: combine_options_cases) simp_all + +lemma combine_options_assoc: + "(\x y z. f (f x y) z = f x (f y z)) \ + combine_options f (combine_options f x y) z = + combine_options f x (combine_options f y z)" + by (auto simp: combine_options_def split: option.splits) + +lemma combine_options_left_commute: + "(\x y. f x y = f y x) \ (\x y z. f (f x y) z = f x (f y z)) \ + combine_options f y (combine_options f x z) = + combine_options f x (combine_options f y z)" + by (auto simp: combine_options_def split: option.splits) + +lemmas combine_options_ac = + combine_options_commute combine_options_assoc combine_options_left_commute + + context begin