# HG changeset patch # User haftmann # Date 1455742317 -3600 # Node ID 66a381d3f88fa734d75045462e4ecde33bd62337 # Parent 7c23469b5118361891d3143c3679f033dbe29fa9 more sophisticated GCD syntax diff -r 7c23469b5118 -r 66a381d3f88f src/HOL/GCD.thy --- a/src/HOL/GCD.thy Wed Feb 17 21:51:57 2016 +0100 +++ b/src/HOL/GCD.thy Wed Feb 17 21:51:57 2016 +0100 @@ -44,8 +44,40 @@ end class Gcd = gcd + - fixes Gcd :: "'a set \ 'a" - and Lcm :: "'a set \ 'a" + fixes Gcd :: "'a set \ 'a" ("Gcd") + and Lcm :: "'a set \ 'a" ("Lcm") +begin + +abbreviation GCD :: "'b set \ ('b \ 'a) \ 'a" +where + "GCD A f \ Gcd (f ` A)" + +abbreviation LCM :: "'b set \ ('b \ 'a) \ 'a" +where + "LCM A f \ Lcm (f ` A)" + +end + +syntax + "_GCD1" :: "pttrns \ 'b \ 'b" ("(3Gcd _./ _)" [0, 10] 10) + "_GCD" :: "pttrn \ 'a set \ 'b \ 'b" ("(3Gcd _\_./ _)" [0, 0, 10] 10) + "_LCM1" :: "pttrns \ 'b \ 'b" ("(3Lcm _./ _)" [0, 10] 10) + "_LCM" :: "pttrn \ 'a set \ 'b \ 'b" ("(3Lcm _\_./ _)" [0, 0, 10] 10) + +translations + "Gcd x y. B" \ "Gcd x. Gcd y. B" + "Gcd x. B" \ "CONST GCD CONST UNIV (\x. B)" + "Gcd x. B" \ "Gcd x \ CONST UNIV. B" + "Gcd x\A. B" \ "CONST GCD A (\x. B)" + "Lcm x y. B" \ "Lcm x. Lcm y. B" + "Lcm x. B" \ "CONST LCM CONST UNIV (\x. B)" + "Lcm x. B" \ "Lcm x \ CONST UNIV. B" + "Lcm x\A. B" \ "CONST LCM A (\x. B)" + +print_translation \ + [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax GCD} @{syntax_const "_GCD"}, + Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax LCM} @{syntax_const "_LCM"}] +\ \ \to avoid eta-contraction of body\ class semiring_gcd = normalization_semidom + gcd + assumes gcd_dvd1 [iff]: "gcd a b dvd a" @@ -571,7 +603,7 @@ have "Gcd (normalize ` A) dvd a" if "a \ A" for a proof - from that obtain B where "A = insert a B" by blast - moreover have " gcd (normalize a) (Gcd (normalize ` B)) dvd normalize a" + moreover have "gcd (normalize a) (Gcd (normalize ` B)) dvd normalize a" by (rule gcd_dvd1) ultimately show "Gcd (normalize ` A) dvd a" by simp @@ -596,8 +628,7 @@ shows "Lcm A = a" using assms by (blast intro: associated_eqI Lcm_least dvd_Lcm normalize_Lcm) -end - +end subsection \GCD and LCM on @{typ nat} and @{typ int}\