src/HOL/Integ/IntDef.thy
author paulson
Fri, 28 Nov 2003 12:09:37 +0100
changeset 14269 502a7c95de73
parent 14259 79f7d3451b1e
child 14271 8ed6989228bb
permissions -rw-r--r--
conversion of some Real theories to Isar scripts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
     1
(*  Title:      IntDef.thy
691c70898518 new files in Integ
paulson
parents:
diff changeset
     2
    ID:         $Id$
691c70898518 new files in Integ
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
691c70898518 new files in Integ
paulson
parents:
diff changeset
     4
    Copyright   1996  University of Cambridge
691c70898518 new files in Integ
paulson
parents:
diff changeset
     5
691c70898518 new files in Integ
paulson
parents:
diff changeset
     6
The integers as equivalence classes over nat*nat.
691c70898518 new files in Integ
paulson
parents:
diff changeset
     7
*)
691c70898518 new files in Integ
paulson
parents:
diff changeset
     8
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
     9
theory IntDef = Equiv + NatArith:
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    10
constdefs
691c70898518 new files in Integ
paulson
parents:
diff changeset
    11
  intrel      :: "((nat * nat) * (nat * nat)) set"
9392
c8e6529cc082 changed / to // for quotienting
paulson
parents: 8937
diff changeset
    12
  "intrel == {p. EX x1 y1 x2 y2. p=((x1::nat,y1),(x2,y2)) & x1+y2 = x2+y1}"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    13
691c70898518 new files in Integ
paulson
parents:
diff changeset
    14
typedef (Integ)
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    15
  int = "UNIV//intrel"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    16
    by (auto simp add: quotient_def) 
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    17
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    18
instance int :: ord ..
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    19
instance int :: zero ..
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    20
instance int :: one ..
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    21
instance int :: plus ..
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    22
instance int :: times ..
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    23
instance int :: minus ..
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    24
691c70898518 new files in Integ
paulson
parents:
diff changeset
    25
defs
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    26
  zminus_def:
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10797
diff changeset
    27
    "- Z == Abs_Integ(UN (x,y):Rep_Integ(Z). intrel``{(y,x)})"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    28
691c70898518 new files in Integ
paulson
parents:
diff changeset
    29
constdefs
691c70898518 new files in Integ
paulson
parents:
diff changeset
    30
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    31
  int :: "nat => int"
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10797
diff changeset
    32
  "int m == Abs_Integ(intrel `` {(m,0)})"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    33
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    34
  neg   :: "int => bool"
5540
0f16c3b66ab4 much renaming and reorganization
paulson
parents: 5508
diff changeset
    35
  "neg(Z) == EX x y. x<y & (x,y::nat):Rep_Integ(Z)"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    36
691c70898518 new files in Integ
paulson
parents:
diff changeset
    37
  (*For simplifying equalities*)
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    38
  iszero :: "int => bool"
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11713
diff changeset
    39
  "iszero z == z = (0::int)"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    40
  
14269
502a7c95de73 conversion of some Real theories to Isar scripts
paulson
parents: 14259
diff changeset
    41
defs (overloaded)
9392
c8e6529cc082 changed / to // for quotienting
paulson
parents: 8937
diff changeset
    42
  
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    43
  Zero_int_def:  "0 == int 0"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    44
  One_int_def:  "1 == int 1"
8937
7328d7c8d201 defining 0::int to be (int 0)
paulson
parents: 7375
diff changeset
    45
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    46
  zadd_def:
5594
e4439230af67 much tidying
paulson
parents: 5582
diff changeset
    47
   "z + w == 
7375
2cb340e66d15 tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents: 7127
diff changeset
    48
       Abs_Integ(UN (x1,y1):Rep_Integ(z). UN (x2,y2):Rep_Integ(w).   
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10797
diff changeset
    49
		 intrel``{(x1+x2, y1+y2)})"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    50
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    51
  zdiff_def:  "z - (w::int) == z + (-w)"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    52
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    53
  zless_def:  "z<w == neg(z - w)"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    54
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    55
  zle_def:    "z <= (w::int) == ~(w < z)"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    56
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    57
  zmult_def:
5594
e4439230af67 much tidying
paulson
parents: 5582
diff changeset
    58
   "z * w == 
7375
2cb340e66d15 tidied, allowing pattern-matching in defs of zadd and zmult
paulson
parents: 7127
diff changeset
    59
       Abs_Integ(UN (x1,y1):Rep_Integ(z). UN (x2,y2):Rep_Integ(w).   
10834
a7897aebbffc *** empty log message ***
nipkow
parents: 10797
diff changeset
    60
		 intrel``{(x1*x2 + y1*y2, x1*y2 + y1*x2)})"
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
    61
14259
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    62
lemma intrel_iff [simp]: "(((x1,y1),(x2,y2)): intrel) = (x1+y2 = x2+y1)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    63
by (unfold intrel_def, blast)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    64
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    65
lemma equiv_intrel: "equiv UNIV intrel"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    66
by (unfold intrel_def equiv_def refl_def sym_def trans_def, auto)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    67
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    68
lemmas equiv_intrel_iff =
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    69
       eq_equiv_class_iff [OF equiv_intrel UNIV_I UNIV_I, simp]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    70
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    71
lemma intrel_in_integ [simp]: "intrel``{(x,y)}:Integ"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    72
by (unfold Integ_def intrel_def quotient_def, fast)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    73
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    74
lemma inj_on_Abs_Integ: "inj_on Abs_Integ Integ"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    75
apply (rule inj_on_inverseI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    76
apply (erule Abs_Integ_inverse)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    77
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    78
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    79
declare inj_on_Abs_Integ [THEN inj_on_iff, simp] 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    80
        Abs_Integ_inverse [simp]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    81
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    82
lemma inj_Rep_Integ: "inj(Rep_Integ)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    83
apply (rule inj_on_inverseI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    84
apply (rule Rep_Integ_inverse)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    85
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    86
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    87
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    88
(** int: the injection from "nat" to "int" **)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    89
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    90
lemma inj_int: "inj int"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    91
apply (rule inj_onI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    92
apply (unfold int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    93
apply (drule inj_on_Abs_Integ [THEN inj_onD])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    94
apply (rule intrel_in_integ)+
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    95
apply (drule eq_equiv_class)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    96
apply (rule equiv_intrel, fast)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    97
apply (simp add: intrel_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    98
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
    99
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   100
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   101
subsection{*zminus: unary negation on Integ*}
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   102
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   103
lemma zminus_congruent: "congruent intrel (%(x,y). intrel``{(y,x)})"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   104
apply (unfold congruent_def intrel_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   105
apply (auto simp add: add_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   106
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   107
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   108
lemma zminus: "- Abs_Integ(intrel``{(x,y)}) = Abs_Integ(intrel `` {(y,x)})"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   109
by (simp add: zminus_def equiv_intrel [THEN UN_equiv_class] zminus_congruent)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   110
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   111
(*Every integer can be written in the form Abs_Integ(...) *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   112
lemma eq_Abs_Integ: 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   113
     "(!!x y. z = Abs_Integ(intrel``{(x,y)}) ==> P) ==> P"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   114
apply (rule_tac x1=z in Rep_Integ [unfolded Integ_def, THEN quotientE]) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   115
apply (drule_tac f = Abs_Integ in arg_cong)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   116
apply (rule_tac p = x in PairE)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   117
apply (simp add: Rep_Integ_inverse)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   118
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   119
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   120
lemma zminus_zminus [simp]: "- (- z) = (z::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   121
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   122
apply (simp (no_asm_simp) add: zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   123
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   124
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   125
lemma inj_zminus: "inj(%z::int. -z)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   126
apply (rule inj_onI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   127
apply (drule_tac f = uminus in arg_cong, simp)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   128
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   129
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   130
lemma zminus_0 [simp]: "- 0 = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   131
by (simp add: int_def Zero_int_def zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   132
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   133
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   134
subsection{*neg: the test for negative integers*}
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   135
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   136
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   137
lemma not_neg_int [simp]: "~ neg(int n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   138
by (simp add: neg_def int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   139
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   140
lemma neg_zminus_int [simp]: "neg(- (int (Suc n)))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   141
by (simp add: neg_def int_def zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   142
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   143
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   144
subsection{*zadd: addition on Integ*}
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   145
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   146
lemma zadd: 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   147
  "Abs_Integ(intrel``{(x1,y1)}) + Abs_Integ(intrel``{(x2,y2)}) =  
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   148
   Abs_Integ(intrel``{(x1+x2, y1+y2)})"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   149
apply (simp add: zadd_def UN_UN_split_split_eq)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   150
apply (subst equiv_intrel [THEN UN_equiv_class2])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   151
apply (auto simp add: congruent2_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   152
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   153
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   154
lemma zminus_zadd_distrib [simp]: "- (z + w) = (- z) + (- w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   155
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   156
apply (rule_tac z = w in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   157
apply (simp (no_asm_simp) add: zminus zadd)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   158
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   159
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   160
lemma zadd_commute: "(z::int) + w = w + z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   161
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   162
apply (rule_tac z = w in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   163
apply (simp (no_asm_simp) add: add_ac zadd)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   164
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   165
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   166
lemma zadd_assoc: "((z1::int) + z2) + z3 = z1 + (z2 + z3)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   167
apply (rule_tac z = z1 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   168
apply (rule_tac z = z2 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   169
apply (rule_tac z = z3 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   170
apply (simp (no_asm_simp) add: zadd add_assoc)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   171
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   172
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   173
(*For AC rewriting*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   174
lemma zadd_left_commute: "x + (y + z) = y + ((x + z)::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   175
  apply (rule mk_left_commute [of "op +"])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   176
  apply (rule zadd_assoc)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   177
  apply (rule zadd_commute)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   178
  done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   179
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   180
(*Integer addition is an AC operator*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   181
lemmas zadd_ac = zadd_assoc zadd_commute zadd_left_commute
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   182
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   183
lemma zadd_int: "(int m) + (int n) = int (m + n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   184
by (simp add: int_def zadd)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   185
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   186
lemma zadd_int_left: "(int m) + (int n + z) = int (m + n) + z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   187
by (simp add: zadd_int zadd_assoc [symmetric])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   188
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   189
lemma int_Suc: "int (Suc m) = 1 + (int m)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   190
by (simp add: One_int_def zadd_int)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   191
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   192
(*also for the instance declaration int :: plus_ac0*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   193
lemma zadd_0 [simp]: "(0::int) + z = z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   194
apply (unfold Zero_int_def int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   195
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   196
apply (simp (no_asm_simp) add: zadd)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   197
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   198
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   199
lemma zadd_0_right [simp]: "z + (0::int) = z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   200
by (rule trans [OF zadd_commute zadd_0])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   201
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   202
lemma zadd_zminus_inverse [simp]: "z + (- z) = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   203
apply (unfold int_def Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   204
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   205
apply (simp (no_asm_simp) add: zminus zadd add_commute)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   206
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   207
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   208
lemma zadd_zminus_inverse2 [simp]: "(- z) + z = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   209
apply (rule zadd_commute [THEN trans])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   210
apply (rule zadd_zminus_inverse)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   211
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   212
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   213
lemma zadd_zminus_cancel [simp]: "z + (- z + w) = (w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   214
by (simp add: zadd_assoc [symmetric] zadd_0)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   215
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   216
lemma zminus_zadd_cancel [simp]: "(-z) + (z + w) = (w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   217
by (simp add: zadd_assoc [symmetric] zadd_0)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   218
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   219
lemma zdiff0 [simp]: "(0::int) - x = -x"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   220
by (simp add: zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   221
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   222
lemma zdiff0_right [simp]: "x - (0::int) = x"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   223
by (simp add: zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   224
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   225
lemma zdiff_self [simp]: "x - x = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   226
by (simp add: zdiff_def Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   227
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   228
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   229
(** Lemmas **)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   230
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   231
lemma zadd_assoc_cong: "(z::int) + v = z' + v' ==> z + (v + w) = z' + (v' + w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   232
by (simp add: zadd_assoc [symmetric])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   233
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   234
lemma zadd_assoc_swap: "(z::int) + (v + w) = v + (z + w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   235
by (rule zadd_commute [THEN zadd_assoc_cong])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   236
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   237
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   238
subsection{*zmult: multiplication on Integ*}
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   239
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   240
(*Congruence property for multiplication*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   241
lemma zmult_congruent2: "congruent2 intrel  
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   242
        (%p1 p2. (%(x1,y1). (%(x2,y2).    
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   243
                    intrel``{(x1*x2 + y1*y2, x1*y2 + y1*x2)}) p2) p1)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   244
apply (rule equiv_intrel [THEN congruent2_commuteI])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   245
apply (rule_tac [2] p=w in PairE)  
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   246
apply (force simp add: add_ac mult_ac, clarify) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   247
apply (simp (no_asm_simp) del: equiv_intrel_iff add: add_ac mult_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   248
apply (rename_tac x1 x2 y1 y2 z1 z2)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   249
apply (rule equiv_class_eq [OF equiv_intrel intrel_iff [THEN iffD2]])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   250
apply (simp add: intrel_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   251
apply (subgoal_tac "x1*z1 + y2*z1 = y1*z1 + x2*z1 & x1*z2 + y2*z2 = y1*z2 + x2*z2", arith)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   252
apply (simp add: add_mult_distrib [symmetric])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   253
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   254
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   255
lemma zmult: 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   256
   "Abs_Integ((intrel``{(x1,y1)})) * Abs_Integ((intrel``{(x2,y2)})) =    
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   257
    Abs_Integ(intrel `` {(x1*x2 + y1*y2, x1*y2 + y1*x2)})"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   258
apply (unfold zmult_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   259
apply (simp (no_asm_simp) add: UN_UN_split_split_eq zmult_congruent2 equiv_intrel [THEN UN_equiv_class2])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   260
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   261
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   262
lemma zmult_zminus: "(- z) * w = - (z * (w::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   263
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   264
apply (rule_tac z = w in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   265
apply (simp (no_asm_simp) add: zminus zmult add_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   266
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   267
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   268
lemma zmult_commute: "(z::int) * w = w * z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   269
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   270
apply (rule_tac z = w in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   271
apply (simp (no_asm_simp) add: zmult add_ac mult_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   272
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   273
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   274
lemma zmult_assoc: "((z1::int) * z2) * z3 = z1 * (z2 * z3)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   275
apply (rule_tac z = z1 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   276
apply (rule_tac z = z2 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   277
apply (rule_tac z = z3 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   278
apply (simp (no_asm_simp) add: add_mult_distrib2 zmult add_ac mult_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   279
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   280
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   281
(*For AC rewriting*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   282
lemma zmult_left_commute: "x * (y * z) = y * ((x * z)::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   283
  apply (rule mk_left_commute [of "op *"])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   284
  apply (rule zmult_assoc)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   285
  apply (rule zmult_commute)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   286
  done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   287
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   288
(*Integer multiplication is an AC operator*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   289
lemmas zmult_ac = zmult_assoc zmult_commute zmult_left_commute
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   290
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   291
lemma zadd_zmult_distrib: "((z1::int) + z2) * w = (z1 * w) + (z2 * w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   292
apply (rule_tac z = z1 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   293
apply (rule_tac z = z2 in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   294
apply (rule_tac z = w in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   295
apply (simp add: add_mult_distrib2 zadd zmult add_ac mult_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   296
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   297
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   298
lemma zmult_zminus_right: "w * (- z) = - (w * (z::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   299
by (simp add: zmult_commute [of w] zmult_zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   300
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   301
lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   302
by (simp add: zmult_commute [of w] zadd_zmult_distrib)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   303
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   304
lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   305
apply (unfold zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   306
apply (subst zadd_zmult_distrib)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   307
apply (simp add: zmult_zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   308
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   309
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   310
lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   311
by (simp add: zmult_commute [of w] zdiff_zmult_distrib)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   312
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   313
lemmas int_distrib =
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   314
  zadd_zmult_distrib zadd_zmult_distrib2 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   315
  zdiff_zmult_distrib zdiff_zmult_distrib2
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   316
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   317
lemma zmult_int: "(int m) * (int n) = int (m * n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   318
by (simp add: int_def zmult)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   319
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   320
lemma zmult_0 [simp]: "0 * z = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   321
apply (unfold Zero_int_def int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   322
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   323
apply (simp (no_asm_simp) add: zmult)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   324
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   325
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   326
lemma zmult_1 [simp]: "(1::int) * z = z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   327
apply (unfold One_int_def int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   328
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   329
apply (simp (no_asm_simp) add: zmult)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   330
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   331
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   332
lemma zmult_0_right [simp]: "z * 0 = (0::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   333
by (rule trans [OF zmult_commute zmult_0])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   334
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   335
lemma zmult_1_right [simp]: "z * (1::int) = z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   336
by (rule trans [OF zmult_commute zmult_1])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   337
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   338
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   339
(* Theorems about less and less_equal *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   340
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   341
(*This lemma allows direct proofs of other <-properties*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   342
lemma zless_iff_Suc_zadd: 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   343
    "(w < z) = (EX n. z = w + int(Suc n))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   344
apply (unfold zless_def neg_def zdiff_def int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   345
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   346
apply (rule_tac z = w in eq_Abs_Integ, clarify)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   347
apply (simp add: zadd zminus)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   348
apply (safe dest!: less_imp_Suc_add)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   349
apply (rule_tac x = k in exI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   350
apply (simp_all add: add_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   351
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   352
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   353
lemma zless_zadd_Suc: "z < z + int (Suc n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   354
by (auto simp add: zless_iff_Suc_zadd zadd_assoc zadd_int)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   355
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   356
lemma zless_trans: "[| z1<z2; z2<z3 |] ==> z1 < (z3::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   357
by (auto simp add: zless_iff_Suc_zadd zadd_assoc zadd_int)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   358
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   359
lemma zless_not_sym: "!!w::int. z<w ==> ~w<z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   360
apply (safe dest!: zless_iff_Suc_zadd [THEN iffD1])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   361
apply (rule_tac z = z in eq_Abs_Integ, safe)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   362
apply (simp add: int_def zadd)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   363
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   364
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   365
(* [| n<m;  ~P ==> m<n |] ==> P *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   366
lemmas zless_asym = zless_not_sym [THEN swap, standard]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   367
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   368
lemma zless_not_refl: "!!z::int. ~ z<z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   369
apply (rule zless_asym [THEN notI])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   370
apply (assumption+)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   371
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   372
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   373
(* z<z ==> R *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   374
lemmas zless_irrefl = zless_not_refl [THEN notE, standard, elim!]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   375
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   376
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   377
(*"Less than" is a linear ordering*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   378
lemma zless_linear: 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   379
    "z<w | z=w | w<(z::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   380
apply (unfold zless_def neg_def zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   381
apply (rule_tac z = z in eq_Abs_Integ)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   382
apply (rule_tac z = w in eq_Abs_Integ, safe)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   383
apply (simp add: zadd zminus Image_iff Bex_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   384
apply (rule_tac m1 = "x+ya" and n1 = "xa+y" in less_linear [THEN disjE])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   385
apply (force simp add: add_ac)+
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   386
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   387
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   388
lemma int_neq_iff: "!!w::int. (w ~= z) = (w<z | z<w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   389
by (cut_tac zless_linear, blast)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   390
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   391
(*** eliminates ~= in premises ***)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   392
lemmas int_neqE = int_neq_iff [THEN iffD1, THEN disjE, standard]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   393
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   394
lemma int_int_eq [iff]: "(int m = int n) = (m = n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   395
by (fast elim!: inj_int [THEN injD])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   396
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   397
lemma int_eq_0_conv [simp]: "(int n = 0) = (n = 0)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   398
by (simp add: Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   399
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   400
lemma zless_int [simp]: "(int m < int n) = (m<n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   401
by (simp add: less_iff_Suc_add zless_iff_Suc_zadd zadd_int)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   402
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   403
lemma int_less_0_conv [simp]: "~ (int k < 0)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   404
by (simp add: Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   405
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   406
lemma zero_less_int_conv [simp]: "(0 < int n) = (0 < n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   407
by (simp add: Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   408
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   409
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   410
(*** Properties of <= ***)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   411
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   412
lemma zle_int [simp]: "(int m <= int n) = (m<=n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   413
by (simp add: zle_def le_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   414
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   415
lemma zero_zle_int [simp]: "(0 <= int n)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   416
by (simp add: Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   417
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   418
lemma int_le_0_conv [simp]: "(int n <= 0) = (n = 0)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   419
by (simp add: Zero_int_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   420
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   421
lemma zle_imp_zless_or_eq: "z <= w ==> z < w | z=(w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   422
apply (unfold zle_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   423
apply (cut_tac zless_linear)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   424
apply (blast elim: zless_asym)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   425
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   426
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   427
lemma zless_or_eq_imp_zle: "z<w | z=w ==> z <= (w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   428
apply (unfold zle_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   429
apply (cut_tac zless_linear)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   430
apply (blast elim: zless_asym)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   431
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   432
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   433
lemma int_le_less: "(x <= (y::int)) = (x < y | x=y)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   434
apply (rule iffI) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   435
apply (erule zle_imp_zless_or_eq) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   436
apply (erule zless_or_eq_imp_zle) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   437
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   438
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   439
lemma zle_refl: "w <= (w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   440
by (simp add: int_le_less)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   441
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   442
(* Axiom 'linorder_linear' of class 'linorder': *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   443
lemma zle_linear: "(z::int) <= w | w <= z"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   444
apply (simp add: int_le_less)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   445
apply (cut_tac zless_linear, blast)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   446
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   447
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   448
(* Axiom 'order_trans of class 'order': *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   449
lemma zle_trans: "[| i <= j; j <= k |] ==> i <= (k::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   450
apply (drule zle_imp_zless_or_eq) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   451
apply (drule zle_imp_zless_or_eq) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   452
apply (rule zless_or_eq_imp_zle) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   453
apply (blast intro: zless_trans) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   454
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   455
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   456
lemma zle_anti_sym: "[| z <= w; w <= z |] ==> z = (w::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   457
apply (drule zle_imp_zless_or_eq) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   458
apply (drule zle_imp_zless_or_eq) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   459
apply (blast elim: zless_asym) 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   460
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   461
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   462
(* Axiom 'order_less_le' of class 'order': *)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   463
lemma int_less_le: "((w::int) < z) = (w <= z & w ~= z)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   464
apply (simp add: zle_def int_neq_iff)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   465
apply (blast elim!: zless_asym)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   466
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   467
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   468
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   469
(*** Subtraction laws ***)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   470
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   471
lemma zadd_zdiff_eq: "x + (y - z) = (x + y) - (z::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   472
by (simp add: zdiff_def zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   473
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   474
lemma zdiff_zadd_eq: "(x - y) + z = (x + z) - (y::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   475
by (simp add: zdiff_def zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   476
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   477
lemma zdiff_zdiff_eq: "(x - y) - z = x - (y + (z::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   478
by (simp add: zdiff_def zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   479
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   480
lemma zdiff_zdiff_eq2: "x - (y - z) = (x + z) - (y::int)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   481
by (simp add: zdiff_def zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   482
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   483
lemma zdiff_zless_eq: "(x-y < z) = (x < z + (y::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   484
apply (unfold zless_def zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   485
apply (simp add: zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   486
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   487
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   488
lemma zless_zdiff_eq: "(x < z-y) = (x + (y::int) < z)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   489
apply (unfold zless_def zdiff_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   490
apply (simp add: zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   491
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   492
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   493
lemma zdiff_zle_eq: "(x-y <= z) = (x <= z + (y::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   494
apply (unfold zle_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   495
apply (simp add: zless_zdiff_eq)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   496
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   497
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   498
lemma zle_zdiff_eq: "(x <= z-y) = (x + (y::int) <= z)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   499
apply (unfold zle_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   500
apply (simp add: zdiff_zless_eq)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   501
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   502
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   503
lemma zdiff_eq_eq: "(x-y = z) = (x = z + (y::int))"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   504
by (auto simp add: zdiff_def zadd_assoc Zero_int_def [symmetric])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   505
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   506
lemma eq_zdiff_eq: "(x = z-y) = (x + (y::int) = z)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   507
by (auto simp add: zdiff_def zadd_assoc Zero_int_def [symmetric])
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   508
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   509
(*This list of rewrites simplifies (in)equalities by bringing subtractions
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   510
  to the top and then moving negative terms to the other side.  
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   511
  Use with zadd_ac*)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   512
lemmas zcompare_rls =
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   513
     zdiff_def [symmetric]
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   514
     zadd_zdiff_eq zdiff_zadd_eq zdiff_zdiff_eq zdiff_zdiff_eq2 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   515
     zdiff_zless_eq zless_zdiff_eq zdiff_zle_eq zle_zdiff_eq 
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   516
     zdiff_eq_eq eq_zdiff_eq
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   517
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   518
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   519
(** Cancellation laws **)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   520
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   521
lemma zadd_left_cancel [simp]: "!!w::int. (z + w' = z + w) = (w' = w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   522
apply safe
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   523
apply (drule_tac f = "%x. x + (-z) " in arg_cong)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   524
apply (simp add: Zero_int_def [symmetric] zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   525
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   526
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   527
lemma zadd_right_cancel [simp]: "!!z::int. (w' + z = w + z) = (w' = w)"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   528
by (simp add: zadd_ac)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   529
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   530
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   531
(** For the cancellation simproc.
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   532
    The idea is to cancel like terms on opposite sides by subtraction **)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   533
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   534
lemma zless_eqI: "(x::int) - y = x' - y' ==> (x<y) = (x'<y')"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   535
by (simp add: zless_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   536
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   537
lemma zle_eqI: "(x::int) - y = x' - y' ==> (y<=x) = (y'<=x')"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   538
apply (drule zless_eqI)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   539
apply (simp (no_asm_simp) add: zle_def)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   540
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   541
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   542
lemma zeq_eqI: "(x::int) - y = x' - y' ==> (x=y) = (x'=y')"
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   543
apply safe
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   544
apply (simp_all add: eq_zdiff_eq zdiff_eq_eq)
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   545
done
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   546
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   547
ML
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   548
{*
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   549
val int_def = thm "int_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   550
val neg_def = thm "neg_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   551
val iszero_def = thm "iszero_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   552
val Zero_int_def = thm "Zero_int_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   553
val One_int_def = thm "One_int_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   554
val zadd_def = thm "zadd_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   555
val zdiff_def = thm "zdiff_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   556
val zless_def = thm "zless_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   557
val zle_def = thm "zle_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   558
val zmult_def = thm "zmult_def";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   559
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   560
val intrel_iff = thm "intrel_iff";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   561
val equiv_intrel = thm "equiv_intrel";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   562
val equiv_intrel_iff = thm "equiv_intrel_iff";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   563
val intrel_in_integ = thm "intrel_in_integ";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   564
val inj_on_Abs_Integ = thm "inj_on_Abs_Integ";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   565
val inj_Rep_Integ = thm "inj_Rep_Integ";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   566
val inj_int = thm "inj_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   567
val zminus_congruent = thm "zminus_congruent";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   568
val zminus = thm "zminus";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   569
val eq_Abs_Integ = thm "eq_Abs_Integ";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   570
val zminus_zminus = thm "zminus_zminus";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   571
val inj_zminus = thm "inj_zminus";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   572
val zminus_0 = thm "zminus_0";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   573
val not_neg_int = thm "not_neg_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   574
val neg_zminus_int = thm "neg_zminus_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   575
val zadd = thm "zadd";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   576
val zminus_zadd_distrib = thm "zminus_zadd_distrib";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   577
val zadd_commute = thm "zadd_commute";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   578
val zadd_assoc = thm "zadd_assoc";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   579
val zadd_left_commute = thm "zadd_left_commute";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   580
val zadd_ac = thms "zadd_ac";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   581
val zadd_int = thm "zadd_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   582
val zadd_int_left = thm "zadd_int_left";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   583
val int_Suc = thm "int_Suc";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   584
val zadd_0 = thm "zadd_0";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   585
val zadd_0_right = thm "zadd_0_right";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   586
val zadd_zminus_inverse = thm "zadd_zminus_inverse";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   587
val zadd_zminus_inverse2 = thm "zadd_zminus_inverse2";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   588
val zadd_zminus_cancel = thm "zadd_zminus_cancel";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   589
val zminus_zadd_cancel = thm "zminus_zadd_cancel";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   590
val zdiff0 = thm "zdiff0";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   591
val zdiff0_right = thm "zdiff0_right";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   592
val zdiff_self = thm "zdiff_self";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   593
val zadd_assoc_cong = thm "zadd_assoc_cong";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   594
val zadd_assoc_swap = thm "zadd_assoc_swap";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   595
val zmult_congruent2 = thm "zmult_congruent2";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   596
val zmult = thm "zmult";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   597
val zmult_zminus = thm "zmult_zminus";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   598
val zmult_commute = thm "zmult_commute";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   599
val zmult_assoc = thm "zmult_assoc";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   600
val zmult_left_commute = thm "zmult_left_commute";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   601
val zmult_ac = thms "zmult_ac";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   602
val zadd_zmult_distrib = thm "zadd_zmult_distrib";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   603
val zmult_zminus_right = thm "zmult_zminus_right";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   604
val zadd_zmult_distrib2 = thm "zadd_zmult_distrib2";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   605
val zdiff_zmult_distrib = thm "zdiff_zmult_distrib";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   606
val zdiff_zmult_distrib2 = thm "zdiff_zmult_distrib2";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   607
val int_distrib = thms "int_distrib";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   608
val zmult_int = thm "zmult_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   609
val zmult_0 = thm "zmult_0";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   610
val zmult_1 = thm "zmult_1";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   611
val zmult_0_right = thm "zmult_0_right";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   612
val zmult_1_right = thm "zmult_1_right";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   613
val zless_iff_Suc_zadd = thm "zless_iff_Suc_zadd";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   614
val zless_zadd_Suc = thm "zless_zadd_Suc";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   615
val zless_trans = thm "zless_trans";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   616
val zless_not_sym = thm "zless_not_sym";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   617
val zless_asym = thm "zless_asym";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   618
val zless_not_refl = thm "zless_not_refl";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   619
val zless_irrefl = thm "zless_irrefl";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   620
val zless_linear = thm "zless_linear";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   621
val int_neq_iff = thm "int_neq_iff";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   622
val int_neqE = thm "int_neqE";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   623
val int_int_eq = thm "int_int_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   624
val int_eq_0_conv = thm "int_eq_0_conv";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   625
val zless_int = thm "zless_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   626
val int_less_0_conv = thm "int_less_0_conv";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   627
val zero_less_int_conv = thm "zero_less_int_conv";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   628
val zle_int = thm "zle_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   629
val zero_zle_int = thm "zero_zle_int";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   630
val int_le_0_conv = thm "int_le_0_conv";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   631
val zle_imp_zless_or_eq = thm "zle_imp_zless_or_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   632
val zless_or_eq_imp_zle = thm "zless_or_eq_imp_zle";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   633
val int_le_less = thm "int_le_less";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   634
val zle_refl = thm "zle_refl";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   635
val zle_linear = thm "zle_linear";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   636
val zle_trans = thm "zle_trans";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   637
val zle_anti_sym = thm "zle_anti_sym";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   638
val int_less_le = thm "int_less_le";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   639
val zadd_zdiff_eq = thm "zadd_zdiff_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   640
val zdiff_zadd_eq = thm "zdiff_zadd_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   641
val zdiff_zdiff_eq = thm "zdiff_zdiff_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   642
val zdiff_zdiff_eq2 = thm "zdiff_zdiff_eq2";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   643
val zdiff_zless_eq = thm "zdiff_zless_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   644
val zless_zdiff_eq = thm "zless_zdiff_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   645
val zdiff_zle_eq = thm "zdiff_zle_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   646
val zle_zdiff_eq = thm "zle_zdiff_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   647
val zdiff_eq_eq = thm "zdiff_eq_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   648
val eq_zdiff_eq = thm "eq_zdiff_eq";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   649
val zcompare_rls = thms "zcompare_rls";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   650
val zadd_left_cancel = thm "zadd_left_cancel";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   651
val zadd_right_cancel = thm "zadd_right_cancel";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   652
val zless_eqI = thm "zless_eqI";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   653
val zle_eqI = thm "zle_eqI";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   654
val zeq_eqI = thm "zeq_eqI";
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   655
*}
79f7d3451b1e conversion of ML to Isar scripts
paulson
parents: 13487
diff changeset
   656
5508
691c70898518 new files in Integ
paulson
parents:
diff changeset
   657
end