src/HOL/SetInterval.thy
author nipkow
Thu Jul 15 15:39:40 2004 +0200 (2004-07-15)
changeset 15048 11b4dce71d73
parent 15047 fa62de5862b9
child 15052 cc562a263609
permissions -rw-r--r--
more syntax
nipkow@8924
     1
(*  Title:      HOL/SetInterval.thy
nipkow@8924
     2
    ID:         $Id$
ballarin@13735
     3
    Author:     Tobias Nipkow and Clemens Ballarin
paulson@14485
     4
                Additions by Jeremy Avigad in March 2004
paulson@8957
     5
    Copyright   2000  TU Muenchen
nipkow@8924
     6
ballarin@13735
     7
lessThan, greaterThan, atLeast, atMost and two-sided intervals
nipkow@8924
     8
*)
nipkow@8924
     9
wenzelm@14577
    10
header {* Set intervals *}
wenzelm@14577
    11
paulson@14485
    12
theory SetInterval = IntArith:
nipkow@8924
    13
nipkow@8924
    14
constdefs
nipkow@15045
    15
  lessThan    :: "('a::ord) => 'a set"	("(1{..<_})")
nipkow@15045
    16
  "{..<u} == {x. x<u}"
nipkow@8924
    17
wenzelm@11609
    18
  atMost      :: "('a::ord) => 'a set"	("(1{.._})")
wenzelm@11609
    19
  "{..u} == {x. x<=u}"
nipkow@8924
    20
nipkow@15045
    21
  greaterThan :: "('a::ord) => 'a set"	("(1{_<..})")
nipkow@15045
    22
  "{l<..} == {x. l<x}"
nipkow@8924
    23
wenzelm@11609
    24
  atLeast     :: "('a::ord) => 'a set"	("(1{_..})")
wenzelm@11609
    25
  "{l..} == {x. l<=x}"
nipkow@8924
    26
nipkow@15045
    27
  greaterThanLessThan :: "['a::ord, 'a] => 'a set"  ("(1{_<..<_})")
nipkow@15045
    28
  "{l<..<u} == {l<..} Int {..<u}"
ballarin@13735
    29
nipkow@15045
    30
  atLeastLessThan :: "['a::ord, 'a] => 'a set"      ("(1{_..<_})")
nipkow@15045
    31
  "{l..<u} == {l..} Int {..<u}"
ballarin@13735
    32
nipkow@15045
    33
  greaterThanAtMost :: "['a::ord, 'a] => 'a set"    ("(1{_<.._})")
nipkow@15045
    34
  "{l<..u} == {l<..} Int {..u}"
ballarin@13735
    35
ballarin@13735
    36
  atLeastAtMost :: "['a::ord, 'a] => 'a set"        ("(1{_.._})")
ballarin@13735
    37
  "{l..u} == {l..} Int {..u}"
ballarin@13735
    38
nipkow@15045
    39
(* Old syntax, will disappear! *)
nipkow@15045
    40
syntax
nipkow@15045
    41
  "_lessThan"    :: "('a::ord) => 'a set"	("(1{.._'(})")
nipkow@15045
    42
  "_greaterThan" :: "('a::ord) => 'a set"	("(1{')_..})")
nipkow@15045
    43
  "_greaterThanLessThan" :: "['a::ord, 'a] => 'a set"  ("(1{')_.._'(})")
nipkow@15045
    44
  "_atLeastLessThan" :: "['a::ord, 'a] => 'a set"      ("(1{_.._'(})")
nipkow@15045
    45
  "_greaterThanAtMost" :: "['a::ord, 'a] => 'a set"    ("(1{')_.._})")
nipkow@15045
    46
translations
nipkow@15045
    47
  "{..m(}" => "{..<m}"
nipkow@15045
    48
  "{)m..}" => "{m<..}"
nipkow@15045
    49
  "{)m..n(}" => "{m<..<n}"
nipkow@15045
    50
  "{m..n(}" => "{m..<n}"
nipkow@15045
    51
  "{)m..n}" => "{m<..n}"
nipkow@15045
    52
nipkow@15048
    53
nipkow@15048
    54
text{* A note of warning when using @{term"{..<n}"} on type @{typ
nipkow@15048
    55
nat}: it is equivalent to @{term"{0::nat..<n}"} but some lemmas involving
nipkow@15048
    56
@{term"{m..<n}"} may not exist for in @{term"{..<n}"}-form as well. *}
nipkow@15048
    57
kleing@14418
    58
syntax
kleing@14418
    59
  "@UNION_le"   :: "nat => nat => 'b set => 'b set"       ("(3UN _<=_./ _)" 10)
kleing@14418
    60
  "@UNION_less" :: "nat => nat => 'b set => 'b set"       ("(3UN _<_./ _)" 10)
kleing@14418
    61
  "@INTER_le"   :: "nat => nat => 'b set => 'b set"       ("(3INT _<=_./ _)" 10)
kleing@14418
    62
  "@INTER_less" :: "nat => nat => 'b set => 'b set"       ("(3INT _<_./ _)" 10)
kleing@14418
    63
kleing@14418
    64
syntax (input)
kleing@14418
    65
  "@UNION_le"   :: "nat => nat => 'b set => 'b set"       ("(3\<Union> _\<le>_./ _)" 10)
kleing@14418
    66
  "@UNION_less" :: "nat => nat => 'b set => 'b set"       ("(3\<Union> _<_./ _)" 10)
kleing@14418
    67
  "@INTER_le"   :: "nat => nat => 'b set => 'b set"       ("(3\<Inter> _\<le>_./ _)" 10)
kleing@14418
    68
  "@INTER_less" :: "nat => nat => 'b set => 'b set"       ("(3\<Inter> _<_./ _)" 10)
kleing@14418
    69
kleing@14418
    70
syntax (xsymbols)
wenzelm@14846
    71
  "@UNION_le"   :: "nat \<Rightarrow> nat => 'b set => 'b set"       ("(3\<Union>(00\<^bsub>_ \<le> _\<^esub>)/ _)" 10)
wenzelm@14846
    72
  "@UNION_less" :: "nat \<Rightarrow> nat => 'b set => 'b set"       ("(3\<Union>(00\<^bsub>_ < _\<^esub>)/ _)" 10)
wenzelm@14846
    73
  "@INTER_le"   :: "nat \<Rightarrow> nat => 'b set => 'b set"       ("(3\<Inter>(00\<^bsub>_ \<le> _\<^esub>)/ _)" 10)
wenzelm@14846
    74
  "@INTER_less" :: "nat \<Rightarrow> nat => 'b set => 'b set"       ("(3\<Inter>(00\<^bsub>_ < _\<^esub>)/ _)" 10)
kleing@14418
    75
kleing@14418
    76
translations
kleing@14418
    77
  "UN i<=n. A"  == "UN i:{..n}. A"
nipkow@15045
    78
  "UN i<n. A"   == "UN i:{..<n}. A"
kleing@14418
    79
  "INT i<=n. A" == "INT i:{..n}. A"
nipkow@15045
    80
  "INT i<n. A"  == "INT i:{..<n}. A"
kleing@14418
    81
kleing@14418
    82
paulson@14485
    83
subsection {* Various equivalences *}
ballarin@13735
    84
paulson@13850
    85
lemma lessThan_iff [iff]: "(i: lessThan k) = (i<k)"
paulson@13850
    86
by (simp add: lessThan_def)
ballarin@13735
    87
paulson@13850
    88
lemma Compl_lessThan [simp]: 
ballarin@13735
    89
    "!!k:: 'a::linorder. -lessThan k = atLeast k"
paulson@13850
    90
apply (auto simp add: lessThan_def atLeast_def)
ballarin@13735
    91
done
ballarin@13735
    92
paulson@13850
    93
lemma single_Diff_lessThan [simp]: "!!k:: 'a::order. {k} - lessThan k = {k}"
paulson@13850
    94
by auto
ballarin@13735
    95
paulson@13850
    96
lemma greaterThan_iff [iff]: "(i: greaterThan k) = (k<i)"
paulson@13850
    97
by (simp add: greaterThan_def)
ballarin@13735
    98
paulson@13850
    99
lemma Compl_greaterThan [simp]: 
ballarin@13735
   100
    "!!k:: 'a::linorder. -greaterThan k = atMost k"
paulson@13850
   101
apply (simp add: greaterThan_def atMost_def le_def, auto)
ballarin@13735
   102
done
ballarin@13735
   103
paulson@13850
   104
lemma Compl_atMost [simp]: "!!k:: 'a::linorder. -atMost k = greaterThan k"
paulson@13850
   105
apply (subst Compl_greaterThan [symmetric])
paulson@13850
   106
apply (rule double_complement) 
ballarin@13735
   107
done
ballarin@13735
   108
paulson@13850
   109
lemma atLeast_iff [iff]: "(i: atLeast k) = (k<=i)"
paulson@13850
   110
by (simp add: atLeast_def)
ballarin@13735
   111
paulson@13850
   112
lemma Compl_atLeast [simp]: 
ballarin@13735
   113
    "!!k:: 'a::linorder. -atLeast k = lessThan k"
paulson@13850
   114
apply (simp add: lessThan_def atLeast_def le_def, auto)
ballarin@13735
   115
done
ballarin@13735
   116
paulson@13850
   117
lemma atMost_iff [iff]: "(i: atMost k) = (i<=k)"
paulson@13850
   118
by (simp add: atMost_def)
ballarin@13735
   119
paulson@14485
   120
lemma atMost_Int_atLeast: "!!n:: 'a::order. atMost n Int atLeast n = {n}"
paulson@14485
   121
by (blast intro: order_antisym)
paulson@13850
   122
paulson@13850
   123
paulson@14485
   124
subsection {* Logical Equivalences for Set Inclusion and Equality *}
paulson@13850
   125
paulson@13850
   126
lemma atLeast_subset_iff [iff]:
paulson@13850
   127
     "(atLeast x \<subseteq> atLeast y) = (y \<le> (x::'a::order))" 
paulson@13850
   128
by (blast intro: order_trans) 
paulson@13850
   129
paulson@13850
   130
lemma atLeast_eq_iff [iff]:
paulson@13850
   131
     "(atLeast x = atLeast y) = (x = (y::'a::linorder))" 
paulson@13850
   132
by (blast intro: order_antisym order_trans)
paulson@13850
   133
paulson@13850
   134
lemma greaterThan_subset_iff [iff]:
paulson@13850
   135
     "(greaterThan x \<subseteq> greaterThan y) = (y \<le> (x::'a::linorder))" 
paulson@13850
   136
apply (auto simp add: greaterThan_def) 
paulson@13850
   137
 apply (subst linorder_not_less [symmetric], blast) 
paulson@13850
   138
done
paulson@13850
   139
paulson@13850
   140
lemma greaterThan_eq_iff [iff]:
paulson@13850
   141
     "(greaterThan x = greaterThan y) = (x = (y::'a::linorder))" 
paulson@13850
   142
apply (rule iffI) 
paulson@13850
   143
 apply (erule equalityE) 
paulson@13850
   144
 apply (simp add: greaterThan_subset_iff order_antisym, simp) 
paulson@13850
   145
done
paulson@13850
   146
paulson@13850
   147
lemma atMost_subset_iff [iff]: "(atMost x \<subseteq> atMost y) = (x \<le> (y::'a::order))" 
paulson@13850
   148
by (blast intro: order_trans)
paulson@13850
   149
paulson@13850
   150
lemma atMost_eq_iff [iff]: "(atMost x = atMost y) = (x = (y::'a::linorder))" 
paulson@13850
   151
by (blast intro: order_antisym order_trans)
paulson@13850
   152
paulson@13850
   153
lemma lessThan_subset_iff [iff]:
paulson@13850
   154
     "(lessThan x \<subseteq> lessThan y) = (x \<le> (y::'a::linorder))" 
paulson@13850
   155
apply (auto simp add: lessThan_def) 
paulson@13850
   156
 apply (subst linorder_not_less [symmetric], blast) 
paulson@13850
   157
done
paulson@13850
   158
paulson@13850
   159
lemma lessThan_eq_iff [iff]:
paulson@13850
   160
     "(lessThan x = lessThan y) = (x = (y::'a::linorder))" 
paulson@13850
   161
apply (rule iffI) 
paulson@13850
   162
 apply (erule equalityE) 
paulson@13850
   163
 apply (simp add: lessThan_subset_iff order_antisym, simp) 
ballarin@13735
   164
done
ballarin@13735
   165
ballarin@13735
   166
paulson@13850
   167
subsection {*Two-sided intervals*}
ballarin@13735
   168
wenzelm@14577
   169
text {* @{text greaterThanLessThan} *}
ballarin@13735
   170
ballarin@13735
   171
lemma greaterThanLessThan_iff [simp]:
nipkow@15045
   172
  "(i : {l<..<u}) = (l < i & i < u)"
ballarin@13735
   173
by (simp add: greaterThanLessThan_def)
ballarin@13735
   174
wenzelm@14577
   175
text {* @{text atLeastLessThan} *}
ballarin@13735
   176
ballarin@13735
   177
lemma atLeastLessThan_iff [simp]:
nipkow@15045
   178
  "(i : {l..<u}) = (l <= i & i < u)"
ballarin@13735
   179
by (simp add: atLeastLessThan_def)
ballarin@13735
   180
wenzelm@14577
   181
text {* @{text greaterThanAtMost} *}
ballarin@13735
   182
ballarin@13735
   183
lemma greaterThanAtMost_iff [simp]:
nipkow@15045
   184
  "(i : {l<..u}) = (l < i & i <= u)"
ballarin@13735
   185
by (simp add: greaterThanAtMost_def)
ballarin@13735
   186
wenzelm@14577
   187
text {* @{text atLeastAtMost} *}
ballarin@13735
   188
ballarin@13735
   189
lemma atLeastAtMost_iff [simp]:
ballarin@13735
   190
  "(i : {l..u}) = (l <= i & i <= u)"
ballarin@13735
   191
by (simp add: atLeastAtMost_def)
ballarin@13735
   192
wenzelm@14577
   193
text {* The above four lemmas could be declared as iffs.
wenzelm@14577
   194
  If we do so, a call to blast in Hyperreal/Star.ML, lemma @{text STAR_Int}
wenzelm@14577
   195
  seems to take forever (more than one hour). *}
ballarin@13735
   196
paulson@14485
   197
paulson@14485
   198
subsection {* Intervals of natural numbers *}
paulson@14485
   199
paulson@15047
   200
subsubsection {* The Constant @{term lessThan} *}
paulson@15047
   201
paulson@14485
   202
lemma lessThan_0 [simp]: "lessThan (0::nat) = {}"
paulson@14485
   203
by (simp add: lessThan_def)
paulson@14485
   204
paulson@14485
   205
lemma lessThan_Suc: "lessThan (Suc k) = insert k (lessThan k)"
paulson@14485
   206
by (simp add: lessThan_def less_Suc_eq, blast)
paulson@14485
   207
paulson@14485
   208
lemma lessThan_Suc_atMost: "lessThan (Suc k) = atMost k"
paulson@14485
   209
by (simp add: lessThan_def atMost_def less_Suc_eq_le)
paulson@14485
   210
paulson@14485
   211
lemma UN_lessThan_UNIV: "(UN m::nat. lessThan m) = UNIV"
paulson@14485
   212
by blast
paulson@14485
   213
paulson@15047
   214
subsubsection {* The Constant @{term greaterThan} *}
paulson@15047
   215
paulson@14485
   216
lemma greaterThan_0 [simp]: "greaterThan 0 = range Suc"
paulson@14485
   217
apply (simp add: greaterThan_def)
paulson@14485
   218
apply (blast dest: gr0_conv_Suc [THEN iffD1])
paulson@14485
   219
done
paulson@14485
   220
paulson@14485
   221
lemma greaterThan_Suc: "greaterThan (Suc k) = greaterThan k - {Suc k}"
paulson@14485
   222
apply (simp add: greaterThan_def)
paulson@14485
   223
apply (auto elim: linorder_neqE)
paulson@14485
   224
done
paulson@14485
   225
paulson@14485
   226
lemma INT_greaterThan_UNIV: "(INT m::nat. greaterThan m) = {}"
paulson@14485
   227
by blast
paulson@14485
   228
paulson@15047
   229
subsubsection {* The Constant @{term atLeast} *}
paulson@15047
   230
paulson@14485
   231
lemma atLeast_0 [simp]: "atLeast (0::nat) = UNIV"
paulson@14485
   232
by (unfold atLeast_def UNIV_def, simp)
paulson@14485
   233
paulson@14485
   234
lemma atLeast_Suc: "atLeast (Suc k) = atLeast k - {k}"
paulson@14485
   235
apply (simp add: atLeast_def)
paulson@14485
   236
apply (simp add: Suc_le_eq)
paulson@14485
   237
apply (simp add: order_le_less, blast)
paulson@14485
   238
done
paulson@14485
   239
paulson@14485
   240
lemma atLeast_Suc_greaterThan: "atLeast (Suc k) = greaterThan k"
paulson@14485
   241
  by (auto simp add: greaterThan_def atLeast_def less_Suc_eq_le)
paulson@14485
   242
paulson@14485
   243
lemma UN_atLeast_UNIV: "(UN m::nat. atLeast m) = UNIV"
paulson@14485
   244
by blast
paulson@14485
   245
paulson@15047
   246
subsubsection {* The Constant @{term atMost} *}
paulson@15047
   247
paulson@14485
   248
lemma atMost_0 [simp]: "atMost (0::nat) = {0}"
paulson@14485
   249
by (simp add: atMost_def)
paulson@14485
   250
paulson@14485
   251
lemma atMost_Suc: "atMost (Suc k) = insert (Suc k) (atMost k)"
paulson@14485
   252
apply (simp add: atMost_def)
paulson@14485
   253
apply (simp add: less_Suc_eq order_le_less, blast)
paulson@14485
   254
done
paulson@14485
   255
paulson@14485
   256
lemma UN_atMost_UNIV: "(UN m::nat. atMost m) = UNIV"
paulson@14485
   257
by blast
paulson@14485
   258
paulson@15047
   259
subsubsection {* The Constant @{term atLeastLessThan} *}
paulson@15047
   260
paulson@15047
   261
text{*But not a simprule because some concepts are better left in terms
paulson@15047
   262
  of @{term atLeastLessThan}*}
paulson@15047
   263
lemma atLeast0LessThan: "{0::nat..<n} = {..<n}"
nipkow@15042
   264
by(simp add:lessThan_def atLeastLessThan_def)
nipkow@15042
   265
paulson@15047
   266
lemma atLeastLessThan0 [simp]: "{m..<0::nat} = {}"
paulson@15047
   267
by (simp add: atLeastLessThan_def)
paulson@15047
   268
paulson@15047
   269
lemma atLeastLessThan_self [simp]: "{n::'a::order..<n} = {}"
paulson@15047
   270
by (auto simp add: atLeastLessThan_def)
paulson@15047
   271
paulson@15047
   272
lemma atLeastLessThan_empty: "n \<le> m ==> {m..<n::'a::order} = {}"
paulson@15047
   273
by (auto simp add: atLeastLessThan_def)
paulson@15047
   274
paulson@15047
   275
subsubsection {* Intervals of nats with @{term Suc} *}
paulson@15047
   276
paulson@15047
   277
text{*Not a simprule because the RHS is too messy.*}
paulson@15047
   278
lemma atLeastLessThanSuc:
paulson@15047
   279
    "{m..<Suc n} = (if m \<le> n then insert n {m..<n} else {})"
paulson@15047
   280
by (auto simp add: atLeastLessThan_def) 
paulson@15047
   281
paulson@15047
   282
lemma atLeastLessThan_singleton [simp]: "{m..<Suc m} = {m}" 
paulson@15047
   283
by (auto simp add: atLeastLessThan_def)
paulson@15047
   284
paulson@15047
   285
lemma atLeast_sum_LessThan [simp]: "{m + k..<k::nat} = {}"
paulson@15047
   286
by (induct k, simp_all add: atLeastLessThanSuc)
paulson@15047
   287
paulson@15047
   288
lemma atLeastSucLessThan [simp]: "{Suc n..<n} = {}"
paulson@15047
   289
by (auto simp add: atLeastLessThan_def)
paulson@14485
   290
nipkow@15045
   291
lemma atLeastLessThanSuc_atLeastAtMost: "{l..<Suc u} = {l..u}"
paulson@14485
   292
  by (simp add: lessThan_Suc_atMost atLeastAtMost_def atLeastLessThan_def)
paulson@14485
   293
nipkow@15045
   294
lemma atLeastSucAtMost_greaterThanAtMost: "{Suc l..u} = {l<..u}"  
paulson@14485
   295
  by (simp add: atLeast_Suc_greaterThan atLeastAtMost_def 
paulson@14485
   296
    greaterThanAtMost_def)
paulson@14485
   297
nipkow@15045
   298
lemma atLeastSucLessThan_greaterThanLessThan: "{Suc l..<u} = {l<..<u}"  
paulson@14485
   299
  by (simp add: atLeast_Suc_greaterThan atLeastLessThan_def 
paulson@14485
   300
    greaterThanLessThan_def)
paulson@14485
   301
paulson@14485
   302
subsubsection {* Finiteness *}
paulson@14485
   303
nipkow@15045
   304
lemma finite_lessThan [iff]: fixes k :: nat shows "finite {..<k}"
paulson@14485
   305
  by (induct k) (simp_all add: lessThan_Suc)
paulson@14485
   306
paulson@14485
   307
lemma finite_atMost [iff]: fixes k :: nat shows "finite {..k}"
paulson@14485
   308
  by (induct k) (simp_all add: atMost_Suc)
paulson@14485
   309
paulson@14485
   310
lemma finite_greaterThanLessThan [iff]:
nipkow@15045
   311
  fixes l :: nat shows "finite {l<..<u}"
paulson@14485
   312
by (simp add: greaterThanLessThan_def)
paulson@14485
   313
paulson@14485
   314
lemma finite_atLeastLessThan [iff]:
nipkow@15045
   315
  fixes l :: nat shows "finite {l..<u}"
paulson@14485
   316
by (simp add: atLeastLessThan_def)
paulson@14485
   317
paulson@14485
   318
lemma finite_greaterThanAtMost [iff]:
nipkow@15045
   319
  fixes l :: nat shows "finite {l<..u}"
paulson@14485
   320
by (simp add: greaterThanAtMost_def)
paulson@14485
   321
paulson@14485
   322
lemma finite_atLeastAtMost [iff]:
paulson@14485
   323
  fixes l :: nat shows "finite {l..u}"
paulson@14485
   324
by (simp add: atLeastAtMost_def)
paulson@14485
   325
paulson@14485
   326
lemma bounded_nat_set_is_finite:
paulson@14485
   327
    "(ALL i:N. i < (n::nat)) ==> finite N"
paulson@14485
   328
  -- {* A bounded set of natural numbers is finite. *}
paulson@14485
   329
  apply (rule finite_subset)
paulson@14485
   330
   apply (rule_tac [2] finite_lessThan, auto)
paulson@14485
   331
  done
paulson@14485
   332
paulson@14485
   333
subsubsection {* Cardinality *}
paulson@14485
   334
nipkow@15045
   335
lemma card_lessThan [simp]: "card {..<u} = u"
paulson@14485
   336
  by (induct_tac u, simp_all add: lessThan_Suc)
paulson@14485
   337
paulson@14485
   338
lemma card_atMost [simp]: "card {..u} = Suc u"
paulson@14485
   339
  by (simp add: lessThan_Suc_atMost [THEN sym])
paulson@14485
   340
nipkow@15045
   341
lemma card_atLeastLessThan [simp]: "card {l..<u} = u - l"
nipkow@15045
   342
  apply (subgoal_tac "card {l..<u} = card {..<u-l}")
paulson@14485
   343
  apply (erule ssubst, rule card_lessThan)
nipkow@15045
   344
  apply (subgoal_tac "(%x. x + l) ` {..<u-l} = {l..<u}")
paulson@14485
   345
  apply (erule subst)
paulson@14485
   346
  apply (rule card_image)
paulson@14485
   347
  apply (rule finite_lessThan)
paulson@14485
   348
  apply (simp add: inj_on_def)
paulson@14485
   349
  apply (auto simp add: image_def atLeastLessThan_def lessThan_def)
paulson@14485
   350
  apply arith
paulson@14485
   351
  apply (rule_tac x = "x - l" in exI)
paulson@14485
   352
  apply arith
paulson@14485
   353
  done
paulson@14485
   354
paulson@15047
   355
lemma card_atLeastAtMost [simp]: "card {l..u} = Suc u - l"  
paulson@14485
   356
  by (subst atLeastLessThanSuc_atLeastAtMost [THEN sym], simp)
paulson@14485
   357
nipkow@15045
   358
lemma card_greaterThanAtMost [simp]: "card {l<..u} = u - l" 
paulson@14485
   359
  by (subst atLeastSucAtMost_greaterThanAtMost [THEN sym], simp)
paulson@14485
   360
nipkow@15045
   361
lemma card_greaterThanLessThan [simp]: "card {l<..<u} = u - Suc l"
paulson@14485
   362
  by (subst atLeastSucLessThan_greaterThanLessThan [THEN sym], simp)
paulson@14485
   363
paulson@14485
   364
subsection {* Intervals of integers *}
paulson@14485
   365
nipkow@15045
   366
lemma atLeastLessThanPlusOne_atLeastAtMost_int: "{l..<u+1} = {l..(u::int)}"
paulson@14485
   367
  by (auto simp add: atLeastAtMost_def atLeastLessThan_def)
paulson@14485
   368
nipkow@15045
   369
lemma atLeastPlusOneAtMost_greaterThanAtMost_int: "{l+1..u} = {l<..(u::int)}"  
paulson@14485
   370
  by (auto simp add: atLeastAtMost_def greaterThanAtMost_def)
paulson@14485
   371
paulson@14485
   372
lemma atLeastPlusOneLessThan_greaterThanLessThan_int: 
nipkow@15045
   373
    "{l+1..<u} = {l<..<u::int}"  
paulson@14485
   374
  by (auto simp add: atLeastLessThan_def greaterThanLessThan_def)
paulson@14485
   375
paulson@14485
   376
subsubsection {* Finiteness *}
paulson@14485
   377
paulson@14485
   378
lemma image_atLeastZeroLessThan_int: "0 \<le> u ==> 
nipkow@15045
   379
    {(0::int)..<u} = int ` {..<nat u}"
paulson@14485
   380
  apply (unfold image_def lessThan_def)
paulson@14485
   381
  apply auto
paulson@14485
   382
  apply (rule_tac x = "nat x" in exI)
paulson@14485
   383
  apply (auto simp add: zless_nat_conj zless_nat_eq_int_zless [THEN sym])
paulson@14485
   384
  done
paulson@14485
   385
nipkow@15045
   386
lemma finite_atLeastZeroLessThan_int: "finite {(0::int)..<u}"
paulson@14485
   387
  apply (case_tac "0 \<le> u")
paulson@14485
   388
  apply (subst image_atLeastZeroLessThan_int, assumption)
paulson@14485
   389
  apply (rule finite_imageI)
paulson@14485
   390
  apply auto
nipkow@15045
   391
  apply (subgoal_tac "{0..<u} = {}")
paulson@14485
   392
  apply auto
paulson@14485
   393
  done
paulson@14485
   394
paulson@14485
   395
lemma image_atLeastLessThan_int_shift: 
nipkow@15045
   396
    "(%x. x + (l::int)) ` {0..<u-l} = {l..<u}"
paulson@14485
   397
  apply (auto simp add: image_def atLeastLessThan_iff)
paulson@14485
   398
  apply (rule_tac x = "x - l" in bexI)
paulson@14485
   399
  apply auto
paulson@14485
   400
  done
paulson@14485
   401
nipkow@15045
   402
lemma finite_atLeastLessThan_int [iff]: "finite {l..<u::int}"
nipkow@15045
   403
  apply (subgoal_tac "(%x. x + l) ` {0..<u-l} = {l..<u}")
paulson@14485
   404
  apply (erule subst)
paulson@14485
   405
  apply (rule finite_imageI)
paulson@14485
   406
  apply (rule finite_atLeastZeroLessThan_int)
paulson@14485
   407
  apply (rule image_atLeastLessThan_int_shift)
paulson@14485
   408
  done
paulson@14485
   409
paulson@14485
   410
lemma finite_atLeastAtMost_int [iff]: "finite {l..(u::int)}" 
paulson@14485
   411
  by (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym], simp)
paulson@14485
   412
nipkow@15045
   413
lemma finite_greaterThanAtMost_int [iff]: "finite {l<..(u::int)}" 
paulson@14485
   414
  by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
paulson@14485
   415
nipkow@15045
   416
lemma finite_greaterThanLessThan_int [iff]: "finite {l<..<u::int}" 
paulson@14485
   417
  by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
paulson@14485
   418
paulson@14485
   419
subsubsection {* Cardinality *}
paulson@14485
   420
nipkow@15045
   421
lemma card_atLeastZeroLessThan_int: "card {(0::int)..<u} = nat u"
paulson@14485
   422
  apply (case_tac "0 \<le> u")
paulson@14485
   423
  apply (subst image_atLeastZeroLessThan_int, assumption)
paulson@14485
   424
  apply (subst card_image)
paulson@14485
   425
  apply (auto simp add: inj_on_def)
paulson@14485
   426
  done
paulson@14485
   427
nipkow@15045
   428
lemma card_atLeastLessThan_int [simp]: "card {l..<u} = nat (u - l)"
nipkow@15045
   429
  apply (subgoal_tac "card {l..<u} = card {0..<u-l}")
paulson@14485
   430
  apply (erule ssubst, rule card_atLeastZeroLessThan_int)
nipkow@15045
   431
  apply (subgoal_tac "(%x. x + l) ` {0..<u-l} = {l..<u}")
paulson@14485
   432
  apply (erule subst)
paulson@14485
   433
  apply (rule card_image)
paulson@14485
   434
  apply (rule finite_atLeastZeroLessThan_int)
paulson@14485
   435
  apply (simp add: inj_on_def)
paulson@14485
   436
  apply (rule image_atLeastLessThan_int_shift)
paulson@14485
   437
  done
paulson@14485
   438
paulson@14485
   439
lemma card_atLeastAtMost_int [simp]: "card {l..u} = nat (u - l + 1)"
paulson@14485
   440
  apply (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym])
paulson@14485
   441
  apply (auto simp add: compare_rls)
paulson@14485
   442
  done
paulson@14485
   443
nipkow@15045
   444
lemma card_greaterThanAtMost_int [simp]: "card {l<..u} = nat (u - l)" 
paulson@14485
   445
  by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp)
paulson@14485
   446
nipkow@15045
   447
lemma card_greaterThanLessThan_int [simp]: "card {l<..<u} = nat (u - (l + 1))"
paulson@14485
   448
  by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp)
paulson@14485
   449
paulson@14485
   450
paulson@13850
   451
subsection {*Lemmas useful with the summation operator setsum*}
paulson@13850
   452
wenzelm@14577
   453
text {* For examples, see Algebra/poly/UnivPoly.thy *}
ballarin@13735
   454
wenzelm@14577
   455
subsubsection {* Disjoint Unions *}
ballarin@13735
   456
wenzelm@14577
   457
text {* Singletons and open intervals *}
ballarin@13735
   458
ballarin@13735
   459
lemma ivl_disj_un_singleton:
nipkow@15045
   460
  "{l::'a::linorder} Un {l<..} = {l..}"
nipkow@15045
   461
  "{..<u} Un {u::'a::linorder} = {..u}"
nipkow@15045
   462
  "(l::'a::linorder) < u ==> {l} Un {l<..<u} = {l..<u}"
nipkow@15045
   463
  "(l::'a::linorder) < u ==> {l<..<u} Un {u} = {l<..u}"
nipkow@15045
   464
  "(l::'a::linorder) <= u ==> {l} Un {l<..u} = {l..u}"
nipkow@15045
   465
  "(l::'a::linorder) <= u ==> {l..<u} Un {u} = {l..u}"
ballarin@14398
   466
by auto
ballarin@13735
   467
wenzelm@14577
   468
text {* One- and two-sided intervals *}
ballarin@13735
   469
ballarin@13735
   470
lemma ivl_disj_un_one:
nipkow@15045
   471
  "(l::'a::linorder) < u ==> {..l} Un {l<..<u} = {..<u}"
nipkow@15045
   472
  "(l::'a::linorder) <= u ==> {..<l} Un {l..<u} = {..<u}"
nipkow@15045
   473
  "(l::'a::linorder) <= u ==> {..l} Un {l<..u} = {..u}"
nipkow@15045
   474
  "(l::'a::linorder) <= u ==> {..<l} Un {l..u} = {..u}"
nipkow@15045
   475
  "(l::'a::linorder) <= u ==> {l<..u} Un {u<..} = {l<..}"
nipkow@15045
   476
  "(l::'a::linorder) < u ==> {l<..<u} Un {u..} = {l<..}"
nipkow@15045
   477
  "(l::'a::linorder) <= u ==> {l..u} Un {u<..} = {l..}"
nipkow@15045
   478
  "(l::'a::linorder) <= u ==> {l..<u} Un {u..} = {l..}"
ballarin@14398
   479
by auto
ballarin@13735
   480
wenzelm@14577
   481
text {* Two- and two-sided intervals *}
ballarin@13735
   482
ballarin@13735
   483
lemma ivl_disj_un_two:
nipkow@15045
   484
  "[| (l::'a::linorder) < m; m <= u |] ==> {l<..<m} Un {m..<u} = {l<..<u}"
nipkow@15045
   485
  "[| (l::'a::linorder) <= m; m < u |] ==> {l<..m} Un {m<..<u} = {l<..<u}"
nipkow@15045
   486
  "[| (l::'a::linorder) <= m; m <= u |] ==> {l..<m} Un {m..<u} = {l..<u}"
nipkow@15045
   487
  "[| (l::'a::linorder) <= m; m < u |] ==> {l..m} Un {m<..<u} = {l..<u}"
nipkow@15045
   488
  "[| (l::'a::linorder) < m; m <= u |] ==> {l<..<m} Un {m..u} = {l<..u}"
nipkow@15045
   489
  "[| (l::'a::linorder) <= m; m <= u |] ==> {l<..m} Un {m<..u} = {l<..u}"
nipkow@15045
   490
  "[| (l::'a::linorder) <= m; m <= u |] ==> {l..<m} Un {m..u} = {l..u}"
nipkow@15045
   491
  "[| (l::'a::linorder) <= m; m <= u |] ==> {l..m} Un {m<..u} = {l..u}"
ballarin@14398
   492
by auto
ballarin@13735
   493
ballarin@13735
   494
lemmas ivl_disj_un = ivl_disj_un_singleton ivl_disj_un_one ivl_disj_un_two
ballarin@13735
   495
wenzelm@14577
   496
subsubsection {* Disjoint Intersections *}
ballarin@13735
   497
wenzelm@14577
   498
text {* Singletons and open intervals *}
ballarin@13735
   499
ballarin@13735
   500
lemma ivl_disj_int_singleton:
nipkow@15045
   501
  "{l::'a::order} Int {l<..} = {}"
nipkow@15045
   502
  "{..<u} Int {u} = {}"
nipkow@15045
   503
  "{l} Int {l<..<u} = {}"
nipkow@15045
   504
  "{l<..<u} Int {u} = {}"
nipkow@15045
   505
  "{l} Int {l<..u} = {}"
nipkow@15045
   506
  "{l..<u} Int {u} = {}"
ballarin@13735
   507
  by simp+
ballarin@13735
   508
wenzelm@14577
   509
text {* One- and two-sided intervals *}
ballarin@13735
   510
ballarin@13735
   511
lemma ivl_disj_int_one:
nipkow@15045
   512
  "{..l::'a::order} Int {l<..<u} = {}"
nipkow@15045
   513
  "{..<l} Int {l..<u} = {}"
nipkow@15045
   514
  "{..l} Int {l<..u} = {}"
nipkow@15045
   515
  "{..<l} Int {l..u} = {}"
nipkow@15045
   516
  "{l<..u} Int {u<..} = {}"
nipkow@15045
   517
  "{l<..<u} Int {u..} = {}"
nipkow@15045
   518
  "{l..u} Int {u<..} = {}"
nipkow@15045
   519
  "{l..<u} Int {u..} = {}"
ballarin@14398
   520
  by auto
ballarin@13735
   521
wenzelm@14577
   522
text {* Two- and two-sided intervals *}
ballarin@13735
   523
ballarin@13735
   524
lemma ivl_disj_int_two:
nipkow@15045
   525
  "{l::'a::order<..<m} Int {m..<u} = {}"
nipkow@15045
   526
  "{l<..m} Int {m<..<u} = {}"
nipkow@15045
   527
  "{l..<m} Int {m..<u} = {}"
nipkow@15045
   528
  "{l..m} Int {m<..<u} = {}"
nipkow@15045
   529
  "{l<..<m} Int {m..u} = {}"
nipkow@15045
   530
  "{l<..m} Int {m<..u} = {}"
nipkow@15045
   531
  "{l..<m} Int {m..u} = {}"
nipkow@15045
   532
  "{l..m} Int {m<..u} = {}"
ballarin@14398
   533
  by auto
ballarin@13735
   534
ballarin@13735
   535
lemmas ivl_disj_int = ivl_disj_int_singleton ivl_disj_int_one ivl_disj_int_two
ballarin@13735
   536
nipkow@15041
   537
nipkow@15042
   538
subsection {* Summation indexed over intervals *}
nipkow@15042
   539
nipkow@15042
   540
text{* We introduce the obvious syntax @{text"\<Sum>x=a..b. e"} for
nipkow@15048
   541
@{term"\<Sum>x\<in>{a..b}. e"}, @{text"\<Sum>x=a..<b. e"} for
nipkow@15048
   542
@{term"\<Sum>x\<in>{a..<b}. e"}, and @{text"\<Sum>x<b. e"} for @{term"\<Sum>x\<in>{..<b}. e"}.
nipkow@15048
   543
nipkow@15048
   544
Note that for uniformity on @{typ nat} it is better to use
nipkow@15048
   545
@{text"\<Sum>x=0..<n. e"} rather than @{text"\<Sum>x<n. e"}: @{text setsum} may
nipkow@15048
   546
not provide all lemmas available for @{term"{m..<n}"} also in the
nipkow@15048
   547
special form for @{term"{..<n}"}. *}
nipkow@15042
   548
nipkow@15042
   549
syntax
nipkow@15042
   550
  "_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _ = _.._./ _)" [0,0,0,10] 10)
nipkow@15048
   551
  "_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _ = _..<_./ _)" [0,0,0,10] 10)
nipkow@15048
   552
  "_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(SUM _<_./ _)" [0,0,10] 10)
nipkow@15042
   553
syntax (xsymbols)
nipkow@15042
   554
  "_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _.._./ _)" [0,0,0,10] 10)
nipkow@15048
   555
  "_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _..<_./ _)" [0,0,0,10] 10)
nipkow@15048
   556
  "_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_<_./ _)" [0,0,10] 10)
nipkow@15042
   557
syntax (HTML output)
nipkow@15042
   558
  "_from_to_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _.._./ _)" [0,0,0,10] 10)
nipkow@15048
   559
  "_from_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_ = _..<_./ _)" [0,0,0,10] 10)
nipkow@15048
   560
  "_upto_setsum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" ("(3\<Sum>_<_./ _)" [0,0,10] 10)
nipkow@15041
   561
nipkow@15048
   562
translations
nipkow@15048
   563
  "\<Sum>x=a..b. t" == "setsum (%x. t) {a..b}"
nipkow@15048
   564
  "\<Sum>x=a..<b. t" == "setsum (%x. t) {a..<b}"
nipkow@15048
   565
  "\<Sum>i<n. t" == "setsum (\<lambda>i. t) {..<n}"
nipkow@15041
   566
nipkow@15041
   567
nipkow@15041
   568
lemma Summation_Suc[simp]: "(\<Sum>i < Suc n. b i) = b n + (\<Sum>i < n. b i)"
nipkow@15041
   569
by (simp add:lessThan_Suc)
nipkow@15041
   570
nipkow@8924
   571
end