src/HOL/Library/Nonpos_Ints.thy
author eberlm
Mon Jan 04 17:45:36 2016 +0100 (2016-01-04)
changeset 62049 b0f941e207cf
child 62055 755fda743c49
permissions -rw-r--r--
Added lots of material on infinite sums, convergence radii, harmonic numbers, Gamma function
eberlm@62049
     1
(*
eberlm@62049
     2
  Title:    HOL/Library/Nonpos_Ints.thy
eberlm@62049
     3
  Author:   Manuel Eberl, TU M√ľnchen
eberlm@62049
     4
  
eberlm@62049
     5
  The set of non-positive integers on a ring. (in analogy to the set of non-negative
eberlm@62049
     6
  integers @{term "\<nat>"}) This is useful e.g. for the Gamma function.
eberlm@62049
     7
*)
eberlm@62049
     8
theory Nonpos_Ints
eberlm@62049
     9
imports Complex_Main
eberlm@62049
    10
begin
eberlm@62049
    11
eberlm@62049
    12
subsection \<open>Non-positive integers\<close>
eberlm@62049
    13
eberlm@62049
    14
definition nonpos_Ints ("\<int>\<^sub>\<le>\<^sub>0") where "\<int>\<^sub>\<le>\<^sub>0 = {of_int n |n. n \<le> 0}"
eberlm@62049
    15
eberlm@62049
    16
lemma zero_in_nonpos_Ints [simp,intro]: "0 \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    17
  unfolding nonpos_Ints_def by (auto intro!: exI[of _ "0::int"])
eberlm@62049
    18
eberlm@62049
    19
lemma neg_one_in_nonpos_Ints [simp,intro]: "-1 \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    20
  unfolding nonpos_Ints_def by (auto intro!: exI[of _ "-1::int"])
eberlm@62049
    21
eberlm@62049
    22
lemma neg_numeral_in_nonpos_Ints [simp,intro]: "-numeral n \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    23
  unfolding nonpos_Ints_def by (auto intro!: exI[of _ "-numeral n::int"])
eberlm@62049
    24
eberlm@62049
    25
lemma one_notin_nonpos_Ints [simp]: "(1 :: 'a :: ring_char_0) \<notin> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    26
  by (auto simp: nonpos_Ints_def)
eberlm@62049
    27
eberlm@62049
    28
lemma numeral_notin_nonpos_Ints [simp]: "(numeral n :: 'a :: ring_char_0) \<notin> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    29
  by (auto simp: nonpos_Ints_def)
eberlm@62049
    30
eberlm@62049
    31
eberlm@62049
    32
lemma minus_of_nat_in_nonpos_Ints [simp, intro]: "- of_nat n \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    33
proof -
eberlm@62049
    34
  have "- of_nat n = of_int (-int n)" by simp
eberlm@62049
    35
  also have "-int n \<le> 0" by simp
eberlm@62049
    36
  hence "of_int (-int n) \<in> \<int>\<^sub>\<le>\<^sub>0" unfolding nonpos_Ints_def by blast
eberlm@62049
    37
  finally show ?thesis .
eberlm@62049
    38
qed
eberlm@62049
    39
eberlm@62049
    40
lemma of_nat_in_nonpos_Ints_iff: "(of_nat n :: 'a :: {ring_1,ring_char_0}) \<in> \<int>\<^sub>\<le>\<^sub>0 \<longleftrightarrow> n = 0"
eberlm@62049
    41
proof
eberlm@62049
    42
  assume "(of_nat n :: 'a) \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    43
  then obtain m where "of_nat n = (of_int m :: 'a)" "m \<le> 0" by (auto simp: nonpos_Ints_def)
eberlm@62049
    44
  hence "(of_int m :: 'a) = of_nat n" by simp
eberlm@62049
    45
  also have "... = of_int (int n)" by simp
eberlm@62049
    46
  finally have "m = int n" by (subst (asm) of_int_eq_iff)
eberlm@62049
    47
  with `m \<le> 0` show "n = 0" by auto
eberlm@62049
    48
qed simp
eberlm@62049
    49
eberlm@62049
    50
lemma nonpos_Ints_of_int: "n \<le> 0 \<Longrightarrow> of_int n \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    51
  unfolding nonpos_Ints_def by blast
eberlm@62049
    52
eberlm@62049
    53
lemma nonpos_IntsI: 
eberlm@62049
    54
  "x \<in> \<int> \<Longrightarrow> x \<le> 0 \<Longrightarrow> (x :: 'a :: linordered_idom) \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    55
  using assms unfolding nonpos_Ints_def Ints_def by auto
eberlm@62049
    56
eberlm@62049
    57
lemma nonpos_Ints_subset_Ints: "\<int>\<^sub>\<le>\<^sub>0 \<subseteq> \<int>"
eberlm@62049
    58
  unfolding nonpos_Ints_def Ints_def by blast
eberlm@62049
    59
eberlm@62049
    60
lemma nonpos_Ints_nonpos [dest]: "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x \<le> (0 :: 'a :: linordered_idom)"
eberlm@62049
    61
  unfolding nonpos_Ints_def by auto
eberlm@62049
    62
eberlm@62049
    63
lemma nonpos_Ints_Int [dest]: "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x \<in> \<int>"
eberlm@62049
    64
  unfolding nonpos_Ints_def Ints_def by blast
eberlm@62049
    65
eberlm@62049
    66
lemma nonpos_Ints_cases:
eberlm@62049
    67
  assumes "x \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    68
  obtains n where "x = of_int n" "n \<le> 0"
eberlm@62049
    69
  using assms unfolding nonpos_Ints_def by (auto elim!: Ints_cases)
eberlm@62049
    70
eberlm@62049
    71
lemma nonpos_Ints_cases':
eberlm@62049
    72
  assumes "x \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    73
  obtains n where "x = -of_nat n"
eberlm@62049
    74
proof -
eberlm@62049
    75
  from assms obtain m where "x = of_int m" and m: "m \<le> 0" by (auto elim!: nonpos_Ints_cases)
eberlm@62049
    76
  hence "x = - of_int (-m)" by auto
eberlm@62049
    77
  also from m have "(of_int (-m) :: 'a) = of_nat (nat (-m))" by simp_all
eberlm@62049
    78
  finally show ?thesis by (rule that)
eberlm@62049
    79
qed
eberlm@62049
    80
eberlm@62049
    81
lemma of_real_in_nonpos_Ints_iff: "(of_real x :: 'a :: real_algebra_1) \<in> \<int>\<^sub>\<le>\<^sub>0 \<longleftrightarrow> x \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    82
proof
eberlm@62049
    83
  assume "of_real x \<in> (\<int>\<^sub>\<le>\<^sub>0 :: 'a set)"
eberlm@62049
    84
  then obtain n where "(of_real x :: 'a) = of_int n" "n \<le> 0" by (erule nonpos_Ints_cases)
eberlm@62049
    85
  note `of_real x = of_int n`
eberlm@62049
    86
  also have "of_int n = of_real (of_int n)" by (rule of_real_of_int_eq [symmetric])
eberlm@62049
    87
  finally have "x = of_int n" by (subst (asm) of_real_eq_iff)
eberlm@62049
    88
  with `n \<le> 0` show "x \<in> \<int>\<^sub>\<le>\<^sub>0" by (simp add: nonpos_Ints_of_int)
eberlm@62049
    89
qed (auto elim!: nonpos_Ints_cases intro!: nonpos_Ints_of_int)
eberlm@62049
    90
eberlm@62049
    91
lemma nonpos_Ints_altdef: "\<int>\<^sub>\<le>\<^sub>0 = {n \<in> \<int>. (n :: 'a :: linordered_idom) \<le> 0}"
eberlm@62049
    92
  by (auto intro!: nonpos_IntsI elim!: nonpos_Ints_cases)
eberlm@62049
    93
eberlm@62049
    94
lemma uminus_in_Nats_iff: "-x \<in> \<nat> \<longleftrightarrow> x \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
    95
proof
eberlm@62049
    96
  assume "-x \<in> \<nat>"
eberlm@62049
    97
  then obtain n where "n \<ge> 0" "-x = of_int n" by (auto simp: Nats_altdef1)
eberlm@62049
    98
  hence "-n \<le> 0" "x = of_int (-n)" by (simp_all add: eq_commute minus_equation_iff[of x])
eberlm@62049
    99
  thus "x \<in> \<int>\<^sub>\<le>\<^sub>0" unfolding nonpos_Ints_def by blast
eberlm@62049
   100
next
eberlm@62049
   101
  assume "x \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   102
  then obtain n where "n \<le> 0" "x = of_int n" by (auto simp: nonpos_Ints_def)
eberlm@62049
   103
  hence "-n \<ge> 0" "-x = of_int (-n)" by (simp_all add: eq_commute minus_equation_iff[of x])
eberlm@62049
   104
  thus "-x \<in> \<nat>" unfolding Nats_altdef1 by blast
eberlm@62049
   105
qed
eberlm@62049
   106
eberlm@62049
   107
lemma uminus_in_nonpos_Ints_iff: "-x \<in> \<int>\<^sub>\<le>\<^sub>0 \<longleftrightarrow> x \<in> \<nat>"
eberlm@62049
   108
  using uminus_in_Nats_iff[of "-x"] by simp
eberlm@62049
   109
eberlm@62049
   110
lemma nonpos_Ints_mult: "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> y \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x * y \<in> \<nat>"
eberlm@62049
   111
  using Nats_mult[of "-x" "-y"] by (simp add: uminus_in_Nats_iff)
eberlm@62049
   112
eberlm@62049
   113
lemma Nats_mult_nonpos_Ints: "x \<in> \<nat> \<Longrightarrow> y \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x * y \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   114
  using Nats_mult[of x "-y"] by (simp add: uminus_in_Nats_iff)
eberlm@62049
   115
eberlm@62049
   116
lemma nonpos_Ints_mult_Nats:
eberlm@62049
   117
  "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> y \<in> \<nat> \<Longrightarrow> x * y \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   118
  using Nats_mult[of "-x" y] by (simp add: uminus_in_Nats_iff)
eberlm@62049
   119
eberlm@62049
   120
lemma nonpos_Ints_add:
eberlm@62049
   121
  "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> y \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x + y \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   122
  using Nats_add[of "-x" "-y"] uminus_in_Nats_iff[of "y+x", simplified minus_add] 
eberlm@62049
   123
  by (simp add: uminus_in_Nats_iff add.commute)
eberlm@62049
   124
eberlm@62049
   125
lemma nonpos_Ints_diff_Nats:
eberlm@62049
   126
  "x \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> y \<in> \<nat> \<Longrightarrow> x - y \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   127
  using Nats_add[of "-x" "y"] uminus_in_Nats_iff[of "x-y", simplified minus_add] 
eberlm@62049
   128
  by (simp add: uminus_in_Nats_iff add.commute)
eberlm@62049
   129
eberlm@62049
   130
lemma Nats_diff_nonpos_Ints:
eberlm@62049
   131
  "x \<in> \<nat> \<Longrightarrow> y \<in> \<int>\<^sub>\<le>\<^sub>0 \<Longrightarrow> x - y \<in> \<nat>"
eberlm@62049
   132
  using Nats_add[of "x" "-y"] by (simp add: uminus_in_Nats_iff add.commute)
eberlm@62049
   133
eberlm@62049
   134
lemma plus_of_nat_eq_0_imp: "z + of_nat n = 0 \<Longrightarrow> z \<in> \<int>\<^sub>\<le>\<^sub>0"
eberlm@62049
   135
proof -
eberlm@62049
   136
  assume "z + of_nat n = 0"
eberlm@62049
   137
  hence A: "z = - of_nat n" by (simp add: eq_neg_iff_add_eq_0)
eberlm@62049
   138
  show "z \<in> \<int>\<^sub>\<le>\<^sub>0" by (subst A) simp
eberlm@62049
   139
qed
eberlm@62049
   140
eberlm@62049
   141
end