src/HOL/GCD.thy
changeset 63025 92680537201f
parent 62429 25271ff79171
child 63145 703edebd1d92
equal deleted inserted replaced
63024:adeac19dd410 63025:92680537201f
    42   where "coprime x y \<equiv> gcd x y = 1"
    42   where "coprime x y \<equiv> gcd x y = 1"
    43 
    43 
    44 end
    44 end
    45 
    45 
    46 class Gcd = gcd +
    46 class Gcd = gcd +
    47   fixes Gcd :: "'a set \<Rightarrow> 'a" ("Gcd")
    47   fixes Gcd :: "'a set \<Rightarrow> 'a"
    48     and Lcm :: "'a set \<Rightarrow> 'a" ("Lcm")
    48     and Lcm :: "'a set \<Rightarrow> 'a"
    49 begin
    49 begin
    50 
    50 
    51 abbreviation GCD :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
    51 abbreviation GREATEST_COMMON_DIVISOR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
    52 where
    52 where
    53   "GCD A f \<equiv> Gcd (f ` A)"
    53   "GREATEST_COMMON_DIVISOR A f \<equiv> Gcd (f ` A)"
    54 
    54 
    55 abbreviation LCM :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
    55 abbreviation LEAST_COMMON_MULTIPLE :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a"
    56 where
    56 where
    57   "LCM A f \<equiv> Lcm (f ` A)"
    57   "LEAST_COMMON_MULTIPLE A f \<equiv> Lcm (f ` A)"
    58 
    58 
    59 end
    59 end
    60 
    60 
    61 syntax
    61 syntax
    62   "_GCD1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3Gcd _./ _)" [0, 10] 10)
    62   "_GCD1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3GCD _./ _)" [0, 10] 10)
    63   "_GCD"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3Gcd _\<in>_./ _)" [0, 0, 10] 10)
    63   "_GCD"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3GCD _\<in>_./ _)" [0, 0, 10] 10)
    64   "_LCM1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3Lcm _./ _)" [0, 10] 10)
    64   "_LCM1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3LCM _./ _)" [0, 10] 10)
    65   "_LCM"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3Lcm _\<in>_./ _)" [0, 0, 10] 10)
    65   "_LCM"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3LCM _\<in>_./ _)" [0, 0, 10] 10)
    66 
    66 
    67 translations
    67 translations
    68   "Gcd x y. B"   \<rightleftharpoons> "Gcd x. Gcd y. B"
    68   "GCD x y. B"   \<rightleftharpoons> "GCD x. GCD y. B"
    69   "Gcd x. B"     \<rightleftharpoons> "CONST GCD CONST UNIV (\<lambda>x. B)"
    69   "GCD x. B"     \<rightleftharpoons> "CONST GREATEST_COMMON_DIVISOR CONST UNIV (\<lambda>x. B)"
    70   "Gcd x. B"     \<rightleftharpoons> "Gcd x \<in> CONST UNIV. B"
    70   "GCD x. B"     \<rightleftharpoons> "GCD x \<in> CONST UNIV. B"
    71   "Gcd x\<in>A. B"   \<rightleftharpoons> "CONST GCD A (\<lambda>x. B)"
    71   "GCD x\<in>A. B"   \<rightleftharpoons> "CONST GREATEST_COMMON_DIVISOR A (\<lambda>x. B)"
    72   "Lcm x y. B"   \<rightleftharpoons> "Lcm x. Lcm y. B"
    72   "LCM x y. B"   \<rightleftharpoons> "LCM x. LCM y. B"
    73   "Lcm x. B"     \<rightleftharpoons> "CONST LCM CONST UNIV (\<lambda>x. B)"
    73   "LCM x. B"     \<rightleftharpoons> "CONST LEAST_COMMON_MULTIPLE CONST UNIV (\<lambda>x. B)"
    74   "Lcm x. B"     \<rightleftharpoons> "Lcm x \<in> CONST UNIV. B"
    74   "LCM x. B"     \<rightleftharpoons> "LCM x \<in> CONST UNIV. B"
    75   "Lcm x\<in>A. B"   \<rightleftharpoons> "CONST LCM A (\<lambda>x. B)"
    75   "LCM x\<in>A. B"   \<rightleftharpoons> "CONST LEAST_COMMON_MULTIPLE A (\<lambda>x. B)"
    76 
    76 
    77 print_translation \<open>
    77 print_translation \<open>
    78   [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax GCD} @{syntax_const "_GCD"},
    78   [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax GREATEST_COMMON_DIVISOR} @{syntax_const "_GCD"},
    79     Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax LCM} @{syntax_const "_LCM"}]
    79     Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax LEAST_COMMON_MULTIPLE} @{syntax_const "_LCM"}]
    80 \<close> \<comment> \<open>to avoid eta-contraction of body\<close>
    80 \<close> \<comment> \<open>to avoid eta-contraction of body\<close>
    81 
    81 
    82 class semiring_gcd = normalization_semidom + gcd +
    82 class semiring_gcd = normalization_semidom + gcd +
    83   assumes gcd_dvd1 [iff]: "gcd a b dvd a"
    83   assumes gcd_dvd1 [iff]: "gcd a b dvd a"
    84     and gcd_dvd2 [iff]: "gcd a b dvd b"
    84     and gcd_dvd2 [iff]: "gcd a b dvd b"
  2164 
  2164 
  2165 instantiation int :: semiring_Gcd
  2165 instantiation int :: semiring_Gcd
  2166 begin
  2166 begin
  2167 
  2167 
  2168 definition
  2168 definition
  2169   "Lcm M = int (Lcm m\<in>M. (nat \<circ> abs) m)"
  2169   "Lcm M = int (LCM m\<in>M. (nat \<circ> abs) m)"
  2170 
  2170 
  2171 definition
  2171 definition
  2172   "Gcd M = int (Gcd m\<in>M. (nat \<circ> abs) m)"
  2172   "Gcd M = int (GCD m\<in>M. (nat \<circ> abs) m)"
  2173 
  2173 
  2174 instance by standard
  2174 instance by standard
  2175   (auto intro!: Gcd_dvd Gcd_greatest simp add: Gcd_int_def
  2175   (auto intro!: Gcd_dvd Gcd_greatest simp add: Gcd_int_def
  2176     Lcm_int_def int_dvd_iff dvd_int_iff dvd_int_unfold_dvd_nat [symmetric])
  2176     Lcm_int_def int_dvd_iff dvd_int_iff dvd_int_unfold_dvd_nat [symmetric])
  2177 
  2177