src/HOL/ex/Simproc_Tests.thy
author bulwahn
Fri Oct 21 11:17:14 2011 +0200 (2011-10-21)
changeset 45231 d85a2fdc586c
parent 45224 b1d5b3820d82
child 45270 d5b5c9259afd
permissions -rw-r--r--
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
     1 (*  Title:      HOL/ex/Simproc_Tests.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Testing of arithmetic simprocs *}
     6 
     7 theory Simproc_Tests
     8 imports Rat
     9 begin
    10 
    11 text {*
    12   This theory tests the various simprocs defined in
    13   @{file "~~/src/HOL/Numeral_Simprocs.thy"}. Many of the tests
    14   are derived from commented-out code originally found in
    15   @{file "~~/src/HOL/Tools/numeral_simprocs.ML"}.
    16 *}
    17 
    18 subsection {* ML bindings *}
    19 
    20 ML {*
    21   val semiring_assoc_fold = Numeral_Simprocs.assoc_fold_simproc
    22   val int_combine_numerals = Numeral_Simprocs.combine_numerals
    23   val field_combine_numerals = Numeral_Simprocs.field_combine_numerals
    24   val [inteq_cancel_numerals, intless_cancel_numerals, intle_cancel_numerals]
    25     = Numeral_Simprocs.cancel_numerals
    26   val [ring_eq_cancel_factor, linordered_ring_le_cancel_factor,
    27       linordered_ring_less_cancel_factor, int_div_cancel_factor,
    28       int_mod_cancel_factor, dvd_cancel_factor, divide_cancel_factor]
    29     = Numeral_Simprocs.cancel_factors
    30   val [ring_eq_cancel_numeral_factor, ring_less_cancel_numeral_factor,
    31       ring_le_cancel_numeral_factor, int_div_cancel_numeral_factors,
    32       divide_cancel_numeral_factor]
    33     = Numeral_Simprocs.cancel_numeral_factors
    34   val field_combine_numerals = Numeral_Simprocs.field_combine_numerals
    35   val [field_eq_cancel_numeral_factor, field_cancel_numeral_factor]
    36     = Numeral_Simprocs.field_cancel_numeral_factors
    37 
    38   fun test ps = CHANGED (asm_simp_tac (HOL_basic_ss addsimprocs ps) 1)
    39 *}
    40 
    41 
    42 subsection {* @{text int_combine_numerals} *}
    43 
    44 lemma assumes "10 + (2 * l + oo) = uu"
    45   shows "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::int)"
    46 by (tactic {* test [int_combine_numerals] *}) fact
    47 
    48 lemma assumes "-3 + (i + (j + k)) = y"
    49   shows "(i + j + 12 + (k::int)) - 15 = y"
    50 by (tactic {* test [int_combine_numerals] *}) fact
    51 
    52 lemma assumes "7 + (i + (j + k)) = y"
    53   shows "(i + j + 12 + (k::int)) - 5 = y"
    54 by (tactic {* test [int_combine_numerals] *}) fact
    55 
    56 lemma assumes "-4 * (u * v) + (2 * x + y) = w"
    57   shows "(2*x - (u*v) + y) - v*3*u = (w::int)"
    58 by (tactic {* test [int_combine_numerals] *}) fact
    59 
    60 lemma assumes "Numeral0 * (u*v) + (2 * x * u * v + y) = w"
    61   shows "(2*x*u*v + (u*v)*4 + y) - v*u*4 = (w::int)"
    62 by (tactic {* test [int_combine_numerals] *}) fact
    63 
    64 lemma assumes "3 * (u * v) + (2 * x * u * v + y) = w"
    65   shows "(2*x*u*v + (u*v)*4 + y) - v*u = (w::int)"
    66 by (tactic {* test [int_combine_numerals] *}) fact
    67 
    68 lemma assumes "-3 * (u * v) + (- (x * u * v) + - y) = w"
    69   shows "u*v - (x*u*v + (u*v)*4 + y) = (w::int)"
    70 by (tactic {* test [int_combine_numerals] *}) fact
    71 
    72 lemma assumes "Numeral0 * b + (a + - c) = d"
    73   shows "a + -(b+c) + b = (d::int)"
    74 apply (simp only: minus_add_distrib)
    75 by (tactic {* test [int_combine_numerals] *}) fact
    76 
    77 lemma assumes "-2 * b + (a + - c) = d"
    78   shows "a + -(b+c) - b = (d::int)"
    79 apply (simp only: minus_add_distrib)
    80 by (tactic {* test [int_combine_numerals] *}) fact
    81 
    82 lemma assumes "-7 + (i + (j + (k + (- u + - y)))) = zz"
    83   shows "(i + j + -2 + (k::int)) - (u + 5 + y) = zz"
    84 by (tactic {* test [int_combine_numerals] *}) fact
    85 
    86 lemma assumes "-27 + (i + (j + k)) = y"
    87   shows "(i + j + -12 + (k::int)) - 15 = y"
    88 by (tactic {* test [int_combine_numerals] *}) fact
    89 
    90 lemma assumes "27 + (i + (j + k)) = y"
    91   shows "(i + j + 12 + (k::int)) - -15 = y"
    92 by (tactic {* test [int_combine_numerals] *}) fact
    93 
    94 lemma assumes "3 + (i + (j + k)) = y"
    95   shows "(i + j + -12 + (k::int)) - -15 = y"
    96 by (tactic {* test [int_combine_numerals] *}) fact
    97 
    98 
    99 subsection {* @{text inteq_cancel_numerals} *}
   100 
   101 lemma assumes "u = Numeral0" shows "2*u = (u::int)"
   102 by (tactic {* test [inteq_cancel_numerals] *}) fact
   103 (* conclusion matches Rings.ring_1_no_zero_divisors_class.mult_cancel_right2 *)
   104 
   105 lemma assumes "i + (j + k) = 3 + (u + y)"
   106   shows "(i + j + 12 + (k::int)) = u + 15 + y"
   107 by (tactic {* test [inteq_cancel_numerals] *}) fact
   108 
   109 lemma assumes "7 + (j + (i + k)) = y"
   110   shows "(i + j*2 + 12 + (k::int)) = j + 5 + y"
   111 by (tactic {* test [inteq_cancel_numerals] *}) fact
   112 
   113 lemma assumes "u + (6*z + (4*y + 6*w)) = 6*z' + (4*y' + (6*w' + vv))"
   114   shows "2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::int)"
   115 by (tactic {* test [int_combine_numerals, inteq_cancel_numerals] *}) fact
   116 
   117 
   118 subsection {* @{text intless_cancel_numerals} *}
   119 
   120 lemma assumes "y < 2 * b" shows "y - b < (b::int)"
   121 by (tactic {* test [intless_cancel_numerals] *}) fact
   122 
   123 lemma assumes "c + y < 4 * b" shows "y - (3*b + c) < (b::int) - 2*c"
   124 by (tactic {* test [intless_cancel_numerals] *}) fact
   125 
   126 lemma assumes "i + (j + k) < 8 + (u + y)"
   127   shows "(i + j + -3 + (k::int)) < u + 5 + y"
   128 by (tactic {* test [intless_cancel_numerals] *}) fact
   129 
   130 lemma assumes "9 + (i + (j + k)) < u + y"
   131   shows "(i + j + 3 + (k::int)) < u + -6 + y"
   132 by (tactic {* test [intless_cancel_numerals] *}) fact
   133 
   134 
   135 subsection {* @{text ring_eq_cancel_numeral_factor} *}
   136 
   137 lemma assumes "3*x = 4*y" shows "9*x = 12 * (y::int)"
   138 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   139 
   140 lemma assumes "-3*x = 4*y" shows "-99*x = 132 * (y::int)"
   141 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   142 
   143 
   144 subsection {* @{text int_div_cancel_numeral_factors} *}
   145 
   146 lemma assumes "(3*x) div (4*y) = z" shows "(9*x) div (12*y) = (z::int)"
   147 by (tactic {* test [int_div_cancel_numeral_factors] *}) fact
   148 
   149 lemma assumes "(-3*x) div (4*y) = z" shows "(-99*x) div (132*y) = (z::int)"
   150 by (tactic {* test [int_div_cancel_numeral_factors] *}) fact
   151 
   152 lemma assumes "(111*x) div (-44*y) = z" shows "(999*x) div (-396*y) = (z::int)"
   153 by (tactic {* test [int_div_cancel_numeral_factors] *}) fact
   154 
   155 lemma assumes "(11*x) div (9*y) = z" shows "(-99*x) div (-81*y) = (z::int)"
   156 by (tactic {* test [int_div_cancel_numeral_factors] *}) fact
   157 
   158 lemma assumes "(2*x) div (Numeral1*y) = z"
   159   shows "(-2 * x) div (-1 * (y::int)) = z"
   160 by (tactic {* test [int_div_cancel_numeral_factors] *}) fact
   161 
   162 
   163 subsection {* @{text ring_less_cancel_numeral_factor} *}
   164 
   165 lemma assumes "3*x < 4*y" shows "9*x < 12 * (y::int)"
   166 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   167 
   168 lemma assumes "-3*x < 4*y" shows "-99*x < 132 * (y::int)"
   169 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   170 
   171 lemma assumes "111*x < -44*y" shows "999*x < -396 * (y::int)"
   172 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   173 
   174 lemma assumes "9*y < 11*x" shows "-99*x < -81 * (y::int)"
   175 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   176 
   177 lemma assumes "Numeral1*y < 2*x" shows "-2 * x < -(y::int)"
   178 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   179 
   180 lemma assumes "23*y < Numeral1*x" shows "-x < -23 * (y::int)"
   181 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   182 
   183 lemma assumes "3*x < 4*y" shows "9*x < 12 * (y::rat)"
   184 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   185 
   186 lemma assumes "-3*x < 4*y" shows "-99*x < 132 * (y::rat)"
   187 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   188 
   189 lemma assumes "111*x < -44*y" shows "999*x < -396 * (y::rat)"
   190 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   191 
   192 lemma assumes "9*y < 11*x" shows "-99*x < -81 * (y::rat)"
   193 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   194 
   195 lemma assumes "Numeral1*y < 2*x" shows "-2 * x < -(y::rat)"
   196 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   197 
   198 lemma assumes "23*y < Numeral1*x" shows "-x < -23 * (y::rat)"
   199 by (tactic {* test [ring_less_cancel_numeral_factor] *}) fact
   200 
   201 
   202 subsection {* @{text ring_le_cancel_numeral_factor} *}
   203 
   204 lemma assumes "3*x \<le> 4*y" shows "9*x \<le> 12 * (y::int)"
   205 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   206 
   207 lemma assumes "-3*x \<le> 4*y" shows "-99*x \<le> 132 * (y::int)"
   208 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   209 
   210 lemma assumes "111*x \<le> -44*y" shows "999*x \<le> -396 * (y::int)"
   211 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   212 
   213 lemma assumes "9*y \<le> 11*x" shows "-99*x \<le> -81 * (y::int)"
   214 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   215 
   216 lemma assumes "Numeral1*y \<le> 2*x" shows "-2 * x \<le> -1 * (y::int)"
   217 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   218 
   219 lemma assumes "23*y \<le> Numeral1*x" shows "-x \<le> -23 * (y::int)"
   220 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   221 
   222 lemma assumes "Numeral1*y \<le> Numeral0" shows "0 \<le> (y::rat) * -2"
   223 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   224 
   225 lemma assumes "3*x \<le> 4*y" shows "9*x \<le> 12 * (y::rat)"
   226 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   227 
   228 lemma assumes "-3*x \<le> 4*y" shows "-99*x \<le> 132 * (y::rat)"
   229 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   230 
   231 lemma assumes "111*x \<le> -44*y" shows "999*x \<le> -396 * (y::rat)"
   232 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   233 
   234 lemma assumes "-1*x \<le> Numeral1*y" shows "- ((2::rat) * x) \<le> 2*y"
   235 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   236 
   237 lemma assumes "9*y \<le> 11*x" shows "-99*x \<le> -81 * (y::rat)"
   238 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   239 
   240 lemma assumes "Numeral1*y \<le> 2*x" shows "-2 * x \<le> -1 * (y::rat)"
   241 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   242 
   243 lemma assumes "23*y \<le> Numeral1*x" shows "-x \<le> -23 * (y::rat)"
   244 by (tactic {* test [ring_le_cancel_numeral_factor] *}) fact
   245 
   246 
   247 subsection {* @{text ring_eq_cancel_numeral_factor} *}
   248 
   249 lemma assumes "111*x = -44*y" shows "999*x = -396 * (y::int)"
   250 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   251 
   252 lemma assumes "11*x = 9*y" shows "-99*x = -81 * (y::int)"
   253 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   254 
   255 lemma assumes "2*x = Numeral1*y" shows "-2 * x = -1 * (y::int)"
   256 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   257 
   258 lemma assumes "2*x = Numeral1*y" shows "-2 * x = -(y::int)"
   259 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   260 
   261 lemma assumes "3*x = 4*y" shows "9*x = 12 * (y::rat)"
   262 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   263 
   264 lemma assumes "-3*x = 4*y" shows "-99*x = 132 * (y::rat)"
   265 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   266 
   267 lemma assumes "111*x = -44*y" shows "999*x = -396 * (y::rat)"
   268 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   269 
   270 lemma assumes "11*x = 9*y" shows "-99*x = -81 * (y::rat)"
   271 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   272 
   273 lemma assumes "2*x = Numeral1*y" shows "-2 * x = -1 * (y::rat)"
   274 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   275 
   276 lemma assumes "2*x = Numeral1*y" shows "-2 * x = -(y::rat)"
   277 by (tactic {* test [ring_eq_cancel_numeral_factor] *}) fact
   278 
   279 
   280 subsection {* @{text field_cancel_numeral_factor} *}
   281 
   282 lemma assumes "(3*x) / (4*y) = z" shows "(9*x) / (12 * (y::rat)) = z"
   283 by (tactic {* test [field_cancel_numeral_factor] *}) fact
   284 
   285 lemma assumes "(-3*x) / (4*y) = z" shows "(-99*x) / (132 * (y::rat)) = z"
   286 by (tactic {* test [field_cancel_numeral_factor] *}) fact
   287 
   288 lemma assumes "(111*x) / (-44*y) = z" shows "(999*x) / (-396 * (y::rat)) = z"
   289 by (tactic {* test [field_cancel_numeral_factor] *}) fact
   290 
   291 lemma assumes "(11*x) / (9*y) = z" shows "(-99*x) / (-81 * (y::rat)) = z"
   292 by (tactic {* test [field_cancel_numeral_factor] *}) fact
   293 
   294 lemma assumes "(2*x) / (Numeral1*y) = z" shows "(-2 * x) / (-1 * (y::rat)) = z"
   295 by (tactic {* test [field_cancel_numeral_factor] *}) fact
   296 
   297 
   298 subsection {* @{text ring_eq_cancel_factor} *}
   299 
   300 lemma assumes "k = 0 \<or> x = y" shows "x*k = k*(y::int)"
   301 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   302 
   303 lemma assumes "k = 0 \<or> 1 = y" shows "k = k*(y::int)"
   304 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   305 
   306 lemma assumes "b = 0 \<or> a*c = 1" shows "a*(b*c) = (b::int)"
   307 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   308 
   309 lemma assumes "a = 0 \<or> b = 0 \<or> c = d*x" shows "a*(b*c) = d*(b::int)*(x*a)"
   310 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   311 
   312 lemma assumes "k = 0 \<or> x = y" shows "x*k = k*(y::rat)"
   313 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   314 
   315 lemma assumes "k = 0 \<or> 1 = y" shows "k = k*(y::rat)"
   316 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   317 
   318 lemma assumes "b = 0 \<or> a*c = 1" shows "a*(b*c) = (b::rat)"
   319 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   320 
   321 lemma assumes "a = 0 \<or> b = 0 \<or> c = d*x" shows "a*(b*c) = d*(b::rat)*(x*a)"
   322 by (tactic {* test [ring_eq_cancel_factor] *}) fact
   323 
   324 
   325 subsection {* @{text int_div_cancel_factor} *}
   326 
   327 lemma assumes "(if k = 0 then 0 else x div y) = uu"
   328   shows "(x*k) div (k*(y::int)) = (uu::int)"
   329 by (tactic {* test [int_div_cancel_factor] *}) fact
   330 
   331 lemma assumes "(if k = 0 then 0 else 1 div y) = uu"
   332   shows "(k) div (k*(y::int)) = (uu::int)"
   333 by (tactic {* test [int_div_cancel_factor] *}) fact
   334 
   335 lemma assumes "(if b = 0 then 0 else a * c) = uu"
   336   shows "(a*(b*c)) div ((b::int)) = (uu::int)"
   337 by (tactic {* test [int_div_cancel_factor] *}) fact
   338 
   339 lemma assumes "(if a = 0 then 0 else if b = 0 then 0 else c div (d * x)) = uu"
   340   shows "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)"
   341 by (tactic {* test [int_div_cancel_factor] *}) fact
   342 
   343 
   344 subsection {* @{text divide_cancel_factor} *}
   345 
   346 lemma assumes "(if k = 0 then 0 else x / y) = uu"
   347   shows "(x*k) / (k*(y::rat)) = (uu::rat)"
   348 by (tactic {* test [divide_cancel_factor] *}) fact
   349 
   350 lemma assumes "(if k = 0 then 0 else 1 / y) = uu"
   351   shows "(k) / (k*(y::rat)) = (uu::rat)"
   352 by (tactic {* test [divide_cancel_factor] *}) fact
   353 
   354 lemma assumes "(if b = 0 then 0 else a * c / 1) = uu"
   355   shows "(a*(b*c)) / ((b::rat)) = (uu::rat)"
   356 by (tactic {* test [divide_cancel_factor] *}) fact
   357 
   358 lemma assumes "(if a = 0 then 0 else if b = 0 then 0 else c / (d * x)) = uu"
   359   shows "(a*(b*c)) / (d*(b::rat)*(x*a)) = (uu::rat)"
   360 by (tactic {* test [divide_cancel_factor] *}) fact
   361 
   362 lemma shows "a*(b*c)/(y*z) = d*(b::rat)*(x*a)/z"
   363 oops -- "FIXME: need simproc to cover this case"
   364 
   365 
   366 subsection {* @{text linordered_ring_less_cancel_factor} *}
   367 
   368 lemma assumes "0 < z \<Longrightarrow> x < y" shows "(0::rat) < z \<Longrightarrow> x*z < y*z"
   369 by (tactic {* test [linordered_ring_less_cancel_factor] *}) fact
   370 
   371 lemma assumes "0 < z \<Longrightarrow> x < y" shows "(0::rat) < z \<Longrightarrow> x*z < z*y"
   372 by (tactic {* test [linordered_ring_less_cancel_factor] *}) fact
   373 
   374 lemma assumes "0 < z \<Longrightarrow> x < y" shows "(0::rat) < z \<Longrightarrow> z*x < y*z"
   375 by (tactic {* test [linordered_ring_less_cancel_factor] *}) fact
   376 
   377 lemma "(0::rat) < z \<Longrightarrow> z*x < z*y"
   378 apply (tactic {* test [linordered_ring_less_cancel_factor] *})?
   379 oops -- "FIXME: test fails"
   380 
   381 
   382 subsection {* @{text linordered_ring_le_cancel_factor} *}
   383 
   384 lemma assumes "0 < z \<Longrightarrow> x \<le> y" shows "(0::rat) < z \<Longrightarrow> x*z \<le> y*z"
   385 by (tactic {* test [linordered_ring_le_cancel_factor] *}) fact
   386 
   387 lemma assumes "0 < z \<Longrightarrow> x \<le> y" shows "(0::rat) < z \<Longrightarrow> z*x \<le> z*y"
   388 apply (tactic {* test [linordered_ring_le_cancel_factor] *})?
   389 oops -- "FIXME: test fails"
   390 
   391 
   392 subsection {* @{text field_combine_numerals} *}
   393 
   394 lemma assumes "5 / 6 * x = uu" shows "(x::rat) / 2 + x / 3 = uu"
   395 by (tactic {* test [field_combine_numerals] *}) fact
   396 
   397 lemma assumes "6 / 9 * x + y = uu" shows "(x::rat) / 3 + y + x / 3 = uu"
   398 by (tactic {* test [field_combine_numerals] *}) fact
   399 
   400 lemma assumes "9 / 9 * x = uu" shows "2 * (x::rat) / 3 + x / 3 = uu"
   401 by (tactic {* test [field_combine_numerals] *}) fact
   402 
   403 lemma "2/3 * (x::rat) + x / 3 = uu"
   404 apply (tactic {* test [field_combine_numerals] *})?
   405 oops -- "FIXME: test fails"
   406 
   407 
   408 subsection {* @{text field_eq_cancel_numeral_factor} *}
   409 
   410 text {* TODO: tests for @{text field_eq_cancel_numeral_factor} simproc *}
   411 
   412 
   413 subsection {* @{text field_cancel_numeral_factor} *}
   414 
   415 text {* TODO: tests for @{text field_cancel_numeral_factor} simproc *}
   416 
   417 end