src/HOL/Complex/hcomplex_arith.ML
author paulson
Mon, 02 Feb 2004 12:23:46 +0100
changeset 14371 c78c7da09519
parent 14335 9c0b5e081037
permissions -rw-r--r--
Conversion of HyperNat to Isar format and its declaration as a semiring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14326
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     1
(*  Title:       hcomplex_arith.ML
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     2
    Author:      Jacques D. Fleuriot
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     3
    Copyright:   2001  University of Edinburgh
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     4
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     5
Common factor cancellation
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     6
*)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     7
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     8
local
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
     9
  open HComplex_Numeral_Simprocs
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    10
in
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    11
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    12
val rel_hcomplex_number_of = [eq_hcomplex_number_of];
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    13
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    14
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    15
structure CancelNumeralFactorCommon =
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    16
  struct
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    17
  val mk_coeff		= mk_coeff
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    18
  val dest_coeff	= dest_coeff 1
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    19
  val trans_tac         = Real_Numeral_Simprocs.trans_tac
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    20
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps hcomplex_minus_from_mult_simps @ mult_1s))
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    21
                 THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hcomplex_mult_minus_simps))
14335
9c0b5e081037 conversion of Real/PReal to Isar script;
paulson
parents: 14326
diff changeset
    22
                 THEN ALLGOALS (simp_tac (HOL_ss addsimps mult_ac))
14326
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    23
  val numeral_simp_tac	= 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    24
         ALLGOALS (simp_tac (HOL_ss addsimps rel_hcomplex_number_of@bin_simps))
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    25
  val simplify_meta_eq  = simplify_meta_eq
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    26
  end
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    27
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    28
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    29
structure DivCancelNumeralFactor = CancelNumeralFactorFun
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    30
 (open CancelNumeralFactorCommon
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    31
  val prove_conv = Bin_Simprocs.prove_conv
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    32
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    33
  val dest_bal = HOLogic.dest_bin "HOL.divide" hcomplexT
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    34
  val cancel = mult_divide_cancel_left RS trans
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    35
  val neg_exchanges = false
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    36
)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    37
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    38
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    39
structure EqCancelNumeralFactor = CancelNumeralFactorFun
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    40
 (open CancelNumeralFactorCommon
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    41
  val prove_conv = Bin_Simprocs.prove_conv
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    42
  val mk_bal   = HOLogic.mk_eq
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    43
  val dest_bal = HOLogic.dest_bin "op =" hcomplexT
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    44
  val cancel = field_mult_cancel_left RS trans
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    45
  val neg_exchanges = false
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    46
)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    47
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    48
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    49
val hcomplex_cancel_numeral_factors_relations = 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    50
  map prep_simproc
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    51
   [("hcomplexeq_cancel_numeral_factor",
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    52
    ["(l::hcomplex) * m = n", "(l::hcomplex) = m * n"], 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    53
     EqCancelNumeralFactor.proc)];
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    54
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    55
val hcomplex_cancel_numeral_factors_divide = prep_simproc
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    56
	("hcomplexdiv_cancel_numeral_factor", 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    57
	 ["((l::hcomplex) * m) / n", "(l::hcomplex) / (m * n)", 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    58
                     "((number_of v)::hcomplex) / (number_of w)"], 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    59
	 DivCancelNumeralFactor.proc);
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    60
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    61
val hcomplex_cancel_numeral_factors = 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    62
    hcomplex_cancel_numeral_factors_relations @ 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    63
    [hcomplex_cancel_numeral_factors_divide];
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    64
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    65
end;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    66
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    67
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    68
Addsimprocs hcomplex_cancel_numeral_factors;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    69
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    70
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    71
(*examples:
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    72
print_depth 22;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    73
set timing;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    74
set trace_simp;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    75
fun test s = (Goal s; by (Simp_tac 1)); 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    76
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    77
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    78
test "#9*x = #12 * (y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    79
test "(#9*x) / (#12 * (y::hcomplex)) = z";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    80
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    81
test "#-99*x = #132 * (y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    82
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    83
test "#999*x = #-396 * (y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    84
test "(#999*x) / (#-396 * (y::hcomplex)) = z";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    85
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    86
test "#-99*x = #-81 * (y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    87
test "(#-99*x) / (#-81 * (y::hcomplex)) = z";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    88
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    89
test "#-2 * x = #-1 * (y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    90
test "#-2 * x = -(y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    91
test "(#-2 * x) / (#-1 * (y::hcomplex)) = z";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    92
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    93
*)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    94
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    95
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    96
(** Declarations for ExtractCommonTerm **)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    97
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    98
local
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
    99
  open HComplex_Numeral_Simprocs
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   100
in
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   101
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   102
structure CancelFactorCommon =
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   103
  struct
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   104
  val mk_sum    	= long_mk_prod
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   105
  val dest_sum		= dest_prod
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   106
  val mk_coeff		= mk_coeff
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   107
  val dest_coeff	= dest_coeff
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   108
  val find_first	= find_first []
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   109
  val trans_tac         = Real_Numeral_Simprocs.trans_tac
14335
9c0b5e081037 conversion of Real/PReal to Isar script;
paulson
parents: 14326
diff changeset
   110
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@mult_ac))
14326
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   111
  end;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   112
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   113
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   114
structure EqCancelFactor = ExtractCommonTermFun
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   115
 (open CancelFactorCommon
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   116
  val prove_conv = Bin_Simprocs.prove_conv
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   117
  val mk_bal   = HOLogic.mk_eq
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   118
  val dest_bal = HOLogic.dest_bin "op =" hcomplexT
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   119
  val simplify_meta_eq  = cancel_simplify_meta_eq field_mult_cancel_left
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   120
);
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   121
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   122
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   123
structure DivideCancelFactor = ExtractCommonTermFun
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   124
 (open CancelFactorCommon
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   125
  val prove_conv = Bin_Simprocs.prove_conv
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   126
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   127
  val dest_bal = HOLogic.dest_bin "HOL.divide" hcomplexT
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   128
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_divide_cancel_eq_if
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   129
);
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   130
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   131
val hcomplex_cancel_factor = 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   132
  map prep_simproc
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   133
   [("hcomplex_eq_cancel_factor", ["(l::hcomplex) * m = n", "(l::hcomplex) = m * n"], 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   134
     EqCancelFactor.proc),
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   135
    ("hcomplex_divide_cancel_factor", ["((l::hcomplex) * m) / n", "(l::hcomplex) / (m * n)"], 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   136
     DivideCancelFactor.proc)];
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   137
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   138
end;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   139
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   140
Addsimprocs hcomplex_cancel_factor;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   141
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   142
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   143
(*examples:
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   144
print_depth 22;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   145
set timing;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   146
set trace_simp;
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   147
fun test s = (Goal s; by (Asm_simp_tac 1)); 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   148
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   149
test "x*k = k*(y::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   150
test "k = k*(y::hcomplex)"; 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   151
test "a*(b*c) = (b::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   152
test "a*(b*c) = d*(b::hcomplex)*(x*a)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   153
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   154
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   155
test "(x*k) / (k*(y::hcomplex)) = (uu::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   156
test "(k) / (k*(y::hcomplex)) = (uu::hcomplex)"; 
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   157
test "(a*(b*c)) / ((b::hcomplex)) = (uu::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   158
test "(a*(b*c)) / (d*(b::hcomplex)*(x*a)) = (uu::hcomplex)";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   159
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   160
(*FIXME: what do we do about this?*)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   161
test "a*(b*c)/(y*z) = d*(b::hcomplex)*(x*a)/z";
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   162
*)
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   163
c817dd885a32 reorganised complex arithmetic
paulson
parents:
diff changeset
   164