Quot/Examples/LarryInt.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 11 Dec 2009 15:58:15 +0100
changeset 715 3d7a9d4d2bb6
child 717 337dd914e1cb
permissions -rw-r--r--
added Int example from Larry
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
715
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
header{*The Integers as Equivalence Classes over Pairs of Natural Numbers*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
theory LarryInt 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
imports Nat "../QuotMain"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
begin
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
fun
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
  intrel :: "(nat \<times> nat) \<Rightarrow> (nat \<times> nat) \<Rightarrow> bool" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
where
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
  "intrel (x, y) (u, v) = (x + v = u + y)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
quotient int = "nat \<times> nat" / intrel
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  by (auto simp add: equivp_def expand_fun_eq)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
instantiation int :: "{zero, one, plus, uminus, minus, times, ord}"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
begin
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
quotient_def 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
  Zero_int_def: "0::int" as "(0::nat, 0::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
quotient_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
  One_int_def: "1::int" as "(1::nat, 0::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
quotient_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  "(op +) :: int \<Rightarrow> int \<Rightarrow> int" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
as 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
  "\<lambda>(x, y) (u, v). (x + (u::nat), y + (v::nat))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
quotient_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
  "uminus :: int \<Rightarrow> int" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
as 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
  "\<lambda>(x, y). (y::nat, x::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
fun
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  mult_aux::"nat \<times> nat \<Rightarrow> nat \<times> nat \<Rightarrow> nat \<times> nat"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
where
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  "mult_aux (x, y) (u, v) = (x*u + y*v, x*v + y*u)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
quotient_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
  "(op *) :: int \<Rightarrow> int \<Rightarrow> int" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
as 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  "mult_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
quotient_def 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
  le_int_def: "(op \<le>) :: int \<Rightarrow> int \<Rightarrow> bool" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
as 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  "\<lambda>(x, y) (u, v). (x+v \<le> u+(y::nat))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
definition
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
  less_int_def: "z < (w::int) \<equiv> (z \<le> w & z \<noteq> w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
definition
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  diff_int_def:  "z - (w::int) \<equiv> z + (-w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
instance ..
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
end
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
subsection{*Construction of the Integers*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
abbreviation
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
  "uminus_aux \<equiv> \<lambda>(x, y). (y::nat, x::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
lemma zminus_zminus_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  "uminus_aux (uminus_aux z) = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  by (cases z) (simp)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
lemma [quot_respect]:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  shows "(intrel ===> intrel) uminus_aux uminus_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  by simp
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
lemma zminus_zminus: 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  shows "- (- z) = (z::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
apply(lifting zminus_zminus_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
lemma zminus_0_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  shows "uminus_aux (0, 0) = (0, 0::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
by simp
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
lemma zminus_0: "- 0 = (0::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
apply(lifting zminus_0_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
subsection{*Integer Addition*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
definition
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  "add_aux \<equiv> \<lambda>(x, y) (u, v). (x + (u::nat), y + (v::nat))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
lemma zminus_zadd_distrib_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  shows "uminus_aux (add_aux z w) = add_aux (uminus_aux z) (uminus_aux w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
by (cases z, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
   (auto simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
lemma [quot_respect]:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  shows "(intrel ===> intrel ===> intrel) 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
            (\<lambda>(x, y) (u, v). (x + u, y + (v::nat)))  (\<lambda>(x, y) (u, v). (x + u, y + (v::nat)))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
by simp
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
lemma zminus_zadd_distrib: 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  shows "- (z + w) = (- z) + (- w::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
apply(lifting zminus_zadd_distrib_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
lemma zadd_commute_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
  shows "add_aux z w = add_aux w z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
by (cases z, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
   (simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
lemma zadd_commute: 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  shows "(z::int) + w = w + z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
apply(lifting zadd_commute_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
lemma zadd_assoc_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  shows "add_aux (add_aux z1 z2) z3 = add_aux z1 (add_aux z2 z3)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
by (cases z1, cases z2, cases z3) (simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
lemma zadd_assoc: "((z1::int) + z2) + z3 = z1 + (z2 + z3)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
apply(lifting zadd_assoc_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
lemma zadd_0_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
  fixes z::"nat \<times> nat"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
  shows "add_aux (0, 0) z = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
by (simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
(*also for the instance declaration int :: plus_ac0*)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
lemma zadd_0: "(0::int) + z = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
apply(lifting zadd_0_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
lemma zadd_zminus_inverse_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
  shows "intrel (add_aux (uminus_aux z) z) (0, 0)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
by (cases z) (simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
lemma zadd_zminus_inverse2: "(- z) + z = (0::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
apply(lifting zadd_zminus_inverse_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
subsection{*Integer Multiplication*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
lemma zmult_zminus_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
  shows "mult_aux (uminus_aux z) w = uminus_aux (mult_aux z w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
apply(cases z, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
apply(simp)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
lemma mult_aux_fst:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
  assumes a: "intrel x z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
  shows "intrel (mult_aux x y) (mult_aux z y)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
using a
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
apply(cases x, cases y, cases z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
apply(auto simp add: mult_aux.simps intrel.simps)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
apply(rename_tac u v w x y z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
apply(simp add: mult_ac)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
apply(simp add: add_mult_distrib [symmetric])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
lemma mult_aux_snd:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  assumes a: "intrel x z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
  shows "intrel (mult_aux y x) (mult_aux y z)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
using a
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
apply(cases x, cases y, cases z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
apply(auto simp add: mult_aux.simps intrel.simps)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
apply(rename_tac u v w x y z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
apply(subgoal_tac "u*w + z*w = y*w + v*w  &  u*x + z*x = y*x + v*x")
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
apply(simp add: mult_ac)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
apply(simp add: add_mult_distrib [symmetric])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
lemma [quot_respect]:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
  shows "(intrel ===> intrel ===> intrel) mult_aux mult_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
apply(simp only: fun_rel.simps)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
apply(rule allI | rule impI)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
apply(rule equivp_transp[OF int_equivp])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
apply(rule mult_aux_fst)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
apply(assumption)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
apply(rule mult_aux_snd)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
apply(assumption)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
lemma zmult_zminus: "(- z) * w = - (z * (w::int))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
apply(lifting zmult_zminus_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
lemma zmult_commute_aux: 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  shows "mult_aux z w = mult_aux w z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
apply(cases z, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
apply(simp add: add_ac mult_ac)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
lemma zmult_commute: "(z::int) * w = w * z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
by (lifting zmult_commute_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
lemma zmult_assoc_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
  shows "mult_aux (mult_aux z1 z2) z3 = mult_aux z1 (mult_aux z2 z3)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
apply(cases z1, cases z2, cases z3)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
apply(simp add: add_mult_distrib2 mult_ac)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
lemma zmult_assoc: "((z1::int) * z2) * z3 = z1 * (z2 * z3)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
by (lifting zmult_assoc_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
lemma zadd_mult_distrib_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  shows "mult_aux (add_aux z1 z2) w = add_aux (mult_aux z1 w) (mult_aux z2 w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
apply(cases z1, cases z2, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
apply(simp add: add_mult_distrib2 mult_ac add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
lemma zadd_zmult_distrib: "((z1::int) + z2) * w = (z1 * w) + (z2 * w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
apply(lifting zadd_mult_distrib_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
lemma zadd_zmult_distrib2: "(w::int) * (z1 + z2) = (w * z1) + (w * z2)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
by (simp add: zmult_commute [of w] zadd_zmult_distrib)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
lemma zdiff_zmult_distrib: "((z1::int) - z2) * w = (z1 * w) - (z2 * w)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
by (simp add: diff_int_def zadd_zmult_distrib zmult_zminus)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
lemma zdiff_zmult_distrib2: "(w::int) * (z1 - z2) = (w * z1) - (w * z2)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
by (simp add: zmult_commute [of w] zdiff_zmult_distrib)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
lemmas int_distrib =
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
  zadd_zmult_distrib zadd_zmult_distrib2
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
  zdiff_zmult_distrib zdiff_zmult_distrib2
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
lemma zmult_1_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
  shows "mult_aux (1, 0) z = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
apply(cases z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
lemma zmult_1: "(1::int) * z = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
apply(lifting zmult_1_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
lemma zmult_1_right: "z * (1::int) = z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
by (rule trans [OF zmult_commute zmult_1])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
lemma zero_not_one:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
  shows "(0, 0) \<noteq> (1::nat, 0::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
by simp
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
text{*The Integers Form A Ring*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
instance int :: comm_ring_1
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
proof
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
  fix i j k :: int
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
  show "(i + j) + k = i + (j + k)" by (simp add: zadd_assoc)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
  show "i + j = j + i" by (simp add: zadd_commute)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
  show "0 + i = i" by (rule zadd_0)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
  show "- i + i = 0" by (rule zadd_zminus_inverse2)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
  show "i - j = i + (-j)" by (simp add: diff_int_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
  show "(i * j) * k = i * (j * k)" by (rule zmult_assoc)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
  show "i * j = j * i" by (rule zmult_commute)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
  show "1 * i = i" by (rule zmult_1) 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
  show "(i + j) * k = i * k + j * k" by (simp add: int_distrib)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
  show "0 \<noteq> (1::int)" 
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
    by (lifting zero_not_one) (auto) (* PROBLEM? regularize failed *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
qed
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
subsection{*The @{text "\<le>"} Ordering*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
abbreviation
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
  "le_aux \<equiv> \<lambda>(x, y) (u, v). (x+v \<le> u+(y::nat))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
lemma zle_refl_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
  "le_aux w w"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
apply(cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
apply(simp)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
lemma [quot_respect]:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
  shows "(intrel ===> intrel ===> op =) le_aux le_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   304
by auto
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   305
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   306
lemma zle_refl: "w \<le> (w::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   307
apply(lifting zle_refl_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   308
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   309
apply(rule quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   310
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   311
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   312
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   313
lemma zle_trans_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   314
  shows "\<lbrakk>le_aux i j; le_aux j k\<rbrakk> \<Longrightarrow> le_aux i k"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   315
apply(cases i, cases j, cases k)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   316
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   317
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   318
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   319
lemma zle_trans: "\<lbrakk>i \<le> j; j \<le> k\<rbrakk> \<Longrightarrow> i \<le> (k::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   320
apply(lifting zle_trans_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   321
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   322
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   323
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   324
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   325
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   326
lemma zle_anti_sym_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   327
  shows "\<lbrakk>le_aux z w; le_aux w z\<rbrakk> \<Longrightarrow> intrel z w"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   328
apply(cases z, cases w)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   329
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   330
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   331
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   332
lemma zle_anti_sym: "\<lbrakk>z \<le> w; w \<le> z\<rbrakk> \<Longrightarrow> z = (w::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   333
apply(lifting zle_anti_sym_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   334
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   335
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   336
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   337
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   338
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   339
(* Axiom 'order_less_le' of class 'order': *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   340
lemma zless_le: "((w::int) < z) = (w \<le> z & w \<noteq> z)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   341
by (simp add: less_int_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   342
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   343
instance int :: order
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   344
apply(intro_classes)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   345
apply(auto intro: zle_refl zle_trans zle_anti_sym zless_le simp add: less_int_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   346
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   347
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   348
(* Axiom 'linorder_linear' of class 'linorder': *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   349
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   350
lemma zle_linear_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   351
  "le_aux z w \<or> le_aux w z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   352
apply(cases w, cases z)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   353
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   354
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   355
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   356
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   357
lemma zle_linear: "(z::int) \<le> w \<or> w \<le> z"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   358
apply(lifting zle_linear_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   359
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   360
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   361
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   362
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   363
instance int :: linorder
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   364
proof qed (rule zle_linear)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   365
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   366
lemma zadd_left_mono_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   367
  shows "le_aux i j \<Longrightarrow> le_aux (add_aux k i) (add_aux k j)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   368
apply(cases k)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   369
apply(auto simp add: add_aux_def)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   370
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   371
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   372
lemma zadd_left_mono: "i \<le> j \<Longrightarrow> k + i \<le> k + (j::int)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   373
apply(lifting zadd_left_mono_aux[simplified add_aux_def])
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   374
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   375
apply(rule quot_respect)+
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   376
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   377
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   378
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   379
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   380
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   381
subsection{*Magnitide of an Integer, as a Natural Number: @{term nat}*}
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   382
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   383
(* PROBLEM: this has to be a definition, not an abbreviation *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   384
(* otherwise the lemma nat_le_eq_zle cannot be lifted        *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   385
fun
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   386
  nat_aux
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   387
where
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   388
  "nat_aux (x, y) =  x - (y::nat)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   389
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   390
quotient_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   391
  "nat2::int\<Rightarrow>nat"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   392
as
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   393
  "nat_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   394
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   395
abbreviation
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   396
  "less_aux x y \<equiv> (le_aux x y \<and> \<not>(x = y))"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   397
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   398
lemma nat_le_eq_zle_aux:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   399
  shows "less_aux (0, 0) w \<or> le_aux (0, 0) z \<Longrightarrow> (nat_aux w \<le> nat_aux z) = (le_aux w z)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   400
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   401
sorry
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   402
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   403
lemma [quot_respect]:
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   404
  shows "(intrel ===> op =) nat_aux nat_aux"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   405
apply(auto)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   406
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   407
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   408
lemma nat_le_eq_zle: "0 < w \<or> 0 \<le> z \<Longrightarrow> (nat2 w \<le> nat2 z) = (w\<le>z)"
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   409
unfolding less_int_def
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   410
apply(lifting nat_le_eq_zle_aux)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   411
apply(injection)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   412
apply(simp_all only: quot_respect)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   413
done
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   414
(* PROBLEM *)
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   415
3d7a9d4d2bb6 added Int example from Larry
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   416
end