src/HOL/Nat.thy
changeset 58377 c6f93b8d2d8e
parent 58306 117ba6cbe414
child 58389 ee1f45ca0d73
equal deleted inserted replaced
58376:c9d3074f83b3 58377:c6f93b8d2d8e
  1183 
  1183 
  1184 lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
  1184 lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
  1185   by (fact Let_def)
  1185   by (fact Let_def)
  1186 
  1186 
  1187 
  1187 
  1188 subsubsection {* Monotonicity of Multiplication *}
  1188 subsubsection {* Monotonicity of multiplication *}
  1189 
  1189 
  1190 lemma mult_le_mono1: "i \<le> (j::nat) ==> i * k \<le> j * k"
  1190 lemma mult_le_mono1: "i \<le> (j::nat) ==> i * k \<le> j * k"
  1191 by (simp add: mult_right_mono)
  1191 by (simp add: mult_right_mono)
  1192 
  1192 
  1193 lemma mult_le_mono2: "i \<le> (j::nat) ==> k * i \<le> k * j"
  1193 lemma mult_le_mono2: "i \<le> (j::nat) ==> k * i \<le> k * j"
  1388   show "(f^^k) bot \<le> lfp f"
  1388   show "(f^^k) bot \<le> lfp f"
  1389     using Kleene_iter_lpfp[OF assms(1)] lfp_unfold[OF assms(1)] by simp
  1389     using Kleene_iter_lpfp[OF assms(1)] lfp_unfold[OF assms(1)] by simp
  1390 qed
  1390 qed
  1391 
  1391 
  1392 
  1392 
  1393 subsection {* Embedding of the Naturals into any @{text semiring_1}: @{term of_nat} *}
  1393 subsection {* Embedding of the naturals into any @{text semiring_1}: @{term of_nat} *}
  1394 
  1394 
  1395 context semiring_1
  1395 context semiring_1
  1396 begin
  1396 begin
  1397 
  1397 
  1398 definition of_nat :: "nat \<Rightarrow> 'a" where
  1398 definition of_nat :: "nat \<Rightarrow> 'a" where
  1510 
  1510 
  1511 lemma of_nat_eq_id [simp]: "of_nat = id"
  1511 lemma of_nat_eq_id [simp]: "of_nat = id"
  1512   by (auto simp add: fun_eq_iff)
  1512   by (auto simp add: fun_eq_iff)
  1513 
  1513 
  1514 
  1514 
  1515 subsection {* The Set of Natural Numbers *}
  1515 subsection {* The set of natural numbers *}
  1516 
  1516 
  1517 context semiring_1
  1517 context semiring_1
  1518 begin
  1518 begin
  1519 
  1519 
  1520 definition Nats  :: "'a set" where
  1520 definition Nats  :: "'a set" where
  1565   by (rule Nats_cases) auto
  1565   by (rule Nats_cases) auto
  1566 
  1566 
  1567 end
  1567 end
  1568 
  1568 
  1569 
  1569 
  1570 subsection {* Further Arithmetic Facts Concerning the Natural Numbers *}
  1570 subsection {* Further arithmetic facts concerning the natural numbers *}
  1571 
  1571 
  1572 lemma subst_equals:
  1572 lemma subst_equals:
  1573   assumes 1: "t = s" and 2: "u = t"
  1573   assumes 1: "t = s" and 2: "u = t"
  1574   shows "u = s"
  1574   shows "u = s"
  1575   using 2 1 by (rule trans)
  1575   using 2 1 by (rule trans)
  1823 
  1823 
  1824 lemma dec_induct[consumes 1, case_names base step]:
  1824 lemma dec_induct[consumes 1, case_names base step]:
  1825   "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"
  1825   "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"
  1826   by (induct j arbitrary: i) (auto simp: le_Suc_eq)
  1826   by (induct j arbitrary: i) (auto simp: le_Suc_eq)
  1827  
  1827  
       
  1828 
  1828 subsection {* The divides relation on @{typ nat} *}
  1829 subsection {* The divides relation on @{typ nat} *}
  1829 
  1830 
  1830 lemma dvd_1_left [iff]: "Suc 0 dvd k"
  1831 lemma dvd_1_left [iff]: "Suc 0 dvd k"
  1831 unfolding dvd_def by simp
  1832 unfolding dvd_def by simp
  1832 
  1833 
  1960   also have "\<dots> \<longleftrightarrow> m dvd n + (r * m - q)" by (simp add: add.commute)
  1961   also have "\<dots> \<longleftrightarrow> m dvd n + (r * m - q)" by (simp add: add.commute)
  1961   finally show ?thesis .
  1962   finally show ?thesis .
  1962 qed
  1963 qed
  1963 
  1964 
  1964 
  1965 
  1965 subsection {* aliases *}
  1966 subsection {* Aliases *}
  1966 
  1967 
  1967 lemma nat_mult_1: "(1::nat) * n = n"
  1968 lemma nat_mult_1: "(1::nat) * n = n"
  1968   by (rule mult_1_left)
  1969   by (rule mult_1_left)
  1969  
  1970  
  1970 lemma nat_mult_1_right: "n * (1::nat) = n"
  1971 lemma nat_mult_1_right: "n * (1::nat) = n"
  1971   by (rule mult_1_right)
  1972   by (rule mult_1_right)
  1972 
  1973 
  1973 
  1974 
  1974 subsection {* size of a datatype value *}
  1975 subsection {* Size of a datatype value *}
  1975 
  1976 
  1976 class size =
  1977 class size =
  1977   fixes size :: "'a \<Rightarrow> nat" -- {* see further theory @{text Wellfounded} *}
  1978   fixes size :: "'a \<Rightarrow> nat" -- {* see further theory @{text Wellfounded} *}
  1978 
  1979 
  1979 
  1980 instantiation nat :: size
  1980 subsection {* code module namespace *}
  1981 begin
       
  1982 
       
  1983 definition size_nat where
       
  1984   [simp, code]: "size (n \<Colon> nat) = n"
       
  1985 
       
  1986 instance ..
       
  1987 
       
  1988 end
       
  1989 
       
  1990 
       
  1991 subsection {* Code module namespace *}
  1981 
  1992 
  1982 code_identifier
  1993 code_identifier
  1983   code_module Nat \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
  1994   code_module Nat \<rightharpoonup> (SML) Arith and (OCaml) Arith and (Haskell) Arith
  1984 
  1995 
  1985 hide_const (open) of_nat_aux
  1996 hide_const (open) of_nat_aux