src/HOL/Nat.thy
author nipkow
Wed, 10 Aug 2016 09:33:54 +0200
changeset 63648 f9f3006a5579
parent 63588 d0e2bad67bd4
child 63979 95c3ae4baba8
permissions -rw-r--r--
"split add" -> "split"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title:      HOL/Nat.thy
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     2
    Author:     Tobias Nipkow
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     3
    Author:     Lawrence C Paulson
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     4
    Author:     Markus Wenzel
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents: 7702
diff changeset
     6
Type "nat" is a linear order, and a datatype; arithmetic operators + -
30496
7cdcc9dd95cb vague cleanup in arith proof tools setup: deleted dead code, more proper structures, clearer arrangement
haftmann
parents: 30242
diff changeset
     7
and * (for div and mod, see theory Divides).
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
    10
section \<open>Natural numbers\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    11
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14740
diff changeset
    12
theory Nat
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    13
  imports Inductive Typedef Fun Rings
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14740
diff changeset
    14
begin
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    15
57952
1a9a6dfc255f updated to named_theorems;
wenzelm
parents: 57514
diff changeset
    16
named_theorems arith "arith facts -- only ground formulas"
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 48560
diff changeset
    17
ML_file "Tools/arith_data.ML"
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 48560
diff changeset
    18
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 48560
diff changeset
    19
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
    20
subsection \<open>Type \<open>ind\<close>\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    21
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    22
typedecl ind
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    23
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    24
axiomatization Zero_Rep :: ind and Suc_Rep :: "ind \<Rightarrow> ind"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
    25
  \<comment> \<open>The axiom of infinity in 2 parts:\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    26
  where Suc_Rep_inject: "Suc_Rep x = Suc_Rep y \<Longrightarrow> x = y"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    27
    and Suc_Rep_not_Zero_Rep: "Suc_Rep x \<noteq> Zero_Rep"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    28
19573
340c466c9605 axiomatization;
wenzelm
parents: 18702
diff changeset
    29
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
    30
subsection \<open>Type nat\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
    31
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
    32
text \<open>Type definition\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    33
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    34
inductive Nat :: "ind \<Rightarrow> bool"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    35
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    36
    Zero_RepI: "Nat Zero_Rep"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    37
  | Suc_RepI: "Nat i \<Longrightarrow> Nat (Suc_Rep i)"
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    38
49834
b27bbb021df1 discontinued obsolete typedef (open) syntax;
wenzelm
parents: 49723
diff changeset
    39
typedef nat = "{n. Nat n}"
45696
476ad865f125 prefer typedef without alternative name;
wenzelm
parents: 45231
diff changeset
    40
  morphisms Rep_Nat Abs_Nat
44278
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    41
  using Nat.Zero_RepI by auto
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    42
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    43
lemma Nat_Rep_Nat: "Nat (Rep_Nat n)"
44278
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    44
  using Rep_Nat by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    45
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    46
lemma Nat_Abs_Nat_inverse: "Nat n \<Longrightarrow> Rep_Nat (Abs_Nat n) = n"
44278
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    47
  using Abs_Nat_inverse by simp
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    48
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    49
lemma Nat_Abs_Nat_inject: "Nat n \<Longrightarrow> Nat m \<Longrightarrow> Abs_Nat n = Abs_Nat m \<longleftrightarrow> n = m"
44278
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    50
  using Abs_Nat_inject by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    51
25510
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    52
instantiation nat :: zero
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    53
begin
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    54
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    55
definition Zero_nat_def: "0 = Abs_Nat Zero_Rep"
25510
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    56
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    57
instance ..
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    58
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
    59
end
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
    60
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    61
definition Suc :: "nat \<Rightarrow> nat"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    62
  where "Suc n = Abs_Nat (Suc_Rep (Rep_Nat n))"
44278
1220ecb81e8f observe distinction between sets and predicates more properly
haftmann
parents: 43595
diff changeset
    63
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
    64
lemma Suc_not_Zero: "Suc m \<noteq> 0"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    65
  by (simp add: Zero_nat_def Suc_def Suc_RepI Zero_RepI
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    66
      Nat_Abs_Nat_inject Suc_Rep_not_Zero_Rep Nat_Rep_Nat)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    67
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
    68
lemma Zero_not_Suc: "0 \<noteq> Suc m"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    69
  by (rule not_sym) (rule Suc_not_Zero)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
    70
34208
a7acd6c68d9b more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents: 33657
diff changeset
    71
lemma Suc_Rep_inject': "Suc_Rep x = Suc_Rep y \<longleftrightarrow> x = y"
a7acd6c68d9b more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents: 33657
diff changeset
    72
  by (rule iffI, rule Suc_Rep_inject) simp_all
a7acd6c68d9b more regular axiom of infinity, with no (indirect) reference to overloaded constants
krauss
parents: 33657
diff changeset
    73
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
    74
lemma nat_induct0:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    75
  assumes "P 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    76
    and "\<And>n. P n \<Longrightarrow> P (Suc n)"
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
    77
  shows "P n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    78
  using assms
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    79
  apply (unfold Zero_nat_def Suc_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    80
  apply (rule Rep_Nat_inverse [THEN subst]) \<comment> \<open>types force good instantiation\<close>
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    81
  apply (erule Nat_Rep_Nat [THEN Nat.induct])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    82
  apply (iprover elim: Nat_Abs_Nat_inverse [THEN subst])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    83
  done
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    84
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    85
free_constructors case_nat for "0 :: nat" | Suc pred
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    86
  where "pred (0 :: nat) = (0 :: nat)"
58189
9d714be4f028 added 'plugins' option to control which hooks are enabled
blanchet
parents: 57983
diff changeset
    87
    apply atomize_elim
9d714be4f028 added 'plugins' option to control which hooks are enabled
blanchet
parents: 57983
diff changeset
    88
    apply (rename_tac n, induct_tac n rule: nat_induct0, auto)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    89
   apply (simp add: Suc_def Nat_Abs_Nat_inject Nat_Rep_Nat Suc_RepI Suc_Rep_inject' Rep_Nat_inject)
58189
9d714be4f028 added 'plugins' option to control which hooks are enabled
blanchet
parents: 57983
diff changeset
    90
  apply (simp only: Suc_not_Zero)
9d714be4f028 added 'plugins' option to control which hooks are enabled
blanchet
parents: 57983
diff changeset
    91
  done
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
    92
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
    93
\<comment> \<open>Avoid name clashes by prefixing the output of \<open>old_rep_datatype\<close> with \<open>old\<close>.\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
    94
setup \<open>Sign.mandatory_path "old"\<close>
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
    95
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 61070
diff changeset
    96
old_rep_datatype "0 :: nat" Suc
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    97
    apply (erule nat_induct0)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    98
    apply assumption
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    99
   apply (rule nat.inject)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   100
  apply (rule nat.distinct(1))
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   101
  done
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   102
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   103
setup \<open>Sign.parent_path\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   104
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   105
\<comment> \<open>But erase the prefix for properties that are not generated by \<open>free_constructors\<close>.\<close>
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   106
setup \<open>Sign.mandatory_path "nat"\<close>
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   107
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   108
declare old.nat.inject[iff del]
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   109
  and old.nat.distinct(1)[simp del, induct_simp del]
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   110
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   111
lemmas induct = old.nat.induct
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   112
lemmas inducts = old.nat.inducts
55642
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55575
diff changeset
   113
lemmas rec = old.nat.rec
63beb38e9258 adapted to renaming of datatype 'cases' and 'recs' to 'case' and 'rec'
blanchet
parents: 55575
diff changeset
   114
lemmas simps = nat.inject nat.distinct nat.case nat.rec
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   115
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   116
setup \<open>Sign.parent_path\<close>
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   117
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   118
abbreviation rec_nat :: "'a \<Rightarrow> (nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   119
  where "rec_nat \<equiv> old.rec_nat"
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   120
55424
9ab4129a76a3 remove hidden fact about hidden constant from code generator setup
blanchet
parents: 55423
diff changeset
   121
declare nat.sel[code del]
9ab4129a76a3 remove hidden fact about hidden constant from code generator setup
blanchet
parents: 55423
diff changeset
   122
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   123
hide_const (open) Nat.pred \<comment> \<open>hide everything related to the selector\<close>
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   124
hide_fact
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   125
  nat.case_eq_if
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   126
  nat.collapse
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   127
  nat.expand
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   128
  nat.sel
57983
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57952
diff changeset
   129
  nat.exhaust_sel
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57952
diff changeset
   130
  nat.split_sel
6edc3529bb4e reordered some (co)datatype property names for more consistency
blanchet
parents: 57952
diff changeset
   131
  nat.split_sel_asm
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   132
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   133
lemma nat_exhaust [case_names 0 Suc, cases type: nat]:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   134
  "(y = 0 \<Longrightarrow> P) \<Longrightarrow> (\<And>nat. y = Suc nat \<Longrightarrow> P) \<Longrightarrow> P"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   135
  \<comment> \<open>for backward compatibility -- names of variables differ\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   136
  by (rule old.nat.exhaust)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   137
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   138
lemma nat_induct [case_names 0 Suc, induct type: nat]:
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   139
  fixes n
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   140
  assumes "P 0" and "\<And>n. P n \<Longrightarrow> P (Suc n)"
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   141
  shows "P n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   142
  \<comment> \<open>for backward compatibility -- names of variables differ\<close>
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   143
  using assms by (rule nat.induct)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   144
55417
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   145
hide_fact
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   146
  nat_exhaust
01fbfb60c33e adapted to 'xxx_{case,rec}' renaming, to new theorem names, and to new variable names in theorems
blanchet
parents: 55415
diff changeset
   147
  nat_induct0
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   148
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   149
ML \<open>
58389
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   150
val nat_basic_lfp_sugar =
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   151
  let
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   152
    val ctr_sugar = the (Ctr_Sugar.ctr_sugar_of_global @{theory} @{type_name nat});
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   153
    val recx = Logic.varify_types_global @{term rec_nat};
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   154
    val C = body_type (fastype_of recx);
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   155
  in
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   156
    {T = HOLogic.natT, fp_res_index = 0, C = C, fun_arg_Tsss = [[], [[HOLogic.natT, C]]],
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   157
     ctr_sugar = ctr_sugar, recx = recx, rec_thms = @{thms nat.rec}}
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   158
  end;
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   159
\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   160
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   161
setup \<open>
58389
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   162
let
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   163
  fun basic_lfp_sugars_of _ [@{typ nat}] _ _ ctxt =
62326
3cf7a067599c allow predicator instead of map function in 'primrec'
blanchet
parents: 62217
diff changeset
   164
      ([], [0], [nat_basic_lfp_sugar], [], [], [], TrueI (*dummy*), [], false, ctxt)
58389
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   165
    | basic_lfp_sugars_of bs arg_Ts callers callssss ctxt =
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   166
      BNF_LFP_Rec_Sugar.default_basic_lfp_sugars_of bs arg_Ts callers callssss ctxt;
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   167
in
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   168
  BNF_LFP_Rec_Sugar.register_lfp_rec_extension
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   169
    {nested_simps = [], is_new_datatype = K (K true), basic_lfp_sugars_of = basic_lfp_sugars_of,
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   170
     rewrite_nested_rec_call = NONE}
ee1f45ca0d73 made new 'primrec' bootstrapping-capable
blanchet
parents: 58377
diff changeset
   171
end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   172
\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   173
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   174
text \<open>Injectiveness and distinctness lemmas\<close>
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   175
27104
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   176
lemma inj_Suc[simp]: "inj_on Suc N"
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   177
  by (simp add: inj_on_def)
791607529f6d rep_datatype command now takes list of constructors as input arguments
haftmann
parents: 26748
diff changeset
   178
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   179
lemma Suc_neq_Zero: "Suc m = 0 \<Longrightarrow> R"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   180
  by (rule notE) (rule Suc_not_Zero)
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   181
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   182
lemma Zero_neq_Suc: "0 = Suc m \<Longrightarrow> R"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   183
  by (rule Suc_neq_Zero) (erule sym)
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   184
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   185
lemma Suc_inject: "Suc x = Suc y \<Longrightarrow> x = y"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   186
  by (rule inj_Suc [THEN injD])
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   187
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
   188
lemma n_not_Suc_n: "n \<noteq> Suc n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   189
  by (induct n) simp_all
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   190
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   191
lemma Suc_n_not_n: "Suc n \<noteq> n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   192
  by (rule not_sym) (rule n_not_Suc_n)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   193
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   194
text \<open>A special form of induction for reasoning about @{term "m < n"} and @{term "m - n"}.\<close>
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   195
lemma diff_induct:
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   196
  assumes "\<And>x. P x 0"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   197
    and "\<And>y. P 0 (Suc y)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   198
    and "\<And>x y. P x y \<Longrightarrow> P (Suc x) (Suc y)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   199
  shows "P m n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   200
proof (induct n arbitrary: m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   201
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   202
  show ?case by (rule assms(1))
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   203
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   204
  case (Suc n)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   205
  show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   206
  proof (induct m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   207
    case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   208
    show ?case by (rule assms(2))
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   209
  next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   210
    case (Suc m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   211
    from \<open>P m n\<close> show ?case by (rule assms(3))
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   212
  qed
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   213
qed
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   214
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   215
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   216
subsection \<open>Arithmetic operators\<close>
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   217
49388
1ffd5a055acf typeclass formalising bounded subtraction
haftmann
parents: 48891
diff changeset
   218
instantiation nat :: comm_monoid_diff
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25563
diff changeset
   219
begin
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   220
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   221
primrec plus_nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   222
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   223
    add_0: "0 + n = (n::nat)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   224
  | add_Suc: "Suc m + n = Suc (m + n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   225
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   226
lemma add_0_right [simp]: "m + 0 = m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   227
  for m :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   228
  by (induct m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   229
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   230
lemma add_Suc_right [simp]: "m + Suc n = Suc (m + n)"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   231
  by (induct m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   232
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
   233
declare add_0 [code]
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
   234
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   235
lemma add_Suc_shift [code]: "Suc m + n = m + Suc n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   236
  by simp
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   237
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   238
primrec minus_nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   239
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   240
    diff_0 [code]: "m - 0 = (m::nat)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   241
  | diff_Suc: "m - Suc n = (case m - n of 0 \<Rightarrow> 0 | Suc k \<Rightarrow> k)"
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   242
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
   243
declare diff_Suc [simp del]
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   244
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   245
lemma diff_0_eq_0 [simp, code]: "0 - n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   246
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   247
  by (induct n) (simp_all add: diff_Suc)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   248
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   249
lemma diff_Suc_Suc [simp, code]: "Suc m - Suc n = m - n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   250
  by (induct n) (simp_all add: diff_Suc)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   251
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   252
instance
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   253
proof
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   254
  fix n m q :: nat
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   255
  show "(n + m) + q = n + (m + q)" by (induct n) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   256
  show "n + m = m + n" by (induct n) simp_all
59815
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59582
diff changeset
   257
  show "m + n - m = n" by (induct m) simp_all
cce82e360c2f explicit commutative additive inverse operation;
haftmann
parents: 59582
diff changeset
   258
  show "n - m - q = n - (m + q)" by (induct q) (simp_all add: diff_Suc)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   259
  show "0 + n = n" by simp
49388
1ffd5a055acf typeclass formalising bounded subtraction
haftmann
parents: 48891
diff changeset
   260
  show "0 - n = 0" by simp
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   261
qed
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   262
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   263
end
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   264
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 35828
diff changeset
   265
hide_fact (open) add_0 add_0_right diff_0
35047
1b2bae06c796 hide fact Nat.add_0_right; make add_0_right from Groups priority
haftmann
parents: 35028
diff changeset
   266
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   267
instantiation nat :: comm_semiring_1_cancel
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   268
begin
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   269
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   270
definition One_nat_def [simp]: "1 = Suc 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   271
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   272
primrec times_nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   273
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   274
    mult_0: "0 * n = (0::nat)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   275
  | mult_Suc: "Suc m * n = n + (m * n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   276
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   277
lemma mult_0_right [simp]: "m * 0 = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   278
  for m :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   279
  by (induct m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   280
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   281
lemma mult_Suc_right [simp]: "m * Suc n = m + (m * n)"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57492
diff changeset
   282
  by (induct m) (simp_all add: add.left_commute)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   283
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   284
lemma add_mult_distrib: "(m + n) * k = (m * k) + (n * k)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   285
  for m n k :: nat
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57492
diff changeset
   286
  by (induct m) (simp_all add: add.assoc)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   287
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   288
instance
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   289
proof
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   290
  fix k n m q :: nat
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   291
  show "0 \<noteq> (1::nat)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   292
    by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   293
  show "1 * n = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   294
    by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   295
  show "n * m = m * n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   296
    by (induct n) simp_all
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   297
  show "(n * m) * q = n * (m * q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   298
    by (induct n) (simp_all add: add_mult_distrib)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   299
  show "(n + m) * q = n * q + m * q"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   300
    by (rule add_mult_distrib)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   301
  show "k * (m - n) = (k * m) - (k * n)"
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   302
    by (induct m n rule: diff_induct) simp_all
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   303
qed
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25563
diff changeset
   304
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25563
diff changeset
   305
end
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   306
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   307
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   308
subsubsection \<open>Addition\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   309
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   310
text \<open>Reasoning about \<open>m + 0 = 0\<close>, etc.\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   311
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   312
lemma add_is_0 [iff]: "m + n = 0 \<longleftrightarrow> m = 0 \<and> n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   313
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   314
  by (cases m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   315
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   316
lemma add_is_1: "m + n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = 0 | m = 0 \<and> n = Suc 0"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   317
  by (cases m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   318
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   319
lemma one_is_add: "Suc 0 = m + n \<longleftrightarrow> m = Suc 0 \<and> n = 0 | m = 0 \<and> n = Suc 0"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   320
  by (rule trans, rule eq_commute, rule add_is_1)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   321
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   322
lemma add_eq_self_zero: "m + n = m \<Longrightarrow> n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   323
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   324
  by (induct m) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   325
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   326
lemma inj_on_add_nat [simp]: "inj_on (\<lambda>n. n + k) N"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   327
  for k :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   328
proof (induct k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   329
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   330
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   331
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   332
  case (Suc k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   333
  show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   334
    using comp_inj_on [OF Suc inj_Suc] by (simp add: o_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   335
qed
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   336
47208
9a91b163bb71 move lemmas from Nat_Numeral.thy to Nat.thy
huffman
parents: 47108
diff changeset
   337
lemma Suc_eq_plus1: "Suc n = n + 1"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   338
  by simp
47208
9a91b163bb71 move lemmas from Nat_Numeral.thy to Nat.thy
huffman
parents: 47108
diff changeset
   339
9a91b163bb71 move lemmas from Nat_Numeral.thy to Nat.thy
huffman
parents: 47108
diff changeset
   340
lemma Suc_eq_plus1_left: "Suc n = 1 + n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   341
  by simp
47208
9a91b163bb71 move lemmas from Nat_Numeral.thy to Nat.thy
huffman
parents: 47108
diff changeset
   342
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   343
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   344
subsubsection \<open>Difference\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   345
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   346
lemma Suc_diff_diff [simp]: "(Suc m - n) - Suc k = m - n - k"
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
   347
  by (simp add: diff_diff_add)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   348
30093
ecb557b021b2 add lemma diff_Suc_1
huffman
parents: 30079
diff changeset
   349
lemma diff_Suc_1 [simp]: "Suc n - 1 = n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   350
  by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   351
30093
ecb557b021b2 add lemma diff_Suc_1
huffman
parents: 30079
diff changeset
   352
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   353
subsubsection \<open>Multiplication\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   354
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   355
lemma mult_is_0 [simp]: "m * n = 0 \<longleftrightarrow> m = 0 \<or> n = 0" for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   356
  by (induct m) auto
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   357
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   358
lemma mult_eq_1_iff [simp]: "m * n = Suc 0 \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   359
proof (induct m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   360
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   361
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   362
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   363
  case (Suc m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   364
  then show ?case by (induct n) auto
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   365
qed
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   366
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   367
lemma one_eq_mult_iff [simp]: "Suc 0 = m * n \<longleftrightarrow> m = Suc 0 \<and> n = Suc 0"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   368
  apply (rule trans)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   369
   apply (rule_tac [2] mult_eq_1_iff)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   370
  apply fastforce
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   371
  done
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   372
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   373
lemma nat_mult_eq_1_iff [simp]: "m * n = 1 \<longleftrightarrow> m = 1 \<and> n = 1"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   374
  for m n :: nat
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   375
  unfolding One_nat_def by (rule mult_eq_1_iff)
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   376
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   377
lemma nat_1_eq_mult_iff [simp]: "1 = m * n \<longleftrightarrow> m = 1 \<and> n = 1"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   378
  for m n :: nat
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   379
  unfolding One_nat_def by (rule one_eq_mult_iff)
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   380
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   381
lemma mult_cancel1 [simp]: "k * m = k * n \<longleftrightarrow> m = n \<or> k = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   382
  for k m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   383
proof -
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   384
  have "k \<noteq> 0 \<Longrightarrow> k * m = k * n \<Longrightarrow> m = n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   385
  proof (induct n arbitrary: m)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   386
    case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   387
    then show "m = 0" by simp
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   388
  next
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   389
    case (Suc n)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   390
    then show "m = Suc n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   391
      by (cases m) (simp_all add: eq_commute [of 0])
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   392
  qed
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   393
  then show ?thesis by auto
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   394
qed
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   395
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   396
lemma mult_cancel2 [simp]: "m * k = n * k \<longleftrightarrow> m = n \<or> k = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   397
  for k m n :: nat
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57492
diff changeset
   398
  by (simp add: mult.commute)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   399
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   400
lemma Suc_mult_cancel1: "Suc k * m = Suc k * n \<longleftrightarrow> m = n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   401
  by (subst mult_cancel1) simp
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   402
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   403
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   404
subsection \<open>Orders on @{typ nat}\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   405
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   406
subsubsection \<open>Operation definition\<close>
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   407
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   408
instantiation nat :: linorder
25510
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
   409
begin
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
   410
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   411
primrec less_eq_nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   412
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   413
    "(0::nat) \<le> n \<longleftrightarrow> True"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   414
  | "Suc m \<le> n \<longleftrightarrow> (case n of 0 \<Rightarrow> False | Suc n \<Rightarrow> m \<le> n)"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   415
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
   416
declare less_eq_nat.simps [simp del]
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   417
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   418
lemma le0 [iff]: "0 \<le> n" for
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   419
  n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   420
  by (simp add: less_eq_nat.simps)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   421
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   422
lemma [code]: "0 \<le> n \<longleftrightarrow> True"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   423
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   424
  by simp
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   425
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   426
definition less_nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   427
  where less_eq_Suc_le: "n < m \<longleftrightarrow> Suc n \<le> m"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   428
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   429
lemma Suc_le_mono [iff]: "Suc n \<le> Suc m \<longleftrightarrow> n \<le> m"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   430
  by (simp add: less_eq_nat.simps(2))
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   431
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   432
lemma Suc_le_eq [code]: "Suc m \<le> n \<longleftrightarrow> m < n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   433
  unfolding less_eq_Suc_le ..
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   434
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   435
lemma le_0_eq [iff]: "n \<le> 0 \<longleftrightarrow> n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   436
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   437
  by (induct n) (simp_all add: less_eq_nat.simps(2))
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   438
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   439
lemma not_less0 [iff]: "\<not> n < 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   440
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   441
  by (simp add: less_eq_Suc_le)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   442
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   443
lemma less_nat_zero_code [code]: "n < 0 \<longleftrightarrow> False"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   444
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   445
  by simp
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   446
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   447
lemma Suc_less_eq [iff]: "Suc m < Suc n \<longleftrightarrow> m < n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   448
  by (simp add: less_eq_Suc_le)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   449
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   450
lemma less_Suc_eq_le [code]: "m < Suc n \<longleftrightarrow> m \<le> n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   451
  by (simp add: less_eq_Suc_le)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   452
56194
9ffbb4004c81 fix HOL-NSA; move lemmas
hoelzl
parents: 56020
diff changeset
   453
lemma Suc_less_eq2: "Suc n < m \<longleftrightarrow> (\<exists>m'. m = Suc m' \<and> n < m')"
9ffbb4004c81 fix HOL-NSA; move lemmas
hoelzl
parents: 56020
diff changeset
   454
  by (cases m) auto
9ffbb4004c81 fix HOL-NSA; move lemmas
hoelzl
parents: 56020
diff changeset
   455
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   456
lemma le_SucI: "m \<le> n \<Longrightarrow> m \<le> Suc n"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   457
  by (induct m arbitrary: n) (simp_all add: less_eq_nat.simps(2) split: nat.splits)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   458
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   459
lemma Suc_leD: "Suc m \<le> n \<Longrightarrow> m \<le> n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   460
  by (cases n) (auto intro: le_SucI)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   461
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   462
lemma less_SucI: "m < n \<Longrightarrow> m < Suc n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   463
  by (simp add: less_eq_Suc_le) (erule Suc_leD)
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
   464
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   465
lemma Suc_lessD: "Suc m < n \<Longrightarrow> m < n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   466
  by (simp add: less_eq_Suc_le) (erule Suc_leD)
25510
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
   467
26315
cb3badaa192e removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents: 26300
diff changeset
   468
instance
cb3badaa192e removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents: 26300
diff changeset
   469
proof
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   470
  fix n m q :: nat
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   471
  show "n < m \<longleftrightarrow> n \<le> m \<and> \<not> m \<le> n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   472
  proof (induct n arbitrary: m)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   473
    case 0
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   474
    then show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   475
      by (cases m) (simp_all add: less_eq_Suc_le)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   476
  next
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   477
    case (Suc n)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   478
    then show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   479
      by (cases m) (simp_all add: less_eq_Suc_le)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   480
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   481
  show "n \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   482
    by (induct n) simp_all
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   483
  then show "n = m" if "n \<le> m" and "m \<le> n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   484
    using that by (induct n arbitrary: m)
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   485
      (simp_all add: less_eq_nat.simps(2) split: nat.splits)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   486
  show "n \<le> q" if "n \<le> m" and "m \<le> q"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   487
    using that
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   488
  proof (induct n arbitrary: m q)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   489
    case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   490
    show ?case by simp
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   491
  next
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   492
    case (Suc n)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   493
    then show ?case
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   494
      by (simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits, clarify,
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   495
        simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits, clarify,
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   496
        simp_all (no_asm_use) add: less_eq_nat.simps(2) split: nat.splits)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   497
  qed
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   498
  show "n \<le> m \<or> m \<le> n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   499
    by (induct n arbitrary: m)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   500
      (simp_all add: less_eq_nat.simps(2) split: nat.splits)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   501
qed
25510
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
   502
38c15efe603b adjustions to due to instance target
haftmann
parents: 25502
diff changeset
   503
end
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   504
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 52435
diff changeset
   505
instantiation nat :: order_bot
29652
f4c6e546b7fe nat is a bot instance
haftmann
parents: 29608
diff changeset
   506
begin
f4c6e546b7fe nat is a bot instance
haftmann
parents: 29608
diff changeset
   507
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   508
definition bot_nat :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   509
  where "bot_nat = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   510
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   511
instance
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   512
  by standard (simp add: bot_nat_def)
29652
f4c6e546b7fe nat is a bot instance
haftmann
parents: 29608
diff changeset
   513
f4c6e546b7fe nat is a bot instance
haftmann
parents: 29608
diff changeset
   514
end
f4c6e546b7fe nat is a bot instance
haftmann
parents: 29608
diff changeset
   515
51329
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51263
diff changeset
   516
instance nat :: no_top
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 61144
diff changeset
   517
  by standard (auto intro: less_Suc_eq_le [THEN iffD2])
52289
83ce5d2841e7 type class for confined subtraction
haftmann
parents: 51329
diff changeset
   518
51329
4a3c453f99a1 split dense into inner_dense_order and no_top/no_bot
hoelzl
parents: 51263
diff changeset
   519
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   520
subsubsection \<open>Introduction properties\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   521
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   522
lemma lessI [iff]: "n < Suc n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   523
  by (simp add: less_Suc_eq_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   524
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   525
lemma zero_less_Suc [iff]: "0 < Suc n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   526
  by (simp add: less_Suc_eq_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   527
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   528
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   529
subsubsection \<open>Elimination properties\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   530
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   531
lemma less_not_refl: "\<not> n < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   532
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   533
  by (rule order_less_irrefl)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   534
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   535
lemma less_not_refl2: "n < m \<Longrightarrow> m \<noteq> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   536
  for m n :: nat
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   537
  by (rule not_sym) (rule less_imp_neq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   538
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   539
lemma less_not_refl3: "s < t \<Longrightarrow> s \<noteq> t"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   540
  for s t :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   541
  by (rule less_imp_neq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   542
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   543
lemma less_irrefl_nat: "n < n \<Longrightarrow> R"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   544
  for n :: nat
26335
961bbcc9d85b removed redundant Nat.less_not_sym, Nat.less_asym;
wenzelm
parents: 26315
diff changeset
   545
  by (rule notE, rule less_not_refl)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   546
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   547
lemma less_zeroE: "n < 0 \<Longrightarrow> R"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   548
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   549
  by (rule notE) (rule not_less0)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   550
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   551
lemma less_Suc_eq: "m < Suc n \<longleftrightarrow> m < n \<or> m = n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   552
  unfolding less_Suc_eq_le le_less ..
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   553
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   554
lemma less_Suc0 [iff]: "(n < Suc 0) = (n = 0)"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   555
  by (simp add: less_Suc_eq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   556
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   557
lemma less_one [iff]: "n < 1 \<longleftrightarrow> n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   558
  for n :: nat
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 30056
diff changeset
   559
  unfolding One_nat_def by (rule less_Suc0)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   560
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   561
lemma Suc_mono: "m < n \<Longrightarrow> Suc m < Suc n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   562
  by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   563
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   564
text \<open>"Less than" is antisymmetric, sort of.\<close>
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   565
lemma less_antisym: "\<not> n < m \<Longrightarrow> n < Suc m \<Longrightarrow> m = n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   566
  unfolding not_less less_Suc_eq_le by (rule antisym)
14302
6c24235e8d5d *** empty log message ***
nipkow
parents: 14267
diff changeset
   567
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   568
lemma nat_neq_iff: "m \<noteq> n \<longleftrightarrow> m < n \<or> n < m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   569
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   570
  by (rule linorder_neq_iff)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   571
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   572
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   573
subsubsection \<open>Inductive (?) properties\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   574
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   575
lemma Suc_lessI: "m < n \<Longrightarrow> Suc m \<noteq> n \<Longrightarrow> Suc m < n"
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   576
  unfolding less_eq_Suc_le [of m] le_less by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   577
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   578
lemma lessE:
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   579
  assumes major: "i < k"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   580
    and 1: "k = Suc i \<Longrightarrow> P"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   581
    and 2: "\<And>j. i < j \<Longrightarrow> k = Suc j \<Longrightarrow> P"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   582
  shows P
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   583
proof -
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   584
  from major have "\<exists>j. i \<le> j \<and> k = Suc j"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   585
    unfolding less_eq_Suc_le by (induct k) simp_all
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   586
  then have "(\<exists>j. i < j \<and> k = Suc j) \<or> k = Suc i"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   587
    by (auto simp add: less_le)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   588
  with 1 2 show P by auto
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   589
qed
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   590
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   591
lemma less_SucE:
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   592
  assumes major: "m < Suc n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   593
    and less: "m < n \<Longrightarrow> P"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   594
    and eq: "m = n \<Longrightarrow> P"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   595
  shows P
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   596
  apply (rule major [THEN lessE])
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   597
   apply (rule eq)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   598
   apply blast
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   599
  apply (rule less)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   600
  apply blast
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   601
  done
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   602
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   603
lemma Suc_lessE:
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   604
  assumes major: "Suc i < k"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   605
    and minor: "\<And>j. i < j \<Longrightarrow> k = Suc j \<Longrightarrow> P"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   606
  shows P
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   607
  apply (rule major [THEN lessE])
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   608
   apply (erule lessI [THEN minor])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   609
  apply (erule Suc_lessD [THEN minor])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   610
  apply assumption
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   611
  done
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   612
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   613
lemma Suc_less_SucD: "Suc m < Suc n \<Longrightarrow> m < n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   614
  by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   615
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   616
lemma less_trans_Suc:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   617
  assumes le: "i < j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   618
  shows "j < k \<Longrightarrow> Suc i < k"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   619
proof (induct k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   620
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   621
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   622
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   623
  case (Suc k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   624
  with le show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   625
    by simp (auto simp add: less_Suc_eq dest: Suc_lessD)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   626
qed
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   627
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   628
text \<open>Can be used with \<open>less_Suc_eq\<close> to get @{prop "n = m \<or> n < m"}.\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   629
lemma not_less_eq: "\<not> m < n \<longleftrightarrow> n < Suc m"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   630
  by (simp only: not_less less_Suc_eq_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   631
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   632
lemma not_less_eq_eq: "\<not> m \<le> n \<longleftrightarrow> Suc n \<le> m"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   633
  by (simp only: not_le Suc_le_eq)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   634
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   635
text \<open>Properties of "less than or equal".\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   636
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   637
lemma le_imp_less_Suc: "m \<le> n \<Longrightarrow> m < Suc n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   638
  by (simp only: less_Suc_eq_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   639
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   640
lemma Suc_n_not_le_n: "\<not> Suc n \<le> n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   641
  by (simp add: not_le less_Suc_eq_le)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   642
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   643
lemma le_Suc_eq: "m \<le> Suc n \<longleftrightarrow> m \<le> n \<or> m = Suc n"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   644
  by (simp add: less_Suc_eq_le [symmetric] less_Suc_eq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   645
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   646
lemma le_SucE: "m \<le> Suc n \<Longrightarrow> (m \<le> n \<Longrightarrow> R) \<Longrightarrow> (m = Suc n \<Longrightarrow> R) \<Longrightarrow> R"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   647
  by (drule le_Suc_eq [THEN iffD1], iprover+)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   648
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   649
lemma Suc_leI: "m < n \<Longrightarrow> Suc m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   650
  by (simp only: Suc_le_eq)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   651
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   652
text \<open>Stronger version of \<open>Suc_leD\<close>.\<close>
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   653
lemma Suc_le_lessD: "Suc m \<le> n \<Longrightarrow> m < n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   654
  by (simp only: Suc_le_eq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   655
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   656
lemma less_imp_le_nat: "m < n \<Longrightarrow> m \<le> n" for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   657
  unfolding less_eq_Suc_le by (rule Suc_leD)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   658
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   659
text \<open>For instance, \<open>(Suc m < Suc n) = (Suc m \<le> n) = (m < n)\<close>\<close>
26315
cb3badaa192e removed redundant less_trans, less_linear, le_imp_less_or_eq, le_less_trans, less_le_trans (cf. Orderings.thy);
wenzelm
parents: 26300
diff changeset
   660
lemmas le_simps = less_imp_le_nat less_Suc_eq_le Suc_le_eq
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   661
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   662
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   663
text \<open>Equivalence of \<open>m \<le> n\<close> and \<open>m < n \<or> m = n\<close>\<close>
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   664
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   665
lemma less_or_eq_imp_le: "m < n \<or> m = n \<Longrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   666
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   667
  unfolding le_less .
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   668
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   669
lemma le_eq_less_or_eq: "m \<le> n \<longleftrightarrow> m < n \<or> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   670
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   671
  by (rule le_less)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   672
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   673
text \<open>Useful with \<open>blast\<close>.\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   674
lemma eq_imp_le: "m = n \<Longrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   675
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   676
  by auto
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   677
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   678
lemma le_refl: "n \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   679
  for n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   680
  by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   681
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   682
lemma le_trans: "i \<le> j \<Longrightarrow> j \<le> k \<Longrightarrow> i \<le> k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   683
  for i j k :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   684
  by (rule order_trans)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   685
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   686
lemma le_antisym: "m \<le> n \<Longrightarrow> n \<le> m \<Longrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   687
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   688
  by (rule antisym)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   689
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   690
lemma nat_less_le: "m < n \<longleftrightarrow> m \<le> n \<and> m \<noteq> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   691
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   692
  by (rule less_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   693
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   694
lemma le_neq_implies_less: "m \<le> n \<Longrightarrow> m \<noteq> n \<Longrightarrow> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   695
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   696
  unfolding less_le ..
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   697
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   698
lemma nat_le_linear: "m \<le> n | n \<le> m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   699
  for m n :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   700
  by (rule linear)
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   701
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
   702
lemmas linorder_neqE_nat = linorder_neqE [where 'a = nat]
15921
b6e345548913 Fixing a problem with lin.arith.
nipkow
parents: 15539
diff changeset
   703
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   704
lemma le_less_Suc_eq: "m \<le> n \<Longrightarrow> n < Suc m \<longleftrightarrow> n = m"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   705
  unfolding less_Suc_eq_le by auto
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   706
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   707
lemma not_less_less_Suc_eq: "\<not> n < m \<Longrightarrow> n < Suc m \<longleftrightarrow> n = m"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
   708
  unfolding not_less by (rule le_less_Suc_eq)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   709
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   710
lemmas not_less_simps = not_less_less_Suc_eq le_less_Suc_eq
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   711
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   712
lemma not0_implies_Suc: "n \<noteq> 0 \<Longrightarrow> \<exists>m. n = Suc m"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   713
  by (cases n) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   714
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   715
lemma gr0_implies_Suc: "n > 0 \<Longrightarrow> \<exists>m. n = Suc m"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   716
  by (cases n) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   717
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   718
lemma gr_implies_not0: "m < n \<Longrightarrow> n \<noteq> 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   719
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   720
  by (cases n) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   721
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   722
lemma neq0_conv[iff]: "n \<noteq> 0 \<longleftrightarrow> 0 < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   723
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   724
  by (cases n) simp_all
25140
273772abbea2 More changes from >0 to ~=0::nat
nipkow
parents: 25134
diff changeset
   725
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   726
text \<open>This theorem is useful with \<open>blast\<close>\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   727
lemma gr0I: "(n = 0 \<Longrightarrow> False) \<Longrightarrow> 0 < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   728
  for n :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   729
  by (rule neq0_conv[THEN iffD1]) iprover
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   730
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   731
lemma gr0_conv_Suc: "0 < n \<longleftrightarrow> (\<exists>m. n = Suc m)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   732
  by (fast intro: not0_implies_Suc)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   733
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   734
lemma not_gr0 [iff]: "\<not> 0 < n \<longleftrightarrow> n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   735
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   736
  using neq0_conv by blast
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   737
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   738
lemma Suc_le_D: "Suc n \<le> m' \<Longrightarrow> \<exists>m. m' = Suc m"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   739
  by (induct m') simp_all
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   740
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   741
text \<open>Useful in certain inductive arguments\<close>
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   742
lemma less_Suc_eq_0_disj: "m < Suc n \<longleftrightarrow> m = 0 \<or> (\<exists>j. m = Suc j \<and> j < n)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   743
  by (cases m) simp_all
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   744
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   745
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   746
subsubsection \<open>Monotonicity of Addition\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   747
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   748
lemma Suc_pred [simp]: "n > 0 \<Longrightarrow> Suc (n - Suc 0) = n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   749
  by (simp add: diff_Suc split: nat.split)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   750
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   751
lemma Suc_diff_1 [simp]: "0 < n \<Longrightarrow> Suc (n - 1) = n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   752
  unfolding One_nat_def by (rule Suc_pred)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   753
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   754
lemma nat_add_left_cancel_le [simp]: "k + m \<le> k + n \<longleftrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   755
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   756
  by (induct k) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   757
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   758
lemma nat_add_left_cancel_less [simp]: "k + m < k + n \<longleftrightarrow> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   759
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   760
  by (induct k) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   761
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   762
lemma add_gr_0 [iff]: "m + n > 0 \<longleftrightarrow> m > 0 \<or> n > 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   763
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   764
  by (auto dest: gr0_implies_Suc)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
   765
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   766
text \<open>strict, in 1st argument\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   767
lemma add_less_mono1: "i < j \<Longrightarrow> i + k < j + k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   768
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   769
  by (induct k) simp_all
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   770
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   771
text \<open>strict, in both arguments\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   772
lemma add_less_mono: "i < j \<Longrightarrow> k < l \<Longrightarrow> i + k < j + l"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   773
  for i j k l :: nat
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   774
  apply (rule add_less_mono1 [THEN less_trans], assumption+)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   775
  apply (induct j)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   776
   apply simp_all
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   777
  done
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   778
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   779
text \<open>Deleted \<open>less_natE\<close>; use \<open>less_imp_Suc_add RS exE\<close>\<close>
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   780
lemma less_imp_Suc_add: "m < n \<Longrightarrow> \<exists>k. n = Suc (m + k)"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   781
proof (induct n)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   782
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   783
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   784
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   785
  case Suc
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   786
  then show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   787
    by (simp add: order_le_less)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   788
      (blast elim!: less_SucE intro!: Nat.add_0_right [symmetric] add_Suc_right [symmetric])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   789
qed
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   790
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   791
lemma le_Suc_ex: "k \<le> l \<Longrightarrow> (\<exists>n. l = k + n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   792
  for k l :: nat
56194
9ffbb4004c81 fix HOL-NSA; move lemmas
hoelzl
parents: 56020
diff changeset
   793
  by (auto simp: less_Suc_eq_le[symmetric] dest: less_imp_Suc_add)
9ffbb4004c81 fix HOL-NSA; move lemmas
hoelzl
parents: 56020
diff changeset
   794
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
   795
text \<open>strict, in 1st argument; proof is by induction on \<open>k > 0\<close>\<close>
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   796
lemma mult_less_mono2:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   797
  fixes i j :: nat
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   798
  assumes "i < j" and "0 < k"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   799
  shows "k * i < k * j"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   800
  using \<open>0 < k\<close>
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   801
proof (induct k)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   802
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   803
  then show ?case by simp
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   804
next
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   805
  case (Suc k)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   806
  with \<open>i < j\<close> show ?case
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   807
    by (cases k) (simp_all add: add_less_mono)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
   808
qed
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   809
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   810
text \<open>Addition is the inverse of subtraction:
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   811
  if @{term "n \<le> m"} then @{term "n + (m - n) = m"}.\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   812
lemma add_diff_inverse_nat: "\<not> m < n \<Longrightarrow> n + (m - n) = m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   813
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   814
  by (induct m n rule: diff_induct) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   815
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   816
lemma nat_le_iff_add: "m \<le> n \<longleftrightarrow> (\<exists>k. n = m + k)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   817
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   818
  using nat_add_left_cancel_le[of m 0] by (auto dest: le_Suc_ex)
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   819
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   820
text \<open>The naturals form an ordered \<open>semidom\<close> and a \<open>dioid\<close>.\<close>
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   821
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34208
diff changeset
   822
instance nat :: linordered_semidom
14341
a09441bd4f1e Ring_and_Field now requires axiom add_left_imp_eq for semirings.
paulson
parents: 14331
diff changeset
   823
proof
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   824
  fix m n q :: nat
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   825
  show "0 < (1::nat)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   826
    by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   827
  show "m \<le> n \<Longrightarrow> q + m \<le> q + n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   828
    by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   829
  show "m < n \<Longrightarrow> 0 < q \<Longrightarrow> q * m < q * n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   830
    by (simp add: mult_less_mono2)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   831
  show "m \<noteq> 0 \<Longrightarrow> n \<noteq> 0 \<Longrightarrow> m * n \<noteq> 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   832
    by simp
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   833
  show "n \<le> m \<Longrightarrow> (m - n) + n = m"
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
   834
    by (simp add: add_diff_inverse_nat add.commute linorder_not_less)
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   835
qed
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   836
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   837
instance nat :: dioid
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   838
  by standard (rule nat_le_iff_add)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   839
63145
703edebd1d92 isabelle update_cartouches -c -t;
wenzelm
parents: 63113
diff changeset
   840
declare le0[simp del] \<comment> \<open>This is now @{thm zero_le}\<close>
703edebd1d92 isabelle update_cartouches -c -t;
wenzelm
parents: 63113
diff changeset
   841
declare le_0_eq[simp del] \<comment> \<open>This is now @{thm le_zero_eq}\<close>
703edebd1d92 isabelle update_cartouches -c -t;
wenzelm
parents: 63113
diff changeset
   842
declare not_less0[simp del] \<comment> \<open>This is now @{thm not_less_zero}\<close>
703edebd1d92 isabelle update_cartouches -c -t;
wenzelm
parents: 63113
diff changeset
   843
declare not_gr0[simp del] \<comment> \<open>This is now @{thm not_gr_zero}\<close>
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
   844
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   845
instance nat :: ordered_cancel_comm_monoid_add ..
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   846
instance nat :: ordered_cancel_comm_monoid_diff ..
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   847
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   848
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   849
subsubsection \<open>@{term min} and @{term max}\<close>
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   850
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   851
lemma mono_Suc: "mono Suc"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   852
  by (rule monoI) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   853
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   854
lemma min_0L [simp]: "min 0 n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   855
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   856
  by (rule min_absorb1) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   857
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   858
lemma min_0R [simp]: "min n 0 = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   859
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   860
  by (rule min_absorb2) simp
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   861
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   862
lemma min_Suc_Suc [simp]: "min (Suc m) (Suc n) = Suc (min m n)"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   863
  by (simp add: mono_Suc min_of_mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   864
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   865
lemma min_Suc1: "min (Suc n) m = (case m of 0 \<Rightarrow> 0 | Suc m' \<Rightarrow> Suc(min n m'))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   866
  by (simp split: nat.split)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   867
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   868
lemma min_Suc2: "min m (Suc n) = (case m of 0 \<Rightarrow> 0 | Suc m' \<Rightarrow> Suc(min m' n))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   869
  by (simp split: nat.split)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   870
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   871
lemma max_0L [simp]: "max 0 n = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   872
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   873
  by (rule max_absorb2) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   874
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   875
lemma max_0R [simp]: "max n 0 = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   876
  for n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   877
  by (rule max_absorb1) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   878
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   879
lemma max_Suc_Suc [simp]: "max (Suc m) (Suc n) = Suc (max m n)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   880
  by (simp add: mono_Suc max_of_mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   881
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   882
lemma max_Suc1: "max (Suc n) m = (case m of 0 \<Rightarrow> Suc n | Suc m' \<Rightarrow> Suc (max n m'))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   883
  by (simp split: nat.split)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   884
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   885
lemma max_Suc2: "max m (Suc n) = (case m of 0 \<Rightarrow> Suc n | Suc m' \<Rightarrow> Suc (max m' n))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   886
  by (simp split: nat.split)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   887
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   888
lemma nat_mult_min_left: "min m n * q = min (m * q) (n * q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   889
  for m n q :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   890
  by (simp add: min_def not_le)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   891
    (auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   892
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   893
lemma nat_mult_min_right: "m * min n q = min (m * n) (m * q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   894
  for m n q :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   895
  by (simp add: min_def not_le)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   896
    (auto dest: mult_left_le_imp_le mult_left_less_imp_less le_less_trans)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   897
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   898
lemma nat_add_max_left: "max m n + q = max (m + q) (n + q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   899
  for m n q :: nat
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   900
  by (simp add: max_def)
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   901
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   902
lemma nat_add_max_right: "m + max n q = max (m + n) (m + q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   903
  for m n q :: nat
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   904
  by (simp add: max_def)
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
   905
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   906
lemma nat_mult_max_left: "max m n * q = max (m * q) (n * q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   907
  for m n q :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   908
  by (simp add: max_def not_le)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   909
    (auto dest: mult_right_le_imp_le mult_right_less_imp_less le_less_trans)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   910
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   911
lemma nat_mult_max_right: "m * max n q = max (m * n) (m * q)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   912
  for m n q :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   913
  by (simp add: max_def not_le)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   914
    (auto dest: mult_left_le_imp_le mult_left_less_imp_less le_less_trans)
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
   915
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
   916
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   917
subsubsection \<open>Additional theorems about @{term "op \<le>"}\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   918
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
   919
text \<open>Complete induction, aka course-of-values induction\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   920
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   921
instance nat :: wellorder
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   922
proof
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   923
  fix P and n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   924
  assume step: "(\<And>m. m < n \<Longrightarrow> P m) \<Longrightarrow> P n" for n :: nat
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   925
  have "\<And>q. q \<le> n \<Longrightarrow> P q"
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   926
  proof (induct n)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   927
    case (0 n)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   928
    have "P 0" by (rule step) auto
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   929
    with 0 show ?case by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   930
  next
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   931
    case (Suc m n)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   932
    then have "n \<le> m \<or> n = Suc m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   933
      by (simp add: le_Suc_eq)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   934
    then show ?case
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   935
    proof
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   936
      assume "n \<le> m"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   937
      then show "P n" by (rule Suc(1))
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   938
    next
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   939
      assume n: "n = Suc m"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   940
      show "P n" by (rule step) (rule Suc(1), simp add: n le_simps)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   941
    qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   942
  qed
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   943
  then show "P n" by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   944
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   945
57015
842bb6d36263 added lemma
nipkow
parents: 56194
diff changeset
   946
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   947
lemma Least_eq_0[simp]: "P 0 \<Longrightarrow> Least P = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   948
  for P :: "nat \<Rightarrow> bool"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   949
  by (rule Least_equality[OF _ le0])
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   950
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   951
lemma Least_Suc: "P n \<Longrightarrow> \<not> P 0 \<Longrightarrow> (LEAST n. P n) = Suc (LEAST m. P (Suc m))"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   952
  apply (cases n)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   953
   apply auto
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   954
  apply (frule LeastI)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   955
  apply (drule_tac P = "\<lambda>x. P (Suc x)" in LeastI)
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   956
  apply (subgoal_tac " (LEAST x. P x) \<le> Suc (LEAST x. P (Suc x))")
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   957
   apply (erule_tac [2] Least_le)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   958
  apply (cases "LEAST x. P x")
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   959
   apply auto
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   960
  apply (drule_tac P = "\<lambda>x. P (Suc x)" in Least_le)
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   961
  apply (blast intro: order_antisym)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   962
  done
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   963
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   964
lemma Least_Suc2: "P n \<Longrightarrow> Q m \<Longrightarrow> \<not> P 0 \<Longrightarrow> \<forall>k. P (Suc k) = Q k \<Longrightarrow> Least P = Suc (Least Q)"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   965
  by (erule (1) Least_Suc [THEN ssubst]) simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   966
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   967
lemma ex_least_nat_le: "\<not> P 0 \<Longrightarrow> P n \<Longrightarrow> \<exists>k\<le>n. (\<forall>i<k. \<not> P i) \<and> P k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   968
  for P :: "nat \<Rightarrow> bool"
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   969
  apply (cases n)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   970
   apply blast
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   971
  apply (rule_tac x="LEAST k. P k" in exI)
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   972
  apply (blast intro: Least_le dest: not_less_Least intro: LeastI_ex)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   973
  done
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   974
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   975
lemma ex_least_nat_less: "\<not> P 0 \<Longrightarrow> P n \<Longrightarrow> \<exists>k<n. (\<forall>i\<le>k. \<not> P i) \<and> P (k + 1)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   976
  for P :: "nat \<Rightarrow> bool"
27823
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   977
  apply (cases n)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   978
   apply blast
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   979
  apply (frule (1) ex_least_nat_le)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   980
  apply (erule exE)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   981
  apply (case_tac k)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   982
   apply simp
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   983
  apply (rename_tac k1)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   984
  apply (rule_tac x=k1 in exI)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   985
  apply (auto simp add: less_eq_Suc_le)
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   986
  done
52971512d1a2 moved class wellorder to theory Orderings
haftmann
parents: 27789
diff changeset
   987
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   988
lemma nat_less_induct:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   989
  fixes P :: "nat \<Rightarrow> bool"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   990
  assumes "\<And>n. \<forall>m. m < n \<longrightarrow> P m \<Longrightarrow> P n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   991
  shows "P n"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   992
  using assms less_induct by blast
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   993
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   994
lemma measure_induct_rule [case_names less]:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   995
  fixes f :: "'a \<Rightarrow> nat"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   996
  assumes step: "\<And>x. (\<And>y. f y < f x \<Longrightarrow> P y) \<Longrightarrow> P x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   997
  shows "P a"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
   998
  by (induct m \<equiv> "f a" arbitrary: a rule: less_induct) (auto intro: step)
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
   999
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1000
text \<open>old style induction rules:\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1001
lemma measure_induct:
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1002
  fixes f :: "'a \<Rightarrow> nat"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1003
  shows "(\<And>x. \<forall>y. f y < f x \<longrightarrow> P y \<Longrightarrow> P x) \<Longrightarrow> P a"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1004
  by (rule measure_induct_rule [of f P a]) iprover
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1005
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1006
lemma full_nat_induct:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1007
  assumes step: "\<And>n. (\<forall>m. Suc m \<le> n \<longrightarrow> P m) \<Longrightarrow> P n"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1008
  shows "P n"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1009
  by (rule less_induct) (auto intro: step simp:le_simps)
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
  1010
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1011
text\<open>An induction rule for establishing binary relations\<close>
62683
ddd1c864408b clarified rule structure;
wenzelm
parents: 62608
diff changeset
  1012
lemma less_Suc_induct [consumes 1]:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1013
  assumes less: "i < j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1014
    and step: "\<And>i. P i (Suc i)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1015
    and trans: "\<And>i j k. i < j \<Longrightarrow> j < k \<Longrightarrow> P i j \<Longrightarrow> P j k \<Longrightarrow> P i k"
19870
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1016
  shows "P i j"
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1017
proof -
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1018
  from less obtain k where j: "j = Suc (i + k)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1019
    by (auto dest: less_imp_Suc_add)
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1020
  have "P i (Suc (i + k))"
19870
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1021
  proof (induct k)
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1022
    case 0
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1023
    show ?case by (simp add: step)
19870
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1024
  next
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1025
    case (Suc k)
31714
347e9d18f372 generalized less_Suc_induct
krauss
parents: 31155
diff changeset
  1026
    have "0 + i < Suc k + i" by (rule add_less_mono1) simp
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1027
    then have "i < Suc (i + k)" by (simp add: add.commute)
31714
347e9d18f372 generalized less_Suc_induct
krauss
parents: 31155
diff changeset
  1028
    from trans[OF this lessI Suc step]
347e9d18f372 generalized less_Suc_induct
krauss
parents: 31155
diff changeset
  1029
    show ?case by simp
19870
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1030
  qed
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1031
  then show "P i j" by (simp add: j)
19870
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1032
qed
ef037d1b32d1 new results
paulson
parents: 19573
diff changeset
  1033
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1034
text \<open>
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1035
  The method of infinite descent, frequently used in number theory.
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1036
  Provided by Roelof Oosterhuis.
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1037
  \<open>P n\<close> is true for all natural numbers if
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1038
  \<^item> case ``0'': given \<open>n = 0\<close> prove \<open>P n\<close>
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1039
  \<^item> case ``smaller'': given \<open>n > 0\<close> and \<open>\<not> P n\<close> prove there exists
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1040
    a smaller natural number \<open>m\<close> such that \<open>\<not> P m\<close>.
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1041
\<close>
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1042
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1043
lemma infinite_descent: "(\<And>n. \<not> P n \<Longrightarrow> \<exists>m<n. \<not> P m) \<Longrightarrow> P n" for P :: "nat \<Rightarrow> bool"
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1044
  \<comment> \<open>compact version without explicit base case\<close>
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1045
  by (induct n rule: less_induct) auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1046
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1047
lemma infinite_descent0 [case_names 0 smaller]:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1048
  fixes P :: "nat \<Rightarrow> bool"
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1049
  assumes "P 0"
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1050
    and "\<And>n. n > 0 \<Longrightarrow> \<not> P n \<Longrightarrow> \<exists>m. m < n \<and> \<not> P m"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1051
  shows "P n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1052
  apply (rule infinite_descent)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1053
  using assms
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1054
  apply (case_tac "n > 0")
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1055
   apply auto
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1056
  done
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1057
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1058
text \<open>
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1059
  Infinite descent using a mapping to \<open>nat\<close>:
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1060
  \<open>P x\<close> is true for all \<open>x \<in> D\<close> if there exists a \<open>V \<in> D \<Rightarrow> nat\<close> and
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1061
  \<^item> case ``0'': given \<open>V x = 0\<close> prove \<open>P x\<close>
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1062
  \<^item> ``smaller'': given \<open>V x > 0\<close> and \<open>\<not> P x\<close> prove
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1063
  there exists a \<open>y \<in> D\<close> such that \<open>V y < V x\<close> and \<open>\<not> P y\<close>.
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1064
\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1065
corollary infinite_descent0_measure [case_names 0 smaller]:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1066
  fixes V :: "'a \<Rightarrow> nat"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1067
  assumes 1: "\<And>x. V x = 0 \<Longrightarrow> P x"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1068
    and 2: "\<And>x. V x > 0 \<Longrightarrow> \<not> P x \<Longrightarrow> \<exists>y. V y < V x \<and> \<not> P y"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1069
  shows "P x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1070
proof -
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1071
  obtain n where "n = V x" by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1072
  moreover have "\<And>x. V x = n \<Longrightarrow> P x"
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1073
  proof (induct n rule: infinite_descent0)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1074
    case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1075
    with 1 show "P x" by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1076
  next
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1077
    case (smaller n)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1078
    then obtain x where *: "V x = n " and "V x > 0 \<and> \<not> P x" by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1079
    with 2 obtain y where "V y < V x \<and> \<not> P y" by auto
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1080
    with * obtain m where "m = V y \<and> m < n \<and> \<not> P y" by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1081
    then show ?case by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1082
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1083
  ultimately show "P x" by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1084
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1085
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1086
text \<open>Again, without explicit base case:\<close>
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1087
lemma infinite_descent_measure:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1088
  fixes V :: "'a \<Rightarrow> nat"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1089
  assumes "\<And>x. \<not> P x \<Longrightarrow> \<exists>y. V y < V x \<and> \<not> P y"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1090
  shows "P x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1091
proof -
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1092
  from assms obtain n where "n = V x" by auto
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1093
  moreover have "\<And>x. V x = n \<Longrightarrow> P x"
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1094
  proof (induct n rule: infinite_descent, auto)
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1095
    show "\<exists>m < V x. \<exists>y. V y = m \<and> \<not> P y" if "\<not> P x" for x
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1096
      using assms and that by auto
26748
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1097
  qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1098
  ultimately show "P x" by auto
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1099
qed
4d51ddd6aa5c Merged theories about wellfoundedness into one: Wellfounded.thy
krauss
parents: 26335
diff changeset
  1100
63111
caa0c513bbca tuned document;
wenzelm
parents: 63110
diff changeset
  1101
text \<open>A (clumsy) way of lifting \<open><\<close> monotonicity to \<open>\<le>\<close> monotonicity\<close>
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
  1102
lemma less_mono_imp_le_mono:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1103
  fixes f :: "nat \<Rightarrow> nat"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1104
    and i j :: nat
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1105
  assumes "\<And>i j::nat. i < j \<Longrightarrow> f i < f j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1106
    and "i \<le> j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1107
  shows "f i \<le> f j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1108
  using assms by (auto simp add: order_le_less)
24438
2d8058804a76 Added infinite_descent
nipkow
parents: 24286
diff changeset
  1109
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
  1110
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1111
text \<open>non-strict, in 1st argument\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1112
lemma add_le_mono1: "i \<le> j \<Longrightarrow> i + k \<le> j + k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1113
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1114
  by (rule add_right_mono)
14267
b963e9cee2a0 More refinements to Ring_and_Field and numerics. Conversion of Divides_lemmas
paulson
parents: 14266
diff changeset
  1115
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1116
text \<open>non-strict, in both arguments\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1117
lemma add_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i + k \<le> j + l"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1118
  for i j k l :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1119
  by (rule add_mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1120
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1121
lemma le_add2: "n \<le> m + n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1122
  for m n :: nat
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62502
diff changeset
  1123
  by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1124
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1125
lemma le_add1: "n \<le> n + m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1126
  for m n :: nat
62608
19f87fa0cfcb more theorems on orderings
haftmann
parents: 62502
diff changeset
  1127
  by simp
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1128
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1129
lemma less_add_Suc1: "i < Suc (i + m)"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1130
  by (rule le_less_trans, rule le_add1, rule lessI)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1131
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1132
lemma less_add_Suc2: "i < Suc (m + i)"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1133
  by (rule le_less_trans, rule le_add2, rule lessI)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1134
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1135
lemma less_iff_Suc_add: "m < n \<longleftrightarrow> (\<exists>k. n = Suc (m + k))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1136
  by (iprover intro!: less_add_Suc1 less_imp_Suc_add)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1137
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1138
lemma trans_le_add1: "i \<le> j \<Longrightarrow> i \<le> j + m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1139
  for i j m :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1140
  by (rule le_trans, assumption, rule le_add1)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1141
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1142
lemma trans_le_add2: "i \<le> j \<Longrightarrow> i \<le> m + j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1143
  for i j m :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1144
  by (rule le_trans, assumption, rule le_add2)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1145
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1146
lemma trans_less_add1: "i < j \<Longrightarrow> i < j + m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1147
  for i j m :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1148
  by (rule less_le_trans, assumption, rule le_add1)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1149
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1150
lemma trans_less_add2: "i < j \<Longrightarrow> i < m + j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1151
  for i j m :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1152
  by (rule less_le_trans, assumption, rule le_add2)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1153
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1154
lemma add_lessD1: "i + j < k \<Longrightarrow> i < k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1155
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1156
  by (rule le_less_trans [of _ "i+j"]) (simp_all add: le_add1)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1157
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1158
lemma not_add_less1 [iff]: "\<not> i + j < i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1159
  for i j :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1160
  apply (rule notI)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1161
  apply (drule add_lessD1)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1162
  apply (erule less_irrefl [THEN notE])
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1163
  done
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1164
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1165
lemma not_add_less2 [iff]: "\<not> j + i < i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1166
  for i j :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1167
  by (simp add: add.commute)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1168
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1169
lemma add_leD1: "m + k \<le> n \<Longrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1170
  for k m n :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1171
  by (rule order_trans [of _ "m + k"]) (simp_all add: le_add1)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1172
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1173
lemma add_leD2: "m + k \<le> n \<Longrightarrow> k \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1174
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1175
  apply (simp add: add.commute)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1176
  apply (erule add_leD1)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1177
  done
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1178
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1179
lemma add_leE: "m + k \<le> n \<Longrightarrow> (m \<le> n \<Longrightarrow> k \<le> n \<Longrightarrow> R) \<Longrightarrow> R"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1180
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1181
  by (blast dest: add_leD1 add_leD2)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1182
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1183
text \<open>needs \<open>\<And>k\<close> for \<open>ac_simps\<close> to work\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1184
lemma less_add_eq_less: "\<And>k. k < l \<Longrightarrow> m + l = k + n \<Longrightarrow> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1185
  for l m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1186
  by (force simp del: add_Suc_right simp add: less_iff_Suc_add add_Suc_right [symmetric] ac_simps)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1187
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1188
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1189
subsubsection \<open>More results about difference\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1190
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1191
lemma Suc_diff_le: "n \<le> m \<Longrightarrow> Suc m - n = Suc (m - n)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1192
  by (induct m n rule: diff_induct) simp_all
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1193
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1194
lemma diff_less_Suc: "m - n < Suc m"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1195
  apply (induct m n rule: diff_induct)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1196
    apply (erule_tac [3] less_SucE)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1197
     apply (simp_all add: less_Suc_eq)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1198
  done
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1199
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1200
lemma diff_le_self [simp]: "m - n \<le> m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1201
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1202
  by (induct m n rule: diff_induct) (simp_all add: le_SucI)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1203
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1204
lemma less_imp_diff_less: "j < k \<Longrightarrow> j - n < k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1205
  for j k n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1206
  by (rule le_less_trans, rule diff_le_self)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1207
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1208
lemma diff_Suc_less [simp]: "0 < n \<Longrightarrow> n - Suc i < n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1209
  by (cases n) (auto simp add: le_simps)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1210
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1211
lemma diff_add_assoc: "k \<le> j \<Longrightarrow> (i + j) - k = i + (j - k)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1212
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1213
  by (induct j k rule: diff_induct) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1214
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1215
lemma add_diff_assoc [simp]: "k \<le> j \<Longrightarrow> i + (j - k) = i + j - k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1216
  for i j k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1217
  by (fact diff_add_assoc [symmetric])
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1218
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1219
lemma diff_add_assoc2: "k \<le> j \<Longrightarrow> (j + i) - k = (j - k) + i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1220
  for i j k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1221
  by (simp add: ac_simps)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1222
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1223
lemma add_diff_assoc2 [simp]: "k \<le> j \<Longrightarrow> j - k + i = j + i - k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1224
  for i j k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1225
  by (fact diff_add_assoc2 [symmetric])
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1226
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1227
lemma le_imp_diff_is_add: "i \<le> j \<Longrightarrow> (j - i = k) = (j = k + i)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1228
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1229
  by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1230
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1231
lemma diff_is_0_eq [simp]: "m - n = 0 \<longleftrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1232
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1233
  by (induct m n rule: diff_induct) simp_all
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1234
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1235
lemma diff_is_0_eq' [simp]: "m \<le> n \<Longrightarrow> m - n = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1236
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1237
  by (rule iffD2, rule diff_is_0_eq)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1238
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1239
lemma zero_less_diff [simp]: "0 < n - m \<longleftrightarrow> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1240
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1241
  by (induct m n rule: diff_induct) simp_all
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1242
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1243
lemma less_imp_add_positive:
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1244
  assumes "i < j"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1245
  shows "\<exists>k::nat. 0 < k \<and> i + k = j"
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1246
proof
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1247
  from assms show "0 < j - i \<and> i + (j - i) = j"
23476
839db6346cc8 fix looping simp rule
huffman
parents: 23438
diff changeset
  1248
    by (simp add: order_less_imp_le)
22718
936f7580937d tuned proofs;
wenzelm
parents: 22483
diff changeset
  1249
qed
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents: 7702
diff changeset
  1250
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1251
text \<open>a nice rewrite for bounded subtraction\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1252
lemma nat_minus_add_max: "n - m + m = max n m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1253
  for m n :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1254
  by (simp add: max_def not_le order_less_imp_le)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1255
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1256
lemma nat_diff_split: "P (a - b) \<longleftrightarrow> (a < b \<longrightarrow> P 0) \<and> (\<forall>d. a = b + d \<longrightarrow> P d)"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1257
  for a b :: nat
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1258
  \<comment> \<open>elimination of \<open>-\<close> on \<open>nat\<close>\<close>
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1259
  by (cases "a < b") (auto simp add: not_less le_less dest!: add_eq_self_zero [OF sym])
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1260
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1261
lemma nat_diff_split_asm: "P (a - b) \<longleftrightarrow> \<not> (a < b \<and> \<not> P 0 \<or> (\<exists>d. a = b + d \<and> \<not> P d))"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1262
  for a b :: nat
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1263
  \<comment> \<open>elimination of \<open>-\<close> on \<open>nat\<close> in assumptions\<close>
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  1264
  by (auto split: nat_diff_split)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1265
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1266
lemma Suc_pred': "0 < n \<Longrightarrow> n = Suc(n - 1)"
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1267
  by simp
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1268
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1269
lemma add_eq_if: "m + n = (if m = 0 then n else Suc ((m - 1) + n))"
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1270
  unfolding One_nat_def by (cases m) simp_all
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1271
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1272
lemma mult_eq_if: "m * n = (if m = 0 then 0 else n + ((m - 1) * n))"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1273
  for m n :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1274
  by (cases m) simp_all
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1275
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1276
lemma Suc_diff_eq_diff_pred: "0 < n \<Longrightarrow> Suc m - n = m - (n - 1)"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1277
  by (cases n) simp_all
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1278
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1279
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1280
  by (cases m) simp_all
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1281
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1282
lemma Let_Suc [simp]: "Let (Suc n) f \<equiv> f (Suc n)"
47255
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1283
  by (fact Let_def)
30a1692557b0 removed Nat_Numeral.thy, moving all theorems elsewhere
huffman
parents: 47208
diff changeset
  1284
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1285
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1286
subsubsection \<open>Monotonicity of multiplication\<close>
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1287
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1288
lemma mult_le_mono1: "i \<le> j \<Longrightarrow> i * k \<le> j * k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1289
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1290
  by (simp add: mult_right_mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1291
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1292
lemma mult_le_mono2: "i \<le> j \<Longrightarrow> k * i \<le> k * j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1293
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1294
  by (simp add: mult_left_mono)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1295
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
  1296
text \<open>\<open>\<le>\<close> monotonicity, BOTH arguments\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1297
lemma mult_le_mono: "i \<le> j \<Longrightarrow> k \<le> l \<Longrightarrow> i * k \<le> j * l"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1298
  for i j k l :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1299
  by (simp add: mult_mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1300
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1301
lemma mult_less_mono1: "i < j \<Longrightarrow> 0 < k \<Longrightarrow> i * k < j * k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1302
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1303
  by (simp add: mult_strict_right_mono)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1304
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1305
text \<open>Differs from the standard \<open>zero_less_mult_iff\<close> in that there are no negative numbers.\<close>
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1306
lemma nat_0_less_mult_iff [simp]: "0 < m * n \<longleftrightarrow> 0 < m \<and> 0 < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1307
  for m n :: nat
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1308
proof (induct m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1309
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1310
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1311
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1312
  case (Suc m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1313
  then show ?case by (cases n) simp_all
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1314
qed
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1315
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1316
lemma one_le_mult_iff [simp]: "Suc 0 \<le> m * n \<longleftrightarrow> Suc 0 \<le> m \<and> Suc 0 \<le> n"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1317
proof (induct m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1318
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1319
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1320
next
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1321
  case (Suc m)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1322
  then show ?case by (cases n) simp_all
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1323
qed
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1324
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1325
lemma mult_less_cancel2 [simp]: "m * k < n * k \<longleftrightarrow> 0 < k \<and> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1326
  for k m n :: nat
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1327
  apply (safe intro!: mult_less_mono1)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1328
   apply (cases k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1329
    apply auto
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1330
  apply (simp add: linorder_not_le [symmetric])
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1331
  apply (blast intro: mult_le_mono1)
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1332
  done
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1333
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1334
lemma mult_less_cancel1 [simp]: "k * m < k * n \<longleftrightarrow> 0 < k \<and> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1335
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1336
  by (simp add: mult.commute [of k])
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1337
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1338
lemma mult_le_cancel1 [simp]: "k * m \<le> k * n \<longleftrightarrow> (0 < k \<longrightarrow> m \<le> n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1339
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1340
  by (simp add: linorder_not_less [symmetric], auto)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1341
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1342
lemma mult_le_cancel2 [simp]: "m * k \<le> n * k \<longleftrightarrow> (0 < k \<longrightarrow> m \<le> n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1343
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1344
  by (simp add: linorder_not_less [symmetric], auto)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1345
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1346
lemma Suc_mult_less_cancel1: "Suc k * m < Suc k * n \<longleftrightarrow> m < n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1347
  by (subst mult_less_cancel1) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1348
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1349
lemma Suc_mult_le_cancel1: "Suc k * m \<le> Suc k * n \<longleftrightarrow> m \<le> n"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1350
  by (subst mult_le_cancel1) simp
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1351
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1352
lemma le_square: "m \<le> m * m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1353
  for m :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1354
  by (cases m) (auto intro: le_add1)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1355
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1356
lemma le_cube: "m \<le> m * (m * m)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1357
  for m :: nat
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1358
  by (cases m) (auto intro: le_add1)
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1359
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
  1360
text \<open>Lemma for \<open>gcd\<close>\<close>
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1361
lemma mult_eq_self_implies_10: "m = m * n \<Longrightarrow> n = 1 \<or> m = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1362
  for m n :: nat
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1363
  apply (drule sym)
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1364
  apply (rule disjCI)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1365
  apply (rule linorder_cases)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1366
    defer
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1367
    apply assumption
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1368
   apply (drule mult_less_mono2)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1369
    apply auto
13449
43c9ec498291 - Converted to new theory format
berghofe
parents: 12338
diff changeset
  1370
  done
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents: 7702
diff changeset
  1371
51263
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1372
lemma mono_times_nat:
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1373
  fixes n :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1374
  assumes "n > 0"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1375
  shows "mono (times n)"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1376
proof
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1377
  fix m q :: nat
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1378
  assume "m \<le> q"
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1379
  with assms show "n * m \<le> n * q" by simp
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1380
qed
31e786e0e6a7 turned example into library for comparing growth of functions
haftmann
parents: 51173
diff changeset
  1381
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1382
text \<open>The lattice order on @{typ nat}.\<close>
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
  1383
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1384
instantiation nat :: distrib_lattice
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1385
begin
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
  1386
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1387
definition "(inf :: nat \<Rightarrow> nat \<Rightarrow> nat) = min"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1388
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1389
definition "(sup :: nat \<Rightarrow> nat \<Rightarrow> nat) = max"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1390
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1391
instance
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1392
  by intro_classes
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1393
    (auto simp add: inf_nat_def sup_nat_def max_def not_le min_def
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1394
      intro: order_less_imp_le antisym elim!: order_trans order_less_trans)
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
  1395
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1396
end
24995
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
  1397
c26e0166e568 refined; moved class power to theory Power
haftmann
parents: 24729
diff changeset
  1398
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1399
subsection \<open>Natural operation of natural numbers on functions\<close>
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1400
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1401
text \<open>
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1402
  We use the same logical constant for the power operations on
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1403
  functions and relations, in order to share the same syntax.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1404
\<close>
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1405
45965
2af982715e5c generalized type signature to permit overloading on `set`
haftmann
parents: 45933
diff changeset
  1406
consts compow :: "nat \<Rightarrow> 'a \<Rightarrow> 'a"
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1407
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1408
abbreviation compower :: "'a \<Rightarrow> nat \<Rightarrow> 'a" (infixr "^^" 80)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1409
  where "f ^^ n \<equiv> compow n f"
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1410
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1411
notation (latex output)
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1412
  compower ("(_\<^bsup>_\<^esup>)" [1000] 1000)
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1413
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1414
text \<open>\<open>f ^^ n = f \<circ> \<dots> \<circ> f\<close>, the \<open>n\<close>-fold composition of \<open>f\<close>\<close>
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1415
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1416
overloading
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1417
  funpow \<equiv> "compow :: nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a)"
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1418
begin
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1419
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1420
primrec funpow :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1421
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1422
    "funpow 0 f = id"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1423
  | "funpow (Suc n) f = f \<circ> funpow n f"
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1424
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1425
end
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1426
62217
527488dc8b90 Reorganised a huge proof
paulson <lp15@cam.ac.uk>
parents: 61799
diff changeset
  1427
lemma funpow_0 [simp]: "(f ^^ 0) x = x"
527488dc8b90 Reorganised a huge proof
paulson <lp15@cam.ac.uk>
parents: 61799
diff changeset
  1428
  by simp
527488dc8b90 Reorganised a huge proof
paulson <lp15@cam.ac.uk>
parents: 61799
diff changeset
  1429
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1430
lemma funpow_Suc_right: "f ^^ Suc n = f ^^ n \<circ> f"
49723
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1431
proof (induct n)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1432
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1433
  then show ?case by simp
49723
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1434
next
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1435
  fix n
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1436
  assume "f ^^ Suc n = f ^^ n \<circ> f"
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1437
  then show "f ^^ Suc (Suc n) = f ^^ Suc n \<circ> f"
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1438
    by (simp add: o_assoc)
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1439
qed
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1440
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1441
lemmas funpow_simps_right = funpow.simps(1) funpow_Suc_right
bbc2942ba09f alternative simplification of ^^ to the righthand side;
haftmann
parents: 49388
diff changeset
  1442
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1443
text \<open>For code generation.\<close>
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1444
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1445
definition funpow :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1446
  where funpow_code_def [code_abbrev]: "funpow = compow"
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1447
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1448
lemma [code]:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1449
  "funpow (Suc n) f = f \<circ> funpow n f"
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1450
  "funpow 0 f = id"
37430
a77740fc3957 added lemma funpow_mult
haftmann
parents: 37387
diff changeset
  1451
  by (simp_all add: funpow_code_def)
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1452
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 35828
diff changeset
  1453
hide_const (open) funpow
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1454
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1455
lemma funpow_add: "f ^^ (m + n) = f ^^ m \<circ> f ^^ n"
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1456
  by (induct m) simp_all
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1457
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1458
lemma funpow_mult: "(f ^^ m) ^^ n = f ^^ (m * n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1459
  for f :: "'a \<Rightarrow> 'a"
37430
a77740fc3957 added lemma funpow_mult
haftmann
parents: 37387
diff changeset
  1460
  by (induct n) (simp_all add: funpow_add)
a77740fc3957 added lemma funpow_mult
haftmann
parents: 37387
diff changeset
  1461
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1462
lemma funpow_swap1: "f ((f ^^ n) x) = (f ^^ n) (f x)"
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1463
proof -
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1464
  have "f ((f ^^ n) x) = (f ^^ (n + 1)) x" by simp
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1465
  also have "\<dots>  = (f ^^ n \<circ> f ^^ 1) x" by (simp only: funpow_add)
30971
7fbebf75b3ef funpow and relpow with shared "^^" syntax
haftmann
parents: 30966
diff changeset
  1466
  also have "\<dots> = (f ^^ n) (f x)" by simp
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1467
  finally show ?thesis .
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1468
qed
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1469
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1470
lemma comp_funpow: "comp f ^^ n = comp (f ^^ n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1471
  for f :: "'a \<Rightarrow> 'a"
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1472
  by (induct n) simp_all
30954
cf50e67bc1d1 power operation on functions in theory Nat; power operation on relations in theory Transitive_Closure
haftmann
parents: 30686
diff changeset
  1473
54496
178922b63b58 add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents: 54411
diff changeset
  1474
lemma Suc_funpow[simp]: "Suc ^^ n = (op + n)"
178922b63b58 add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents: 54411
diff changeset
  1475
  by (induct n) simp_all
178922b63b58 add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents: 54411
diff changeset
  1476
178922b63b58 add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents: 54411
diff changeset
  1477
lemma id_funpow[simp]: "id ^^ n = id"
178922b63b58 add lemmas Suc_funpow and id_funpow to simpset; add lemma map_add_upt
hoelzl
parents: 54411
diff changeset
  1478
  by (induct n) simp_all
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1479
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1480
lemma funpow_mono: "mono f \<Longrightarrow> A \<le> B \<Longrightarrow> (f ^^ n) A \<le> (f ^^ n) B"
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1481
  for f :: "'a \<Rightarrow> ('a::order)"
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  1482
  by (induct n arbitrary: A B)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  1483
     (auto simp del: funpow.simps(2) simp add: funpow_Suc_right mono_def)
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  1484
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1485
lemma funpow_mono2:
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1486
  assumes "mono f"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1487
    and "i \<le> j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1488
    and "x \<le> y"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1489
    and "x \<le> f x"
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1490
  shows "(f ^^ i) x \<le> (f ^^ j) y"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1491
  using assms(2,3)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1492
proof (induct j arbitrary: y)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1493
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1494
  then show ?case by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1495
next
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1496
  case (Suc j)
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1497
  show ?case
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1498
  proof(cases "i = Suc j")
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1499
    case True
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1500
    with assms(1) Suc show ?thesis
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1501
      by (simp del: funpow.simps add: funpow_simps_right monoD funpow_mono)
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1502
  next
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1503
    case False
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1504
    with assms(1,4) Suc show ?thesis
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1505
      by (simp del: funpow.simps add: funpow_simps_right le_eq_less_or_eq less_Suc_eq_le)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1506
        (simp add: Suc.hyps monoD order_subst1)
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1507
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1508
qed
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1509
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1510
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1511
subsection \<open>Kleene iteration\<close>
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1512
52729
412c9e0381a1 factored syntactic type classes for bot and top (by Alessandro Coglio)
haftmann
parents: 52435
diff changeset
  1513
lemma Kleene_iter_lpfp:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1514
  fixes f :: "'a::order_bot \<Rightarrow> 'a"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1515
  assumes "mono f"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1516
    and "f p \<le> p"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1517
  shows "(f ^^ k) bot \<le> p"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1518
proof (induct k)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1519
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1520
  show ?case by simp
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1521
next
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1522
  case Suc
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1523
  show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1524
    using monoD[OF assms(1) Suc] assms(2) by simp
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1525
qed
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1526
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1527
lemma lfp_Kleene_iter:
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1528
  assumes "mono f"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1529
    and "(f ^^ Suc k) bot = (f ^^ k) bot"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1530
  shows "lfp f = (f ^^ k) bot"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1531
proof (rule antisym)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1532
  show "lfp f \<le> (f ^^ k) bot"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1533
  proof (rule lfp_lowerbound)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1534
    show "f ((f ^^ k) bot) \<le> (f ^^ k) bot"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1535
      using assms(2) by simp
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1536
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1537
  show "(f ^^ k) bot \<le> lfp f"
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1538
    using Kleene_iter_lpfp[OF assms(1)] lfp_unfold[OF assms(1)] by simp
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1539
qed
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1540
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1541
lemma mono_pow: "mono f \<Longrightarrow> mono (f ^^ n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1542
  for f :: "'a \<Rightarrow> 'a::complete_lattice"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1543
  by (induct n) (auto simp: mono_def)
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1544
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1545
lemma lfp_funpow:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1546
  assumes f: "mono f"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1547
  shows "lfp (f ^^ Suc n) = lfp f"
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1548
proof (rule antisym)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1549
  show "lfp f \<le> lfp (f ^^ Suc n)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1550
  proof (rule lfp_lowerbound)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1551
    have "f (lfp (f ^^ Suc n)) = lfp (\<lambda>x. f ((f ^^ n) x))"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1552
      unfolding funpow_Suc_right by (simp add: lfp_rolling f mono_pow comp_def)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1553
    then show "f (lfp (f ^^ Suc n)) \<le> lfp (f ^^ Suc n)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1554
      by (simp add: comp_def)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1555
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1556
  have "(f ^^ n) (lfp f) = lfp f" for n
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1557
    by (induct n) (auto intro: f lfp_unfold[symmetric])
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1558
  then show "lfp (f ^^ Suc n) \<le> lfp f"
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1559
    by (intro lfp_lowerbound) (simp del: funpow.simps)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1560
qed
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1561
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1562
lemma gfp_funpow:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1563
  assumes f: "mono f"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1564
  shows "gfp (f ^^ Suc n) = gfp f"
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1565
proof (rule antisym)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1566
  show "gfp f \<ge> gfp (f ^^ Suc n)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1567
  proof (rule gfp_upperbound)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1568
    have "f (gfp (f ^^ Suc n)) = gfp (\<lambda>x. f ((f ^^ n) x))"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1569
      unfolding funpow_Suc_right by (simp add: gfp_rolling f mono_pow comp_def)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1570
    then show "f (gfp (f ^^ Suc n)) \<ge> gfp (f ^^ Suc n)"
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1571
      by (simp add: comp_def)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1572
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1573
  have "(f ^^ n) (gfp f) = gfp f" for n
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1574
    by (induct n) (auto intro: f gfp_unfold[symmetric])
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1575
  then show "gfp (f ^^ Suc n) \<ge> gfp f"
60636
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1576
    by (intro gfp_upperbound) (simp del: funpow.simps)
ee18efe9b246 add named theorems order_continuous_intros; lfp/gfp_funpow; bounded variant for lfp/gfp transfer
hoelzl
parents: 60562
diff changeset
  1577
qed
45833
033cb3a668b9 lemmas about Kleene iteration
nipkow
parents: 45696
diff changeset
  1578
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1579
lemma Kleene_iter_gpfp:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1580
  fixes f :: "'a::order_top \<Rightarrow> 'a"
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1581
  assumes "mono f"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1582
    and "p \<le> f p"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1583
  shows "p \<le> (f ^^ k) top"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1584
proof (induct k)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1585
  case 0
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1586
  show ?case by simp
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1587
next
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1588
  case Suc
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1589
  show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1590
    using monoD[OF assms(1) Suc] assms(2) by simp
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1591
qed
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1592
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1593
lemma gfp_Kleene_iter:
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1594
  assumes "mono f"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1595
    and "(f ^^ Suc k) top = (f ^^ k) top"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1596
  shows "gfp f = (f ^^ k) top"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1597
    (is "?lhs = ?rhs")
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1598
proof (rule antisym)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1599
  have "?rhs \<le> f ?rhs"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1600
    using assms(2) by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1601
  then show "?rhs \<le> ?lhs"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1602
    by (rule gfp_upperbound)
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1603
  show "?lhs \<le> ?rhs"
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1604
    using Kleene_iter_gpfp[OF assms(1)] gfp_unfold[OF assms(1)] by simp
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1605
qed
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63197
diff changeset
  1606
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1607
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
  1608
subsection \<open>Embedding of the naturals into any \<open>semiring_1\<close>: @{term of_nat}\<close>
24196
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1609
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1610
context semiring_1
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1611
begin
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1612
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1613
definition of_nat :: "nat \<Rightarrow> 'a"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1614
  where "of_nat n = (plus 1 ^^ n) 0"
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1615
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1616
lemma of_nat_simps [simp]:
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1617
  shows of_nat_0: "of_nat 0 = 0"
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1618
    and of_nat_Suc: "of_nat (Suc m) = 1 + of_nat m"
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1619
  by (simp_all add: of_nat_def)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1620
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1621
lemma of_nat_1 [simp]: "of_nat 1 = 1"
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1622
  by (simp add: of_nat_def)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1623
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1624
lemma of_nat_add [simp]: "of_nat (m + n) = of_nat m + of_nat n"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
  1625
  by (induct m) (simp_all add: ac_simps)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1626
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61531
diff changeset
  1627
lemma of_nat_mult [simp]: "of_nat (m * n) = of_nat m * of_nat n"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
  1628
  by (induct m) (simp_all add: ac_simps distrib_right)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1629
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
  1630
lemma mult_of_nat_commute: "of_nat x * y = y * of_nat x"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1631
  by (induct x) (simp_all add: algebra_simps)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
  1632
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1633
primrec of_nat_aux :: "('a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> 'a"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1634
  where
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1635
    "of_nat_aux inc 0 i = i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1636
  | "of_nat_aux inc (Suc n) i = of_nat_aux inc n (inc i)" \<comment> \<open>tail recursive\<close>
25928
042e877d9841 tuned code setup
haftmann
parents: 25690
diff changeset
  1637
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1638
lemma of_nat_code: "of_nat n = of_nat_aux (\<lambda>i. i + 1) n 0"
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1639
proof (induct n)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1640
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1641
  then show ?case by simp
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1642
next
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1643
  case (Suc n)
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1644
  have "\<And>i. of_nat_aux (\<lambda>i. i + 1) n (i + 1) = of_nat_aux (\<lambda>i. i + 1) n i + 1"
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1645
    by (induct n) simp_all
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1646
  from this [of 0] have "of_nat_aux (\<lambda>i. i + 1) n 1 = of_nat_aux (\<lambda>i. i + 1) n 0 + 1"
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1647
    by simp
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1648
  with Suc show ?case
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1649
    by (simp add: add.commute)
28514
da83a614c454 tuned of_nat code generation
haftmann
parents: 27823
diff changeset
  1650
qed
30966
55104c664185 avoid local [code]
haftmann
parents: 30954
diff changeset
  1651
24196
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1652
end
f1dbfd7e3223 localized of_nat
haftmann
parents: 24162
diff changeset
  1653
45231
d85a2fdc586c replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
bulwahn
parents: 44890
diff changeset
  1654
declare of_nat_code [code]
30966
55104c664185 avoid local [code]
haftmann
parents: 30954
diff changeset
  1655
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1656
context ring_1
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1657
begin
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1658
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1659
lemma of_nat_diff: "n \<le> m \<Longrightarrow> of_nat (m - n) = of_nat m - of_nat n"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1660
  by (simp add: algebra_simps of_nat_add [symmetric])
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1661
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1662
end
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1663
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1664
text \<open>Class for unital semirings with characteristic zero.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1665
 Includes non-ordered rings like the complex numbers.\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1666
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1667
class semiring_char_0 = semiring_1 +
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1668
  assumes inj_of_nat: "inj of_nat"
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1669
begin
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1670
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1671
lemma of_nat_eq_iff [simp]: "of_nat m = of_nat n \<longleftrightarrow> m = n"
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1672
  by (auto intro: inj_of_nat injD)
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1673
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1674
text \<open>Special cases where either operand is zero\<close>
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1675
54147
97a8ff4e4ac9 killed most "no_atp", to make Sledgehammer more complete
blanchet
parents: 53986
diff changeset
  1676
lemma of_nat_0_eq_iff [simp]: "0 = of_nat n \<longleftrightarrow> 0 = n"
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1677
  by (fact of_nat_eq_iff [of 0 n, unfolded of_nat_0])
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1678
54147
97a8ff4e4ac9 killed most "no_atp", to make Sledgehammer more complete
blanchet
parents: 53986
diff changeset
  1679
lemma of_nat_eq_0_iff [simp]: "of_nat m = 0 \<longleftrightarrow> m = 0"
38621
d6cb7e625d75 more concise characterization of of_nat operation and class semiring_char_0
haftmann
parents: 37767
diff changeset
  1680
  by (fact of_nat_eq_iff [of m 0, unfolded of_nat_0])
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1681
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1682
lemma of_nat_neq_0 [simp]: "of_nat (Suc n) \<noteq> 0"
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 60175
diff changeset
  1683
  unfolding of_nat_eq_0_iff by simp
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 60175
diff changeset
  1684
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1685
lemma of_nat_0_neq [simp]: "0 \<noteq> of_nat (Suc n)"
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
  1686
  unfolding of_nat_0_eq_iff by simp
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
  1687
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1688
end
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1689
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1690
class ring_char_0 = ring_1 + semiring_char_0
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1691
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34208
diff changeset
  1692
context linordered_semidom
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1693
begin
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1694
47489
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1695
lemma of_nat_0_le_iff [simp]: "0 \<le> of_nat n"
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1696
  by (induct n) simp_all
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1697
47489
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1698
lemma of_nat_less_0_iff [simp]: "\<not> of_nat m < 0"
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1699
  by (simp add: not_less)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1700
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1701
lemma of_nat_less_iff [simp]: "of_nat m < of_nat n \<longleftrightarrow> m < n"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 62365
diff changeset
  1702
  by (induct m n rule: diff_induct) (simp_all add: add_pos_nonneg)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1703
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1704
lemma of_nat_le_iff [simp]: "of_nat m \<le> of_nat n \<longleftrightarrow> m \<le> n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1705
  by (simp add: not_less [symmetric] linorder_not_less [symmetric])
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1706
47489
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1707
lemma less_imp_of_nat_less: "m < n \<Longrightarrow> of_nat m < of_nat n"
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1708
  by simp
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1709
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1710
lemma of_nat_less_imp_less: "of_nat m < of_nat n \<Longrightarrow> m < n"
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1711
  by simp
04e7d09ade7a tuned some proofs;
huffman
parents: 47255
diff changeset
  1712
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1713
text \<open>Every \<open>linordered_semidom\<close> has characteristic zero.\<close>
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1714
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1715
subclass semiring_char_0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1716
  by standard (auto intro!: injI simp add: eq_iff)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1717
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1718
text \<open>Special cases where either operand is zero\<close>
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1719
54147
97a8ff4e4ac9 killed most "no_atp", to make Sledgehammer more complete
blanchet
parents: 53986
diff changeset
  1720
lemma of_nat_le_0_iff [simp]: "of_nat m \<le> 0 \<longleftrightarrow> m = 0"
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1721
  by (rule of_nat_le_iff [of _ 0, simplified])
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1722
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1723
lemma of_nat_0_less_iff [simp]: "0 < of_nat n \<longleftrightarrow> 0 < n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1724
  by (rule of_nat_less_iff [of 0, simplified])
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1725
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1726
end
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1727
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 34208
diff changeset
  1728
context linordered_idom
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1729
begin
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1730
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1731
lemma abs_of_nat [simp]: "\<bar>of_nat n\<bar> = of_nat n"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1732
  unfolding abs_if by auto
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1733
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1734
end
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1735
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1736
lemma of_nat_id [simp]: "of_nat n = n"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35121
diff changeset
  1737
  by (induct n) simp_all
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1738
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1739
lemma of_nat_eq_id [simp]: "of_nat = id"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
  1740
  by (auto simp add: fun_eq_iff)
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1741
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1742
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1743
subsection \<open>The set of natural numbers\<close>
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1744
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1745
context semiring_1
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1746
begin
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1747
61070
b72a990adfe2 prefer symbols;
wenzelm
parents: 60758
diff changeset
  1748
definition Nats :: "'a set"  ("\<nat>")
b72a990adfe2 prefer symbols;
wenzelm
parents: 60758
diff changeset
  1749
  where "\<nat> = range of_nat"
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1750
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1751
lemma of_nat_in_Nats [simp]: "of_nat n \<in> \<nat>"
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1752
  by (simp add: Nats_def)
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1753
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1754
lemma Nats_0 [simp]: "0 \<in> \<nat>"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1755
  apply (simp add: Nats_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1756
  apply (rule range_eqI)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1757
  apply (rule of_nat_0 [symmetric])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1758
  done
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1759
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1760
lemma Nats_1 [simp]: "1 \<in> \<nat>"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1761
  apply (simp add: Nats_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1762
  apply (rule range_eqI)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1763
  apply (rule of_nat_1 [symmetric])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1764
  done
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1765
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1766
lemma Nats_add [simp]: "a \<in> \<nat> \<Longrightarrow> b \<in> \<nat> \<Longrightarrow> a + b \<in> \<nat>"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1767
  apply (auto simp add: Nats_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1768
  apply (rule range_eqI)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1769
  apply (rule of_nat_add [symmetric])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1770
  done
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1771
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25928
diff changeset
  1772
lemma Nats_mult [simp]: "a \<in> \<nat> \<Longrightarrow> b \<in> \<nat> \<Longrightarrow> a * b \<in> \<nat>"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1773
  apply (auto simp add: Nats_def)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1774
  apply (rule range_eqI)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1775
  apply (rule of_nat_mult [symmetric])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1776
  done
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1777
35633
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1778
lemma Nats_cases [cases set: Nats]:
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1779
  assumes "x \<in> \<nat>"
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1780
  obtains (of_nat) n where "x = of_nat n"
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1781
  unfolding Nats_def
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1782
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1783
  from \<open>x \<in> \<nat>\<close> have "x \<in> range of_nat" unfolding Nats_def .
35633
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1784
  then obtain n where "x = of_nat n" ..
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1785
  then show thesis ..
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1786
qed
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1787
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1788
lemma Nats_induct [case_names of_nat, induct set: Nats]: "x \<in> \<nat> \<Longrightarrow> (\<And>n. P (of_nat n)) \<Longrightarrow> P x"
35633
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1789
  by (rule Nats_cases) auto
5da59c1ddece add lemmas Nats_cases and Nats_induct
huffman
parents: 35416
diff changeset
  1790
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1791
end
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1792
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  1793
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1794
subsection \<open>Further arithmetic facts concerning the natural numbers\<close>
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1795
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1796
lemma subst_equals:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1797
  assumes "t = s" and "u = t"
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1798
  shows "u = s"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1799
  using assms(2,1) by (rule trans)
22845
5f9138bcb3d7 changed code generator invocation syntax
haftmann
parents: 22744
diff changeset
  1800
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 48560
diff changeset
  1801
ML_file "Tools/nat_arith.ML"
48559
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1802
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1803
simproc_setup nateq_cancel_sums
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1804
  ("(l::nat) + m = n" | "(l::nat) = m + n" | "Suc m = n" | "m = Suc n") =
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1805
  \<open>fn phi => try o Nat_Arith.cancel_eq_conv\<close>
48559
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1806
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1807
simproc_setup natless_cancel_sums
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1808
  ("(l::nat) + m < n" | "(l::nat) < m + n" | "Suc m < n" | "m < Suc n") =
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1809
  \<open>fn phi => try o Nat_Arith.cancel_less_conv\<close>
48559
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1810
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1811
simproc_setup natle_cancel_sums
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1812
  ("(l::nat) + m \<le> n" | "(l::nat) \<le> m + n" | "Suc m \<le> n" | "m \<le> Suc n") =
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1813
  \<open>fn phi => try o Nat_Arith.cancel_le_conv\<close>
48559
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1814
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1815
simproc_setup natdiff_cancel_sums
686cc7c47589 give Nat_Arith simprocs proper name bindings by using simproc_setup
huffman
parents: 47988
diff changeset
  1816
  ("(l::nat) + m - n" | "(l::nat) - (m + n)" | "Suc m - n" | "m - Suc n") =
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1817
  \<open>fn phi => try o Nat_Arith.cancel_diff_conv\<close>
24091
109f19a13872 added Tools/lin_arith.ML;
wenzelm
parents: 24075
diff changeset
  1818
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1819
context order
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1820
begin
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1821
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1822
lemma lift_Suc_mono_le:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1823
  assumes mono: "\<And>n. f n \<le> f (Suc n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1824
    and "n \<le> n'"
27627
93016de79b02 simplified proofs
krauss
parents: 27625
diff changeset
  1825
  shows "f n \<le> f n'"
93016de79b02 simplified proofs
krauss
parents: 27625
diff changeset
  1826
proof (cases "n < n'")
93016de79b02 simplified proofs
krauss
parents: 27625
diff changeset
  1827
  case True
53986
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1828
  then show ?thesis
62683
ddd1c864408b clarified rule structure;
wenzelm
parents: 62608
diff changeset
  1829
    by (induct n n' rule: less_Suc_induct) (auto intro: mono)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1830
next
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1831
  case False
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1832
  with \<open>n \<le> n'\<close> show ?thesis by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1833
qed
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1834
56020
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1835
lemma lift_Suc_antimono_le:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1836
  assumes mono: "\<And>n. f n \<ge> f (Suc n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1837
    and "n \<le> n'"
56020
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1838
  shows "f n \<ge> f n'"
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1839
proof (cases "n < n'")
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1840
  case True
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1841
  then show ?thesis
62683
ddd1c864408b clarified rule structure;
wenzelm
parents: 62608
diff changeset
  1842
    by (induct n n' rule: less_Suc_induct) (auto intro: mono)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1843
next
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1844
  case False
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1845
  with \<open>n \<le> n'\<close> show ?thesis by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1846
qed
56020
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1847
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1848
lemma lift_Suc_mono_less:
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1849
  assumes mono: "\<And>n. f n < f (Suc n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1850
    and "n < n'"
27627
93016de79b02 simplified proofs
krauss
parents: 27625
diff changeset
  1851
  shows "f n < f n'"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1852
  using \<open>n < n'\<close> by (induct n n' rule: less_Suc_induct) (auto intro: mono)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1853
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1854
lemma lift_Suc_mono_less_iff: "(\<And>n. f n < f (Suc n)) \<Longrightarrow> f n < f m \<longleftrightarrow> n < m"
53986
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1855
  by (blast intro: less_asym' lift_Suc_mono_less [of f]
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1856
    dest: linorder_not_less[THEN iffD1] le_eq_less_or_eq [THEN iffD1])
27789
1bf827e3258d added lemmas
nipkow
parents: 27679
diff changeset
  1857
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1858
end
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1859
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1860
lemma mono_iff_le_Suc: "mono f \<longleftrightarrow> (\<forall>n. f n \<le> f (Suc n))"
37387
3581483cca6c qualified types "+" and nat; qualified constants Ball, Bex, Suc, curry; modernized some specifications
haftmann
parents: 36977
diff changeset
  1861
  unfolding mono_def by (auto intro: lift_Suc_mono_le [of f])
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  1862
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1863
lemma antimono_iff_le_Suc: "antimono f \<longleftrightarrow> (\<forall>n. f (Suc n) \<le> f n)"
56020
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1864
  unfolding antimono_def by (auto intro: lift_Suc_antimono_le [of f])
f92479477c52 introduced antimono; incseq, decseq are now abbreviations for mono and antimono; renamed Library/Continuity to Library/Order_Continuity; removed up_cont; renamed down_cont to down_continuity and generalized to complete_lattices
hoelzl
parents: 55642
diff changeset
  1865
27789
1bf827e3258d added lemmas
nipkow
parents: 27679
diff changeset
  1866
lemma mono_nat_linear_lb:
53986
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1867
  fixes f :: "nat \<Rightarrow> nat"
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1868
  assumes "\<And>m n. m < n \<Longrightarrow> f m < f n"
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1869
  shows "f m + k \<le> f (m + k)"
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1870
proof (induct k)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1871
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1872
  then show ?case by simp
53986
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1873
next
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1874
  case (Suc k)
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1875
  then have "Suc (f m + k) \<le> Suc (f (m + k))" by simp
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1876
  also from assms [of "m + k" "Suc (m + k)"] have "Suc (f (m + k)) \<le> f (Suc (m + k))"
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1877
    by (simp add: Suc_le_eq)
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1878
  finally show ?case by simp
a269577d97c0 tuned proofs
haftmann
parents: 53374
diff changeset
  1879
qed
27789
1bf827e3258d added lemmas
nipkow
parents: 27679
diff changeset
  1880
1bf827e3258d added lemmas
nipkow
parents: 27679
diff changeset
  1881
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1882
text \<open>Subtraction laws, mostly by Clemens Ballarin\<close>
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1883
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1884
lemma diff_less_mono:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1885
  fixes a b c :: nat
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1886
  assumes "a < b" and "c \<le> a"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1887
  shows "a - c < b - c"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1888
proof -
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1889
  from assms obtain d e where "b = c + (d + e)" and "a = c + e" and "d > 0"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1890
    by (auto dest!: le_Suc_ex less_imp_Suc_add simp add: ac_simps)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1891
  then show ?thesis by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1892
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1893
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1894
lemma less_diff_conv: "i < j - k \<longleftrightarrow> i + k < j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1895
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1896
  by (cases "k \<le> j") (auto simp add: not_le dest: less_imp_Suc_add le_Suc_ex)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1897
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1898
lemma less_diff_conv2: "k \<le> j \<Longrightarrow> j - k < i \<longleftrightarrow> j < i + k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1899
  for j k i :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1900
  by (auto dest: le_Suc_ex)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1901
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1902
lemma le_diff_conv: "j - k \<le> i \<longleftrightarrow> j \<le> i + k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1903
  for j k i :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1904
  by (cases "k \<le> j") (auto simp add: not_le dest!: less_imp_Suc_add le_Suc_ex)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1905
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1906
lemma diff_diff_cancel [simp]: "i \<le> n \<Longrightarrow> n - (n - i) = i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1907
  for i n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1908
  by (auto dest: le_Suc_ex)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1909
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1910
lemma diff_less [simp]: "0 < n \<Longrightarrow> 0 < m \<Longrightarrow> m - n < m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1911
  for i n :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1912
  by (auto dest: less_imp_Suc_add)
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1913
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  1914
text \<open>Simplification of relational expressions involving subtraction\<close>
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1915
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1916
lemma diff_diff_eq: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k - (n - k) = m - n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1917
  for m n k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1918
  by (auto dest!: le_Suc_ex)
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1919
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 35828
diff changeset
  1920
hide_fact (open) diff_diff_eq
35064
1bdef0c013d3 hide fact names clashing with fact names from Group.thy
haftmann
parents: 35047
diff changeset
  1921
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1922
lemma eq_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k = n - k \<longleftrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1923
  for m n k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1924
  by (auto dest: le_Suc_ex)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1925
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1926
lemma less_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k < n - k \<longleftrightarrow> m < n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1927
  for m n k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1928
  by (auto dest!: le_Suc_ex)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1929
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1930
lemma le_diff_iff: "k \<le> m \<Longrightarrow> k \<le> n \<Longrightarrow> m - k \<le> n - k \<longleftrightarrow> m \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1931
  for m n k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1932
  by (auto dest!: le_Suc_ex)
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  1933
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1934
lemma le_diff_iff': "a \<le> c \<Longrightarrow> b \<le> c \<Longrightarrow> c - a \<le> c - b \<longleftrightarrow> b \<le> a"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1935
  for a b c :: nat
63099
af0e964aad7b Moved material from AFP/Randomised_Social_Choice to distribution
eberlm
parents: 63040
diff changeset
  1936
  by (force dest: le_Suc_ex)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1937
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1938
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1939
text \<open>(Anti)Monotonicity of subtraction -- by Stephan Merz\<close>
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1940
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1941
lemma diff_le_mono: "m \<le> n \<Longrightarrow> m - l \<le> n - l"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1942
  for m n l :: nat
63648
f9f3006a5579 "split add" -> "split"
nipkow
parents: 63588
diff changeset
  1943
  by (auto dest: less_imp_le less_imp_Suc_add split: nat_diff_split)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1944
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1945
lemma diff_le_mono2: "m \<le> n \<Longrightarrow> l - n \<le> l - m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1946
  for m n l :: nat
63648
f9f3006a5579 "split add" -> "split"
nipkow
parents: 63588
diff changeset
  1947
  by (auto dest: less_imp_le le_Suc_ex less_imp_Suc_add less_le_trans split: nat_diff_split)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1948
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1949
lemma diff_less_mono2: "m < n \<Longrightarrow> m < l \<Longrightarrow> l - n < l - m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1950
  for m n l :: nat
63648
f9f3006a5579 "split add" -> "split"
nipkow
parents: 63588
diff changeset
  1951
  by (auto dest: less_imp_Suc_add split: nat_diff_split)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1952
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1953
lemma diffs0_imp_equal: "m - n = 0 \<Longrightarrow> n - m = 0 \<Longrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1954
  for m n :: nat
63648
f9f3006a5579 "split add" -> "split"
nipkow
parents: 63588
diff changeset
  1955
  by (simp split: nat_diff_split)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1956
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1957
lemma min_diff: "min (m - i) (n - i) = min m n - i"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1958
  for m n i :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1959
  by (cases m n rule: le_cases)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1960
    (auto simp add: not_le min.absorb1 min.absorb2 min.absorb_iff1 [symmetric] diff_le_mono)
26143
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1961
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
  1962
lemma inj_on_diff_nat:
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1963
  fixes k :: nat
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1964
  assumes "\<forall>n \<in> N. k \<le> n"
26143
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1965
  shows "inj_on (\<lambda>n. n - k) N"
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1966
proof (rule inj_onI)
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1967
  fix x y
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1968
  assume a: "x \<in> N" "y \<in> N" "x - k = y - k"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1969
  with assms have "x - k + k = y - k + k" by auto
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1970
  with a assms show "x = y" by (auto simp add: eq_diff_iff)
26143
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1971
qed
314c0bcb7df7 Added useful general lemmas from the work with the HeapMonad
bulwahn
parents: 26101
diff changeset
  1972
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1973
text \<open>Rewriting to pull differences out\<close>
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  1974
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1975
lemma diff_diff_right [simp]: "k \<le> j \<Longrightarrow> i - (j - k) = i + k - j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1976
  for i j k :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1977
  by (fact diff_diff_right)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1978
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1979
lemma diff_Suc_diff_eq1 [simp]:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1980
  assumes "k \<le> j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1981
  shows "i - Suc (j - k) = i + k - Suc j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1982
proof -
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1983
  from assms have *: "Suc (j - k) = Suc j - k"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1984
    by (simp add: Suc_diff_le)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1985
  from assms have "k \<le> Suc j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1986
    by (rule order_trans) simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1987
  with diff_diff_right [of k "Suc j" i] * show ?thesis
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1988
    by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1989
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1990
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1991
lemma diff_Suc_diff_eq2 [simp]:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1992
  assumes "k \<le> j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1993
  shows "Suc (j - k) - i = Suc j - (k + i)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1994
proof -
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1995
  from assms obtain n where "j = k + n"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1996
    by (auto dest: le_Suc_ex)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1997
  moreover have "Suc n - i = (k + Suc n) - (k + i)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1998
    using add_diff_cancel_left [of k "Suc n" i] by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1999
  ultimately show ?thesis by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2000
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2001
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2002
lemma Suc_diff_Suc:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2003
  assumes "n < m"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2004
  shows "Suc (m - Suc n) = m - n"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2005
proof -
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2006
  from assms obtain q where "m = n + Suc q"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2007
    by (auto dest: less_imp_Suc_add)
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62683
diff changeset
  2008
  moreover define r where "r = Suc q"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2009
  ultimately have "Suc (m - Suc n) = r" and "m = n + r"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2010
    by simp_all
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2011
  then show ?thesis by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2012
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2013
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2014
lemma one_less_mult: "Suc 0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> Suc 0 < m * n"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2015
  using less_1_mult [of n m] by (simp add: ac_simps)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2016
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2017
lemma n_less_m_mult_n: "0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> n < m * n"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2018
  using mult_strict_right_mono [of 1 m n] by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2019
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2020
lemma n_less_n_mult_m: "0 < n \<Longrightarrow> Suc 0 < m \<Longrightarrow> n < n * m"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2021
  using mult_strict_left_mono [of 1 m n] by simp
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  2022
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2023
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  2024
text \<open>Specialized induction principles that work "backwards":\<close>
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2025
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2026
lemma inc_induct [consumes 1, case_names base step]:
54411
f72e58a5a75f stronger inc_induct and dec_induct
hoelzl
parents: 54223
diff changeset
  2027
  assumes less: "i \<le> j"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2028
    and base: "P j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2029
    and step: "\<And>n. i \<le> n \<Longrightarrow> n < j \<Longrightarrow> P (Suc n) \<Longrightarrow> P n"
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2030
  shows "P i"
54411
f72e58a5a75f stronger inc_induct and dec_induct
hoelzl
parents: 54223
diff changeset
  2031
  using less step
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2032
proof (induct "j - i" arbitrary: i)
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2033
  case (0 i)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2034
  then have "i = j" by simp
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2035
  with base show ?case by simp
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2036
next
54411
f72e58a5a75f stronger inc_induct and dec_induct
hoelzl
parents: 54223
diff changeset
  2037
  case (Suc d n)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2038
  from Suc.hyps have "n \<noteq> j" by auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2039
  with Suc have "n < j" by (simp add: less_le)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2040
  from \<open>Suc d = j - n\<close> have "d + 1 = j - n" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2041
  then have "d + 1 - 1 = j - n - 1" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2042
  then have "d = j - n - 1" by simp
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2043
  then have "d = j - (n + 1)" by (simp add: diff_diff_eq)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2044
  then have "d = j - Suc n" by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2045
  moreover from \<open>n < j\<close> have "Suc n \<le> j" by (simp add: Suc_le_eq)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2046
  ultimately have "P (Suc n)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2047
  proof (rule Suc.hyps)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2048
    fix q
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2049
    assume "Suc n \<le> q"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2050
    then have "n \<le> q" by (simp add: Suc_le_eq less_imp_le)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2051
    moreover assume "q < j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2052
    moreover assume "P (Suc q)"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2053
    ultimately show "P q" by (rule Suc.prems)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2054
  qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2055
  with order_refl \<open>n < j\<close> show "P n" by (rule Suc.prems)
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2056
qed
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2057
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2058
lemma strict_inc_induct [consumes 1, case_names base step]:
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2059
  assumes less: "i < j"
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2060
    and base: "\<And>i. j = Suc i \<Longrightarrow> P i"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2061
    and step: "\<And>i. i < j \<Longrightarrow> P (Suc i) \<Longrightarrow> P i"
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2062
  shows "P i"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2063
using less proof (induct "j - i - 1" arbitrary: i)
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2064
  case (0 i)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2065
  from \<open>i < j\<close> obtain n where "j = i + n" and "n > 0"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2066
    by (auto dest!: less_imp_Suc_add)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2067
  with 0 have "j = Suc i"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2068
    by (auto intro: order_antisym simp add: Suc_le_eq)
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2069
  with base show ?case by simp
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2070
next
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2071
  case (Suc d i)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2072
  from \<open>Suc d = j - i - 1\<close> have *: "Suc d = j - Suc i"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2073
    by (simp add: diff_diff_add)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2074
  then have "Suc d - 1 = j - Suc i - 1" by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2075
  then have "d = j - Suc i - 1" by simp
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2076
  moreover from * have "j - Suc i \<noteq> 0" by auto
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2077
  then have "Suc i < j" by (simp add: not_le)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2078
  ultimately have "P (Suc i)" by (rule Suc.hyps)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2079
  with \<open>i < j\<close> show "P i" by (rule step)
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2080
qed
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2081
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2082
lemma zero_induct_lemma: "P k \<Longrightarrow> (\<And>n. P (Suc n) \<Longrightarrow> P n) \<Longrightarrow> P (k - i)"
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2083
  using inc_induct[of "k - i" k P, simplified] by blast
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2084
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2085
lemma zero_induct: "P k \<Longrightarrow> (\<And>n. P (Suc n) \<Longrightarrow> P n) \<Longrightarrow> P 0"
23001
3608f0362a91 added induction principles for induction "backwards": P (Suc n) ==> P n
krauss
parents: 22920
diff changeset
  2086
  using inc_induct[of 0 k P] by blast
21243
afffe1f72143 removed theory NatArith (now part of Nat);
wenzelm
parents: 21191
diff changeset
  2087
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2088
text \<open>Further induction rule similar to @{thm inc_induct}.\<close>
27625
3a45b555001a added lemmas
nipkow
parents: 27213
diff changeset
  2089
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2090
lemma dec_induct [consumes 1, case_names base step]:
54411
f72e58a5a75f stronger inc_induct and dec_induct
hoelzl
parents: 54223
diff changeset
  2091
  "i \<le> j \<Longrightarrow> P i \<Longrightarrow> (\<And>n. i \<le> n \<Longrightarrow> n < j \<Longrightarrow> P n \<Longrightarrow> P (Suc n)) \<Longrightarrow> P j"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2092
proof (induct j arbitrary: i)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2093
  case 0
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2094
  then show ?case by simp
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2095
next
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2096
  case (Suc j)
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2097
  from Suc.prems consider "i \<le> j" | "i = Suc j"
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2098
    by (auto simp add: le_Suc_eq)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2099
  then show ?case
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2100
  proof cases
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2101
    case 1
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2102
    moreover have "j < Suc j" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2103
    moreover have "P j" using \<open>i \<le> j\<close> \<open>P i\<close>
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2104
    proof (rule Suc.hyps)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2105
      fix q
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2106
      assume "i \<le> q"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2107
      moreover assume "q < j" then have "q < Suc j"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2108
        by (simp add: less_Suc_eq)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2109
      moreover assume "P q"
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2110
      ultimately show "P (Suc q)" by (rule Suc.prems)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2111
    qed
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2112
    ultimately show "P (Suc j)" by (rule Suc.prems)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2113
  next
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2114
    case 2
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2115
    with \<open>P i\<close> show "P (Suc j)" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2116
  qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2117
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2118
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  2119
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2120
subsection \<open>Monotonicity of \<open>funpow\<close>\<close>
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  2121
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2122
lemma funpow_increasing: "m \<le> n \<Longrightarrow> mono f \<Longrightarrow> (f ^^ n) \<top> \<le> (f ^^ m) \<top>"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2123
  for f :: "'a::{lattice,order_top} \<Rightarrow> 'a"
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  2124
  by (induct rule: inc_induct)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2125
    (auto simp del: funpow.simps(2) simp add: funpow_Suc_right
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2126
      intro: order_trans[OF _ funpow_mono])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2127
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2128
lemma funpow_decreasing: "m \<le> n \<Longrightarrow> mono f \<Longrightarrow> (f ^^ m) \<bottom> \<le> (f ^^ n) \<bottom>"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2129
  for f :: "'a::{lattice,order_bot} \<Rightarrow> 'a"
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  2130
  by (induct rule: dec_induct)
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2131
    (auto simp del: funpow.simps(2) simp add: funpow_Suc_right
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2132
      intro: order_trans[OF _ funpow_mono])
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2133
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2134
lemma mono_funpow: "mono Q \<Longrightarrow> mono (\<lambda>i. (Q ^^ i) \<bottom>)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2135
  for Q :: "'a::{lattice,order_bot} \<Rightarrow> 'a"
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58952
diff changeset
  2136
  by (auto intro!: funpow_decreasing simp: mono_def)
58377
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2137
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2138
lemma antimono_funpow: "mono Q \<Longrightarrow> antimono (\<lambda>i. (Q ^^ i) \<top>)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2139
  for Q :: "'a::{lattice,order_top} \<Rightarrow> 'a"
60175
831ddb69db9b add lfp/gfp rule for nn_integral
hoelzl
parents: 59833
diff changeset
  2140
  by (auto intro!: funpow_increasing simp: antimono_def)
831ddb69db9b add lfp/gfp rule for nn_integral
hoelzl
parents: 59833
diff changeset
  2141
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2142
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  2143
subsection \<open>The divides relation on @{typ nat}\<close>
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2144
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2145
lemma dvd_1_left [iff]: "Suc 0 dvd k"
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2146
  by (simp add: dvd_def)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2147
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2148
lemma dvd_1_iff_1 [simp]: "m dvd Suc 0 \<longleftrightarrow> m = Suc 0"
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2149
  by (simp add: dvd_def)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2150
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2151
lemma nat_dvd_1_iff_1 [simp]: "m dvd 1 \<longleftrightarrow> m = 1"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2152
  for m :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2153
  by (simp add: dvd_def)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2154
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2155
lemma dvd_antisym: "m dvd n \<Longrightarrow> n dvd m \<Longrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2156
  for m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2157
  unfolding dvd_def by (force dest: mult_eq_self_implies_10 simp add: mult.assoc)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2158
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2159
lemma dvd_diff_nat [simp]: "k dvd m \<Longrightarrow> k dvd n \<Longrightarrow> k dvd (m - n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2160
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2161
  unfolding dvd_def by (blast intro: right_diff_distrib' [symmetric])
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2162
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2163
lemma dvd_diffD: "k dvd m - n \<Longrightarrow> k dvd n \<Longrightarrow> n \<le> m \<Longrightarrow> k dvd m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2164
  for k m n :: nat
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2165
  apply (erule linorder_not_less [THEN iffD2, THEN add_diff_inverse, THEN subst])
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2166
  apply (blast intro: dvd_add)
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2167
  done
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2168
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2169
lemma dvd_diffD1: "k dvd m - n \<Longrightarrow> k dvd m \<Longrightarrow> n \<le> m \<Longrightarrow> k dvd n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2170
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2171
  by (drule_tac m = m in dvd_diff_nat) auto
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2172
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2173
lemma dvd_mult_cancel:
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2174
  fixes m n k :: nat
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2175
  assumes "k * m dvd k * n" and "0 < k"
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2176
  shows "m dvd n"
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2177
proof -
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2178
  from assms(1) obtain q where "k * n = (k * m) * q" ..
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2179
  then have "k * n = k * (m * q)" by (simp add: ac_simps)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2180
  with \<open>0 < k\<close> have "n = m * q" by (auto simp add: mult_left_cancel)
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2181
  then show ?thesis ..
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2182
qed
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2183
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2184
lemma dvd_mult_cancel1: "0 < m \<Longrightarrow> m * n dvd m \<longleftrightarrow> n = 1"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2185
  for m n :: nat
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2186
  apply auto
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2187
  apply (subgoal_tac "m * n dvd m * 1")
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2188
   apply (drule dvd_mult_cancel)
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2189
    apply auto
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2190
  done
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2191
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2192
lemma dvd_mult_cancel2: "0 < m \<Longrightarrow> n * m dvd m \<longleftrightarrow> n = 1"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2193
  for m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2194
  using dvd_mult_cancel1 [of m n] by (simp add: ac_simps)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2195
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2196
lemma dvd_imp_le: "k dvd n \<Longrightarrow> 0 < n \<Longrightarrow> k \<le> n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2197
  for k n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2198
  by (auto elim!: dvdE) (auto simp add: gr0_conv_Suc)
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2199
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2200
lemma nat_dvd_not_less: "0 < m \<Longrightarrow> m < n \<Longrightarrow> \<not> n dvd m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2201
  for m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2202
  by (auto elim!: dvdE) (auto simp add: gr0_conv_Suc)
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2203
54222
24874b4024d1 generalised lemma
haftmann
parents: 54147
diff changeset
  2204
lemma less_eq_dvd_minus:
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2205
  fixes m n :: nat
54222
24874b4024d1 generalised lemma
haftmann
parents: 54147
diff changeset
  2206
  assumes "m \<le> n"
24874b4024d1 generalised lemma
haftmann
parents: 54147
diff changeset
  2207
  shows "m dvd n \<longleftrightarrow> m dvd n - m"
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2208
proof -
54222
24874b4024d1 generalised lemma
haftmann
parents: 54147
diff changeset
  2209
  from assms have "n = m + (n - m)" by simp
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2210
  then obtain q where "n = m + q" ..
58647
fce800afeec7 more facts about abstract divisibility
haftmann
parents: 58389
diff changeset
  2211
  then show ?thesis by (simp add: add.commute [of m])
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2212
qed
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2213
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2214
lemma dvd_minus_self: "m dvd n - m \<longleftrightarrow> n < m \<or> m dvd n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2215
  for m n :: nat
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  2216
  by (cases "n < m") (auto elim!: dvdE simp add: not_less le_imp_diff_is_add dest: less_imp_le)
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2217
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2218
lemma dvd_minus_add:
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2219
  fixes m n q r :: nat
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2220
  assumes "q \<le> n" "q \<le> r * m"
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2221
  shows "m dvd n - q \<longleftrightarrow> m dvd n + (r * m - q)"
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2222
proof -
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2223
  have "m dvd n - q \<longleftrightarrow> m dvd r * m + (n - q)"
58649
a62065b5e1e2 generalized and consolidated some theorems concerning divisibility
haftmann
parents: 58647
diff changeset
  2224
    using dvd_add_times_triv_left_iff [of m r] by simp
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 52729
diff changeset
  2225
  also from assms have "\<dots> \<longleftrightarrow> m dvd r * m + n - q" by simp
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 52729
diff changeset
  2226
  also from assms have "\<dots> \<longleftrightarrow> m dvd (r * m - q) + n" by simp
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57492
diff changeset
  2227
  also have "\<dots> \<longleftrightarrow> m dvd n + (r * m - q)" by (simp add: add.commute)
51173
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2228
  finally show ?thesis .
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2229
qed
3cbb4e95a565 Sieve of Eratosthenes
haftmann
parents: 49962
diff changeset
  2230
33274
b6ff7db522b5 moved lemmas for dvd on nat to theories Nat and Power
haftmann
parents: 32772
diff changeset
  2231
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2232
subsection \<open>Aliasses\<close>
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
  2233
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2234
lemma nat_mult_1: "1 * n = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2235
  for n :: nat
58647
fce800afeec7 more facts about abstract divisibility
haftmann
parents: 58389
diff changeset
  2236
  by (fact mult_1_left)
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60427
diff changeset
  2237
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2238
lemma nat_mult_1_right: "n * 1 = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2239
  for n :: nat
58647
fce800afeec7 more facts about abstract divisibility
haftmann
parents: 58389
diff changeset
  2240
  by (fact mult_1_right)
fce800afeec7 more facts about abstract divisibility
haftmann
parents: 58389
diff changeset
  2241
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2242
lemma nat_add_left_cancel: "k + m = k + n \<longleftrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2243
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2244
  by (fact add_left_cancel)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2245
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2246
lemma nat_add_right_cancel: "m + k = n + k \<longleftrightarrow> m = n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2247
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2248
  by (fact add_right_cancel)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2249
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2250
lemma diff_mult_distrib: "(m - n) * k = (m * k) - (n * k)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2251
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2252
  by (fact left_diff_distrib')
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2253
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2254
lemma diff_mult_distrib2: "k * (m - n) = (k * m) - (k * n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2255
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2256
  by (fact right_diff_distrib')
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2257
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2258
lemma le_add_diff: "k \<le> n \<Longrightarrow> m \<le> n + m - k"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2259
  for k m n :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2260
  by (fact le_add_diff)  (* FIXME delete *)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2261
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2262
lemma le_diff_conv2: "k \<le> j \<Longrightarrow> (i \<le> j - k) = (i + k \<le> j)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2263
  for i j k :: nat
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2264
  by (fact le_diff_conv2) (* FIXME delete *)
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2265
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2266
lemma diff_self_eq_0 [simp]: "m - m = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2267
  for m :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2268
  by (fact diff_cancel)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2269
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2270
lemma diff_diff_left [simp]: "i - j - k = i - (j + k)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2271
  for i j k :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2272
  by (fact diff_diff_add)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2273
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2274
lemma diff_commute: "i - j - k = i - k - j"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2275
  for i j k :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2276
  by (fact diff_right_commute)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2277
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2278
lemma diff_add_inverse: "(n + m) - n = m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2279
  for m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2280
  by (fact add_diff_cancel_left')
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2281
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2282
lemma diff_add_inverse2: "(m + n) - n = m"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2283
  for m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2284
  by (fact add_diff_cancel_right')
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2285
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2286
lemma diff_cancel: "(k + m) - (k + n) = m - n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2287
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2288
  by (fact add_diff_cancel_left)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2289
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2290
lemma diff_cancel2: "(m + k) - (n + k) = m - n"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2291
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2292
  by (fact add_diff_cancel_right)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2293
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2294
lemma diff_add_0: "n - (n + m) = 0"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2295
  for m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2296
  by (fact diff_add_zero)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2297
63588
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2298
lemma add_mult_distrib2: "k * (m + n) = (k * m) + (k * n)"
d0e2bad67bd4 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  2299
  for k m n :: nat
62365
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2300
  by (fact distrib_left)
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2301
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2302
lemmas nat_distrib =
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2303
  add_mult_distrib distrib_left diff_mult_distrib diff_mult_distrib2
8a105c235b1f sorted out some duplicate fact bindings
haftmann
parents: 62344
diff changeset
  2304
44817
b63e445c8f6d lemmas about +, *, min, max on nat
haftmann
parents: 44325
diff changeset
  2305
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  2306
subsection \<open>Size of a datatype value\<close>
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  2307
29608
564ea783ace8 no base sort in class import
haftmann
parents: 28952
diff changeset
  2308
class size =
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61649
diff changeset
  2309
  fixes size :: "'a \<Rightarrow> nat" \<comment> \<open>see further theory \<open>Wellfounded\<close>\<close>
23852
3736cdf9398b moved set Nats to Nat.thy
haftmann
parents: 23740
diff changeset
  2310
58377
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2311
instantiation nat :: size
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2312
begin
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2313
63110
ccbdce905fca misc tuning and modernization;
wenzelm
parents: 63099
diff changeset
  2314
definition size_nat where [simp, code]: "size (n::nat) = n"
58377
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2315
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2316
instance ..
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2317
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2318
end
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2319
c6f93b8d2d8e moved old 'size' generator together with 'old_datatype'
blanchet
parents: 58306
diff changeset
  2320
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60636
diff changeset
  2321
subsection \<open>Code module namespace\<close>
33364
2bd12592c5e8 tuned code setup
haftmann
parents: 33274
diff changeset
  2322
52435
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52289
diff changeset
  2323
code_identifier
6646bb548c6b migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents: 52289
diff changeset
  2324
  code_module Nat \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
33364
2bd12592c5e8 tuned code setup
haftmann
parents: 33274
diff changeset
  2325
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46351
diff changeset
  2326
hide_const (open) of_nat_aux
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46351
diff changeset
  2327
25193
e2e1a4b00de3 various localizations
haftmann
parents: 25162
diff changeset
  2328
end