src/HOL/Real/RealBin.ML
author wenzelm
Thu, 17 Aug 2000 10:33:37 +0200
changeset 9619 6125cc9efc18
parent 9574 da0a964aa601
child 10606 e3229a37d53f
permissions -rw-r--r--
fixed deps;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
     1
(*  Title:      HOL/Real/RealBin.ML
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     2
    ID:         $Id$
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     5
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
     6
Binary arithmetic for the reals (integer literals only).
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     7
*)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     8
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
     9
(** real_of_int (coercion from int to real) **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    10
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    11
Goal "real_of_int (number_of w) = number_of w";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    12
by (simp_tac (simpset() addsimps [real_number_of_def]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    13
qed "real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    14
Addsimps [real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    15
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
    16
Goalw [real_number_of_def] "(0::real) = #0";
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    17
by (simp_tac (simpset() addsimps [real_of_int_zero RS sym]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    18
qed "zero_eq_numeral_0";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    19
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    20
Goalw [real_number_of_def] "1r = #1";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    21
by (simp_tac (simpset() addsimps [real_of_int_one RS sym]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    22
qed "one_eq_numeral_1";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    23
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    24
(** Addition **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    25
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    26
Goal "(number_of v :: real) + number_of v' = number_of (bin_add v v')";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    27
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    28
    (HOL_ss addsimps [real_number_of_def, 
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    29
				  real_of_int_add, number_of_add]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    30
qed "add_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    31
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    32
Addsimps [add_real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    33
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    34
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    35
(** Subtraction **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    36
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    37
Goalw [real_number_of_def] "- (number_of w :: real) = number_of (bin_minus w)";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    38
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    39
    (HOL_ss addsimps [number_of_minus, real_of_int_minus]) 1);
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    40
qed "minus_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    41
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    42
Goalw [real_number_of_def]
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    43
   "(number_of v :: real) - number_of w = number_of (bin_add v (bin_minus w))";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    44
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    45
    (HOL_ss addsimps [diff_number_of_eq, real_of_int_diff]) 1);
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    46
qed "diff_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    47
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    48
Addsimps [minus_real_number_of, diff_real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    49
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    50
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    51
(** Multiplication **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    52
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    53
Goal "(number_of v :: real) * number_of v' = number_of (bin_mult v v')";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    54
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    55
    (HOL_ss addsimps [real_number_of_def, 
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    56
				  real_of_int_mult, number_of_mult]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    57
qed "mult_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    58
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    59
Addsimps [mult_real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    60
7588
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    61
Goal "(#2::real) = #1 + #1";
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    62
by (Simp_tac 1);
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    63
val lemma = result();
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    64
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    65
(*For specialist use: NOT as default simprules*)
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    66
Goal "#2 * z = (z+z::real)";
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    67
by (simp_tac (simpset ()
7588
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    68
	      addsimps [lemma, real_add_mult_distrib,
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    69
			one_eq_numeral_1 RS sym]) 1);
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    70
qed "real_mult_2";
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    71
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    72
Goal "z * #2 = (z+z::real)";
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    73
by (stac real_mult_commute 1 THEN rtac real_mult_2 1);
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    74
qed "real_mult_2_right";
26384af93359 Tidying to exploit the new arith_tac. RealBin no longer imports RealPow or
paulson
parents: 7583
diff changeset
    75
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    76
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    77
(*** Comparisons ***)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    78
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    79
(** Equals (=) **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    80
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    81
Goal "((number_of v :: real) = number_of v') = \
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    82
\     iszero (number_of (bin_add v (bin_minus v')))";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    83
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    84
    (HOL_ss addsimps [real_number_of_def, 
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    85
				  real_of_int_eq_iff, eq_number_of_eq]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    86
qed "eq_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    87
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    88
Addsimps [eq_real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    89
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    90
(** Less-than (<) **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    91
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    92
(*"neg" is used in rewrite rules for binary comparisons*)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    93
Goal "((number_of v :: real) < number_of v') = \
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    94
\     neg (number_of (bin_add v (bin_minus v')))";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    95
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
    96
    (HOL_ss addsimps [real_number_of_def, real_of_int_less_iff, 
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    97
				  less_number_of_eq_neg]) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    98
qed "less_real_number_of";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
    99
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   100
Addsimps [less_real_number_of];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   101
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   102
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   103
(** Less-than-or-equals (<=) **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   104
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   105
Goal "(number_of x <= (number_of y::real)) = \
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   106
\     (~ number_of y < (number_of x::real))";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   107
by (rtac (linorder_not_less RS sym) 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   108
qed "le_real_number_of_eq_not_less"; 
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   109
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   110
Addsimps [le_real_number_of_eq_not_less];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   111
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   112
(*** New versions of existing theorems involving 0, 1r ***)
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   113
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   114
Goal "- #1 = (#-1::real)";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   115
by (Simp_tac 1);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   116
qed "minus_numeral_one";
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   117
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   118
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   119
(*Maps 0 to #0 and 1r to #1 and -1r to #-1*)
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   120
val real_numeral_ss = 
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   121
    HOL_ss addsimps [zero_eq_numeral_0, one_eq_numeral_1, 
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   122
		     minus_numeral_one];
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   123
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   124
fun rename_numerals th = 
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   125
    asm_full_simplify real_numeral_ss (Thm.transfer (the_context ()) th);
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   126
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   127
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   128
(*Now insert some identities previously stated for 0 and 1r*)
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   129
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   130
(** RealDef & Real **)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   131
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   132
Addsimps (map rename_numerals
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   133
	  [real_minus_zero, real_minus_zero_iff,
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   134
	   real_add_zero_left, real_add_zero_right, 
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   135
	   real_diff_0, real_diff_0_right,
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   136
	   real_mult_0_right, real_mult_0, real_mult_1_right, real_mult_1,
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   137
	   real_mult_minus_1_right, real_mult_minus_1, real_rinv_1,
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   138
	   real_minus_zero_less_iff]);
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   139
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   140
AddIffs (map rename_numerals [real_mult_is_0, real_0_is_mult]);
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   141
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   142
bind_thm ("real_0_less_mult_iff", 
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   143
	  rename_numerals real_zero_less_mult_iff);
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   144
bind_thm ("real_0_le_mult_iff", 
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   145
	  rename_numerals real_zero_le_mult_iff);
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   146
bind_thm ("real_mult_less_0_iff", 
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   147
	  rename_numerals real_mult_less_zero_iff);
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   148
bind_thm ("real_mult_le_0_iff", 
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   149
	  rename_numerals real_mult_le_zero_iff);
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   150
7292
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   151
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   152
(*Perhaps add some theorems that aren't in the default simpset, as
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   153
  done in Integ/NatBin.ML*)
dff3470c5c62 real literals using binary arithmetic
paulson
parents:
diff changeset
   154
7583
d1b40e0464b1 Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents: 7292
diff changeset
   155
9013
9dd0274f76af Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents: 8838
diff changeset
   156
Addsimps [zero_eq_numeral_0,one_eq_numeral_1];
7583
d1b40e0464b1 Restructured lin.arith.package and fixed a proof in RComplete.
nipkow
parents: 7292
diff changeset
   157
9013
9dd0274f76af Updated files to remove 0r and 1r from theorems in descendant theories
fleuriot
parents: 8838
diff changeset
   158
9043
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   159
(** Simplification of arithmetic when nested to the right **)
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   160
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   161
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::real)";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   162
by Auto_tac; 
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   163
qed "real_add_number_of_left";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   164
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   165
Goal "number_of v * (number_of w * z) = (number_of(bin_mult v w) * z::real)";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   166
by (simp_tac (simpset() addsimps [real_mult_assoc RS sym]) 1);
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   167
qed "real_mult_number_of_left";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   168
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   169
Goalw [real_diff_def]
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   170
    "number_of v + (number_of w - c) = number_of(bin_add v w) - (c::real)";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   171
by (rtac real_add_number_of_left 1);
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   172
qed "real_add_number_of_diff1";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   173
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   174
Goal "number_of v + (c - number_of w) = \
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   175
\    number_of (bin_add v (bin_minus w)) + (c::real)";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   176
by (stac (diff_real_number_of RS sym) 1);
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   177
by Auto_tac;
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   178
qed "real_add_number_of_diff2";
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   179
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   180
Addsimps [real_add_number_of_left, real_mult_number_of_left,
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   181
	  real_add_number_of_diff1, real_add_number_of_diff2]; 
ca761fe227d8 First round of changes, towards installation of simprocs
paulson
parents: 9013
diff changeset
   182
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   183
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   184
(*"neg" is used in rewrite rules for binary comparisons*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   185
Goal "real_of_nat (number_of v :: nat) = \
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   186
\        (if neg (number_of v) then #0 \
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   187
\         else (number_of v :: real))";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   188
by (simp_tac
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   189
    (HOL_ss addsimps [nat_number_of_def, real_of_nat_real_of_int,
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   190
				  real_of_nat_neg_int, real_number_of,
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   191
				  zero_eq_numeral_0]) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   192
qed "real_of_nat_number_of";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   193
Addsimps [real_of_nat_number_of];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   194
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   195
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   196
(**** Simprocs for numeric literals ****)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   197
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   198
(** Combining of literal coefficients in sums of products **)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   199
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   200
Goal "(x < y) = (x-y < (#0::real))";
9080
67ca888af420 fixed the installation of linear arithmetic for the reals
paulson
parents: 9068
diff changeset
   201
by (simp_tac (simpset() addsimps [real_diff_less_eq]) 1);   
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   202
qed "real_less_iff_diff_less_0";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   203
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   204
Goal "(x = y) = (x-y = (#0::real))";
9080
67ca888af420 fixed the installation of linear arithmetic for the reals
paulson
parents: 9068
diff changeset
   205
by (simp_tac (simpset() addsimps [real_diff_eq_eq]) 1);   
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   206
qed "real_eq_iff_diff_eq_0";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   207
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   208
Goal "(x <= y) = (x-y <= (#0::real))";
9080
67ca888af420 fixed the installation of linear arithmetic for the reals
paulson
parents: 9068
diff changeset
   209
by (simp_tac (simpset() addsimps [real_diff_le_eq]) 1);   
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   210
qed "real_le_iff_diff_le_0";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   211
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   212
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   213
(** For combine_numerals **)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   214
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   215
Goal "i*u + (j*u + k) = (i+j)*u + (k::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   216
by (asm_simp_tac (simpset() addsimps [real_add_mult_distrib]) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   217
qed "left_real_add_mult_distrib";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   218
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   219
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   220
(** For cancel_numerals **)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   221
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   222
val rel_iff_rel_0_rls = map (inst "y" "?u+?v")
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   223
                          [real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   224
			   real_le_iff_diff_le_0] @
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   225
		        map (inst "y" "n")
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   226
                          [real_less_iff_diff_less_0, real_eq_iff_diff_eq_0, 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   227
			   real_le_iff_diff_le_0];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   228
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   229
Goal "!!i::real. (i*u + m = j*u + n) = ((i-j)*u + m = n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   230
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   231
		                     real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   232
qed "real_eq_add_iff1";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   233
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   234
Goal "!!i::real. (i*u + m = j*u + n) = (m = (j-i)*u + n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   235
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   236
                                     real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   237
qed "real_eq_add_iff2";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   238
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   239
Goal "!!i::real. (i*u + m < j*u + n) = ((i-j)*u + m < n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   240
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   241
                                     real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   242
qed "real_less_add_iff1";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   243
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   244
Goal "!!i::real. (i*u + m < j*u + n) = (m < (j-i)*u + n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   245
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   246
                                     real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   247
qed "real_less_add_iff2";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   248
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   249
Goal "!!i::real. (i*u + m <= j*u + n) = ((i-j)*u + m <= n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   250
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   251
                                     real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   252
qed "real_le_add_iff1";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   253
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   254
Goal "!!i::real. (i*u + m <= j*u + n) = (m <= (j-i)*u + n)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   255
by (asm_simp_tac (simpset() addsimps [real_diff_def, real_add_mult_distrib]
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   256
                                     @real_add_ac@rel_iff_rel_0_rls) 1);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   257
qed "real_le_add_iff2";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   258
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   259
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   260
structure Real_Numeral_Simprocs =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   261
struct
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   262
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   263
(*Utilities*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   264
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   265
fun mk_numeral n = HOLogic.number_of_const HOLogic.realT $ 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   266
                   NumeralSyntax.mk_bin n;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   267
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   268
(*Decodes a binary real constant*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   269
fun dest_numeral (Const("Numeral.number_of", _) $ w) = 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   270
     (NumeralSyntax.dest_bin w
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   271
      handle Match => raise TERM("Real_Numeral_Simprocs.dest_numeral:1", [w]))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   272
  | dest_numeral t = raise TERM("Real_Numeral_Simprocs.dest_numeral:2", [t]);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   273
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   274
fun find_first_numeral past (t::terms) =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   275
	((dest_numeral t, rev past @ terms)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   276
	 handle TERM _ => find_first_numeral (t::past) terms)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   277
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   278
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   279
val zero = mk_numeral 0;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   280
val mk_plus = HOLogic.mk_binop "op +";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   281
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   282
val uminus_const = Const ("uminus", HOLogic.realT --> HOLogic.realT);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   283
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   284
(*Thus mk_sum[t] yields t+#0; longer sums don't have a trailing zero*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   285
fun mk_sum []        = zero
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   286
  | mk_sum [t,u]     = mk_plus (t, u)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   287
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   288
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   289
(*this version ALWAYS includes a trailing zero*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   290
fun long_mk_sum []        = zero
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   291
  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   292
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   293
val dest_plus = HOLogic.dest_bin "op +" HOLogic.realT;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   294
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   295
(*decompose additions AND subtractions as a sum*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   296
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   297
        dest_summing (pos, t, dest_summing (pos, u, ts))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   298
  | dest_summing (pos, Const ("op -", _) $ t $ u, ts) =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   299
        dest_summing (pos, t, dest_summing (not pos, u, ts))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   300
  | dest_summing (pos, t, ts) =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   301
	if pos then t::ts else uminus_const$t :: ts;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   302
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   303
fun dest_sum t = dest_summing (true, t, []);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   304
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   305
val mk_diff = HOLogic.mk_binop "op -";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   306
val dest_diff = HOLogic.dest_bin "op -" HOLogic.realT;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   307
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   308
val one = mk_numeral 1;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   309
val mk_times = HOLogic.mk_binop "op *";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   310
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   311
fun mk_prod [] = one
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   312
  | mk_prod [t] = t
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   313
  | mk_prod (t :: ts) = if t = one then mk_prod ts
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   314
                        else mk_times (t, mk_prod ts);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   315
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   316
val dest_times = HOLogic.dest_bin "op *" HOLogic.realT;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   317
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   318
fun dest_prod t =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   319
      let val (t,u) = dest_times t 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   320
      in  dest_prod t @ dest_prod u  end
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   321
      handle TERM _ => [t];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   322
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   323
(*DON'T do the obvious simplifications; that would create special cases*) 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   324
fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   325
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   326
(*Express t as a product of (possibly) a numeral with other sorted terms*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   327
fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   328
  | dest_coeff sign t =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   329
    let val ts = sort Term.term_ord (dest_prod t)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   330
	val (n, ts') = find_first_numeral [] ts
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   331
                          handle TERM _ => (1, ts)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   332
    in (sign*n, mk_prod ts') end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   333
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   334
(*Find first coefficient-term THAT MATCHES u*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   335
fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   336
  | find_first_coeff past u (t::terms) =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   337
	let val (n,u') = dest_coeff 1 t
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   338
	in  if u aconv u' then (n, rev past @ terms)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   339
			  else find_first_coeff (t::past) u terms
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   340
	end
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   341
	handle TERM _ => find_first_coeff (t::past) u terms;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   342
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   343
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   344
(*Simplify #1*n and n*#1 to n*)
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   345
val add_0s = map rename_numerals
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   346
                 [real_add_zero_left, real_add_zero_right];
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   347
val mult_1s = map rename_numerals
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   348
                  [real_mult_1, real_mult_1_right, 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   349
		   real_mult_minus_1, real_mult_minus_1_right];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   350
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   351
(*To perform binary arithmetic*)
9108
9fff97d29837 bind_thm(s);
wenzelm
parents: 9080
diff changeset
   352
val bin_simps =
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   353
    [add_real_number_of, real_add_number_of_left, minus_real_number_of, 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   354
     diff_real_number_of] @ 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   355
    bin_arith_simps @ bin_rel_simps;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   356
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   357
(*To evaluate binary negations of coefficients*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   358
val real_minus_simps = NCons_simps @
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   359
                   [minus_real_number_of, 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   360
		    bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   361
		    bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   362
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   363
(*To let us treat subtraction as addition*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   364
val diff_simps = [real_diff_def, real_minus_add_distrib, real_minus_minus];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   365
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   366
(*Apply the given rewrite (if present) just once*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   367
fun trans_tac None      = all_tac
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   368
  | trans_tac (Some th) = ALLGOALS (rtac (th RS trans));
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   369
9544
f9202e219a29 added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents: 9433
diff changeset
   370
fun prove_conv name tacs sg (hyps: thm list) (t,u) =
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   371
  if t aconv u then None
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   372
  else
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   373
  let val ct = cterm_of sg (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   374
  in Some
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   375
     (prove_goalw_cterm [] ct (K tacs)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   376
      handle ERROR => error 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   377
	  ("The error(s) above occurred while trying to prove " ^
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   378
	   string_of_cterm ct ^ "\nInternal failure of simproc " ^ name))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   379
  end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   380
9544
f9202e219a29 added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents: 9433
diff changeset
   381
(*version without the hyps argument*)
f9202e219a29 added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents: 9433
diff changeset
   382
fun prove_conv_nohyps name tacs sg = prove_conv name tacs sg [];
f9202e219a29 added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents: 9433
diff changeset
   383
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   384
(*Final simplification: cancel + and *  *)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   385
val simplify_meta_eq = 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   386
    Int_Numeral_Simprocs.simplify_meta_eq
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   387
         [real_add_zero_left, real_add_zero_right,
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   388
 	  real_mult_0, real_mult_0_right, real_mult_1, real_mult_1_right];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   389
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   390
fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc;
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   391
fun prep_pat s = Thm.read_cterm (Theory.sign_of (the_context ())) (s, HOLogic.termT);
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   392
val prep_pats = map prep_pat;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   393
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   394
structure CancelNumeralsCommon =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   395
  struct
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   396
  val mk_sum    	= mk_sum
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   397
  val dest_sum		= dest_sum
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   398
  val mk_coeff		= mk_coeff
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   399
  val dest_coeff	= dest_coeff 1
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   400
  val find_first_coeff	= find_first_coeff []
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   401
  val trans_tac         = trans_tac
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   402
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   403
                                                real_minus_simps@real_add_ac))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   404
                 THEN ALLGOALS
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   405
                    (simp_tac (HOL_ss addsimps [real_minus_mult_eq2]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   406
                                         bin_simps@real_add_ac@real_mult_ac))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   407
  val numeral_simp_tac	= ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   408
  val simplify_meta_eq  = simplify_meta_eq
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   409
  end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   410
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   411
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   412
structure EqCancelNumerals = CancelNumeralsFun
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   413
 (open CancelNumeralsCommon
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   414
  val prove_conv = prove_conv "realeq_cancel_numerals"
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   415
  val mk_bal   = HOLogic.mk_eq
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   416
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   417
  val bal_add1 = real_eq_add_iff1 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   418
  val bal_add2 = real_eq_add_iff2 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   419
);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   420
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   421
structure LessCancelNumerals = CancelNumeralsFun
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   422
 (open CancelNumeralsCommon
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   423
  val prove_conv = prove_conv "realless_cancel_numerals"
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   424
  val mk_bal   = HOLogic.mk_binrel "op <"
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   425
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   426
  val bal_add1 = real_less_add_iff1 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   427
  val bal_add2 = real_less_add_iff2 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   428
);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   429
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   430
structure LeCancelNumerals = CancelNumeralsFun
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   431
 (open CancelNumeralsCommon
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   432
  val prove_conv = prove_conv "realle_cancel_numerals"
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   433
  val mk_bal   = HOLogic.mk_binrel "op <="
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   434
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   435
  val bal_add1 = real_le_add_iff1 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   436
  val bal_add2 = real_le_add_iff2 RS trans
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   437
);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   438
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   439
val cancel_numerals = 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   440
  map prep_simproc
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   441
   [("realeq_cancel_numerals",
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   442
     prep_pats ["(l::real) + m = n", "(l::real) = m + n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   443
		"(l::real) - m = n", "(l::real) = m - n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   444
		"(l::real) * m = n", "(l::real) = m * n"], 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   445
     EqCancelNumerals.proc),
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   446
    ("realless_cancel_numerals", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   447
     prep_pats ["(l::real) + m < n", "(l::real) < m + n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   448
		"(l::real) - m < n", "(l::real) < m - n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   449
		"(l::real) * m < n", "(l::real) < m * n"], 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   450
     LessCancelNumerals.proc),
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   451
    ("realle_cancel_numerals", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   452
     prep_pats ["(l::real) + m <= n", "(l::real) <= m + n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   453
		"(l::real) - m <= n", "(l::real) <= m - n", 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   454
		"(l::real) * m <= n", "(l::real) <= m * n"], 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   455
     LeCancelNumerals.proc)];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   456
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   457
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   458
structure CombineNumeralsData =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   459
  struct
9574
da0a964aa601 new structure field "add" for CombineNumerals
paulson
parents: 9544
diff changeset
   460
  val add		= op + : int*int -> int 
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   461
  val mk_sum    	= long_mk_sum    (*to work for e.g. #2*x + #3*x *)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   462
  val dest_sum		= dest_sum
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   463
  val mk_coeff		= mk_coeff
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   464
  val dest_coeff	= dest_coeff 1
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   465
  val left_distrib	= left_real_add_mult_distrib RS trans
9544
f9202e219a29 added a dummy "thm list" argument to prove_conv for the new interface to
paulson
parents: 9433
diff changeset
   466
  val prove_conv	= prove_conv_nohyps "real_combine_numerals"
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   467
  val trans_tac          = trans_tac
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   468
  val norm_tac = ALLGOALS
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   469
                   (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   470
                                              real_minus_simps@real_add_ac))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   471
                 THEN ALLGOALS
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   472
                    (simp_tac (HOL_ss addsimps [real_minus_mult_eq2]@
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   473
                                               bin_simps@real_add_ac@real_mult_ac))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   474
  val numeral_simp_tac	= ALLGOALS 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   475
                    (simp_tac (HOL_ss addsimps add_0s@bin_simps))
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   476
  val simplify_meta_eq  = simplify_meta_eq
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   477
  end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   478
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   479
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   480
  
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   481
val combine_numerals = 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   482
    prep_simproc ("real_combine_numerals",
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   483
		  prep_pats ["(i::real) + j", "(i::real) - j"],
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   484
		  CombineNumerals.proc);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   485
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   486
end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   487
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   488
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   489
Addsimprocs Real_Numeral_Simprocs.cancel_numerals;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   490
Addsimprocs [Real_Numeral_Simprocs.combine_numerals];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   491
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   492
(*The Abel_Cancel simprocs are now obsolete*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   493
Delsimprocs [Real_Cancel.sum_conv, Real_Cancel.rel_conv];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   494
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   495
(*examples:
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   496
print_depth 22;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   497
set timing;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   498
set trace_simp;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   499
fun test s = (Goal s; by (Simp_tac 1)); 
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   500
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   501
test "l + #2 + #2 + #2 + (l + #2) + (oo + #2) = (uu::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   502
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   503
test "#2*u = (u::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   504
test "(i + j + #12 + (k::real)) - #15 = y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   505
test "(i + j + #12 + (k::real)) - #5 = y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   506
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   507
test "y - b < (b::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   508
test "y - (#3*b + c) < (b::real) - #2*c";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   509
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   510
test "(#2*x - (u*v) + y) - v*#3*u = (w::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   511
test "(#2*x*u*v + (u*v)*#4 + y) - v*u*#4 = (w::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   512
test "(#2*x*u*v + (u*v)*#4 + y) - v*u = (w::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   513
test "u*v - (x*u*v + (u*v)*#4 + y) = (w::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   514
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   515
test "(i + j + #12 + (k::real)) = u + #15 + y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   516
test "(i + j*#2 + #12 + (k::real)) = j + #5 + y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   517
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   518
test "#2*y + #3*z + #6*w + #2*y + #3*z + #2*u = #2*y' + #3*z' + #6*w' + #2*y' + #3*z' + u + (vv::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   519
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   520
test "a + -(b+c) + b = (d::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   521
test "a + -(b+c) - b = (d::real)";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   522
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   523
(*negative numerals*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   524
test "(i + j + #-2 + (k::real)) - (u + #5 + y) = zz";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   525
test "(i + j + #-3 + (k::real)) < u + #5 + y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   526
test "(i + j + #3 + (k::real)) < u + #-6 + y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   527
test "(i + j + #-12 + (k::real)) - #15 = y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   528
test "(i + j + #12 + (k::real)) - #-15 = y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   529
test "(i + j + #-12 + (k::real)) - #-15 = y";
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   530
*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   531
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   532
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   533
(** Constant folding for real plus and times **)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   534
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   535
(*We do not need
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   536
    structure Real_Plus_Assoc = Assoc_Fold (Real_Plus_Assoc_Data);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   537
  because combine_numerals does the same thing*)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   538
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   539
structure Real_Times_Assoc_Data : ASSOC_FOLD_DATA =
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   540
struct
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   541
  val ss		= HOL_ss
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   542
  val eq_reflection	= eq_reflection
9433
ac20534ce4d1 avoid referencing thy value;
wenzelm
parents: 9108
diff changeset
   543
  val sg_ref    = Sign.self_ref (Theory.sign_of (the_context ()))
9068
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   544
  val T	     = HOLogic.realT
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   545
  val plus   = Const ("op *", [HOLogic.realT,HOLogic.realT] ---> HOLogic.realT)
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   546
  val add_ac = real_mult_ac
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   547
end;
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   548
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   549
structure Real_Times_Assoc = Assoc_Fold (Real_Times_Assoc_Data);
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   550
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   551
Addsimprocs [Real_Times_Assoc.conv];
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   552
202fdf72cf23 installing the cancel_numerals and combine_numerals simprocs
paulson
parents: 9043
diff changeset
   553