src/HOL/Library/Fraction_Field.thy
author hoelzl
Tue Jul 19 14:37:49 2011 +0200 (2011-07-19)
changeset 43922 c6f35921056e
parent 40822 98a5faa5aec0
child 45694 4a8743618257
permissions -rw-r--r--
add nat => enat coercion
     1 (*  Title:      HOL/Library/Fraction_Field.thy
     2     Author:     Amine Chaieb, University of Cambridge
     3 *)
     4 
     5 header{* A formalization of the fraction field of any integral domain 
     6          A generalization of Rat.thy from int to any integral domain *}
     7 
     8 theory Fraction_Field
     9 imports Main
    10 begin
    11 
    12 subsection {* General fractions construction *}
    13 
    14 subsubsection {* Construction of the type of fractions *}
    15 
    16 definition fractrel :: "(('a::idom * 'a ) * ('a * 'a)) set" where
    17   "fractrel == {(x, y). snd x \<noteq> 0 \<and> snd y \<noteq> 0 \<and> fst x * snd y = fst y * snd x}"
    18 
    19 lemma fractrel_iff [simp]:
    20   "(x, y) \<in> fractrel \<longleftrightarrow> snd x \<noteq> 0 \<and> snd y \<noteq> 0 \<and> fst x * snd y = fst y * snd x"
    21   by (simp add: fractrel_def)
    22 
    23 lemma refl_fractrel: "refl_on {x. snd x \<noteq> 0} fractrel"
    24   by (auto simp add: refl_on_def fractrel_def)
    25 
    26 lemma sym_fractrel: "sym fractrel"
    27   by (simp add: fractrel_def sym_def)
    28 
    29 lemma trans_fractrel: "trans fractrel"
    30 proof (rule transI, unfold split_paired_all)
    31   fix a b a' b' a'' b'' :: 'a
    32   assume A: "((a, b), (a', b')) \<in> fractrel"
    33   assume B: "((a', b'), (a'', b'')) \<in> fractrel"
    34   have "b' * (a * b'') = b'' * (a * b')" by (simp add: mult_ac)
    35   also from A have "a * b' = a' * b" by auto
    36   also have "b'' * (a' * b) = b * (a' * b'')" by (simp add: mult_ac)
    37   also from B have "a' * b'' = a'' * b'" by auto
    38   also have "b * (a'' * b') = b' * (a'' * b)" by (simp add: mult_ac)
    39   finally have "b' * (a * b'') = b' * (a'' * b)" .
    40   moreover from B have "b' \<noteq> 0" by auto
    41   ultimately have "a * b'' = a'' * b" by simp
    42   with A B show "((a, b), (a'', b'')) \<in> fractrel" by auto
    43 qed
    44   
    45 lemma equiv_fractrel: "equiv {x. snd x \<noteq> 0} fractrel"
    46   by (rule equivI [OF refl_fractrel sym_fractrel trans_fractrel])
    47 
    48 lemmas UN_fractrel = UN_equiv_class [OF equiv_fractrel]
    49 lemmas UN_fractrel2 = UN_equiv_class2 [OF equiv_fractrel equiv_fractrel]
    50 
    51 lemma equiv_fractrel_iff [iff]: 
    52   assumes "snd x \<noteq> 0" and "snd y \<noteq> 0"
    53   shows "fractrel `` {x} = fractrel `` {y} \<longleftrightarrow> (x, y) \<in> fractrel"
    54   by (rule eq_equiv_class_iff, rule equiv_fractrel) (auto simp add: assms)
    55 
    56 typedef 'a fract = "{(x::'a\<times>'a). snd x \<noteq> (0::'a::idom)} // fractrel"
    57 proof
    58   have "(0::'a, 1::'a) \<in> {x. snd x \<noteq> 0}" by simp
    59   then show "fractrel `` {(0::'a, 1)} \<in> {x. snd x \<noteq> 0} // fractrel" by (rule quotientI)
    60 qed
    61 
    62 lemma fractrel_in_fract [simp]: "snd x \<noteq> 0 \<Longrightarrow> fractrel `` {x} \<in> fract"
    63   by (simp add: fract_def quotientI)
    64 
    65 declare Abs_fract_inject [simp] Abs_fract_inverse [simp]
    66 
    67 
    68 subsubsection {* Representation and basic operations *}
    69 
    70 definition
    71   Fract :: "'a::idom \<Rightarrow> 'a \<Rightarrow> 'a fract" where
    72   "Fract a b = Abs_fract (fractrel `` {if b = 0 then (0, 1) else (a, b)})"
    73 
    74 code_datatype Fract
    75 
    76 lemma Fract_cases [case_names Fract, cases type: fract]:
    77   assumes "\<And>a b. q = Fract a b \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> C"
    78   shows C
    79   using assms by (cases q) (clarsimp simp add: Fract_def fract_def quotient_def)
    80 
    81 lemma Fract_induct [case_names Fract, induct type: fract]:
    82   assumes "\<And>a b. b \<noteq> 0 \<Longrightarrow> P (Fract a b)"
    83   shows "P q"
    84   using assms by (cases q) simp
    85 
    86 lemma eq_fract:
    87   shows "\<And>a b c d. b \<noteq> 0 \<Longrightarrow> d \<noteq> 0 \<Longrightarrow> Fract a b = Fract c d \<longleftrightarrow> a * d = c * b"
    88   and "\<And>a. Fract a 0 = Fract 0 1"
    89   and "\<And>a c. Fract 0 a = Fract 0 c"
    90   by (simp_all add: Fract_def)
    91 
    92 instantiation fract :: (idom) "{comm_ring_1, power}"
    93 begin
    94 
    95 definition
    96   Zero_fract_def [code_unfold]: "0 = Fract 0 1"
    97 
    98 definition
    99   One_fract_def [code_unfold]: "1 = Fract 1 1"
   100 
   101 definition
   102   add_fract_def:
   103   "q + r = Abs_fract (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r.
   104     fractrel `` {(fst x * snd y + fst y * snd x, snd x * snd y)})"
   105 
   106 lemma add_fract [simp]:
   107   assumes "b \<noteq> (0::'a::idom)" and "d \<noteq> 0"
   108   shows "Fract a b + Fract c d = Fract (a * d + c * b) (b * d)"
   109 proof -
   110   have "(\<lambda>x y. fractrel``{(fst x * snd y + fst y * snd x, snd x * snd y :: 'a)})
   111     respects2 fractrel"
   112   apply (rule equiv_fractrel [THEN congruent2_commuteI]) apply (auto simp add: algebra_simps)
   113   unfolding mult_assoc[symmetric] .
   114   with assms show ?thesis by (simp add: Fract_def add_fract_def UN_fractrel2)
   115 qed
   116 
   117 definition
   118   minus_fract_def:
   119   "- q = Abs_fract (\<Union>x \<in> Rep_fract q. fractrel `` {(- fst x, snd x)})"
   120 
   121 lemma minus_fract [simp, code]: "- Fract a b = Fract (- a) (b::'a::idom)"
   122 proof -
   123   have "(\<lambda>x. fractrel `` {(- fst x, snd x :: 'a)}) respects fractrel"
   124     by (simp add: congruent_def split_paired_all)
   125   then show ?thesis by (simp add: Fract_def minus_fract_def UN_fractrel)
   126 qed
   127 
   128 lemma minus_fract_cancel [simp]: "Fract (- a) (- b) = Fract a b"
   129   by (cases "b = 0") (simp_all add: eq_fract)
   130 
   131 definition
   132   diff_fract_def: "q - r = q + - (r::'a fract)"
   133 
   134 lemma diff_fract [simp]:
   135   assumes "b \<noteq> 0" and "d \<noteq> 0"
   136   shows "Fract a b - Fract c d = Fract (a * d - c * b) (b * d)"
   137   using assms by (simp add: diff_fract_def diff_minus)
   138 
   139 definition
   140   mult_fract_def:
   141   "q * r = Abs_fract (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r.
   142     fractrel``{(fst x * fst y, snd x * snd y)})"
   143 
   144 lemma mult_fract [simp]: "Fract (a::'a::idom) b * Fract c d = Fract (a * c) (b * d)"
   145 proof -
   146   have "(\<lambda>x y. fractrel `` {(fst x * fst y, snd x * snd y :: 'a)}) respects2 fractrel"
   147     apply (rule equiv_fractrel [THEN congruent2_commuteI]) apply (auto simp add: algebra_simps)
   148     unfolding mult_assoc[symmetric] .
   149   then show ?thesis by (simp add: Fract_def mult_fract_def UN_fractrel2)
   150 qed
   151 
   152 lemma mult_fract_cancel:
   153   assumes "c \<noteq> 0"
   154   shows "Fract (c * a) (c * b) = Fract a b"
   155 proof -
   156   from assms have "Fract c c = Fract 1 1" by (simp add: Fract_def)
   157   then show ?thesis by (simp add: mult_fract [symmetric])
   158 qed
   159 
   160 instance proof
   161   fix q r s :: "'a fract" show "(q * r) * s = q * (r * s)" 
   162     by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps)
   163 next
   164   fix q r :: "'a fract" show "q * r = r * q"
   165     by (cases q, cases r) (simp add: eq_fract algebra_simps)
   166 next
   167   fix q :: "'a fract" show "1 * q = q"
   168     by (cases q) (simp add: One_fract_def eq_fract)
   169 next
   170   fix q r s :: "'a fract" show "(q + r) + s = q + (r + s)"
   171     by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps)
   172 next
   173   fix q r :: "'a fract" show "q + r = r + q"
   174     by (cases q, cases r) (simp add: eq_fract algebra_simps)
   175 next
   176   fix q :: "'a fract" show "0 + q = q"
   177     by (cases q) (simp add: Zero_fract_def eq_fract)
   178 next
   179   fix q :: "'a fract" show "- q + q = 0"
   180     by (cases q) (simp add: Zero_fract_def eq_fract)
   181 next
   182   fix q r :: "'a fract" show "q - r = q + - r"
   183     by (cases q, cases r) (simp add: eq_fract)
   184 next
   185   fix q r s :: "'a fract" show "(q + r) * s = q * s + r * s"
   186     by (cases q, cases r, cases s) (simp add: eq_fract algebra_simps)
   187 next
   188   show "(0::'a fract) \<noteq> 1" by (simp add: Zero_fract_def One_fract_def eq_fract)
   189 qed
   190 
   191 end
   192 
   193 lemma of_nat_fract: "of_nat k = Fract (of_nat k) 1"
   194   by (induct k) (simp_all add: Zero_fract_def One_fract_def)
   195 
   196 lemma Fract_of_nat_eq: "Fract (of_nat k) 1 = of_nat k"
   197   by (rule of_nat_fract [symmetric])
   198 
   199 lemma fract_collapse [code_post]:
   200   "Fract 0 k = 0"
   201   "Fract 1 1 = 1"
   202   "Fract k 0 = 0"
   203   by (cases "k = 0")
   204     (simp_all add: Zero_fract_def One_fract_def eq_fract Fract_def)
   205 
   206 lemma fract_expand [code_unfold]:
   207   "0 = Fract 0 1"
   208   "1 = Fract 1 1"
   209   by (simp_all add: fract_collapse)
   210 
   211 lemma Fract_cases_nonzero [case_names Fract 0]:
   212   assumes Fract: "\<And>a b. q = Fract a b \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> C"
   213   assumes 0: "q = 0 \<Longrightarrow> C"
   214   shows C
   215 proof (cases "q = 0")
   216   case True then show C using 0 by auto
   217 next
   218   case False
   219   then obtain a b where "q = Fract a b" and "b \<noteq> 0" by (cases q) auto
   220   moreover with False have "0 \<noteq> Fract a b" by simp
   221   with `b \<noteq> 0` have "a \<noteq> 0" by (simp add: Zero_fract_def eq_fract)
   222   with Fract `q = Fract a b` `b \<noteq> 0` show C by auto
   223 qed
   224   
   225 
   226 
   227 subsubsection {* The field of rational numbers *}
   228 
   229 context idom
   230 begin
   231 subclass ring_no_zero_divisors ..
   232 thm mult_eq_0_iff
   233 end
   234 
   235 instantiation fract :: (idom) field_inverse_zero
   236 begin
   237 
   238 definition
   239   inverse_fract_def:
   240   "inverse q = Abs_fract (\<Union>x \<in> Rep_fract q.
   241      fractrel `` {if fst x = 0 then (0, 1) else (snd x, fst x)})"
   242 
   243 
   244 lemma inverse_fract [simp]: "inverse (Fract a b) = Fract (b::'a::idom) a"
   245 proof -
   246   have stupid: "\<And>x. (0::'a) = x \<longleftrightarrow> x = 0" by auto
   247   have "(\<lambda>x. fractrel `` {if fst x = 0 then (0, 1) else (snd x, fst x :: 'a)}) respects fractrel"
   248     by (auto simp add: congruent_def stupid algebra_simps)
   249   then show ?thesis by (simp add: Fract_def inverse_fract_def UN_fractrel)
   250 qed
   251 
   252 definition
   253   divide_fract_def: "q / r = q * inverse (r:: 'a fract)"
   254 
   255 lemma divide_fract [simp]: "Fract a b / Fract c d = Fract (a * d) (b * c)"
   256   by (simp add: divide_fract_def)
   257 
   258 instance proof
   259   fix q :: "'a fract"
   260   assume "q \<noteq> 0"
   261   then show "inverse q * q = 1" apply (cases q rule: Fract_cases_nonzero)
   262     by (simp_all add: mult_fract  inverse_fract fract_expand eq_fract mult_commute)
   263 next
   264   fix q r :: "'a fract"
   265   show "q / r = q * inverse r" by (simp add: divide_fract_def)
   266 next
   267   show "inverse 0 = (0:: 'a fract)" by (simp add: fract_expand)
   268     (simp add: fract_collapse)
   269 qed
   270 
   271 end
   272 
   273 
   274 subsubsection {* The ordered field of fractions over an ordered idom *}
   275 
   276 lemma le_congruent2:
   277   "(\<lambda>x y::'a \<times> 'a::linordered_idom.
   278     {(fst x * snd y)*(snd x * snd y) \<le> (fst y * snd x)*(snd x * snd y)})
   279     respects2 fractrel"
   280 proof (clarsimp simp add: congruent2_def)
   281   fix a b a' b' c d c' d' :: 'a
   282   assume neq: "b \<noteq> 0"  "b' \<noteq> 0"  "d \<noteq> 0"  "d' \<noteq> 0"
   283   assume eq1: "a * b' = a' * b"
   284   assume eq2: "c * d' = c' * d"
   285 
   286   let ?le = "\<lambda>a b c d. ((a * d) * (b * d) \<le> (c * b) * (b * d))"
   287   {
   288     fix a b c d x :: 'a assume x: "x \<noteq> 0"
   289     have "?le a b c d = ?le (a * x) (b * x) c d"
   290     proof -
   291       from x have "0 < x * x" by (auto simp add: zero_less_mult_iff)
   292       hence "?le a b c d =
   293           ((a * d) * (b * d) * (x * x) \<le> (c * b) * (b * d) * (x * x))"
   294         by (simp add: mult_le_cancel_right)
   295       also have "... = ?le (a * x) (b * x) c d"
   296         by (simp add: mult_ac)
   297       finally show ?thesis .
   298     qed
   299   } note le_factor = this
   300 
   301   let ?D = "b * d" and ?D' = "b' * d'"
   302   from neq have D: "?D \<noteq> 0" by simp
   303   from neq have "?D' \<noteq> 0" by simp
   304   hence "?le a b c d = ?le (a * ?D') (b * ?D') c d"
   305     by (rule le_factor)
   306   also have "... = ((a * b') * ?D * ?D' * d * d' \<le> (c * d') * ?D * ?D' * b * b')"
   307     by (simp add: mult_ac)
   308   also have "... = ((a' * b) * ?D * ?D' * d * d' \<le> (c' * d) * ?D * ?D' * b * b')"
   309     by (simp only: eq1 eq2)
   310   also have "... = ?le (a' * ?D) (b' * ?D) c' d'"
   311     by (simp add: mult_ac)
   312   also from D have "... = ?le a' b' c' d'"
   313     by (rule le_factor [symmetric])
   314   finally show "?le a b c d = ?le a' b' c' d'" .
   315 qed
   316 
   317 instantiation fract :: (linordered_idom) linorder
   318 begin
   319 
   320 definition
   321   le_fract_def:
   322    "q \<le> r \<longleftrightarrow> the_elem (\<Union>x \<in> Rep_fract q. \<Union>y \<in> Rep_fract r.
   323       {(fst x * snd y)*(snd x * snd y) \<le> (fst y * snd x)*(snd x * snd y)})"
   324 
   325 definition
   326   less_fract_def: "z < (w::'a fract) \<longleftrightarrow> z \<le> w \<and> \<not> w \<le> z"
   327 
   328 lemma le_fract [simp]:
   329   assumes "b \<noteq> 0" and "d \<noteq> 0"
   330   shows "Fract a b \<le> Fract c d \<longleftrightarrow> (a * d) * (b * d) \<le> (c * b) * (b * d)"
   331 by (simp add: Fract_def le_fract_def le_congruent2 UN_fractrel2 assms)
   332 
   333 lemma less_fract [simp]:
   334   assumes "b \<noteq> 0" and "d \<noteq> 0"
   335   shows "Fract a b < Fract c d \<longleftrightarrow> (a * d) * (b * d) < (c * b) * (b * d)"
   336 by (simp add: less_fract_def less_le_not_le mult_ac assms)
   337 
   338 instance proof
   339   fix q r s :: "'a fract"
   340   assume "q \<le> r" and "r \<le> s" thus "q \<le> s"
   341   proof (induct q, induct r, induct s)
   342     fix a b c d e f :: 'a
   343     assume neq: "b \<noteq> 0"  "d \<noteq> 0"  "f \<noteq> 0"
   344     assume 1: "Fract a b \<le> Fract c d" and 2: "Fract c d \<le> Fract e f"
   345     show "Fract a b \<le> Fract e f"
   346     proof -
   347       from neq obtain bb: "0 < b * b" and dd: "0 < d * d" and ff: "0 < f * f"
   348         by (auto simp add: zero_less_mult_iff linorder_neq_iff)
   349       have "(a * d) * (b * d) * (f * f) \<le> (c * b) * (b * d) * (f * f)"
   350       proof -
   351         from neq 1 have "(a * d) * (b * d) \<le> (c * b) * (b * d)"
   352           by simp
   353         with ff show ?thesis by (simp add: mult_le_cancel_right)
   354       qed
   355       also have "... = (c * f) * (d * f) * (b * b)"
   356         by (simp only: mult_ac)
   357       also have "... \<le> (e * d) * (d * f) * (b * b)"
   358       proof -
   359         from neq 2 have "(c * f) * (d * f) \<le> (e * d) * (d * f)"
   360           by simp
   361         with bb show ?thesis by (simp add: mult_le_cancel_right)
   362       qed
   363       finally have "(a * f) * (b * f) * (d * d) \<le> e * b * (b * f) * (d * d)"
   364         by (simp only: mult_ac)
   365       with dd have "(a * f) * (b * f) \<le> (e * b) * (b * f)"
   366         by (simp add: mult_le_cancel_right)
   367       with neq show ?thesis by simp
   368     qed
   369   qed
   370 next
   371   fix q r :: "'a fract"
   372   assume "q \<le> r" and "r \<le> q" thus "q = r"
   373   proof (induct q, induct r)
   374     fix a b c d :: 'a
   375     assume neq: "b \<noteq> 0"  "d \<noteq> 0"
   376     assume 1: "Fract a b \<le> Fract c d" and 2: "Fract c d \<le> Fract a b"
   377     show "Fract a b = Fract c d"
   378     proof -
   379       from neq 1 have "(a * d) * (b * d) \<le> (c * b) * (b * d)"
   380         by simp
   381       also have "... \<le> (a * d) * (b * d)"
   382       proof -
   383         from neq 2 have "(c * b) * (d * b) \<le> (a * d) * (d * b)"
   384           by simp
   385         thus ?thesis by (simp only: mult_ac)
   386       qed
   387       finally have "(a * d) * (b * d) = (c * b) * (b * d)" .
   388       moreover from neq have "b * d \<noteq> 0" by simp
   389       ultimately have "a * d = c * b" by simp
   390       with neq show ?thesis by (simp add: eq_fract)
   391     qed
   392   qed
   393 next
   394   fix q r :: "'a fract"
   395   show "q \<le> q"
   396     by (induct q) simp
   397   show "(q < r) = (q \<le> r \<and> \<not> r \<le> q)"
   398     by (simp only: less_fract_def)
   399   show "q \<le> r \<or> r \<le> q"
   400     by (induct q, induct r)
   401        (simp add: mult_commute, rule linorder_linear)
   402 qed
   403 
   404 end
   405 
   406 instantiation fract :: (linordered_idom) "{distrib_lattice, abs_if, sgn_if}"
   407 begin
   408 
   409 definition
   410   abs_fract_def: "\<bar>q\<bar> = (if q < 0 then -q else (q::'a fract))"
   411 
   412 definition
   413   sgn_fract_def:
   414     "sgn (q::'a fract) = (if q=0 then 0 else if 0<q then 1 else - 1)"
   415 
   416 theorem abs_fract [simp]: "\<bar>Fract a b\<bar> = Fract \<bar>a\<bar> \<bar>b\<bar>"
   417   by (auto simp add: abs_fract_def Zero_fract_def le_less
   418       eq_fract zero_less_mult_iff mult_less_0_iff split: abs_split)
   419 
   420 definition
   421   inf_fract_def:
   422     "(inf \<Colon> 'a fract \<Rightarrow> 'a fract \<Rightarrow> 'a fract) = min"
   423 
   424 definition
   425   sup_fract_def:
   426     "(sup \<Colon> 'a fract \<Rightarrow> 'a fract \<Rightarrow> 'a fract) = max"
   427 
   428 instance by intro_classes
   429   (auto simp add: abs_fract_def sgn_fract_def
   430     min_max.sup_inf_distrib1 inf_fract_def sup_fract_def)
   431 
   432 end
   433 
   434 instance fract :: (linordered_idom) linordered_field_inverse_zero
   435 proof
   436   fix q r s :: "'a fract"
   437   show "q \<le> r ==> s + q \<le> s + r"
   438   proof (induct q, induct r, induct s)
   439     fix a b c d e f :: 'a
   440     assume neq: "b \<noteq> 0"  "d \<noteq> 0"  "f \<noteq> 0"
   441     assume le: "Fract a b \<le> Fract c d"
   442     show "Fract e f + Fract a b \<le> Fract e f + Fract c d"
   443     proof -
   444       let ?F = "f * f" from neq have F: "0 < ?F"
   445         by (auto simp add: zero_less_mult_iff)
   446       from neq le have "(a * d) * (b * d) \<le> (c * b) * (b * d)"
   447         by simp
   448       with F have "(a * d) * (b * d) * ?F * ?F \<le> (c * b) * (b * d) * ?F * ?F"
   449         by (simp add: mult_le_cancel_right)
   450       with neq show ?thesis by (simp add: field_simps)
   451     qed
   452   qed
   453   show "q < r ==> 0 < s ==> s * q < s * r"
   454   proof (induct q, induct r, induct s)
   455     fix a b c d e f :: 'a
   456     assume neq: "b \<noteq> 0"  "d \<noteq> 0"  "f \<noteq> 0"
   457     assume le: "Fract a b < Fract c d"
   458     assume gt: "0 < Fract e f"
   459     show "Fract e f * Fract a b < Fract e f * Fract c d"
   460     proof -
   461       let ?E = "e * f" and ?F = "f * f"
   462       from neq gt have "0 < ?E"
   463         by (auto simp add: Zero_fract_def order_less_le eq_fract)
   464       moreover from neq have "0 < ?F"
   465         by (auto simp add: zero_less_mult_iff)
   466       moreover from neq le have "(a * d) * (b * d) < (c * b) * (b * d)"
   467         by simp
   468       ultimately have "(a * d) * (b * d) * ?E * ?F < (c * b) * (b * d) * ?E * ?F"
   469         by (simp add: mult_less_cancel_right)
   470       with neq show ?thesis
   471         by (simp add: mult_ac)
   472     qed
   473   qed
   474 qed
   475 
   476 lemma fract_induct_pos [case_names Fract]:
   477   fixes P :: "'a::linordered_idom fract \<Rightarrow> bool"
   478   assumes step: "\<And>a b. 0 < b \<Longrightarrow> P (Fract a b)"
   479   shows "P q"
   480 proof (cases q)
   481   have step': "\<And>a b. b < 0 \<Longrightarrow> P (Fract a b)"
   482   proof -
   483     fix a::'a and b::'a
   484     assume b: "b < 0"
   485     hence "0 < -b" by simp
   486     hence "P (Fract (-a) (-b))" by (rule step)
   487     thus "P (Fract a b)" by (simp add: order_less_imp_not_eq [OF b])
   488   qed
   489   case (Fract a b)
   490   thus "P q" by (force simp add: linorder_neq_iff step step')
   491 qed
   492 
   493 lemma zero_less_Fract_iff:
   494   "0 < b \<Longrightarrow> 0 < Fract a b \<longleftrightarrow> 0 < a"
   495   by (auto simp add: Zero_fract_def zero_less_mult_iff)
   496 
   497 lemma Fract_less_zero_iff:
   498   "0 < b \<Longrightarrow> Fract a b < 0 \<longleftrightarrow> a < 0"
   499   by (auto simp add: Zero_fract_def mult_less_0_iff)
   500 
   501 lemma zero_le_Fract_iff:
   502   "0 < b \<Longrightarrow> 0 \<le> Fract a b \<longleftrightarrow> 0 \<le> a"
   503   by (auto simp add: Zero_fract_def zero_le_mult_iff)
   504 
   505 lemma Fract_le_zero_iff:
   506   "0 < b \<Longrightarrow> Fract a b \<le> 0 \<longleftrightarrow> a \<le> 0"
   507   by (auto simp add: Zero_fract_def mult_le_0_iff)
   508 
   509 lemma one_less_Fract_iff:
   510   "0 < b \<Longrightarrow> 1 < Fract a b \<longleftrightarrow> b < a"
   511   by (auto simp add: One_fract_def mult_less_cancel_right_disj)
   512 
   513 lemma Fract_less_one_iff:
   514   "0 < b \<Longrightarrow> Fract a b < 1 \<longleftrightarrow> a < b"
   515   by (auto simp add: One_fract_def mult_less_cancel_right_disj)
   516 
   517 lemma one_le_Fract_iff:
   518   "0 < b \<Longrightarrow> 1 \<le> Fract a b \<longleftrightarrow> b \<le> a"
   519   by (auto simp add: One_fract_def mult_le_cancel_right)
   520 
   521 lemma Fract_le_one_iff:
   522   "0 < b \<Longrightarrow> Fract a b \<le> 1 \<longleftrightarrow> a \<le> b"
   523   by (auto simp add: One_fract_def mult_le_cancel_right)
   524 
   525 end