src/HOL/Library/Indicator_Function.thy
author Christian Sternagel
Wed Aug 29 12:23:14 2012 +0900 (2012-08-29)
changeset 49083 01081bca31b6
parent 45425 7fee7d7abf2f
child 54408 67dec4ccaabd
permissions -rw-r--r--
dropped ord and bot instance for list prefixes (use locale interpretation instead, which allows users to decide what order to use on lists)
hoelzl@37665
     1
(*  Title:      HOL/Library/Indicator_Function.thy
hoelzl@37665
     2
    Author:     Johannes Hoelzl (TU Muenchen)
hoelzl@37665
     3
*)
hoelzl@37665
     4
hoelzl@37665
     5
header {* Indicator Function *}
hoelzl@37665
     6
hoelzl@37665
     7
theory Indicator_Function
hoelzl@37665
     8
imports Main
hoelzl@37665
     9
begin
hoelzl@37665
    10
hoelzl@37665
    11
definition "indicator S x = (if x \<in> S then 1 else 0)"
hoelzl@37665
    12
hoelzl@37665
    13
lemma indicator_simps[simp]:
hoelzl@37665
    14
  "x \<in> S \<Longrightarrow> indicator S x = 1"
hoelzl@37665
    15
  "x \<notin> S \<Longrightarrow> indicator S x = 0"
hoelzl@37665
    16
  unfolding indicator_def by auto
hoelzl@37665
    17
wenzelm@45425
    18
lemma indicator_pos_le[intro, simp]: "(0::'a::linordered_semidom) \<le> indicator S x"
hoelzl@37665
    19
  and indicator_le_1[intro, simp]: "indicator S x \<le> (1::'a::linordered_semidom)"
wenzelm@45425
    20
  unfolding indicator_def by auto
wenzelm@45425
    21
wenzelm@45425
    22
lemma indicator_abs_le_1: "\<bar>indicator S x\<bar> \<le> (1::'a::linordered_idom)"
hoelzl@37665
    23
  unfolding indicator_def by auto
hoelzl@37665
    24
hoelzl@37665
    25
lemma split_indicator:
hoelzl@37665
    26
  "P (indicator S x) \<longleftrightarrow> ((x \<in> S \<longrightarrow> P 1) \<and> (x \<notin> S \<longrightarrow> P 0))"
hoelzl@37665
    27
  unfolding indicator_def by auto
hoelzl@37665
    28
wenzelm@45425
    29
lemma indicator_inter_arith: "indicator (A \<inter> B) x = indicator A x * (indicator B x::'a::semiring_1)"
wenzelm@45425
    30
  unfolding indicator_def by (auto simp: min_def max_def)
wenzelm@45425
    31
wenzelm@45425
    32
lemma indicator_union_arith: "indicator (A \<union> B) x =  indicator A x + indicator B x - indicator A x * (indicator B x::'a::ring_1)"
wenzelm@45425
    33
  unfolding indicator_def by (auto simp: min_def max_def)
wenzelm@45425
    34
wenzelm@45425
    35
lemma indicator_inter_min: "indicator (A \<inter> B) x = min (indicator A x) (indicator B x::'a::linordered_semidom)"
hoelzl@37665
    36
  and indicator_union_max: "indicator (A \<union> B) x = max (indicator A x) (indicator B x::'a::linordered_semidom)"
wenzelm@45425
    37
  unfolding indicator_def by (auto simp: min_def max_def)
wenzelm@45425
    38
wenzelm@45425
    39
lemma indicator_compl: "indicator (- A) x = 1 - (indicator A x::'a::ring_1)"
hoelzl@37665
    40
  and indicator_diff: "indicator (A - B) x = indicator A x * (1 - indicator B x::'a::ring_1)"
hoelzl@37665
    41
  unfolding indicator_def by (auto simp: min_def max_def)
hoelzl@37665
    42
wenzelm@45425
    43
lemma indicator_times: "indicator (A \<times> B) x = indicator A (fst x) * (indicator B (snd x)::'a::semiring_1)"
hoelzl@37665
    44
  unfolding indicator_def by (cases x) auto
hoelzl@37665
    45
wenzelm@45425
    46
lemma indicator_sum: "indicator (A <+> B) x = (case x of Inl x \<Rightarrow> indicator A x | Inr x \<Rightarrow> indicator B x)"
hoelzl@37665
    47
  unfolding indicator_def by (cases x) auto
hoelzl@37665
    48
hoelzl@37665
    49
lemma
hoelzl@37665
    50
  fixes f :: "'a \<Rightarrow> 'b::semiring_1" assumes "finite A"
hoelzl@37665
    51
  shows setsum_mult_indicator[simp]: "(\<Sum>x \<in> A. f x * indicator B x) = (\<Sum>x \<in> A \<inter> B. f x)"
hoelzl@37665
    52
  and setsum_indicator_mult[simp]: "(\<Sum>x \<in> A. indicator B x * f x) = (\<Sum>x \<in> A \<inter> B. f x)"
hoelzl@37665
    53
  unfolding indicator_def
hoelzl@37665
    54
  using assms by (auto intro!: setsum_mono_zero_cong_right split: split_if_asm)
hoelzl@37665
    55
hoelzl@37665
    56
lemma setsum_indicator_eq_card:
hoelzl@37665
    57
  assumes "finite A"
hoelzl@37665
    58
  shows "(SUM x : A. indicator B x) = card (A Int B)"
hoelzl@37665
    59
  using setsum_mult_indicator[OF assms, of "%x. 1::nat"]
hoelzl@37665
    60
  unfolding card_eq_setsum by simp
hoelzl@37665
    61
hoelzl@37665
    62
end