src/HOL/Analysis/Change_Of_Vars.thy
author paulson <lp15@cam.ac.uk>
Wed, 18 Apr 2018 21:12:50 +0100
changeset 68001 0a2a1b6507c1
parent 67999 1b05f74f2e5f
child 68017 e99f9b3962bf
child 68072 493b818e8e10
permissions -rw-r--r--
correction of TeX errors and other oversights
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     1
theory Change_Of_Vars
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
     2
  imports Vitali_Covering_Theorem Determinants
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     3
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     4
begin
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     5
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     6
subsection\<open>Induction on matrix row operations\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     7
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
     8
lemma induct_matrix_row_operations:
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
     9
  fixes P :: "real^'n^'n \<Rightarrow> bool"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    10
  assumes zero_row: "\<And>A i. row i A = 0 \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    11
    and diagonal: "\<And>A. (\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0) \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    12
    and swap_cols: "\<And>A m n. \<lbrakk>P A; m \<noteq> n\<rbrakk> \<Longrightarrow> P(\<chi> i j. A $ i $ Fun.swap m n id j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    13
    and row_op: "\<And>A m n c. \<lbrakk>P A; m \<noteq> n\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    14
                   \<Longrightarrow> P(\<chi> i. if i = m then row m A + c *\<^sub>R row n A else row i A)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    15
  shows "P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    16
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    17
  have "P A" if "(\<And>i j. \<lbrakk>j \<in> -K;  i \<noteq> j\<rbrakk> \<Longrightarrow> A$i$j = 0)" for A K
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    18
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    19
    have "finite K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    20
      by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    21
    then show ?thesis using that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    22
    proof (induction arbitrary: A rule: finite_induct)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    23
      case empty
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    24
      with diagonal show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    25
        by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    26
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    27
      case (insert k K)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    28
      note insertK = insert
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    29
      have "P A" if kk: "A$k$k \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    30
        and 0: "\<And>i j. \<lbrakk>j \<in> - insert k K; i \<noteq> j\<rbrakk> \<Longrightarrow> A$i$j = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    31
               "\<And>i. \<lbrakk>i \<in> -L; i \<noteq> k\<rbrakk> \<Longrightarrow> A$i$k = 0" for A L
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    32
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    33
        have "finite L"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    34
          by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    35
        then show ?thesis using 0 kk
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    36
        proof (induction arbitrary: A rule: finite_induct)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    37
          case (empty B)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    38
          show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    39
          proof (rule insertK)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    40
            fix i j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    41
            assume "i \<in> - K" "j \<noteq> i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    42
            show "B $ j $ i = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    43
              using \<open>j \<noteq> i\<close> \<open>i \<in> - K\<close> empty
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    44
              by (metis ComplD ComplI Compl_eq_Diff_UNIV Diff_empty UNIV_I insert_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    45
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    46
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    47
          case (insert l L B)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    48
          show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    49
          proof (cases "k = l")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    50
            case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    51
            with insert show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    52
              by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    53
          next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    54
            case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    55
            let ?C = "\<chi> i. if i = l then row l B - (B $ l $ k / B $ k $ k) *\<^sub>R row k B else row i B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    56
            have 1: "\<lbrakk>j \<in> - insert k K; i \<noteq> j\<rbrakk> \<Longrightarrow> ?C $ i $ j = 0" for j i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    57
              by (auto simp: insert.prems(1) row_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    58
            have 2: "?C $ i $ k = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    59
              if "i \<in> - L" "i \<noteq> k" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    60
            proof (cases "i=l")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    61
              case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    62
              with that insert.prems show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    63
                by (simp add: row_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    64
            next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    65
              case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    66
              with that show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    67
                by (simp add: insert.prems(2) row_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    68
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    69
            have 3: "?C $ k $ k \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    70
              by (auto simp: insert.prems row_def \<open>k \<noteq> l\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    71
            have PC: "P ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    72
              using insert.IH [OF 1 2 3] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    73
            have eqB: "(\<chi> i. if i = l then row l ?C + (B $ l $ k / B $ k $ k) *\<^sub>R row k ?C else row i ?C) = B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    74
              using \<open>k \<noteq> l\<close> by (simp add: vec_eq_iff row_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    75
            show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    76
              using row_op [OF PC, of l k, where c = "B$l$k / B$k$k"] eqB \<open>k \<noteq> l\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    77
              by (simp add: cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    78
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    79
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    80
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    81
      then have nonzero_hyp: "P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    82
        if kk: "A$k$k \<noteq> 0" and zeroes: "\<And>i j. j \<in> - insert k K \<and> i\<noteq>j \<Longrightarrow> A$i$j = 0" for A
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    83
        by (auto simp: intro!: kk zeroes)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    84
      show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    85
      proof (cases "row k A = 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    86
        case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    87
        with zero_row show ?thesis by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    88
      next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    89
        case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    90
        then obtain l where l: "A$k$l \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    91
          by (auto simp: row_def zero_vec_def vec_eq_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    92
        show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    93
        proof (cases "k = l")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    94
          case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    95
          with l nonzero_hyp insert.prems show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    96
            by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    97
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    98
          case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
    99
          have *: "A $ i $ Fun.swap k l id j = 0" if "j \<noteq> k" "j \<notin> K" "i \<noteq> j" for i j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   100
            using False l insert.prems that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   101
            by (auto simp: swap_def insert split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   102
          have "P (\<chi> i j. (\<chi> i j. A $ i $ Fun.swap k l id j) $ i $ Fun.swap k l id j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   103
            by (rule swap_cols [OF nonzero_hyp False]) (auto simp: l *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   104
          moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   105
          have "(\<chi> i j. (\<chi> i j. A $ i $ Fun.swap k l id j) $ i $ Fun.swap k l id j) = A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   106
            by (metis (no_types, lifting) id_apply o_apply swap_id_idempotent vec_lambda_unique vec_lambda_unique)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   107
          ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   108
            by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   109
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   110
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   111
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   112
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   113
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   114
    by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   115
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   116
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   117
lemma induct_matrix_elementary:
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   118
  fixes P :: "real^'n^'n \<Rightarrow> bool"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   119
  assumes mult: "\<And>A B. \<lbrakk>P A; P B\<rbrakk> \<Longrightarrow> P(A ** B)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   120
    and zero_row: "\<And>A i. row i A = 0 \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   121
    and diagonal: "\<And>A. (\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0) \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   122
    and swap1: "\<And>m n. m \<noteq> n \<Longrightarrow> P(\<chi> i j. mat 1 $ i $ Fun.swap m n id j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   123
    and idplus: "\<And>m n c. m \<noteq> n \<Longrightarrow> P(\<chi> i j. if i = m \<and> j = n then c else of_bool (i = j))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   124
  shows "P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   125
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   126
  have swap: "P (\<chi> i j. A $ i $ Fun.swap m n id j)"  (is "P ?C")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   127
    if "P A" "m \<noteq> n" for A m n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   128
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   129
    have "A ** (\<chi> i j. mat 1 $ i $ Fun.swap m n id j) = ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   130
      by (simp add: matrix_matrix_mult_def mat_def vec_eq_iff if_distrib sum.delta_remove)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   131
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   132
      using mult swap1 that by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   133
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   134
  have row: "P (\<chi> i. if i = m then row m A + c *\<^sub>R row n A else row i A)"  (is "P ?C")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   135
    if "P A" "m \<noteq> n" for A m n c
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   136
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   137
    let ?B = "\<chi> i j. if i = m \<and> j = n then c else of_bool (i = j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   138
    have "?B ** A = ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   139
      using \<open>m \<noteq> n\<close> unfolding matrix_matrix_mult_def row_def of_bool_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   140
      by (auto simp: vec_eq_iff if_distrib [of "\<lambda>x. x * y" for y] sum.remove cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   141
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   142
      by (rule subst) (auto simp: that mult idplus)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   143
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   144
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   145
    by (rule induct_matrix_row_operations [OF zero_row diagonal swap row])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   146
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   147
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   148
lemma induct_matrix_elementary_alt:
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   149
  fixes P :: "real^'n^'n \<Rightarrow> bool"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   150
  assumes mult: "\<And>A B. \<lbrakk>P A; P B\<rbrakk> \<Longrightarrow> P(A ** B)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   151
    and zero_row: "\<And>A i. row i A = 0 \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   152
    and diagonal: "\<And>A. (\<And>i j. i \<noteq> j \<Longrightarrow> A$i$j = 0) \<Longrightarrow> P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   153
    and swap1: "\<And>m n. m \<noteq> n \<Longrightarrow> P(\<chi> i j. mat 1 $ i $ Fun.swap m n id j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   154
    and idplus: "\<And>m n. m \<noteq> n \<Longrightarrow> P(\<chi> i j. of_bool (i = m \<and> j = n \<or> i = j))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   155
  shows "P A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   156
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   157
  have *: "P (\<chi> i j. if i = m \<and> j = n then c else of_bool (i = j))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   158
    if "m \<noteq> n" for m n c
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   159
  proof (cases "c = 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   160
    case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   161
    with diagonal show ?thesis by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   162
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   163
    case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   164
    then have eq: "(\<chi> i j. if i = m \<and> j = n then c else of_bool (i = j)) =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   165
                      (\<chi> i j. if i = j then (if j = n then inverse c else 1) else 0) **
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   166
                      (\<chi> i j. of_bool (i = m \<and> j = n \<or> i = j)) **
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   167
                      (\<chi> i j. if i = j then if j = n then c else 1 else 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   168
      using \<open>m \<noteq> n\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   169
      apply (simp add: matrix_matrix_mult_def vec_eq_iff of_bool_def if_distrib [of "\<lambda>x. y * x" for y] cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   170
      apply (simp add: if_if_eq_conj sum.neutral conj_commute cong: conj_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   171
      done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   172
    show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   173
      apply (subst eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   174
      apply (intro mult idplus that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   175
       apply (auto intro: diagonal)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   176
      done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   177
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   178
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   179
    by (rule induct_matrix_elementary) (auto intro: assms *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   180
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   181
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   182
lemma induct_linear_elementary:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   183
  fixes f :: "real^'n \<Rightarrow> real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   184
  assumes "linear f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   185
    and comp: "\<And>f g. \<lbrakk>linear f; linear g; P f; P g\<rbrakk> \<Longrightarrow> P(f \<circ> g)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   186
    and zeroes: "\<And>f i. \<lbrakk>linear f; \<And>x. (f x) $ i = 0\<rbrakk> \<Longrightarrow> P f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   187
    and const: "\<And>c. P(\<lambda>x. \<chi> i. c i * x$i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   188
    and swap: "\<And>m n::'n. m \<noteq> n \<Longrightarrow> P(\<lambda>x. \<chi> i. x $ Fun.swap m n id i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   189
    and idplus: "\<And>m n::'n. m \<noteq> n \<Longrightarrow> P(\<lambda>x. \<chi> i. if i = m then x$m + x$n else x$i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   190
  shows "P f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   191
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   192
  have "P (( *v) A)" for A
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   193
  proof (rule induct_matrix_elementary_alt)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   194
    fix A B
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   195
    assume "P (( *v) A)" and "P (( *v) B)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   196
    then show "P (( *v) (A ** B))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   197
      by (metis (no_types, lifting) comp linear_compose matrix_compose matrix_eq matrix_vector_mul matrix_vector_mul_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   198
  next
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   199
    fix A :: "real^'n^'n" and i
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   200
    assume "row i A = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   201
    then show "P (( *v) A)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   202
      by (metis inner_zero_left matrix_vector_mul_component matrix_vector_mul_linear row_def vec_eq_iff vec_lambda_beta zeroes)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   203
  next
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   204
    fix A :: "real^'n^'n"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   205
    assume 0: "\<And>i j. i \<noteq> j \<Longrightarrow> A $ i $ j = 0"
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   206
    have "A $ i $ i * x $ i = (\<Sum>j\<in>UNIV. A $ i $ j * x $ j)" for x and i :: "'n"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   207
      by (simp add: 0 comm_monoid_add_class.sum.remove [where x=i])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   208
    then have "(\<lambda>x. \<chi> i. A $ i $ i * x $ i) = (( *v) A)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   209
      by (auto simp: 0 matrix_vector_mult_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   210
    then show "P (( *v) A)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   211
      using const [of "\<lambda>i. A $ i $ i"] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   212
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   213
    fix m n :: "'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   214
    assume "m \<noteq> n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   215
    have eq: "(\<Sum>j\<in>UNIV. if i = Fun.swap m n id j then x $ j else 0) =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   216
              (\<Sum>j\<in>UNIV. if j = Fun.swap m n id i then x $ j else 0)"
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   217
      for i and x :: "real^'n"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   218
      unfolding swap_def by (rule sum.cong) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   219
    have "(\<lambda>x::real^'n. \<chi> i. x $ Fun.swap m n id i) = (( *v) (\<chi> i j. if i = Fun.swap m n id j then 1 else 0))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   220
      by (auto simp: mat_def matrix_vector_mult_def eq if_distrib [of "\<lambda>x. x * y" for y] cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   221
    with swap [OF \<open>m \<noteq> n\<close>] show "P (( *v) (\<chi> i j. mat 1 $ i $ Fun.swap m n id j))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   222
      by (simp add: mat_def matrix_vector_mult_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   223
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   224
    fix m n :: "'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   225
    assume "m \<noteq> n"
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   226
    then have "x $ m + x $ n = (\<Sum>j\<in>UNIV. of_bool (j = n \<or> m = j) * x $ j)" for x :: "real^'n"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   227
      by (auto simp: of_bool_def if_distrib [of "\<lambda>x. x * y" for y] sum.remove cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   228
    then have "(\<lambda>x::real^'n. \<chi> i. if i = m then x $ m + x $ n else x $ i) =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   229
               (( *v) (\<chi> i j. of_bool (i = m \<and> j = n \<or> i = j)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   230
      unfolding matrix_vector_mult_def of_bool_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   231
      by (auto simp: vec_eq_iff if_distrib [of "\<lambda>x. x * y" for y] cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   232
    then show "P (( *v) (\<chi> i j. of_bool (i = m \<and> j = n \<or> i = j)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   233
      using idplus [OF \<open>m \<noteq> n\<close>] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   234
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   235
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   236
    by (metis \<open>linear f\<close> matrix_vector_mul)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   237
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   238
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   239
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   240
proposition
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   241
  fixes a :: "real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   242
  assumes "m \<noteq> n" and ab_ne: "cbox a b \<noteq> {}" and an: "0 \<le> a$n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   243
  shows measurable_shear_interval: "(\<lambda>x. \<chi> i. if i = m then x$m + x$n else x$i) ` (cbox a b) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   244
       (is  "?f ` _ \<in> _")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   245
   and measure_shear_interval: "measure lebesgue ((\<lambda>x. \<chi> i. if i = m then x$m + x$n else x$i) ` cbox a b)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   246
               = measure lebesgue (cbox a b)" (is "?Q")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   247
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   248
  have lin: "linear ?f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   249
    by (force simp: plus_vec_def scaleR_vec_def algebra_simps intro: linearI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   250
  show fab: "?f ` cbox a b \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   251
    by (simp add: lin measurable_linear_image_interval)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   252
  let ?c = "\<chi> i. if i = m then b$m + b$n else b$i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   253
  let ?mn = "axis m 1 - axis n (1::real)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   254
  have eq1: "measure lebesgue (cbox a ?c)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   255
            = measure lebesgue (?f ` cbox a b)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   256
            + measure lebesgue (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a$m})
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   257
            + measure lebesgue (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   258
  proof (rule measure_Un3_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   259
    show "cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a$m} \<in> lmeasurable" "cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m} \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   260
      by (auto simp: convex_Int convex_halfspace_le convex_halfspace_ge bounded_Int measurable_convex)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   261
    have "negligible {x. ?mn \<bullet> x = a$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   262
      by (metis \<open>m \<noteq> n\<close> axis_index_axis eq_iff_diff_eq_0 negligible_hyperplane)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   263
    moreover have "?f ` cbox a b \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m}) \<subseteq> {x. ?mn \<bullet> x = a$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   264
      using \<open>m \<noteq> n\<close> antisym_conv by (fastforce simp: algebra_simps mem_box_cart inner_axis')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   265
    ultimately show "negligible ((?f ` cbox a b) \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m}))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   266
      by (rule negligible_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   267
    have "negligible {x. ?mn \<bullet> x = b$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   268
      by (metis \<open>m \<noteq> n\<close> axis_index_axis eq_iff_diff_eq_0 negligible_hyperplane)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   269
    moreover have "(?f ` cbox a b) \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m}) \<subseteq> {x. ?mn \<bullet> x = b$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   270
      using \<open>m \<noteq> n\<close> antisym_conv by (fastforce simp: algebra_simps mem_box_cart inner_axis')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   271
    ultimately show "negligible (?f ` cbox a b \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m}))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   272
      by (rule negligible_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   273
    have "negligible {x. ?mn \<bullet> x = b$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   274
      by (metis \<open>m \<noteq> n\<close> axis_index_axis eq_iff_diff_eq_0 negligible_hyperplane)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   275
    moreover have "(cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m})) \<subseteq> {x. ?mn \<bullet> x = b$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   276
      using \<open>m \<noteq> n\<close> ab_ne
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   277
      apply (auto simp: algebra_simps mem_box_cart inner_axis')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   278
      apply (drule_tac x=m in spec)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   279
      apply simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   280
      done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   281
    ultimately show "negligible (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<inter> (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m}))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   282
      by (rule negligible_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   283
    show "?f ` cbox a b \<union> cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<union> cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m} = cbox a ?c" (is "?lhs = _")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   284
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   285
      show "?lhs \<subseteq> cbox a ?c"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   286
        by (auto simp: mem_box_cart add_mono) (meson add_increasing2 an order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   287
      show "cbox a ?c \<subseteq> ?lhs"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   288
        apply (auto simp: algebra_simps image_iff inner_axis' lambda_add_Galois [OF \<open>m \<noteq> n\<close>])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   289
        apply (auto simp: mem_box_cart split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   290
        done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   291
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   292
  qed (fact fab)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   293
  let ?d = "\<chi> i. if i = m then a $ m - b $ m else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   294
  have eq2: "measure lebesgue (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m}) + measure lebesgue (cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m})
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   295
           = measure lebesgue (cbox a (\<chi> i. if i = m then a $ m + b $ n else b $ i))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   296
  proof (rule measure_translate_add[of "cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a$m}" "cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   297
     "(\<chi> i. if i = m then a$m - b$m else 0)" "cbox a (\<chi> i. if i = m then a$m + b$n else b$i)"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   298
    show "(cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a$m}) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   299
      "cbox a ?c \<inter> {x. ?mn \<bullet> x \<ge> b$m} \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   300
      by (auto simp: convex_Int convex_halfspace_le convex_halfspace_ge bounded_Int measurable_convex)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   301
    have "\<And>x. \<lbrakk>x $ n + a $ m \<le> x $ m\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   302
         \<Longrightarrow> x \<in> (+) (\<chi> i. if i = m then a $ m - b $ m else 0) ` {x. x $ n + b $ m \<le> x $ m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   303
      using \<open>m \<noteq> n\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   304
      by (rule_tac x="x - (\<chi> i. if i = m then a$m - b$m else 0)" in image_eqI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   305
         (simp_all add: mem_box_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   306
    then have imeq: "(+) ?d ` {x. b $ m \<le> ?mn \<bullet> x} = {x. a $ m \<le> ?mn \<bullet> x}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   307
      using \<open>m \<noteq> n\<close> by (auto simp: mem_box_cart inner_axis' algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   308
    have "\<And>x. \<lbrakk>0 \<le> a $ n; x $ n + a $ m \<le> x $ m;
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   309
                \<forall>i. i \<noteq> m \<longrightarrow> a $ i \<le> x $ i \<and> x $ i \<le> b $ i\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   310
         \<Longrightarrow> a $ m \<le> x $ m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   311
      using \<open>m \<noteq> n\<close>  by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   312
    then have "(+) ?d ` (cbox a ?c \<inter> {x. b $ m \<le> ?mn \<bullet> x})
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   313
            = cbox a (\<chi> i. if i = m then a $ m + b $ n else b $ i) \<inter> {x. a $ m \<le> ?mn \<bullet> x}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   314
      using an ab_ne
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   315
      apply (simp add: cbox_translation [symmetric] translation_Int interval_ne_empty_cart imeq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   316
      apply (auto simp: mem_box_cart inner_axis' algebra_simps if_distrib all_if_distrib)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   317
      by (metis (full_types) add_mono mult_2_right)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   318
    then show "cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<union>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   319
          (+) ?d ` (cbox a ?c \<inter> {x. b $ m \<le> ?mn \<bullet> x}) =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   320
          cbox a (\<chi> i. if i = m then a $ m + b $ n else b $ i)"  (is "?lhs = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   321
      using an \<open>m \<noteq> n\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   322
      apply (auto simp: mem_box_cart inner_axis' algebra_simps if_distrib all_if_distrib, force)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   323
        apply (drule_tac x=n in spec)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   324
      by (meson ab_ne add_mono_thms_linordered_semiring(3) dual_order.trans interval_ne_empty_cart(1))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   325
    have "negligible{x. ?mn \<bullet> x = a$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   326
      by (metis \<open>m \<noteq> n\<close> axis_index_axis eq_iff_diff_eq_0 negligible_hyperplane)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   327
    moreover have "(cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<inter>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   328
                                 (+) ?d ` (cbox a ?c \<inter> {x. b $ m \<le> ?mn \<bullet> x})) \<subseteq> {x. ?mn \<bullet> x = a$m}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   329
      using \<open>m \<noteq> n\<close> antisym_conv by (fastforce simp: algebra_simps mem_box_cart inner_axis')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   330
    ultimately show "negligible (cbox a ?c \<inter> {x. ?mn \<bullet> x \<le> a $ m} \<inter>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   331
                                 (+) ?d ` (cbox a ?c \<inter> {x. b $ m \<le> ?mn \<bullet> x}))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   332
      by (rule negligible_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   333
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   334
  have ac_ne: "cbox a ?c \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   335
    using ab_ne an
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   336
    by (clarsimp simp: interval_eq_empty_cart) (meson add_less_same_cancel1 le_less_linear less_le_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   337
  have ax_ne: "cbox a (\<chi> i. if i = m then a $ m + b $ n else b $ i) \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   338
    using ab_ne an
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   339
    by (clarsimp simp: interval_eq_empty_cart) (meson add_less_same_cancel1 le_less_linear less_le_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   340
  have eq3: "measure lebesgue (cbox a ?c) = measure lebesgue (cbox a (\<chi> i. if i = m then a$m + b$n else b$i)) + measure lebesgue (cbox a b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   341
    by (simp add: content_cbox_if_cart ab_ne ac_ne ax_ne algebra_simps prod.delta_remove
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   342
             if_distrib [of "\<lambda>u. u - z" for z] prod.remove)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   343
  show ?Q
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   344
    using eq1 eq2 eq3
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   345
    by (simp add: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   346
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   347
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   348
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   349
proposition
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   350
  fixes S :: "(real^'n) set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   351
  assumes "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   352
  shows measurable_stretch: "((\<lambda>x. \<chi> k. m k * x$k) ` S) \<in> lmeasurable" (is  "?f ` S \<in> _")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   353
    and measure_stretch: "measure lebesgue ((\<lambda>x. \<chi> k. m k * x$k) ` S) = \<bar>prod m UNIV\<bar> * measure lebesgue S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   354
    (is "?MEQ")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   355
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   356
  have "(?f ` S) \<in> lmeasurable \<and> ?MEQ"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   357
  proof (cases "\<forall>k. m k \<noteq> 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   358
    case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   359
    have m0: "0 < \<bar>prod m UNIV\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   360
      using True by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   361
    have "(indicat_real (?f ` S) has_integral \<bar>prod m UNIV\<bar> * measure lebesgue S) UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   362
    proof (clarsimp simp add: has_integral_alt [where i=UNIV])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   363
      fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   364
      assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   365
      have "(indicat_real S has_integral (measure lebesgue S)) UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   366
        using assms lmeasurable_iff_has_integral by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   367
      then obtain B where "B>0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   368
        and B: "\<And>a b. ball 0 B \<subseteq> cbox a b \<Longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   369
                        \<exists>z. (indicat_real S has_integral z) (cbox a b) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   370
                            \<bar>z - measure lebesgue S\<bar> < e / \<bar>prod m UNIV\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   371
        by (simp add: has_integral_alt [where i=UNIV]) (metis (full_types) divide_pos_pos m0  m0 \<open>e > 0\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   372
      show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   373
                  (\<exists>z. (indicat_real (?f ` S) has_integral z) (cbox a b) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   374
                       \<bar>z - \<bar>prod m UNIV\<bar> * measure lebesgue S\<bar> < e)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   375
      proof (intro exI conjI allI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   376
        let ?C = "Max (range (\<lambda>k. \<bar>m k\<bar>)) * B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   377
        show "?C > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   378
          using True \<open>B > 0\<close> by (simp add: Max_gr_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   379
        show "ball 0 ?C \<subseteq> cbox u v \<longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   380
                  (\<exists>z. (indicat_real (?f ` S) has_integral z) (cbox u v) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   381
                       \<bar>z - \<bar>prod m UNIV\<bar> * measure lebesgue S\<bar> < e)" for u v
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   382
        proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   383
          assume uv: "ball 0 ?C \<subseteq> cbox u v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   384
          with \<open>?C > 0\<close> have cbox_ne: "cbox u v \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   385
            using centre_in_ball by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   386
          let ?\<alpha> = "\<lambda>k. u$k / m k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   387
          let ?\<beta> = "\<lambda>k. v$k / m k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   388
          have invm0: "\<And>k. inverse (m k) \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   389
            using True by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   390
          have "ball 0 B \<subseteq> (\<lambda>x. \<chi> k. x $ k / m k) ` ball 0 ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   391
          proof clarsimp
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   392
            fix x :: "real^'n"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   393
            assume x: "norm x < B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   394
            have [simp]: "\<bar>Max (range (\<lambda>k. \<bar>m k\<bar>))\<bar> = Max (range (\<lambda>k. \<bar>m k\<bar>))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   395
              by (meson Max_ge abs_ge_zero abs_of_nonneg finite finite_imageI order_trans rangeI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   396
            have "norm (\<chi> k. m k * x $ k) \<le> norm (Max (range (\<lambda>k. \<bar>m k\<bar>)) *\<^sub>R x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   397
              by (rule norm_le_componentwise_cart) (auto simp: abs_mult intro: mult_right_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   398
            also have "\<dots> < ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   399
              using x by simp (metis \<open>B > 0\<close> \<open>?C > 0\<close> mult.commute real_mult_less_iff1 zero_less_mult_pos)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   400
            finally have "norm (\<chi> k. m k * x $ k) < ?C" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   401
            then show "x \<in> (\<lambda>x. \<chi> k. x $ k / m k) ` ball 0 ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   402
              using stretch_Galois [of "inverse \<circ> m"] True by (auto simp: image_iff field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   403
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   404
          then have Bsub: "ball 0 B \<subseteq> cbox (\<chi> k. min (?\<alpha> k) (?\<beta> k)) (\<chi> k. max (?\<alpha> k) (?\<beta> k))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   405
            using cbox_ne uv image_stretch_interval_cart [of "inverse \<circ> m" u v, symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   406
            by (force simp: field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   407
          obtain z where zint: "(indicat_real S has_integral z) (cbox (\<chi> k. min (?\<alpha> k) (?\<beta> k)) (\<chi> k. max (?\<alpha> k) (?\<beta> k)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   408
                   and zless: "\<bar>z - measure lebesgue S\<bar> < e / \<bar>prod m UNIV\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   409
            using B [OF Bsub] by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   410
          have ind: "indicat_real (?f ` S) = (\<lambda>x. indicator S (\<chi> k. x$k / m k))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   411
            using True stretch_Galois [of m] by (force simp: indicator_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   412
          show "\<exists>z. (indicat_real (?f ` S) has_integral z) (cbox u v) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   413
                       \<bar>z - \<bar>prod m UNIV\<bar> * measure lebesgue S\<bar> < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   414
          proof (simp add: ind, intro conjI exI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   415
            have "((\<lambda>x. indicat_real S (\<chi> k. x $ k/ m k)) has_integral z *\<^sub>R \<bar>prod m UNIV\<bar>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   416
                ((\<lambda>x. \<chi> k. x $ k * m k) ` cbox (\<chi> k. min (?\<alpha> k) (?\<beta> k)) (\<chi> k. max (?\<alpha> k) (?\<beta> k)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   417
              using True has_integral_stretch_cart [OF zint, of "inverse \<circ> m"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   418
              by (simp add: field_simps prod_dividef)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   419
            moreover have "((\<lambda>x. \<chi> k. x $ k * m k) ` cbox (\<chi> k. min (?\<alpha> k) (?\<beta> k)) (\<chi> k. max (?\<alpha> k) (?\<beta> k))) = cbox u v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   420
              using True image_stretch_interval_cart [of "inverse \<circ> m" u v, symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   421
                image_stretch_interval_cart [of "\<lambda>k. 1" u v, symmetric] \<open>cbox u v \<noteq> {}\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   422
              by (simp add: field_simps image_comp o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   423
            ultimately show "((\<lambda>x. indicat_real S (\<chi> k. x $ k/ m k)) has_integral z *\<^sub>R \<bar>prod m UNIV\<bar>) (cbox u v)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   424
              by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   425
            have "\<bar>z *\<^sub>R \<bar>prod m UNIV\<bar> - \<bar>prod m UNIV\<bar> * measure lebesgue S\<bar>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   426
                 = \<bar>prod m UNIV\<bar> * \<bar>z - measure lebesgue S\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   427
              by (metis (no_types, hide_lams) abs_abs abs_scaleR mult.commute real_scaleR_def right_diff_distrib')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   428
            also have "\<dots> < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   429
              using zless True by (simp add: field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   430
            finally show "\<bar>z *\<^sub>R \<bar>prod m UNIV\<bar> - \<bar>prod m UNIV\<bar> * measure lebesgue S\<bar> < e" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   431
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   432
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   433
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   434
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   435
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   436
      by (auto simp: has_integral_integrable integral_unique lmeasure_integral_UNIV measurable_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   437
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   438
    case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   439
    then obtain k where "m k = 0" and prm: "prod m UNIV = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   440
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   441
    have nfS: "negligible (?f ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   442
      by (rule negligible_subset [OF negligible_standard_hyperplane_cart]) (use \<open>m k = 0\<close> in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   443
    then have "(?f ` S) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   444
      by (simp add: negligible_iff_measure)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   445
    with nfS show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   446
      by (simp add: prm negligible_iff_measure0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   447
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   448
  then show "(?f ` S) \<in> lmeasurable" ?MEQ
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   449
    by metis+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   450
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   451
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   452
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   453
proposition
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   454
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   455
  assumes "linear f" "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   456
  shows measurable_linear_image: "(f ` S) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   457
    and measure_linear_image: "measure lebesgue (f ` S) = \<bar>det (matrix f)\<bar> * measure lebesgue S" (is "?Q f S")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   458
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   459
  have "\<forall>S \<in> lmeasurable. (f ` S) \<in> lmeasurable \<and> ?Q f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   460
  proof (rule induct_linear_elementary [OF \<open>linear f\<close>]; intro ballI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   461
    fix f g and S :: "(real,'n) vec set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   462
    assume "linear f" and "linear g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   463
      and f [rule_format]: "\<forall>S \<in> lmeasurable. f ` S \<in> lmeasurable \<and> ?Q f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   464
      and g [rule_format]: "\<forall>S \<in> lmeasurable. g ` S \<in> lmeasurable \<and> ?Q g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   465
      and S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   466
    then have gS: "g ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   467
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   468
    show "(f \<circ> g) ` S \<in> lmeasurable \<and> ?Q (f \<circ> g) S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   469
      using f [OF gS] g [OF S] matrix_compose [OF \<open>linear g\<close> \<open>linear f\<close>]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   470
      by (simp add: o_def image_comp abs_mult det_mul)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   471
  next
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   472
    fix f :: "real^'n::_ \<Rightarrow> real^'n::_" and i and S :: "(real^'n::_) set"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   473
    assume "linear f" and 0: "\<And>x. f x $ i = 0" and "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   474
    then have "\<not> inj f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   475
      by (metis (full_types) linear_injective_imp_surjective one_neq_zero surjE vec_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   476
    have detf: "det (matrix f) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   477
      by (metis "0" \<open>linear f\<close> invertible_det_nz invertible_right_inverse matrix_right_invertible_surjective matrix_vector_mul surjE vec_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   478
    show "f ` S \<in> lmeasurable \<and> ?Q f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   479
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   480
      show "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   481
        using lmeasurable_iff_indicator_has_integral \<open>linear f\<close> \<open>\<not> inj f\<close> negligible_UNIV negligible_linear_singular_image by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   482
      have "measure lebesgue (f ` S) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   483
        by (meson \<open>\<not> inj f\<close> \<open>linear f\<close> negligible_imp_measure0 negligible_linear_singular_image)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   484
      also have "\<dots> = \<bar>det (matrix f)\<bar> * measure lebesgue S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   485
        by (simp add: detf)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   486
      finally show "?Q f S" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   487
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   488
  next
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   489
    fix c and S :: "(real^'n::_) set"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   490
    assume "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   491
    show "(\<lambda>a. \<chi> i. c i * a $ i) ` S \<in> lmeasurable \<and> ?Q (\<lambda>a. \<chi> i. c i * a $ i) S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   492
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   493
      show "(\<lambda>a. \<chi> i. c i * a $ i) ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   494
        by (simp add: \<open>S \<in> lmeasurable\<close> measurable_stretch)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   495
      show "?Q (\<lambda>a. \<chi> i. c i * a $ i) S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   496
        by (simp add: measure_stretch [OF \<open>S \<in> lmeasurable\<close>, of c] axis_def matrix_def det_diagonal)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   497
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   498
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   499
    fix m :: "'n" and n :: "'n" and S :: "(real, 'n) vec set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   500
    assume "m \<noteq> n" and "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   501
    let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   502
    have lin: "linear ?h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   503
      by (simp add: plus_vec_def scaleR_vec_def linearI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   504
    have meq: "measure lebesgue ((\<lambda>v::(real, 'n) vec. \<chi> i. v $ Fun.swap m n id i) ` cbox a b)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   505
             = measure lebesgue (cbox a b)" for a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   506
    proof (cases "cbox a b = {}")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   507
      case True then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   508
        by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   509
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   510
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   511
      then have him: "?h ` (cbox a b) \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   512
        by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   513
      have eq: "?h ` (cbox a b) = cbox (?h a) (?h b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   514
        by (auto simp: image_iff lambda_swap_Galois mem_box_cart) (metis swap_id_eq)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   515
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   516
        using him prod.permute [OF permutes_swap_id, where S=UNIV and g="\<lambda>i. (b - a)$i", symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   517
        by (simp add: eq content_cbox_cart False)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   518
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   519
    have "(\<chi> i j. if Fun.swap m n id i = j then 1 else 0) = (\<chi> i j. if j = Fun.swap m n id i then 1 else (0::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   520
      by (auto intro!: Cart_lambda_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   521
    then have "matrix ?h = transpose(\<chi> i j. mat 1 $ i $ Fun.swap m n id j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   522
      by (auto simp: matrix_eq transpose_def axis_def mat_def matrix_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   523
    then have 1: "\<bar>det (matrix ?h)\<bar> = 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   524
      by (simp add: det_permute_columns permutes_swap_id sign_swap_id abs_mult)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   525
    show "?h ` S \<in> lmeasurable \<and> ?Q ?h S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   526
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   527
      show "?h ` S \<in> lmeasurable" "?Q ?h S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   528
        using measure_linear_sufficient [OF lin \<open>S \<in> lmeasurable\<close>] meq 1 by force+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   529
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   530
  next
67999
1b05f74f2e5f tidying up including contributions from Paulo Emílio de Vilhena
paulson <lp15@cam.ac.uk>
parents: 67998
diff changeset
   531
    fix m n :: "'n" and S :: "(real, 'n) vec set"
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   532
    assume "m \<noteq> n" and "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   533
    let ?h = "\<lambda>v::(real, 'n) vec. \<chi> i. if i = m then v $ m + v $ n else v $ i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   534
    have lin: "linear ?h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   535
      by (auto simp: algebra_simps plus_vec_def scaleR_vec_def vec_eq_iff intro: linearI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   536
    consider "m < n" | " n < m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   537
      using \<open>m \<noteq> n\<close> less_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   538
    then have 1: "det(matrix ?h) = 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   539
    proof cases
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   540
      assume "m < n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   541
      have *: "matrix ?h $ i $ j = (0::real)" if "j < i" for i j :: 'n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   542
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   543
        have "axis j 1 = (\<chi> n. if n = j then 1 else (0::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   544
          using axis_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   545
        then have "(\<chi> p q. if p = m then axis q 1 $ m + axis q 1 $ n else axis q 1 $ p) $ i $ j = (0::real)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   546
          using \<open>j < i\<close> axis_def \<open>m < n\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   547
        with \<open>m < n\<close> show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   548
          by (auto simp: matrix_def axis_def cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   549
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   550
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   551
        using \<open>m \<noteq> n\<close> by (subst det_upperdiagonal [OF *]) (auto simp: matrix_def axis_def cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   552
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   553
      assume "n < m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   554
      have *: "matrix ?h $ i $ j = (0::real)" if "j > i" for i j :: 'n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   555
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   556
        have "axis j 1 = (\<chi> n. if n = j then 1 else (0::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   557
          using axis_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   558
        then have "(\<chi> p q. if p = m then axis q 1 $ m + axis q 1 $ n else axis q 1 $ p) $ i $ j = (0::real)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   559
          using \<open>j > i\<close> axis_def \<open>m > n\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   560
        with \<open>m > n\<close> show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   561
          by (auto simp: matrix_def axis_def cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   562
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   563
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   564
        using \<open>m \<noteq> n\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   565
        by (subst det_lowerdiagonal [OF *]) (auto simp: matrix_def axis_def cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   566
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   567
    have meq: "measure lebesgue (?h ` (cbox a b)) = measure lebesgue (cbox a b)" for a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   568
    proof (cases "cbox a b = {}")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   569
      case True then show ?thesis by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   570
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   571
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   572
      then have ne: "(+) (\<chi> i. if i = n then - a $ n else 0) ` cbox a b \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   573
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   574
      let ?v = "\<chi> i. if i = n then - a $ n else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   575
      have "?h ` cbox a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   576
            = (+) (\<chi> i. if i = m \<or> i = n then a $ n else 0) ` ?h ` (+) ?v ` (cbox a b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   577
        using \<open>m \<noteq> n\<close> unfolding image_comp o_def by (force simp: vec_eq_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   578
      then have "measure lebesgue (?h ` (cbox a b))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   579
               = measure lebesgue ((\<lambda>v. \<chi> i. if i = m then v $ m + v $ n else v $ i) `
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   580
                                   (+) ?v ` cbox a b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   581
        by (rule ssubst) (rule measure_translation)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   582
      also have "\<dots> = measure lebesgue ((\<lambda>v. \<chi> i. if i = m then v $ m + v $ n else v $ i) ` cbox (?v +a) (?v + b))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   583
        by (metis (no_types, lifting) cbox_translation)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   584
      also have "\<dots> = measure lebesgue ((+) (\<chi> i. if i = n then - a $ n else 0) ` cbox a b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   585
        apply (subst measure_shear_interval)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   586
        using \<open>m \<noteq> n\<close> ne apply auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   587
        apply (simp add: cbox_translation)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   588
        by (metis cbox_borel cbox_translation measure_completion sets_lborel)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   589
      also have "\<dots> = measure lebesgue (cbox a b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   590
        by (rule measure_translation)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   591
        finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   592
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   593
    show "?h ` S \<in> lmeasurable \<and> ?Q ?h S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   594
      using measure_linear_sufficient [OF lin \<open>S \<in> lmeasurable\<close>] meq 1 by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   595
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   596
  with assms show "(f ` S) \<in> lmeasurable" "?Q f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   597
    by metis+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   598
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   599
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   600
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   601
lemma
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   602
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   603
  assumes f: "orthogonal_transformation f" and S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   604
  shows measurable_orthogonal_image: "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   605
    and measure_orthogonal_image: "measure lebesgue (f ` S) = measure lebesgue S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   606
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   607
  have "linear f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   608
    by (simp add: f orthogonal_transformation_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   609
  then show "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   610
    by (metis S measurable_linear_image)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   611
  show "measure lebesgue (f ` S) = measure lebesgue S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   612
    by (simp add: measure_linear_image \<open>linear f\<close> S f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   613
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   614
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   615
subsection\<open>@{text F_sigma} and @{text G_delta} sets.\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   616
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   617
(*https://en.wikipedia.org/wiki/F\<sigma>_set*)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   618
inductive fsigma :: "'a::topological_space set \<Rightarrow> bool" where
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   619
  "(\<And>n::nat. closed (F n)) \<Longrightarrow> fsigma (UNION UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   620
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   621
inductive gdelta :: "'a::topological_space set \<Rightarrow> bool" where
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   622
  "(\<And>n::nat. open (F n)) \<Longrightarrow> gdelta (INTER UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   623
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   624
lemma fsigma_Union_compact:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   625
  fixes S :: "'a::{real_normed_vector,heine_borel} set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   626
  shows "fsigma S \<longleftrightarrow> (\<exists>F::nat \<Rightarrow> 'a set. range F \<subseteq> Collect compact \<and> S = UNION UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   627
proof safe
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   628
  assume "fsigma S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   629
  then obtain F :: "nat \<Rightarrow> 'a set" where F: "range F \<subseteq> Collect closed" "S = UNION UNIV F"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   630
    by (meson fsigma.cases image_subsetI mem_Collect_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   631
  then have "\<exists>D::nat \<Rightarrow> 'a set. range D \<subseteq> Collect compact \<and> UNION UNIV D = F i" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   632
    using closed_Union_compact_subsets [of "F i"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   633
    by (metis image_subsetI mem_Collect_eq range_subsetD)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   634
  then obtain D :: "nat \<Rightarrow> nat \<Rightarrow> 'a set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   635
    where D: "\<And>i. range (D i) \<subseteq> Collect compact \<and> UNION UNIV (D i) = F i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   636
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   637
  let ?DD = "\<lambda>n. (\<lambda>(i,j). D i j) (prod_decode n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   638
  show "\<exists>F::nat \<Rightarrow> 'a set. range F \<subseteq> Collect compact \<and> S = UNION UNIV F"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   639
  proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   640
    show "range ?DD \<subseteq> Collect compact"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   641
      using D by clarsimp (metis mem_Collect_eq rangeI split_conv subsetCE surj_pair)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   642
    show "S = UNION UNIV ?DD"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   643
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   644
      show "S \<subseteq> UNION UNIV ?DD"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   645
        using D F
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   646
        by clarsimp (metis UN_iff old.prod.case prod_decode_inverse prod_encode_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   647
      show "UNION UNIV ?DD \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   648
        using D F  by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   649
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   650
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   651
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   652
  fix F :: "nat \<Rightarrow> 'a set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   653
  assume "range F \<subseteq> Collect compact" and "S = UNION UNIV F"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   654
  then show "fsigma (UNION UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   655
    by (simp add: compact_imp_closed fsigma.intros image_subset_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   656
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   657
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   658
lemma gdelta_imp_fsigma: "gdelta S \<Longrightarrow> fsigma (- S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   659
proof (induction rule: gdelta.induct)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   660
  case (1 F)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   661
  have "- INTER UNIV F = (\<Union>i. -(F i))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   662
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   663
  then show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   664
    by (simp add: fsigma.intros closed_Compl 1)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   665
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   666
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   667
lemma fsigma_imp_gdelta: "fsigma S \<Longrightarrow> gdelta (- S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   668
proof (induction rule: fsigma.induct)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   669
  case (1 F)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   670
  have "- UNION UNIV F = (\<Inter>i. -(F i))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   671
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   672
  then show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   673
    by (simp add: 1 gdelta.intros open_closed)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   674
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   675
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   676
lemma gdelta_complement: "gdelta(- S) \<longleftrightarrow> fsigma S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   677
  using fsigma_imp_gdelta gdelta_imp_fsigma by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   678
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   679
text\<open>A Lebesgue set is almost an @{text F_sigma} or @{text G_delta}.\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   680
lemma lebesgue_set_almost_fsigma:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   681
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   682
  obtains C T where "fsigma C" "negligible T" "C \<union> T = S" "disjnt C T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   683
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   684
  { fix n::nat
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   685
    have "\<exists>T. closed T \<and> T \<subseteq> S \<and> S - T \<in> lmeasurable \<and> measure lebesgue (S-T) < 1 / Suc n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   686
      using sets_lebesgue_inner_closed [OF assms]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   687
      by (metis divide_pos_pos less_numeral_extra(1) of_nat_0_less_iff zero_less_Suc)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   688
  }
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   689
  then obtain F where F: "\<And>n::nat. closed (F n) \<and> F n \<subseteq> S \<and> S - F n \<in> lmeasurable \<and> measure lebesgue (S - F n) < 1 / Suc n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   690
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   691
  let ?C = "UNION UNIV F"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   692
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   693
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   694
    show "fsigma ?C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   695
      using F by (simp add: fsigma.intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   696
    show "negligible (S - ?C)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   697
    proof (clarsimp simp add: negligible_outer_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   698
      fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   699
      assume "0 < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   700
      then obtain n where n: "1 / Suc n < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   701
        using nat_approx_posE by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   702
      show "\<exists>T. S - (\<Union>x. F x) \<subseteq> T \<and> T \<in> lmeasurable \<and> measure lebesgue T \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   703
      proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   704
        show "measure lebesgue (S - F n) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   705
          by (meson F n less_trans not_le order.asym)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   706
      qed (use F in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   707
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   708
    show "?C \<union> (S - ?C) = S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   709
      using F by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   710
    show "disjnt ?C (S - ?C)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   711
      by (auto simp: disjnt_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   712
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   713
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   714
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   715
lemma lebesgue_set_almost_gdelta:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   716
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   717
  obtains C T where "gdelta C" "negligible T" "S \<union> T = C" "disjnt S T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   718
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   719
  have "-S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   720
    using assms Compl_in_sets_lebesgue by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   721
  then obtain C T where C: "fsigma C" "negligible T" "C \<union> T = -S" "disjnt C T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   722
    using lebesgue_set_almost_fsigma by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   723
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   724
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   725
    show "gdelta (-C)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   726
      by (simp add: \<open>fsigma C\<close> fsigma_imp_gdelta)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   727
    show "S \<union> T = -C" "disjnt S T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   728
      using C by (auto simp: disjnt_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   729
  qed (use C in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   730
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   731
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   732
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   733
proposition measure_semicontinuous_with_hausdist_explicit:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   734
  assumes "bounded S" and neg: "negligible(frontier S)" and "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   735
  obtains d where "d > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   736
                  "\<And>T. \<lbrakk>T \<in> lmeasurable; \<And>y. y \<in> T \<Longrightarrow> \<exists>x. x \<in> S \<and> dist x y < d\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   737
                        \<Longrightarrow> measure lebesgue T < measure lebesgue S + e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   738
proof (cases "S = {}")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   739
  case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   740
  with that \<open>e > 0\<close> show ?thesis by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   741
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   742
  case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   743
  then have frS: "frontier S \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   744
    using \<open>bounded S\<close> frontier_eq_empty not_bounded_UNIV by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   745
  have "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   746
    by (simp add: \<open>bounded S\<close> measurable_Jordan neg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   747
  have null: "(frontier S) \<in> null_sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   748
    by (metis neg negligible_iff_null_sets)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   749
  have "frontier S \<in> lmeasurable" and mS0: "measure lebesgue (frontier S) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   750
    using neg negligible_imp_measurable negligible_iff_measure by blast+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   751
  with \<open>e > 0\<close> lmeasurable_outer_open
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   752
  obtain U where "open U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   753
    and U: "frontier S \<subseteq> U" "U - frontier S \<in> lmeasurable" "measure lebesgue (U - frontier S) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   754
    by (metis fmeasurableD)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   755
  with null have "U \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   756
    by (metis borel_open measurable_Diff_null_set sets_completionI_sets sets_lborel)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   757
  have "measure lebesgue (U - frontier S) = measure lebesgue U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   758
    using mS0 by (simp add: \<open>U \<in> lmeasurable\<close> fmeasurableD measure_Diff_null_set null)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   759
  with U have mU: "measure lebesgue U < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   760
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   761
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   762
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   763
    have "U \<noteq> UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   764
      using \<open>U \<in> lmeasurable\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   765
    then have "- U \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   766
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   767
    with \<open>open U\<close> \<open>frontier S \<subseteq> U\<close> show "setdist (frontier S) (- U) > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   768
      by (auto simp: \<open>bounded S\<close> open_closed compact_frontier_bounded setdist_gt_0_compact_closed frS)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   769
    fix T
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   770
    assume "T \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   771
      and T: "\<And>t. t \<in> T \<Longrightarrow> \<exists>y. y \<in> S \<and> dist y t < setdist (frontier S) (- U)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   772
    then have "measure lebesgue T - measure lebesgue S \<le> measure lebesgue (T - S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   773
      by (simp add: \<open>S \<in> lmeasurable\<close> measure_diff_le_measure_setdiff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   774
    also have "\<dots>  \<le> measure lebesgue U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   775
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   776
      have "T - S \<subseteq> U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   777
      proof clarify
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   778
        fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   779
        assume "x \<in> T" and "x \<notin> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   780
        then obtain y where "y \<in> S" and y: "dist y x < setdist (frontier S) (- U)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   781
          using T by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   782
        have "closed_segment x y \<inter> frontier S \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   783
          using connected_Int_frontier \<open>x \<notin> S\<close> \<open>y \<in> S\<close> by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   784
        then obtain z where z: "z \<in> closed_segment x y" "z \<in> frontier S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   785
          by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   786
        with y have "dist z x < setdist(frontier S) (- U)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   787
          by (auto simp: dist_commute dest!: dist_in_closed_segment)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   788
        with z have False if "x \<in> -U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   789
          using setdist_le_dist [OF \<open>z \<in> frontier S\<close> that] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   790
        then show "x \<in> U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   791
          by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   792
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   793
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   794
        by (simp add: \<open>S \<in> lmeasurable\<close> \<open>T \<in> lmeasurable\<close> \<open>U \<in> lmeasurable\<close> fmeasurableD measure_mono_fmeasurable sets.Diff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   795
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   796
    finally have "measure lebesgue T - measure lebesgue S \<le> measure lebesgue U" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   797
    with mU show "measure lebesgue T < measure lebesgue S + e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   798
      by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   799
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   800
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   801
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   802
proposition lebesgue_regular_inner:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   803
 assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   804
 obtains K C where "negligible K" "\<And>n::nat. compact(C n)" "S = (\<Union>n. C n) \<union> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   805
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   806
  have "\<exists>T. closed T \<and> T \<subseteq> S \<and> (S - T) \<in> lmeasurable \<and> measure lebesgue (S - T) < (1/2)^n" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   807
    using sets_lebesgue_inner_closed assms
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   808
    by (metis sets_lebesgue_inner_closed zero_less_divide_1_iff zero_less_numeral zero_less_power)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   809
  then obtain C where clo: "\<And>n. closed (C n)" and subS: "\<And>n. C n \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   810
    and mea: "\<And>n. (S - C n) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   811
    and less: "\<And>n. measure lebesgue (S - C n) < (1/2)^n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   812
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   813
  have "\<exists>F. (\<forall>n::nat. compact(F n)) \<and> (\<Union>n. F n) = C m" for m::nat
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   814
    by (metis clo closed_Union_compact_subsets)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   815
  then obtain D :: "[nat,nat] \<Rightarrow> 'a set" where D: "\<And>m n. compact(D m n)" "\<And>m. (\<Union>n. D m n) = C m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   816
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   817
  let ?C = "from_nat_into (\<Union>m. range (D m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   818
  have "countable (\<Union>m. range (D m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   819
    by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   820
  have "range (from_nat_into (\<Union>m. range (D m))) = (\<Union>m. range (D m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   821
    using range_from_nat_into by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   822
  then have CD: "\<exists>m n. ?C k = D m n"  for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   823
    by (metis (mono_tags, lifting) UN_iff rangeE range_eqI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   824
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   825
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   826
    show "negligible (S - (\<Union>n. C n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   827
    proof (clarsimp simp: negligible_outer_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   828
      fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   829
      assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   830
      then obtain n where n: "(1/2)^n < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   831
        using real_arch_pow_inv [of e "1/2"] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   832
      show "\<exists>T. S - (\<Union>n. C n) \<subseteq> T \<and> T \<in> lmeasurable \<and> measure lebesgue T \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   833
      proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   834
        show "S - (\<Union>n. C n) \<subseteq> S - C n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   835
          by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   836
        show "S - C n \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   837
          by (simp add: mea)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   838
        show "measure lebesgue (S - C n) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   839
          using less [of n] n by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   840
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   841
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   842
    show "compact (?C n)" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   843
      using CD D by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   844
    show "S = (\<Union>n. ?C n) \<union> (S - (\<Union>n. C n))" (is "_ = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   845
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   846
      show "S \<subseteq> ?rhs"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   847
        using D by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   848
      show "?rhs \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   849
        using subS D CD by auto (metis Sup_upper range_eqI subsetCE)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   850
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   851
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   852
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   853
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   854
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   855
lemma sets_lebesgue_continuous_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   856
  assumes T: "T \<in> sets lebesgue" and contf: "continuous_on S f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   857
    and negim: "\<And>T. \<lbrakk>negligible T; T \<subseteq> S\<rbrakk> \<Longrightarrow> negligible(f ` T)" and "T \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   858
 shows "f ` T \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   859
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   860
  obtain K C where "negligible K" and com: "\<And>n::nat. compact(C n)" and Teq: "T = (\<Union>n. C n) \<union> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   861
    using lebesgue_regular_inner [OF T] by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   862
  then have comf: "\<And>n::nat. compact(f ` C n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   863
    by (metis Un_subset_iff Union_upper \<open>T \<subseteq> S\<close> compact_continuous_image contf continuous_on_subset rangeI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   864
  have "((\<Union>n. f ` C n) \<union> f ` K) \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   865
  proof (rule sets.Un)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   866
    have "K \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   867
      using Teq \<open>T \<subseteq> S\<close> by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   868
    show "(\<Union>n. f ` C n) \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   869
    proof (rule sets.countable_Union)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   870
      show "range (\<lambda>n. f ` C n) \<subseteq> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   871
        using borel_compact comf by (auto simp: borel_compact)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   872
    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   873
    show "f ` K \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   874
      by (simp add: \<open>K \<subseteq> S\<close> \<open>negligible K\<close> negim negligible_imp_sets)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   875
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   876
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   877
    by (simp add: Teq image_Un image_Union)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   878
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   879
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   880
lemma differentiable_image_in_sets_lebesgue:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   881
  fixes f :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   882
  assumes S: "S \<in> sets lebesgue" and dim: "DIM('m) \<le> DIM('n)" and f: "f differentiable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   883
  shows "f`S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   884
proof (rule sets_lebesgue_continuous_image [OF S])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   885
  show "continuous_on S f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   886
    by (meson differentiable_imp_continuous_on f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   887
  show "\<And>T. \<lbrakk>negligible T; T \<subseteq> S\<rbrakk> \<Longrightarrow> negligible (f ` T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   888
    using differentiable_on_subset f
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   889
    by (auto simp: intro!: negligible_differentiable_image_negligible [OF dim])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   890
qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   891
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   892
lemma sets_lebesgue_on_continuous_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   893
  assumes S: "S \<in> sets lebesgue" and X: "X \<in> sets (lebesgue_on S)" and contf: "continuous_on S f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   894
    and negim: "\<And>T. \<lbrakk>negligible T; T \<subseteq> S\<rbrakk> \<Longrightarrow> negligible(f ` T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   895
  shows "f ` X \<in> sets (lebesgue_on (f ` S))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   896
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   897
  have "X \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   898
    by (metis S X sets.Int_space_eq2 sets_restrict_space_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   899
  moreover have "f ` S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   900
    using S contf negim sets_lebesgue_continuous_image by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   901
  moreover have "f ` X \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   902
    by (metis S X contf negim sets_lebesgue_continuous_image sets_restrict_space_iff space_restrict_space space_restrict_space2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   903
  ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   904
    by (auto simp: sets_restrict_space_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   905
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   906
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   907
lemma differentiable_image_in_sets_lebesgue_on:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   908
  fixes f :: "'m::euclidean_space \<Rightarrow> 'n::euclidean_space"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   909
  assumes S: "S \<in> sets lebesgue" and X: "X \<in> sets (lebesgue_on S)" and dim: "DIM('m) \<le> DIM('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   910
       and f: "f differentiable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   911
     shows "f ` X \<in> sets (lebesgue_on (f`S))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   912
proof (rule sets_lebesgue_on_continuous_image [OF S X])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   913
  show "continuous_on S f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   914
    by (meson differentiable_imp_continuous_on f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   915
  show "\<And>T. \<lbrakk>negligible T; T \<subseteq> S\<rbrakk> \<Longrightarrow> negligible (f ` T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   916
    using differentiable_on_subset f
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   917
    by (auto simp: intro!: negligible_differentiable_image_negligible [OF dim])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   918
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   919
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   920
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   921
proposition
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   922
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   923
  assumes S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   924
  and deriv: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   925
  and int: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   926
  and bounded: "\<And>x. x \<in> S \<Longrightarrow> \<bar>det (matrix (f' x))\<bar> \<le> B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   927
  shows measurable_bounded_differentiable_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   928
       "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   929
    and measure_bounded_differentiable_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   930
       "measure lebesgue (f ` S) \<le> B * measure lebesgue S" (is "?M")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   931
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   932
  have "f ` S \<in> lmeasurable \<and> measure lebesgue (f ` S) \<le> B * measure lebesgue S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   933
  proof (cases "B < 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   934
    case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   935
    then have "S = {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   936
      by (meson abs_ge_zero bounded empty_iff equalityI less_le_trans linorder_not_less subsetI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   937
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   938
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   939
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   940
    case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   941
    then have "B \<ge> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   942
      by arith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   943
    let ?\<mu> = "measure lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   944
    have f_diff: "f differentiable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   945
      using deriv by (auto simp: differentiable_on_def differentiable_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   946
    have eps: "f ` S \<in> lmeasurable" "?\<mu> (f ` S) \<le> (B+e) * ?\<mu> S" (is "?ME")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   947
              if "e > 0" for e
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   948
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   949
      have eps_d: "f ` S \<in> lmeasurable"  "?\<mu> (f ` S) \<le> (B+e) * (?\<mu> S + d)" (is "?MD")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   950
                  if "d > 0" for d
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   951
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   952
        obtain T where "open T" "S \<subseteq> T" and TS: "(T-S) \<in> lmeasurable" and "?\<mu> (T-S) < d"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   953
          using S \<open>d > 0\<close> lmeasurable_outer_open by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   954
        with S have "T \<in> lmeasurable" and Tless: "?\<mu> T < ?\<mu> S + d"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   955
          by (auto simp: measurable_measure_Diff dest!: fmeasurable_Diff_D)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   956
        have "\<exists>r. 0 < r \<and> r < d \<and> ball x r \<subseteq> T \<and> f ` (S \<inter> ball x r) \<in> lmeasurable \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   957
                  ?\<mu> (f ` (S \<inter> ball x r)) \<le> (B + e) * ?\<mu> (ball x r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   958
          if "x \<in> S" "d > 0" for x d
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   959
        proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   960
          have lin: "linear (f' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   961
            and lim0: "((\<lambda>y. (f y - (f x + f' x (y - x))) /\<^sub>R norm(y - x)) \<longlongrightarrow> 0) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   962
            using deriv \<open>x \<in> S\<close> by (auto simp: has_derivative_within bounded_linear.linear field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   963
          have bo: "bounded (f' x ` ball 0 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   964
            by (simp add: bounded_linear_image linear_linear lin)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   965
          have neg: "negligible (frontier (f' x ` ball 0 1))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   966
            using deriv has_derivative_linear \<open>x \<in> S\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   967
            by (auto intro!: negligible_convex_frontier [OF convex_linear_image])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   968
          have 0: "0 < e * unit_ball_vol (real CARD('n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   969
            using  \<open>e > 0\<close> by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   970
          obtain k where "k > 0" and k:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   971
                  "\<And>U. \<lbrakk>U \<in> lmeasurable; \<And>y. y \<in> U \<Longrightarrow> \<exists>z. z \<in> f' x ` ball 0 1 \<and> dist z y < k\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   972
                        \<Longrightarrow> ?\<mu> U < ?\<mu> (f' x ` ball 0 1) + e * unit_ball_vol (CARD('n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   973
            using measure_semicontinuous_with_hausdist_explicit [OF bo neg 0] by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   974
          obtain l where "l > 0" and l: "ball x l \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   975
            using \<open>x \<in> S\<close> \<open>open T\<close> \<open>S \<subseteq> T\<close> openE by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   976
          obtain \<zeta> where "0 < \<zeta>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   977
            and \<zeta>: "\<And>y. \<lbrakk>y \<in> S; y \<noteq> x; dist y x < \<zeta>\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   978
                        \<Longrightarrow> norm (f y - (f x + f' x (y - x))) / norm (y - x) < k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   979
            using lim0 \<open>k > 0\<close> by (force simp: Lim_within field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   980
          define r where "r \<equiv> min (min l (\<zeta>/2)) (min 1 (d/2))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   981
          show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   982
          proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   983
            show "r > 0" "r < d"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   984
              using \<open>l > 0\<close> \<open>\<zeta> > 0\<close> \<open>d > 0\<close> by (auto simp: r_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   985
            have "r \<le> l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   986
              by (auto simp: r_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   987
            with l show "ball x r \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   988
              by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   989
            have ex_lessK: "\<exists>x' \<in> ball 0 1. dist (f' x x') ((f y - f x) /\<^sub>R r) < k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   990
              if "y \<in> S" and "dist x y < r" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   991
            proof (cases "y = x")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   992
              case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   993
              with lin linear_0 \<open>k > 0\<close> that show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   994
                by (rule_tac x=0 in bexI) (auto simp: linear_0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   995
            next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   996
              case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   997
              then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   998
              proof (rule_tac x="(y - x) /\<^sub>R r" in bexI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
   999
                have "f' x ((y - x) /\<^sub>R r) = f' x (y - x) /\<^sub>R r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1000
                  by (simp add: lin linear_cmul)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1001
                then have "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) = norm (f' x (y - x) /\<^sub>R r - (f y - f x) /\<^sub>R r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1002
                  by (simp add: dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1003
                also have "\<dots> = norm (f' x (y - x) - (f y - f x)) / r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1004
                  using \<open>r > 0\<close> by (simp add: real_vector.scale_right_diff_distrib [symmetric] divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1005
                also have "\<dots> \<le> norm (f y - (f x + f' x (y - x))) / norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1006
                  using that \<open>r > 0\<close> False by (simp add: algebra_simps divide_simps dist_norm norm_minus_commute mult_right_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1007
                also have "\<dots> < k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1008
                  using that \<open>0 < \<zeta>\<close> by (simp add: dist_commute r_def  \<zeta> [OF \<open>y \<in> S\<close> False])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1009
                finally show "dist (f' x ((y - x) /\<^sub>R r)) ((f y - f x) /\<^sub>R r) < k" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1010
                show "(y - x) /\<^sub>R r \<in> ball 0 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1011
                  using that \<open>r > 0\<close> by (simp add: dist_norm divide_simps norm_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1012
              qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1013
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1014
            let ?rfs = "(\<lambda>x. x /\<^sub>R r) ` (+) (- f x) ` f ` (S \<inter> ball x r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1015
            have rfs_mble: "?rfs \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1016
            proof (rule bounded_set_imp_lmeasurable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1017
              have "f differentiable_on S \<inter> ball x r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1018
                using f_diff by (auto simp: fmeasurableD differentiable_on_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1019
              with S show "?rfs \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1020
                by (auto simp: sets.Int intro!: lebesgue_sets_translation differentiable_image_in_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1021
              let ?B = "(\<lambda>(x, y). x + y) ` (f' x ` ball 0 1 \<times> ball 0 k)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1022
              have "bounded ?B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1023
                by (simp add: bounded_plus [OF bo])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1024
              moreover have "?rfs \<subseteq> ?B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1025
                apply (auto simp: dist_norm image_iff dest!: ex_lessK)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1026
                by (metis (no_types, hide_lams) add.commute diff_add_cancel dist_0_norm dist_commute dist_norm mem_ball)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1027
              ultimately show "bounded (?rfs)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1028
                by (rule bounded_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1029
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1030
            then have "(\<lambda>x. r *\<^sub>R x) ` ?rfs \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1031
              by (simp add: measurable_linear_image)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1032
            with \<open>r > 0\<close> have "(+) (- f x) ` f ` (S \<inter> ball x r) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1033
              by (simp add: image_comp o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1034
            then have "(+) (f x) ` (+) (- f x) ` f ` (S \<inter> ball x r) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1035
              using  measurable_translation by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1036
            then show fsb: "f ` (S \<inter> ball x r) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1037
              by (simp add: image_comp o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1038
            have "?\<mu> (f ` (S \<inter> ball x r)) = ?\<mu> (?rfs) * r ^ CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1039
              using \<open>r > 0\<close> by (simp add: measure_translation measure_linear_image measurable_translation fsb field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1040
            also have "\<dots> \<le> (\<bar>det (matrix (f' x))\<bar> * unit_ball_vol (CARD('n)) + e * unit_ball_vol (CARD('n))) * r ^ CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1041
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1042
              have "?\<mu> (?rfs) < ?\<mu> (f' x ` ball 0 1) + e * unit_ball_vol (CARD('n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1043
                using rfs_mble by (force intro: k dest!: ex_lessK)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1044
              then have "?\<mu> (?rfs) < \<bar>det (matrix (f' x))\<bar> * unit_ball_vol (CARD('n)) + e * unit_ball_vol (CARD('n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1045
                by (simp add: lin measure_linear_image [of "f' x"] content_ball)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1046
              with \<open>r > 0\<close> show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1047
                by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1048
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1049
            also have "\<dots> \<le> (B + e) * ?\<mu> (ball x r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1050
              using bounded [OF \<open>x \<in> S\<close>] \<open>r > 0\<close> by (simp add: content_ball algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1051
            finally show "?\<mu> (f ` (S \<inter> ball x r)) \<le> (B + e) * ?\<mu> (ball x r)" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1052
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1053
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1054
        then obtain r where
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1055
          r0d: "\<And>x d. \<lbrakk>x \<in> S; d > 0\<rbrakk> \<Longrightarrow> 0 < r x d \<and> r x d < d"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1056
          and rT: "\<And>x d. \<lbrakk>x \<in> S; d > 0\<rbrakk> \<Longrightarrow> ball x (r x d) \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1057
          and r: "\<And>x d. \<lbrakk>x \<in> S; d > 0\<rbrakk> \<Longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1058
                  (f ` (S \<inter> ball x (r x d))) \<in> lmeasurable \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1059
                  ?\<mu> (f ` (S \<inter> ball x (r x d))) \<le> (B + e) * ?\<mu> (ball x (r x d))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1060
          by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1061
        obtain C where "countable C" and Csub: "C \<subseteq> {(x,r x t) |x t. x \<in> S \<and> 0 < t}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1062
          and pwC: "pairwise (\<lambda>i j. disjnt (ball (fst i) (snd i)) (ball (fst j) (snd j))) C"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1063
          and negC: "negligible(S - (\<Union>i \<in> C. ball (fst i) (snd i)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1064
          apply (rule Vitali_covering_theorem_balls [of S "{(x,r x t) |x t. x \<in> S \<and> 0 < t}" fst snd])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1065
           apply auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1066
          by (metis dist_eq_0_iff r0d)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1067
        let ?UB = "(\<Union>(x,s) \<in> C. ball x s)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1068
        have eq: "f ` (S \<inter> ?UB) = (\<Union>(x,s) \<in> C. f ` (S \<inter> ball x s))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1069
          by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1070
        have mle: "?\<mu> (\<Union>(x,s) \<in> K. f ` (S \<inter> ball x s)) \<le> (B + e) * (?\<mu> S + d)"  (is "?l \<le> ?r")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1071
          if "K \<subseteq> C" and "finite K" for K
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1072
        proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1073
          have gt0: "b > 0" if "(a, b) \<in> K" for a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1074
            using Csub that \<open>K \<subseteq> C\<close> r0d by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1075
          have inj: "inj_on (\<lambda>(x, y). ball x y) K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1076
            by (force simp: inj_on_def ball_eq_ball_iff dest: gt0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1077
          have disjnt: "disjoint ((\<lambda>(x, y). ball x y) ` K)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1078
            using pwC that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1079
            apply (clarsimp simp: pairwise_def case_prod_unfold ball_eq_ball_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1080
            by (metis subsetD fst_conv snd_conv)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1081
          have "?l \<le> (\<Sum>i\<in>K. ?\<mu> (case i of (x, s) \<Rightarrow> f ` (S \<inter> ball x s)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1082
          proof (rule measure_UNION_le [OF \<open>finite K\<close>], clarify)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1083
            fix x r
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1084
            assume "(x,r) \<in> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1085
            then have "x \<in> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1086
              using Csub \<open>K \<subseteq> C\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1087
            show "f ` (S \<inter> ball x r) \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1088
              by (meson Int_lower1 S differentiable_on_subset f_diff fmeasurableD lmeasurable_ball order_refl sets.Int differentiable_image_in_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1089
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1090
          also have "\<dots> \<le> (\<Sum>(x,s) \<in> K. (B + e) * ?\<mu> (ball x s))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1091
            apply (rule sum_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1092
            using Csub r \<open>K \<subseteq> C\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1093
          also have "\<dots> = (B + e) * (\<Sum>(x,s) \<in> K. ?\<mu> (ball x s))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1094
            by (simp add: prod.case_distrib sum_distrib_left)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1095
          also have "\<dots> = (B + e) * sum ?\<mu> ((\<lambda>(x, y). ball x y) ` K)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1096
            using \<open>B \<ge> 0\<close> \<open>e > 0\<close> by (simp add: inj sum.reindex prod.case_distrib)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1097
          also have "\<dots> = (B + e) * ?\<mu> (\<Union>(x,s) \<in> K. ball x s)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1098
            using \<open>B \<ge> 0\<close> \<open>e > 0\<close> that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1099
            by (subst measure_Union') (auto simp: disjnt measure_Union')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1100
          also have "\<dots> \<le> (B + e) * ?\<mu> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1101
            using \<open>B \<ge> 0\<close> \<open>e > 0\<close> that apply simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1102
            apply (rule measure_mono_fmeasurable [OF _ _ \<open>T \<in> lmeasurable\<close>])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1103
            using Csub rT by force+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1104
          also have "\<dots> \<le> (B + e) * (?\<mu> S + d)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1105
            using \<open>B \<ge> 0\<close> \<open>e > 0\<close> Tless by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1106
          finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1107
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1108
        have fSUB_mble: "(f ` (S \<inter> ?UB)) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1109
          unfolding eq using Csub r False \<open>e > 0\<close> that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1110
          by (auto simp: intro!: fmeasurable_UN_bound [OF \<open>countable C\<close> _ mle])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1111
        have fSUB_meas: "?\<mu> (f ` (S \<inter> ?UB)) \<le> (B + e) * (?\<mu> S + d)"  (is "?MUB")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1112
          unfolding eq using Csub r False \<open>e > 0\<close> that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1113
          by (auto simp: intro!: measure_UN_bound [OF \<open>countable C\<close> _ mle])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1114
        have neg: "negligible ((f ` (S \<inter> ?UB) - f ` S) \<union> (f ` S - f ` (S \<inter> ?UB)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1115
        proof (rule negligible_subset [OF negligible_differentiable_image_negligible [OF order_refl negC, where f=f]])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1116
          show "f differentiable_on S - (\<Union>i\<in>C. ball (fst i) (snd i))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1117
            by (meson DiffE differentiable_on_subset subsetI f_diff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1118
        qed force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1119
        show "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1120
          by (rule lmeasurable_negligible_symdiff [OF fSUB_mble neg])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1121
        show ?MD
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1122
          using fSUB_meas measure_negligible_symdiff [OF fSUB_mble neg] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1123
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1124
      show "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1125
        using eps_d [of 1] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1126
      show ?ME
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1127
      proof (rule field_le_epsilon)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1128
        fix \<delta> :: real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1129
        assume "0 < \<delta>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1130
        then show "?\<mu> (f ` S) \<le> (B + e) * ?\<mu> S + \<delta>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1131
          using eps_d [of "\<delta> / (B+e)"] \<open>e > 0\<close> \<open>B \<ge> 0\<close> by (auto simp: divide_simps mult_ac)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1132
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1133
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1134
    show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1135
    proof (cases "?\<mu> S = 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1136
      case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1137
      with eps have "?\<mu> (f ` S) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1138
        by (metis mult_zero_right not_le zero_less_measure_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1139
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1140
        using eps [of 1] by (simp add: True)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1141
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1142
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1143
      have "?\<mu> (f ` S) \<le> B * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1144
      proof (rule field_le_epsilon)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1145
        fix e :: real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1146
        assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1147
        then show "?\<mu> (f ` S) \<le> B * ?\<mu> S + e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1148
          using eps [of "e / ?\<mu> S"] False by (auto simp: algebra_simps zero_less_measure_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1149
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1150
      with eps [of 1] show ?thesis by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1151
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1152
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1153
  then show "f ` S \<in> lmeasurable" ?M by blast+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1154
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1155
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1156
lemma
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1157
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1158
  assumes S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1159
    and deriv: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1160
    and int: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1161
  shows m_diff_image_weak: "f ` S \<in> lmeasurable \<and> measure lebesgue (f ` S) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1162
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1163
  let ?\<mu> = "measure lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1164
  have aint_S: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1165
    using int unfolding absolutely_integrable_on_def by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1166
  define m where "m \<equiv> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1167
  have *: "f ` S \<in> lmeasurable" "?\<mu> (f ` S) \<le> m + e * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1168
    if "e > 0" for e
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1169
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1170
    define T where "T \<equiv> \<lambda>n. {x \<in> S. n * e \<le> \<bar>det (matrix (f' x))\<bar> \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1171
                                     \<bar>det (matrix (f' x))\<bar> < (Suc n) * e}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1172
    have meas_t: "T n \<in> lmeasurable" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1173
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1174
      have *: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1175
        using aint_S by (simp add: S borel_measurable_restrict_space_iff fmeasurableD set_integrable_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1176
      have [intro]: "x \<in> sets (lebesgue_on S) \<Longrightarrow> x \<in> sets lebesgue" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1177
        using S sets_restrict_space_subset by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1178
      have "{x \<in> S. real n * e \<le> \<bar>det (matrix (f' x))\<bar>} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1179
        using * by (auto simp: borel_measurable_iff_halfspace_ge space_restrict_space)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1180
      then have 1: "{x \<in> S. real n * e \<le> \<bar>det (matrix (f' x))\<bar>} \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1181
        using S by (simp add: fmeasurableI2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1182
      have "{x \<in> S. \<bar>det (matrix (f' x))\<bar> < (1 + real n) * e} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1183
        using * by (auto simp: borel_measurable_iff_halfspace_less space_restrict_space)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1184
      then have 2: "{x \<in> S. \<bar>det (matrix (f' x))\<bar> < (1 + real n) * e} \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1185
        using S by (simp add: fmeasurableI2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1186
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1187
        using fmeasurable.Int [OF 1 2] by (simp add: T_def Int_def cong: conj_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1188
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1189
    have aint_T: "\<And>k. (\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on T k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1190
      using set_integrable_subset [OF aint_S] meas_t T_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1191
    have Seq: "S = (\<Union>n. T n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1192
      apply (auto simp: T_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1193
      apply (rule_tac x="nat(floor(abs(det(matrix(f' x))) / e))" in exI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1194
      using that apply auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1195
      using of_int_floor_le pos_le_divide_eq apply blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1196
      by (metis add.commute pos_divide_less_eq real_of_int_floor_add_one_gt)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1197
    have meas_ft: "f ` T n \<in> lmeasurable" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1198
    proof (rule measurable_bounded_differentiable_image)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1199
      show "T n \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1200
        by (simp add: meas_t)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1201
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1202
      fix x :: "(real,'n) vec"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1203
      assume "x \<in> T n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1204
      show "(f has_derivative f' x) (at x within T n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1205
        by (metis (no_types, lifting) \<open>x \<in> T n\<close> deriv has_derivative_within_subset mem_Collect_eq subsetI T_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1206
      show "\<bar>det (matrix (f' x))\<bar> \<le> (Suc n) * e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1207
        using \<open>x \<in> T n\<close> T_def by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1208
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1209
      show "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on T n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1210
        using aint_T absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1211
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1212
    have disT: "disjoint (range T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1213
      unfolding disjoint_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1214
    proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1215
      show "T m \<inter> T n = {}" if "T m \<noteq> T n" for m n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1216
        using that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1217
      proof (induction m n rule: linorder_less_wlog)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1218
        case (less m n)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1219
        with \<open>e > 0\<close> show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1220
          unfolding T_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1221
          proof (clarsimp simp add: Collect_conj_eq [symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1222
            fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1223
            assume "e > 0"  "m < n"  "n * e \<le> \<bar>det (matrix (f' x))\<bar>"  "\<bar>det (matrix (f' x))\<bar> < (1 + real m) * e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1224
            then have "n < 1 + real m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1225
              by (metis (no_types, hide_lams) less_le_trans mult.commute not_le real_mult_le_cancel_iff2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1226
            then show "False"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1227
              using less.hyps by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1228
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1229
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1230
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1231
    have injT: "inj_on T ({n. T n \<noteq> {}})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1232
      unfolding inj_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1233
    proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1234
      show "m = n" if "T m = T n" "T n \<noteq> {}" for m n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1235
        using that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1236
      proof (induction m n rule: linorder_less_wlog)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1237
        case (less m n)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1238
        have False if "T n \<subseteq> T m" "x \<in> T n" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1239
          using \<open>e > 0\<close> \<open>m < n\<close> that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1240
          apply (auto simp: T_def  mult.commute intro: less_le_trans dest!: subsetD)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1241
          by (metis add.commute less_le_trans nat_less_real_le not_le real_mult_le_cancel_iff2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1242
        then show ?case
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1243
          using less.prems by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1244
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1245
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1246
    have sum_eq_Tim: "(\<Sum>k\<le>n. f (T k)) = sum f (T ` {..n})" if "f {} = 0" for f :: "_ \<Rightarrow> real" and n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1247
    proof (subst sum.reindex_nontrivial)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1248
      fix i j  assume "i \<in> {..n}" "j \<in> {..n}" "i \<noteq> j" "T i = T j"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1249
      with that  injT [unfolded inj_on_def] show "f (T i) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1250
        by simp metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1251
    qed (use atMost_atLeast0 in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1252
    let ?B = "m + e * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1253
    have "(\<Sum>k\<le>n. ?\<mu> (f ` T k)) \<le> ?B" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1254
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1255
      have "(\<Sum>k\<le>n. ?\<mu> (f ` T k)) \<le> (\<Sum>k\<le>n. ((k+1) * e) * ?\<mu>(T k))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1256
      proof (rule sum_mono [OF measure_bounded_differentiable_image])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1257
        show "(f has_derivative f' x) (at x within T k)" if "x \<in> T k" for k x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1258
          using that unfolding T_def by (blast intro: deriv has_derivative_within_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1259
        show "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on T k" for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1260
          using absolutely_integrable_on_def aint_T by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1261
        show "\<bar>det (matrix (f' x))\<bar> \<le> real (k + 1) * e" if "x \<in> T k" for k x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1262
          using T_def that by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1263
      qed (use meas_t in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1264
      also have "\<dots> \<le> (\<Sum>k\<le>n. (k * e) * ?\<mu>(T k)) + (\<Sum>k\<le>n. e * ?\<mu>(T k))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1265
        by (simp add: algebra_simps sum.distrib)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1266
      also have "\<dots> \<le> ?B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1267
      proof (rule add_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1268
        have "(\<Sum>k\<le>n. real k * e * ?\<mu> (T k)) = (\<Sum>k\<le>n. integral (T k) (\<lambda>x. k * e))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1269
          by (simp add: lmeasure_integral [OF meas_t]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1270
                        integral_mult_right [symmetric] integral_mult_left [symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1271
                   del: integral_mult_right integral_mult_left)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1272
        also have "\<dots> \<le> (\<Sum>k\<le>n. integral (T k) (\<lambda>x.  (abs (det (matrix (f' x))))))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1273
        proof (rule sum_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1274
          fix k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1275
          assume "k \<in> {..n}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1276
          show "integral (T k) (\<lambda>x. k * e) \<le> integral (T k) (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1277
          proof (rule integral_le [OF integrable_on_const [OF meas_t]])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1278
            show "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on T k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1279
              using absolutely_integrable_on_def aint_T by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1280
          next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1281
            fix x assume "x \<in> T k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1282
            show "k * e \<le> \<bar>det (matrix (f' x))\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1283
              using \<open>x \<in> T k\<close> T_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1284
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1285
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1286
        also have "\<dots> = sum (\<lambda>T. integral T (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)) (T ` {..n})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1287
          by (auto intro: sum_eq_Tim)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1288
        also have "\<dots> = integral (\<Union>k\<le>n. T k) (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1289
        proof (rule integral_unique [OF has_integral_Union, symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1290
          fix S  assume "S \<in> T ` {..n}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1291
          then show "((\<lambda>x. \<bar>det (matrix (f' x))\<bar>) has_integral integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)) S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1292
          using absolutely_integrable_on_def aint_T by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1293
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1294
          show "pairwise (\<lambda>S S'. negligible (S \<inter> S')) (T ` {..n})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1295
            using disT unfolding disjnt_iff by (auto simp: pairwise_def intro!: empty_imp_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1296
        qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1297
        also have "\<dots> \<le> m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1298
          unfolding m_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1299
        proof (rule integral_subset_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1300
          have "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on (\<Union>k\<le>n. T k)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1301
            apply (rule set_integrable_subset [OF aint_S])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1302
             apply (intro measurable meas_t fmeasurableD)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1303
            apply (force simp: Seq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1304
            done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1305
          then show "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on (\<Union>k\<le>n. T k)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1306
            using absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1307
        qed (use Seq int in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1308
        finally show "(\<Sum>k\<le>n. real k * e * ?\<mu> (T k)) \<le> m" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1309
      next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1310
        have "(\<Sum>k\<le>n. ?\<mu> (T k)) = sum ?\<mu> (T ` {..n})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1311
          by (auto intro: sum_eq_Tim)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1312
        also have "\<dots> = ?\<mu> (\<Union>k\<le>n. T k)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1313
          using S disT by (auto simp: pairwise_def meas_t intro: measure_Union' [symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1314
        also have "\<dots> \<le> ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1315
          using S by (auto simp: Seq intro: meas_t fmeasurableD measure_mono_fmeasurable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1316
        finally have "(\<Sum>k\<le>n. ?\<mu> (T k)) \<le> ?\<mu> S" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1317
        then show "(\<Sum>k\<le>n. e * ?\<mu> (T k)) \<le> e * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1318
          by (metis less_eq_real_def ordered_comm_semiring_class.comm_mult_left_mono sum_distrib_left that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1319
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1320
      finally show "(\<Sum>k\<le>n. ?\<mu> (f ` T k)) \<le> ?B" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1321
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1322
    moreover have "measure lebesgue (\<Union>k\<le>n. f ` T k) \<le> (\<Sum>k\<le>n. ?\<mu> (f ` T k))" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1323
      by (simp add: fmeasurableD meas_ft measure_UNION_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1324
    ultimately have B_ge_m: "?\<mu> (\<Union>k\<le>n. (f ` T k)) \<le> ?B" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1325
      by (meson order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1326
    have "(\<Union>n. f ` T n) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1327
      by (rule fmeasurable_countable_Union [OF meas_ft B_ge_m])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1328
    moreover have "?\<mu> (\<Union>n. f ` T n) \<le> m + e * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1329
      by (rule measure_countable_Union_le [OF meas_ft B_ge_m])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1330
    ultimately show "f ` S \<in> lmeasurable" "?\<mu> (f ` S) \<le> m + e * ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1331
      by (auto simp: Seq image_Union)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1332
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1333
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1334
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1335
    show "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1336
      using * linordered_field_no_ub by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1337
    let ?x = "m - ?\<mu> (f ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1338
    have False if "?\<mu> (f ` S) > integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1339
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1340
      have ml: "m < ?\<mu> (f ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1341
        using m_def that by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1342
      then have "?\<mu> S \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1343
        using "*"(2) bgauge_existence_lemma by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1344
      with ml have 0: "0 < - (m - ?\<mu> (f ` S))/2 / ?\<mu> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1345
        using that zero_less_measure_iff by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1346
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1347
        using * [OF 0] that by (auto simp: divide_simps m_def split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1348
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1349
    then show "?\<mu> (f ` S) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1350
      by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1351
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1352
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1353
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1354
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1355
theorem
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1356
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1357
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1358
    and deriv: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1359
    and int: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1360
  shows measurable_differentiable_image: "f ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1361
    and measure_differentiable_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1362
       "measure lebesgue (f ` S) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)" (is "?M")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1363
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1364
  let ?I = "\<lambda>n::nat. cbox (vec (-n)) (vec n) \<inter> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1365
  let ?\<mu> = "measure lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1366
  have "x \<in> cbox (vec (- real (nat \<lceil>norm x\<rceil>))) (vec (real (nat \<lceil>norm x\<rceil>)))" for x :: "real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1367
    apply (auto simp: mem_box_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1368
    apply (metis abs_le_iff component_le_norm_cart minus_le_iff of_nat_ceiling order.trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1369
    by (meson abs_le_D1 norm_bound_component_le_cart real_nat_ceiling_ge)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1370
  then have Seq: "S = (\<Union>n. ?I n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1371
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1372
  have fIn: "f ` ?I n \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1373
       and mfIn: "?\<mu> (f ` ?I n) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)" (is ?MN) for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1374
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1375
    have In: "?I n \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1376
      by (simp add: S bounded_Int bounded_set_imp_lmeasurable sets.Int)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1377
    moreover have "\<And>x. x \<in> ?I n \<Longrightarrow> (f has_derivative f' x) (at x within ?I n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1378
      by (meson Int_iff deriv has_derivative_within_subset subsetI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1379
    moreover have int_In: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on ?I n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1380
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1381
      have "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1382
        using int absolutely_integrable_integrable_bound by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1383
      then have "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on ?I n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1384
        by (metis (no_types) Int_lower1 In fmeasurableD inf_commute set_integrable_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1385
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1386
        using absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1387
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1388
    ultimately have "f ` ?I n \<in> lmeasurable" "?\<mu> (f ` ?I n) \<le> integral (?I n) (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1389
      using m_diff_image_weak by metis+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1390
    moreover have "integral (?I n) (\<lambda>x. \<bar>det (matrix (f' x))\<bar>) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1391
      by (simp add: int_In int integral_subset_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1392
    ultimately show "f ` ?I n \<in> lmeasurable" ?MN
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1393
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1394
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1395
  have "?I k \<subseteq> ?I n" if "k \<le> n" for k n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1396
    by (rule Int_mono) (use that in \<open>auto simp: subset_interval_imp_cart\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1397
  then have "(\<Union>k\<le>n. f ` ?I k) = f ` ?I n" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1398
    by (fastforce simp add:)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1399
  with mfIn have "?\<mu> (\<Union>k\<le>n. f ` ?I k) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1400
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1401
  then have "(\<Union>n. f ` ?I n) \<in> lmeasurable" "?\<mu> (\<Union>n. f ` ?I n) \<le> integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1402
    by (rule fmeasurable_countable_Union [OF fIn] measure_countable_Union_le [OF fIn])+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1403
  then show "f ` S \<in> lmeasurable" ?M
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1404
    by (metis Seq image_UN)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1405
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1406
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1407
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1408
lemma borel_measurable_simple_function_limit_increasing:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1409
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1410
  shows "(f \<in> borel_measurable lebesgue \<and> (\<forall>x. 0 \<le> f x)) \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1411
         (\<exists>g. (\<forall>n x. 0 \<le> g n x \<and> g n x \<le> f x) \<and> (\<forall>n x. g n x \<le> (g(Suc n) x)) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1412
              (\<forall>n. g n \<in> borel_measurable lebesgue) \<and> (\<forall>n. finite(range (g n))) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1413
              (\<forall>x. (\<lambda>n. g n x) \<longlonglongrightarrow> f x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1414
         (is "?lhs = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1415
proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1416
  assume f: ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1417
  have leb_f: "{x. a \<le> f x \<and> f x < b} \<in> sets lebesgue" for a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1418
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1419
    have "{x. a \<le> f x \<and> f x < b} = {x. f x < b} - {x. f x < a}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1420
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1421
    also have "\<dots> \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1422
      using borel_measurable_vimage_halfspace_component_lt [of f UNIV] f by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1423
    finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1424
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1425
  have "g n x \<le> f x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1426
        if inc_g: "\<And>n x. 0 \<le> g n x \<and> g n x \<le> g (Suc n) x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1427
           and meas_g: "\<And>n. g n \<in> borel_measurable lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1428
           and fin: "\<And>n. finite(range (g n))" and lim: "\<And>x. (\<lambda>n. g n x) \<longlonglongrightarrow> f x" for g n x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1429
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1430
    have "\<exists>r>0. \<forall>N. \<exists>n\<ge>N. dist (g n x) (f x) \<ge> r" if "g n x > f x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1431
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1432
      have g: "g n x \<le> g (N + n) x" for N
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1433
        by (rule transitive_stepwise_le) (use inc_g in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1434
      have "\<exists>na\<ge>N. g n x - f x \<le> dist (g na x) (f x)" for N
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1435
        apply (rule_tac x="N+n" in exI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1436
        using g [of N] by (auto simp: dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1437
      with that show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1438
        using diff_gt_0_iff_gt by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1439
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1440
    with lim show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1441
      apply (auto simp: lim_sequentially)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1442
      by (meson less_le_not_le not_le_imp_less)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1443
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1444
  moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1445
  let ?\<Omega> = "\<lambda>n k. indicator {y. k/2^n \<le> f y \<and> f y < (k+1)/2^n}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1446
  let ?g = "\<lambda>n x. (\<Sum>k::real | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * ?\<Omega> n k x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1447
  have "\<exists>g. (\<forall>n x. 0 \<le> g n x \<and> g n x \<le> (g(Suc n) x)) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1448
             (\<forall>n. g n \<in> borel_measurable lebesgue) \<and> (\<forall>n. finite(range (g n))) \<and>(\<forall>x. (\<lambda>n. g n x) \<longlonglongrightarrow> f x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1449
  proof (intro exI allI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1450
    show "0 \<le> ?g n x" for n x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1451
    proof (clarify intro!: ordered_comm_monoid_add_class.sum_nonneg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1452
      fix k::real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1453
      assume "k \<in> \<int>" and k: "\<bar>k\<bar> \<le> 2 ^ (2*n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1454
      show "0 \<le> k/2^n * ?\<Omega> n k x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1455
        using f \<open>k \<in> \<int>\<close> apply (auto simp: indicator_def divide_simps Ints_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1456
        apply (drule spec [where x=x])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1457
        using zero_le_power [of "2::real" n] mult_nonneg_nonneg [of "f x" "2^n"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1458
        by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1459
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1460
    show "?g n x \<le> ?g (Suc n) x" for n x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1461
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1462
      have "?g n x =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1463
            (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n).
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1464
              k/2^n * (indicator {y. k/2^n \<le> f y \<and> f y < (k+1/2)/2^n} x +
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1465
              indicator {y. (k+1/2)/2^n \<le> f y \<and> f y < (k+1)/2^n} x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1466
        by (rule sum.cong [OF refl]) (simp add: indicator_def divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1467
      also have "\<dots> = (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * indicator {y. k/2^n \<le> f y \<and> f y < (k+1/2)/2^n} x) +
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1468
                       (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * indicator {y. (k+1/2)/2^n \<le> f y \<and> f y < (k+1)/2^n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1469
        by (simp add:  comm_monoid_add_class.sum.distrib algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1470
      also have "\<dots> = (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). (2 * k)/2 ^ Suc n * indicator {y. (2 * k)/2 ^ Suc n \<le> f y \<and> f y < (2 * k+1)/2 ^ Suc n} x) +
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1471
                       (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). (2 * k)/2 ^ Suc n * indicator {y. (2 * k+1)/2 ^ Suc n \<le> f y \<and> f y < ((2 * k+1) + 1)/2 ^ Suc n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1472
        by (force simp: field_simps indicator_def intro: sum.cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1473
      also have "\<dots> \<le> (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2 * Suc n). k/2 ^ Suc n * (indicator {y. k/2 ^ Suc n \<le> f y \<and> f y < (k+1)/2 ^ Suc n} x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1474
                (is "?a + _ \<le> ?b")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1475
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1476
        have *: "\<lbrakk>sum f I \<le> sum h I; a + sum h I \<le> b\<rbrakk> \<Longrightarrow> a + sum f I \<le> b" for I a b f and h :: "real\<Rightarrow>real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1477
          by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1478
        let ?h = "\<lambda>k. (2*k+1)/2 ^ Suc n *
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1479
                      (indicator {y. (2 * k+1)/2 ^ Suc n \<le> f y \<and> f y < ((2*k+1) + 1)/2 ^ Suc n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1480
        show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1481
        proof (rule *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1482
          show "(\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n).
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1483
                  2 * k/2 ^ Suc n * indicator {y. (2 * k+1)/2 ^ Suc n \<le> f y \<and> f y < (2 * k+1 + 1)/2 ^ Suc n} x)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1484
                \<le> sum ?h {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1485
            by (rule sum_mono) (simp add: indicator_def divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1486
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1487
          have \<alpha>: "?a = (\<Sum>k \<in> ( *)2 ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1488
                         k/2 ^ Suc n * indicator {y. k/2 ^ Suc n \<le> f y \<and> f y < (k+1)/2 ^ Suc n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1489
            by (auto simp: inj_on_def field_simps comm_monoid_add_class.sum.reindex)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1490
          have \<beta>: "sum ?h {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1491
                   = (\<Sum>k \<in> (\<lambda>x. 2*x + 1) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1492
                      k/2 ^ Suc n * indicator {y. k/2 ^ Suc n \<le> f y \<and> f y < (k+1)/2 ^ Suc n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1493
            by (auto simp: inj_on_def field_simps comm_monoid_add_class.sum.reindex)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1494
          have 0: "( *) 2 ` {k \<in> \<int>. P k} \<inter> (\<lambda>x. 2 * x + 1) ` {k \<in> \<int>. P k} = {}" for P :: "real \<Rightarrow> bool"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1495
          proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1496
            have "2 * i \<noteq> 2 * j + 1" for i j :: int by arith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1497
            thus ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1498
              unfolding Ints_def by auto (use of_int_eq_iff in fastforce)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1499
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1500
          have "?a + sum ?h {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1501
                = (\<Sum>k \<in> ( *)2 ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)} \<union> (\<lambda>x. 2*x + 1) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1502
                  k/2 ^ Suc n * indicator {y. k/2 ^ Suc n \<le> f y \<and> f y < (k+1)/2 ^ Suc n} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1503
            unfolding \<alpha> \<beta>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1504
            using finite_abs_int_segment [of "2 ^ (2*n)"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1505
            by (subst sum_Un) (auto simp: 0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1506
          also have "\<dots> \<le> ?b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1507
          proof (rule sum_mono2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1508
            show "finite {k::real. k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2 * Suc n)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1509
              by (rule finite_abs_int_segment)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1510
            show "( *) 2 ` {k::real. k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2^(2*n)} \<union> (\<lambda>x. 2*x + 1) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2^(2*n)} \<subseteq> {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2 * Suc n)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1511
              apply auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1512
              using one_le_power [of "2::real" "2*n"]  by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1513
            have *: "\<lbrakk>x \<in> (S \<union> T) - U; \<And>x. x \<in> S \<Longrightarrow> x \<in> U; \<And>x. x \<in> T \<Longrightarrow> x \<in> U\<rbrakk> \<Longrightarrow> P x" for S T U P
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1514
              by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1515
            have "0 \<le> b" if "b \<in> \<int>" "f x * (2 * 2^n) < b + 1" for b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1516
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1517
              have "0 \<le> f x * (2 * 2^n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1518
                by (simp add: f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1519
              also have "\<dots> < b+1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1520
                by (simp add: that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1521
              finally show "0 \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1522
                using \<open>b \<in> \<int>\<close> by (auto simp: elim!: Ints_cases)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1523
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1524
            then show "0 \<le> b/2 ^ Suc n * indicator {y. b/2 ^ Suc n \<le> f y \<and> f y < (b + 1)/2 ^ Suc n} x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1525
                  if "b \<in> {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2 * Suc n)} -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1526
                          (( *) 2 ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)} \<union> (\<lambda>x. 2*x + 1) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)})" for b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1527
              using that by (simp add: indicator_def divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1528
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1529
          finally show "?a + sum ?h {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)} \<le> ?b" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1530
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1531
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1532
      finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1533
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1534
    show "?g n \<in> borel_measurable lebesgue" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1535
      apply (intro borel_measurable_indicator borel_measurable_times borel_measurable_sum)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1536
      using leb_f sets_restrict_UNIV by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1537
    show "finite (range (?g n))" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1538
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1539
      have "(\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * ?\<Omega> n k x)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1540
              \<in> (\<lambda>k. k/2^n) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)}" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1541
      proof (cases "\<exists>k. k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n) \<and> k/2^n \<le> f x \<and> f x < (k+1)/2^n")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1542
        case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1543
        then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1544
          by (blast intro: indicator_sum_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1545
      next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1546
        case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1547
        then have "(\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * ?\<Omega> n k x) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1548
          by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1549
        then show ?thesis by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1550
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1551
      then have "range (?g n) \<subseteq> ((\<lambda>k. (k/2^n)) ` {k. k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n)})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1552
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1553
      moreover have "finite ((\<lambda>k::real. (k/2^n)) ` {k \<in> \<int>. \<bar>k\<bar> \<le> 2 ^ (2*n)})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1554
        by (intro finite_imageI finite_abs_int_segment)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1555
      ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1556
        by (rule finite_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1557
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1558
    show "(\<lambda>n. ?g n x) \<longlonglongrightarrow> f x" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1559
    proof (clarsimp simp add: lim_sequentially)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1560
      fix e::real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1561
      assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1562
      obtain N1 where N1: "2 ^ N1 > abs(f x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1563
        using real_arch_pow by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1564
      obtain N2 where N2: "(1/2) ^ N2 < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1565
        using real_arch_pow_inv \<open>e > 0\<close> by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1566
      have "dist (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * ?\<Omega> n k x) (f x) < e" if "N1 + N2 \<le> n" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1567
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1568
        let ?m = "real_of_int \<lfloor>2^n * f x\<rfloor>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1569
        have "\<bar>?m\<bar> \<le> 2^n * 2^N1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1570
          using N1 apply (simp add: f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1571
          by (meson floor_mono le_floor_iff less_le_not_le mult_le_cancel_left_pos zero_less_numeral zero_less_power)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1572
        also have "\<dots> \<le> 2 ^ (2*n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1573
          by (metis that add_leD1 add_le_cancel_left mult.commute mult_2_right one_less_numeral_iff
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1574
                    power_add power_increasing_iff semiring_norm(76))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1575
        finally have m_le: "\<bar>?m\<bar> \<le> 2 ^ (2*n)" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1576
        have "?m/2^n \<le> f x" "f x < (?m + 1)/2^n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1577
          by (auto simp: mult.commute pos_divide_le_eq mult_imp_less_div_pos)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1578
        then have eq: "dist (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k/2^n * ?\<Omega> n k x) (f x)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1579
                     = dist (?m/2^n) (f x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1580
          by (subst indicator_sum_eq [of ?m]) (auto simp: m_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1581
        have "\<bar>2^n\<bar> * \<bar>?m/2^n - f x\<bar> = \<bar>2^n * (?m/2^n - f x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1582
          by (simp add: abs_mult)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1583
        also have "\<dots> < 2 ^ N2 * e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1584
          using N2 by (simp add: divide_simps mult.commute) linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1585
        also have "\<dots> \<le> \<bar>2^n\<bar> * e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1586
          using that \<open>e > 0\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1587
        finally have "dist (?m/2^n) (f x) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1588
          by (simp add: dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1589
        then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1590
          using eq by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1591
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1592
      then show "\<exists>no. \<forall>n\<ge>no. dist (\<Sum>k | k \<in> \<int> \<and> \<bar>k\<bar> \<le> 2 ^ (2*n). k * ?\<Omega> n k x/2^n) (f x) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1593
        by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1594
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1595
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1596
  ultimately show ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1597
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1598
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1599
  assume RHS: ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1600
  with borel_measurable_simple_function_limit [of f UNIV, unfolded borel_measurable_UNIV_eq]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1601
  show ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1602
    by (blast intro: order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1603
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1604
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1605
subsection\<open>Borel measurable Jacobian determinant\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1606
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1607
lemma lemma_partial_derivatives0:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1608
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1609
  assumes "linear f" and lim0: "((\<lambda>x. f x /\<^sub>R norm x) \<longlongrightarrow> 0) (at 0 within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1610
    and lb: "\<And>v. v \<noteq> 0 \<Longrightarrow> (\<exists>k>0. \<forall>e>0. \<exists>x. x \<in> S - {0} \<and> norm x < e \<and> k * norm x \<le> \<bar>v \<bullet> x\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1611
  shows "f x = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1612
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1613
  have "dim {x. f x = 0} \<le> DIM('a)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1614
    using dim_subset_UNIV by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1615
  moreover have False if less: "dim {x. f x = 0} < DIM('a)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1616
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1617
    obtain d where "d \<noteq> 0" and d: "\<And>y. f y = 0 \<Longrightarrow> d \<bullet> y = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1618
      using orthogonal_to_subspace_exists [OF less] orthogonal_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1619
      by (metis (mono_tags, lifting) mem_Collect_eq span_clauses(1))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1620
    then obtain k where "k > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1621
      and k: "\<And>e. e > 0 \<Longrightarrow> \<exists>y. y \<in> S - {0} \<and> norm y < e \<and> k * norm y \<le> \<bar>d \<bullet> y\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1622
      using lb by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1623
    have "\<exists>h. \<forall>n. ((h n \<in> S \<and> h n \<noteq> 0 \<and> k * norm (h n) \<le> \<bar>d \<bullet> h n\<bar>) \<and> norm (h n) < 1 / real (Suc n)) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1624
               norm (h (Suc n)) < norm (h n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1625
    proof (rule dependent_nat_choice)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1626
      show "\<exists>y. (y \<in> S \<and> y \<noteq> 0 \<and> k * norm y \<le> \<bar>d \<bullet> y\<bar>) \<and> norm y < 1 / real (Suc 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1627
        by simp (metis DiffE insertCI k not_less not_one_le_zero)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1628
    qed (use k [of "min (norm x) (1/(Suc n + 1))" for x n] in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1629
    then obtain \<alpha> where \<alpha>: "\<And>n. \<alpha> n \<in> S - {0}" and kd: "\<And>n. k * norm(\<alpha> n) \<le> \<bar>d \<bullet> \<alpha> n\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1630
         and norm_lt: "\<And>n. norm(\<alpha> n) < 1/(Suc n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1631
      by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1632
    let ?\<beta> = "\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1633
    have com: "\<And>g. (\<forall>n. g n \<in> sphere (0::'a) 1)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1634
              \<Longrightarrow> \<exists>l \<in> sphere 0 1. \<exists>\<rho>::nat\<Rightarrow>nat. strict_mono \<rho> \<and> (g \<circ> \<rho>) \<longlonglongrightarrow> l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1635
      using compact_sphere compact_def by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1636
    moreover have "\<forall>n. ?\<beta> n \<in> sphere 0 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1637
      using \<alpha> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1638
    ultimately obtain l::'a and \<rho>::"nat\<Rightarrow>nat"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1639
       where l: "l \<in> sphere 0 1" and "strict_mono \<rho>" and to_l: "(?\<beta> \<circ> \<rho>) \<longlonglongrightarrow> l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1640
      by meson
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1641
    moreover have "continuous (at l) (\<lambda>x. (\<bar>d \<bullet> x\<bar> - k))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1642
      by (intro continuous_intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1643
    ultimately have lim_dl: "((\<lambda>x. (\<bar>d \<bullet> x\<bar> - k)) \<circ> (?\<beta> \<circ> \<rho>)) \<longlonglongrightarrow> (\<bar>d \<bullet> l\<bar> - k)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1644
      by (meson continuous_imp_tendsto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1645
    have "\<forall>\<^sub>F i in sequentially. 0 \<le> ((\<lambda>x. \<bar>d \<bullet> x\<bar> - k) \<circ> ((\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>)) i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1646
      using \<alpha> kd by (auto simp: divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1647
    then have "k \<le> \<bar>d \<bullet> l\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1648
      using tendsto_lowerbound [OF lim_dl, of 0] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1649
    moreover have "d \<bullet> l = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1650
    proof (rule d)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1651
      show "f l = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1652
      proof (rule LIMSEQ_unique [of "f \<circ> ?\<beta> \<circ> \<rho>"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1653
        have "isCont f l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1654
          using \<open>linear f\<close> linear_continuous_at linear_conv_bounded_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1655
        then show "(f \<circ> (\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>) \<longlonglongrightarrow> f l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1656
          unfolding comp_assoc
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1657
          using to_l continuous_imp_tendsto by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1658
        have "\<alpha> \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1659
          using norm_lt LIMSEQ_norm_0 by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1660
        with \<open>strict_mono \<rho>\<close> have "(\<alpha> \<circ> \<rho>) \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1661
          by (metis LIMSEQ_subseq_LIMSEQ)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1662
        with lim0 \<alpha> have "((\<lambda>x. f x /\<^sub>R norm x) \<circ> (\<alpha> \<circ> \<rho>)) \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1663
          by (force simp: tendsto_at_iff_sequentially)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1664
        then show "(f \<circ> (\<lambda>n. \<alpha> n /\<^sub>R norm (\<alpha> n)) \<circ> \<rho>) \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1665
          by (simp add: o_def linear_cmul \<open>linear f\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1666
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1667
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1668
    ultimately show False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1669
      using \<open>k > 0\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1670
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1671
  ultimately have dim: "dim {x. f x = 0} = DIM('a)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1672
    by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1673
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1674
    by (metis (mono_tags, lifting) UNIV_I assms(1) dim_eq_full linear_eq_0_span mem_Collect_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1675
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1676
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1677
lemma lemma_partial_derivatives:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1678
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1679
  assumes "linear f" and lim: "((\<lambda>x. f (x - a) /\<^sub>R norm (x - a)) \<longlongrightarrow> 0) (at a within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1680
    and lb: "\<And>v. v \<noteq> 0 \<Longrightarrow> (\<exists>k>0.  \<forall>e>0. \<exists>x \<in> S - {a}. norm(a - x) < e \<and> k * norm(a - x) \<le> \<bar>v \<bullet> (x - a)\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1681
  shows "f x = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1682
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1683
  have "((\<lambda>x. f x /\<^sub>R norm x) \<longlongrightarrow> 0) (at 0 within (\<lambda>x. x-a) ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1684
    using lim by (simp add: Lim_within dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1685
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1686
  proof (rule lemma_partial_derivatives0 [OF \<open>linear f\<close>])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1687
    fix v :: "'a"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1688
    assume v: "v \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1689
    show "\<exists>k>0. \<forall>e>0. \<exists>x. x \<in> (\<lambda>x. x - a) ` S - {0} \<and> norm x < e \<and> k * norm x \<le> \<bar>v \<bullet> x\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1690
      using lb [OF v] by (force simp:  norm_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1691
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1692
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1693
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1694
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1695
proposition borel_measurable_partial_derivatives:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1696
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1697
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1698
    and f: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1699
  shows "(\<lambda>x. (matrix(f' x)$m$n)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1700
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1701
  have contf: "continuous_on S f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1702
    using continuous_on_eq_continuous_within f has_derivative_continuous by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1703
  have "{x \<in> S.  (matrix (f' x)$m$n) \<le> b} \<in> sets lebesgue" for b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1704
  proof (rule sets_negligible_symdiff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1705
    let ?T = "{x \<in> S. \<forall>e>0. \<exists>d>0. \<exists>A. A$m$n < b \<and> (\<forall>i j. A$i$j \<in> \<rat>) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1706
                       (\<forall>y \<in> S. norm(y - x) < d \<longrightarrow> norm(f y - f x - A *v (y - x)) \<le> e * norm(y - x))}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1707
    let ?U = "S \<inter>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1708
              (\<Inter>e \<in> {e \<in> \<rat>. e > 0}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1709
                \<Union>A \<in> {A. A$m$n < b \<and> (\<forall>i j. A$i$j \<in> \<rat>)}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1710
                  \<Union>d \<in> {d \<in> \<rat>. 0 < d}.
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1711
                     S \<inter> (\<Inter>y \<in> S. {x \<in> S. norm(y - x) < d \<longrightarrow> norm(f y - f x - A *v (y - x)) \<le> e * norm(y - x)}))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1712
    have "?T = ?U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1713
    proof (intro set_eqI iffI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1714
      fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1715
      assume xT: "x \<in> ?T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1716
      then show "x \<in> ?U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1717
      proof (clarsimp simp add:)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1718
        fix q :: real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1719
        assume "q \<in> \<rat>" "q > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1720
        then obtain d A where "d > 0" and A: "A $ m $ n < b" "\<And>i j. A $ i $ j \<in> \<rat>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1721
          "\<And>y. \<lbrakk>y\<in>S;  norm (y - x) < d\<rbrakk> \<Longrightarrow> norm (f y - f x - A *v (y - x)) \<le> q * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1722
          using xT by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1723
        then obtain \<delta> where "d > \<delta>" "\<delta> > 0" "\<delta> \<in> \<rat>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1724
          using Rats_dense_in_real by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1725
        with A show "\<exists>A. A $ m $ n < b \<and> (\<forall>i j. A $ i $ j \<in> \<rat>) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1726
                         (\<exists>s. s \<in> \<rat> \<and> 0 < s \<and> (\<forall>y\<in>S. norm (y - x) < s \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> q * norm (y - x)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1727
          by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1728
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1729
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1730
      fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1731
      assume xU: "x \<in> ?U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1732
      then show "x \<in> ?T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1733
      proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1734
        fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1735
        assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1736
        then obtain \<epsilon> where \<epsilon>: "e > \<epsilon>" "\<epsilon> > 0" "\<epsilon> \<in> \<rat>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1737
          using Rats_dense_in_real by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1738
        with xU obtain A r where "x \<in> S" and Ar: "A $ m $ n < b" "\<forall>i j. A $ i $ j \<in> \<rat>" "r \<in> \<rat>" "r > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1739
          and "\<forall>y\<in>S. norm (y - x) < r \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> \<epsilon> * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1740
          by (auto simp: split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1741
        then have "\<forall>y\<in>S. norm (y - x) < r \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1742
          by (meson \<open>e > \<epsilon>\<close> less_eq_real_def mult_right_mono norm_ge_zero order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1743
        then show "\<exists>d>0. \<exists>A. A $ m $ n < b \<and> (\<forall>i j. A $ i $ j \<in> \<rat>) \<and> (\<forall>y\<in>S. norm (y - x) < d \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1744
          using \<open>x \<in> S\<close> Ar by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1745
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1746
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1747
    moreover have "?U \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1748
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1749
      have coQ: "countable {e \<in> \<rat>. 0 < e}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1750
        using countable_Collect countable_rat by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1751
      have ne: "{e \<in> \<rat>. (0::real) < e} \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1752
        using zero_less_one Rats_1 by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1753
      have coA: "countable {A. A $ m $ n < b \<and> (\<forall>i j. A $ i $ j \<in> \<rat>)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1754
      proof (rule countable_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1755
        show "countable {A. \<forall>i j. A $ i $ j \<in> \<rat>}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1756
          using countable_vector [OF countable_vector, of "\<lambda>i j. \<rat>"] by (simp add: countable_rat)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1757
      qed blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1758
      have *: "\<lbrakk>U \<noteq> {} \<Longrightarrow> closedin (subtopology euclidean S) (S \<inter> \<Inter> U)\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1759
               \<Longrightarrow> closedin (subtopology euclidean S) (S \<inter> \<Inter> U)" for U
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1760
        by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1761
      have eq: "{x::(real,'m)vec. P x \<and> (Q x \<longrightarrow> R x)} = {x. P x \<and> \<not> Q x} \<union> {x. P x \<and> R x}" for P Q R
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1762
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1763
      have sets: "S \<inter> (\<Inter>y\<in>S. {x \<in> S. norm (y - x) < d \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x)})
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1764
                  \<in> sets lebesgue" for e A d
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1765
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1766
        have clo: "closedin (subtopology euclidean S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1767
                     {x \<in> S. norm (y - x) < d \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1768
          for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1769
        proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1770
          have cont1: "continuous_on S (\<lambda>x. norm (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1771
          and  cont2: "continuous_on S (\<lambda>x. e * norm (y - x) - norm (f y - f x - (A *v y - A *v x)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1772
            by (force intro: contf continuous_intros)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1773
          have clo1: "closedin (subtopology euclidean S) {x \<in> S. d \<le> norm (y - x)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1774
            using continuous_closedin_preimage [OF cont1, of "{d..}"] by (simp add: vimage_def Int_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1775
          have clo2: "closedin (subtopology euclidean S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1776
                       {x \<in> S. norm (f y - f x - (A *v y - A *v x)) \<le> e * norm (y - x)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1777
            using continuous_closedin_preimage [OF cont2, of "{0..}"] by (simp add: vimage_def Int_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1778
          show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1779
            by (auto simp: eq not_less matrix_vector_mult_diff_distrib intro: clo1 clo2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1780
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1781
        show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1782
          by (rule lebesgue_closedin [of S]) (force intro: * S clo)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1783
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1784
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1785
        by (intro sets sets.Int S sets.countable_UN'' sets.countable_INT'' coQ coA) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1786
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1787
    ultimately show "?T \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1788
      by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1789
    let ?M = "(?T - {x \<in> S. matrix (f' x) $ m $ n \<le> b} \<union> ({x \<in> S. matrix (f' x) $ m $ n \<le> b} - ?T))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1790
    let ?\<Theta> = "\<lambda>x v. \<forall>\<xi>>0. \<exists>e>0. \<forall>y \<in> S-{x}. norm (x - y) < e \<longrightarrow> \<bar>v \<bullet> (y - x)\<bar> < \<xi> * norm (x - y)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1791
    have nN: "negligible {x \<in> S. \<exists>v\<noteq>0. ?\<Theta> x v}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1792
      unfolding negligible_eq_zero_density
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1793
    proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1794
      fix x v and r e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1795
      assume "x \<in> S" "v \<noteq> 0" "r > 0" "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1796
      and Theta [rule_format]: "?\<Theta> x v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1797
      moreover have "(norm v * e / 2) / CARD('m) ^ CARD('m) > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1798
        by (simp add: \<open>v \<noteq> 0\<close> \<open>e > 0\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1799
      ultimately obtain d where "d > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1800
         and dless: "\<And>y. \<lbrakk>y \<in> S - {x}; norm (x - y) < d\<rbrakk> \<Longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1801
                        \<bar>v \<bullet> (y - x)\<bar> < ((norm v * e / 2) / CARD('m) ^ CARD('m)) * norm (x - y)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1802
        by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1803
      let ?W = "ball x (min d r) \<inter> {y. \<bar>v \<bullet> (y - x)\<bar> < (norm v * e/2 * min d r) / CARD('m) ^ CARD('m)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1804
      have "open {x. \<bar>v \<bullet> (x - a)\<bar> < b}" for a b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1805
        by (intro open_Collect_less continuous_intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1806
      show "\<exists>d>0. d \<le> r \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1807
            (\<exists>U. {x' \<in> S. \<exists>v\<noteq>0. ?\<Theta> x' v} \<inter> ball x d \<subseteq> U \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1808
                 U \<in> lmeasurable \<and> measure lebesgue U < e * content (ball x d))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1809
      proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1810
        show "0 < min d r" "min d r \<le> r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1811
          using \<open>r > 0\<close> \<open>d > 0\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1812
        show "{x' \<in> S. \<exists>v. v \<noteq> 0 \<and> (\<forall>\<xi>>0. \<exists>e>0. \<forall>z\<in>S - {x'}. norm (x' - z) < e \<longrightarrow> \<bar>v \<bullet> (z - x')\<bar> < \<xi> * norm (x' - z))} \<inter> ball x (min d r) \<subseteq> ?W"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1813
          proof (clarsimp simp: dist_norm norm_minus_commute)
68001
0a2a1b6507c1 correction of TeX errors and other oversights
paulson <lp15@cam.ac.uk>
parents: 67999
diff changeset
  1814
            fix y w
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1815
            assume "y \<in> S" "w \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1816
              and less [rule_format]:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1817
                    "\<forall>\<xi>>0. \<exists>e>0. \<forall>z\<in>S - {y}. norm (y - z) < e \<longrightarrow> \<bar>w \<bullet> (z - y)\<bar> < \<xi> * norm (y - z)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1818
              and d: "norm (y - x) < d" and r: "norm (y - x) < r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1819
            show "\<bar>v \<bullet> (y - x)\<bar> < norm v * e * min d r / (2 * real CARD('m) ^ CARD('m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1820
            proof (cases "y = x")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1821
              case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1822
              with \<open>r > 0\<close> \<open>d > 0\<close> \<open>e > 0\<close> \<open>v \<noteq> 0\<close> show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1823
                by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1824
            next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1825
              case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1826
              have "\<bar>v \<bullet> (y - x)\<bar> < norm v * e / 2 / real (CARD('m) ^ CARD('m)) * norm (x - y)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1827
                apply (rule dless)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1828
                using False \<open>y \<in> S\<close> d by (auto simp: norm_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1829
              also have "\<dots> \<le> norm v * e * min d r / (2 * real CARD('m) ^ CARD('m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1830
                using d r \<open>e > 0\<close> by (simp add: field_simps norm_minus_commute mult_left_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1831
              finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1832
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1833
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1834
          show "?W \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1835
            by (simp add: fmeasurable_Int_fmeasurable borel_open)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1836
          obtain k::'m where True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1837
            by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1838
          obtain T where T: "orthogonal_transformation T" and v: "v = T(norm v *\<^sub>R axis k (1::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1839
            using rotation_rightward_line by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1840
          define b where "b \<equiv> norm v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1841
          have "b > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1842
            using \<open>v \<noteq> 0\<close> by (auto simp: b_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1843
          obtain eqb: "inv T v = b *\<^sub>R axis k (1::real)" and "inj T" "bij T" and invT: "orthogonal_transformation (inv T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1844
            by (metis UNIV_I b_def  T v bij_betw_inv_into_left orthogonal_transformation_inj orthogonal_transformation_bij orthogonal_transformation_inv)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1845
          let ?v = "\<chi> i. min d r / CARD('m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1846
          let ?v' = "\<chi> i. if i = k then (e/2 * min d r) / CARD('m) ^ CARD('m) else min d r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1847
          let ?x' = "inv T x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1848
          let ?W' = "(ball ?x' (min d r) \<inter> {y. \<bar>(y - ?x')$k\<bar> < e * min d r / (2 * CARD('m) ^ CARD('m))})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1849
          have abs: "x - e \<le> y \<and> y \<le> x + e \<longleftrightarrow> abs(y - x) \<le> e" for x y e::real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1850
            by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1851
          have "?W = T ` ?W'"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1852
          proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1853
            have 1: "T ` (ball (inv T x) (min d r)) = ball x (min d r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1854
              by (simp add: T image_orthogonal_transformation_ball orthogonal_transformation_surj surj_f_inv_f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1855
            have 2: "{y. \<bar>v \<bullet> (y - x)\<bar> < b * e * min d r / (2 * real CARD('m) ^ CARD('m))} =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1856
                      T ` {y. \<bar>y $ k - ?x' $ k\<bar> < e * min d r / (2 * real CARD('m) ^ CARD('m))}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1857
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1858
              have *: "\<bar>T (b *\<^sub>R axis k 1) \<bullet> (y - x)\<bar> = b * \<bar>inv T y $ k - ?x' $ k\<bar>" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1859
              proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1860
                have "\<bar>T (b *\<^sub>R axis k 1) \<bullet> (y - x)\<bar> = \<bar>(b *\<^sub>R axis k 1) \<bullet> inv T (y - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1861
                  by (metis (no_types, hide_lams) b_def eqb invT orthogonal_transformation_def v)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1862
                also have "\<dots> = b * \<bar>(axis k 1) \<bullet> inv T (y - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1863
                  using \<open>b > 0\<close> by (simp add: abs_mult)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1864
                also have "\<dots> = b * \<bar>inv T y $ k - ?x' $ k\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1865
                  using orthogonal_transformation_linear [OF invT]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1866
                  by (simp add: inner_axis' linear_diff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1867
                finally show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1868
                  by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1869
              qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1870
              show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1871
                using v b_def [symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1872
                using \<open>b > 0\<close> by (simp add: * bij_image_Collect_eq [OF \<open>bij T\<close>] mult_less_cancel_left_pos times_divide_eq_right [symmetric] del: times_divide_eq_right)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1873
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1874
            show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1875
              using \<open>b > 0\<close> by (simp add: image_Int \<open>inj T\<close> 1 2 b_def [symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1876
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1877
          moreover have "?W' \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1878
            by (auto intro: fmeasurable_Int_fmeasurable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1879
          ultimately have "measure lebesgue ?W = measure lebesgue ?W'"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1880
            by (metis measure_orthogonal_image T)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1881
          also have "\<dots> \<le> measure lebesgue (cbox (?x' - ?v') (?x' + ?v'))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1882
          proof (rule measure_mono_fmeasurable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1883
            show "?W' \<subseteq> cbox (?x' - ?v') (?x' + ?v')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1884
              apply (clarsimp simp add: mem_box_cart abs dist_norm norm_minus_commute simp del: min_less_iff_conj min.bounded_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1885
              by (metis component_le_norm_cart less_eq_real_def le_less_trans vector_minus_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1886
          qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1887
          also have "\<dots> \<le> e/2 * measure lebesgue (cbox (?x' - ?v) (?x' + ?v))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1888
          proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1889
            have "cbox (?x' - ?v) (?x' + ?v) \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1890
              using \<open>r > 0\<close> \<open>d > 0\<close> by (auto simp: interval_eq_empty_cart divide_less_0_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1891
            with \<open>r > 0\<close> \<open>d > 0\<close> \<open>e > 0\<close> show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1892
              apply (simp add: content_cbox_if_cart mem_box_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1893
              apply (auto simp: prod_nonneg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1894
              apply (simp add: abs if_distrib prod.delta_remove prod_constant field_simps power_diff split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1895
              done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1896
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1897
          also have "\<dots> \<le> e/2 * measure lebesgue (cball ?x' (min d r))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1898
          proof (rule mult_left_mono [OF measure_mono_fmeasurable])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1899
            have *: "norm (?x' - y) \<le> min d r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1900
              if y: "\<And>i. \<bar>?x' $ i - y $ i\<bar> \<le> min d r / real CARD('m)" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1901
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1902
              have "norm (?x' - y) \<le> (\<Sum>i\<in>UNIV. \<bar>(?x' - y) $ i\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1903
                by (rule norm_le_l1_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1904
              also have "\<dots> \<le> real CARD('m) * (min d r / real CARD('m))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1905
                by (rule sum_bounded_above) (use y in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1906
              finally show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1907
                by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1908
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1909
            show "cbox (?x' - ?v) (?x' + ?v) \<subseteq> cball ?x' (min d r)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1910
              apply (clarsimp simp only: mem_box_cart dist_norm mem_cball intro!: *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1911
              by (simp add: abs_diff_le_iff abs_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1912
          qed (use \<open>e > 0\<close> in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1913
          also have "\<dots> < e * content (cball ?x' (min d r))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1914
            using \<open>r > 0\<close> \<open>d > 0\<close> \<open>e > 0\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1915
          also have "\<dots> = e * content (ball x (min d r))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1916
            using \<open>r > 0\<close> \<open>d > 0\<close> by (simp add: content_cball content_ball)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1917
          finally show "measure lebesgue ?W < e * content (ball x (min d r))" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1918
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1919
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1920
    have *: "(\<And>x. (x \<notin> S) \<Longrightarrow> (x \<in> T \<longleftrightarrow> x \<in> U)) \<Longrightarrow> (T - U) \<union> (U - T) \<subseteq> S" for S T U :: "(real,'m) vec set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1921
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1922
    have MN: "?M \<subseteq> {x \<in> S. \<exists>v\<noteq>0. ?\<Theta> x v}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1923
    proof (rule *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1924
      fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1925
      assume x: "x \<notin> {x \<in> S. \<exists>v\<noteq>0. ?\<Theta> x v}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1926
      show "(x \<in> ?T) \<longleftrightarrow> (x \<in> {x \<in> S. matrix (f' x) $ m $ n \<le> b})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1927
      proof (cases "x \<in> S")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1928
        case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1929
        then have x: "\<not> ?\<Theta> x v" if "v \<noteq> 0" for v
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1930
          using x that by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1931
        show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1932
        proof (rule iffI; clarsimp)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1933
          assume b: "\<forall>e>0. \<exists>d>0. \<exists>A. A $ m $ n < b \<and> (\<forall>i j. A $ i $ j \<in> \<rat>) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1934
                                    (\<forall>y\<in>S. norm (y - x) < d \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1935
                     (is "\<forall>e>0. \<exists>d>0. \<exists>A. ?\<Phi> e d A")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1936
          then have "\<forall>k. \<exists>d>0. \<exists>A. ?\<Phi> (1 / Suc k) d A"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1937
            by (metis (no_types, hide_lams) less_Suc_eq_0_disj of_nat_0_less_iff zero_less_divide_1_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1938
          then obtain \<delta> A where \<delta>: "\<And>k. \<delta> k > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1939
                           and Ab: "\<And>k. A k $ m $ n < b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1940
                           and A: "\<And>k y. \<lbrakk>y \<in> S; norm (y - x) < \<delta> k\<rbrakk> \<Longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1941
                                          norm (f y - f x - A k *v (y - x)) \<le> 1/(Suc k) * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1942
            by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1943
          have "\<forall>i j. \<exists>a. (\<lambda>n. A n $ i $ j) \<longlonglongrightarrow> a"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1944
          proof (intro allI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1945
            fix i j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1946
            have vax: "(A n *v axis j 1) $ i = A n $ i $ j" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1947
              by (metis cart_eq_inner_axis matrix_vector_mul_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1948
            let ?CA = "{x. Cauchy (\<lambda>n. (A n) *v x)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1949
            have "subspace ?CA"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1950
              unfolding subspace_def convergent_eq_Cauchy [symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1951
                by (force simp: algebra_simps intro: tendsto_intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1952
            then have CA_eq: "?CA = span ?CA"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1953
              by (metis span_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1954
            also have "\<dots> = UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1955
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1956
              have "dim ?CA \<le> CARD('m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1957
                by (rule dim_subset_UNIV_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1958
              moreover have "False" if less: "dim ?CA < CARD('m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1959
              proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1960
                obtain d where "d \<noteq> 0" and d: "\<And>y. y \<in> span ?CA \<Longrightarrow> orthogonal d y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1961
                  using less by (force intro: orthogonal_to_subspace_exists [of ?CA])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1962
                with x [OF \<open>d \<noteq> 0\<close>] obtain \<xi> where "\<xi> > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1963
                  and \<xi>: "\<And>e. e > 0 \<Longrightarrow> \<exists>y \<in> S - {x}. norm (x - y) < e \<and> \<xi> * norm (x - y) \<le> \<bar>d \<bullet> (y - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1964
                  by (fastforce simp: not_le Bex_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1965
                obtain \<gamma> z where \<gamma>Sx: "\<And>i. \<gamma> i \<in> S - {x}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1966
                           and \<gamma>le:   "\<And>i. \<xi> * norm(\<gamma> i - x) \<le> \<bar>d \<bullet> (\<gamma> i - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1967
                           and \<gamma>x:    "\<gamma> \<longlonglongrightarrow> x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1968
                           and z:     "(\<lambda>n. (\<gamma> n - x) /\<^sub>R norm (\<gamma> n - x)) \<longlonglongrightarrow> z"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1969
                proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1970
                  have "\<exists>\<gamma>. (\<forall>i. (\<gamma> i \<in> S - {x} \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1971
                                  \<xi> * norm(\<gamma> i - x) \<le> \<bar>d \<bullet> (\<gamma> i - x)\<bar> \<and> norm(\<gamma> i - x) < 1/Suc i) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1972
                                 norm(\<gamma>(Suc i) - x) < norm(\<gamma> i - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1973
                  proof (rule dependent_nat_choice)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1974
                    show "\<exists>y. y \<in> S - {x} \<and> \<xi> * norm (y - x) \<le> \<bar>d \<bullet> (y - x)\<bar> \<and> norm (y - x) < 1 / Suc 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1975
                      using \<xi> [of 1] by (auto simp: dist_norm norm_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1976
                  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1977
                    fix y i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1978
                    assume "y \<in> S - {x} \<and> \<xi> * norm (y - x) \<le> \<bar>d \<bullet> (y - x)\<bar> \<and> norm (y - x) < 1/Suc i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1979
                    then have "min (norm(y - x)) (1/((Suc i) + 1)) > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1980
                      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1981
                    then obtain y' where "y' \<in> S - {x}" and y': "norm (x - y') < min (norm (y - x)) (1/((Suc i) + 1))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1982
                                         "\<xi> * norm (x - y') \<le> \<bar>d \<bullet> (y' - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1983
                      using \<xi> by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1984
                    with \<xi> show "\<exists>y'. (y' \<in> S - {x} \<and> \<xi> * norm (y' - x) \<le> \<bar>d \<bullet> (y' - x)\<bar> \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1985
                              norm (y' - x) < 1/(Suc (Suc i))) \<and> norm (y' - x) < norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1986
                      by (auto simp: dist_norm norm_minus_commute)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1987
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1988
                  then obtain \<gamma> where
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1989
                        \<gamma>Sx: "\<And>i. \<gamma> i \<in> S - {x}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1990
                        and \<gamma>le: "\<And>i. \<xi> * norm(\<gamma> i - x) \<le> \<bar>d \<bullet> (\<gamma> i - x)\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1991
                        and \<gamma>conv: "\<And>i. norm(\<gamma> i - x) < 1/(Suc i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1992
                    by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1993
                  let ?f = "\<lambda>i. (\<gamma> i - x) /\<^sub>R norm (\<gamma> i - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1994
                  have "?f i \<in> sphere 0 1" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1995
                    using \<gamma>Sx by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1996
                  then obtain l \<rho> where "l \<in> sphere 0 1" "strict_mono \<rho>" and l: "(?f \<circ> \<rho>) \<longlonglongrightarrow> l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1997
                    using compact_sphere [of "0::(real,'m) vec" 1]  unfolding compact_def by meson
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1998
                  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  1999
                  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2000
                    show "(\<gamma> \<circ> \<rho>) i \<in> S - {x}" "\<xi> * norm ((\<gamma> \<circ> \<rho>) i - x) \<le> \<bar>d \<bullet> ((\<gamma> \<circ> \<rho>) i - x)\<bar>" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2001
                      using \<gamma>Sx \<gamma>le by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2002
                    have "\<gamma> \<longlonglongrightarrow> x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2003
                    proof (clarsimp simp add: LIMSEQ_def dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2004
                      fix r :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2005
                      assume "r > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2006
                      with real_arch_invD obtain no where "no \<noteq> 0" "real no > 1/r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2007
                        by (metis divide_less_0_1_iff not_less_iff_gr_or_eq of_nat_0_eq_iff reals_Archimedean2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2008
                      with \<gamma>conv show "\<exists>no. \<forall>n\<ge>no. norm (\<gamma> n - x) < r"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2009
                        by (metis \<open>r > 0\<close> add.commute divide_inverse inverse_inverse_eq inverse_less_imp_less less_trans mult.left_neutral nat_le_real_less of_nat_Suc)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2010
                    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2011
                    with \<open>strict_mono \<rho>\<close> show "(\<gamma> \<circ> \<rho>) \<longlonglongrightarrow> x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2012
                      by (metis LIMSEQ_subseq_LIMSEQ)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2013
                    show "(\<lambda>n. ((\<gamma> \<circ> \<rho>) n - x) /\<^sub>R norm ((\<gamma> \<circ> \<rho>) n - x)) \<longlonglongrightarrow> l"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2014
                      using l by (auto simp: o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2015
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2016
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2017
                have "isCont (\<lambda>x. (\<bar>d \<bullet> x\<bar> - \<xi>)) z"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2018
                  by (intro continuous_intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2019
                from isCont_tendsto_compose [OF this z]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2020
                have lim: "(\<lambda>y. \<bar>d \<bullet> ((\<gamma> y - x) /\<^sub>R norm (\<gamma> y - x))\<bar> - \<xi>) \<longlonglongrightarrow> \<bar>d \<bullet> z\<bar> - \<xi>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2021
                  by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2022
                moreover have "\<forall>\<^sub>F i in sequentially. 0 \<le> \<bar>d \<bullet> ((\<gamma> i - x) /\<^sub>R norm (\<gamma> i - x))\<bar> - \<xi>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2023
                proof (rule eventuallyI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2024
                  fix n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2025
                  show "0 \<le> \<bar>d \<bullet> ((\<gamma> n - x) /\<^sub>R norm (\<gamma> n - x))\<bar> - \<xi>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2026
                  using \<gamma>le [of n] \<gamma>Sx by (auto simp: abs_mult divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2027
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2028
                ultimately have "\<xi> \<le> \<bar>d \<bullet> z\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2029
                  using tendsto_lowerbound [where a=0] by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2030
                have "Cauchy (\<lambda>n. (A n) *v z)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2031
                proof (clarsimp simp add: Cauchy_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2032
                  fix \<epsilon> :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2033
                  assume "0 < \<epsilon>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2034
                  then obtain N::nat where "N > 0" and N: "\<epsilon>/2 > 1/N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2035
                    by (metis half_gt_zero inverse_eq_divide neq0_conv real_arch_inverse)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2036
                  show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (A m *v z) (A n *v z) < \<epsilon>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2037
                  proof (intro exI allI impI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2038
                    fix i j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2039
                    assume ij: "N \<le> i" "N \<le> j"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2040
                    let ?V = "\<lambda>i k. A i *v ((\<gamma> k - x) /\<^sub>R norm (\<gamma> k - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2041
                    have "\<forall>\<^sub>F k in sequentially. dist (\<gamma> k) x < min (\<delta> i) (\<delta> j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2042
                      using \<gamma>x [unfolded tendsto_iff] by (meson min_less_iff_conj \<delta>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2043
                    then have even: "\<forall>\<^sub>F k in sequentially. norm (?V i k - ?V j k) - 2 / N \<le> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2044
                    proof (rule eventually_mono, clarsimp)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2045
                      fix p
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2046
                      assume p: "dist (\<gamma> p) x < \<delta> i" "dist (\<gamma> p) x < \<delta> j"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2047
                      let ?C = "\<lambda>k. f (\<gamma> p) - f x - A k *v (\<gamma> p - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2048
                      have "norm ((A i - A j) *v (\<gamma> p - x)) = norm (?C j - ?C i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2049
                        by (simp add: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2050
                      also have "\<dots> \<le> norm (?C j) + norm (?C i)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2051
                        using norm_triangle_ineq4 by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2052
                      also have "\<dots> \<le> 1/(Suc j) * norm (\<gamma> p - x) + 1/(Suc i) * norm (\<gamma> p - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2053
                        by (metis A Diff_iff \<gamma>Sx dist_norm p add_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2054
                      also have "\<dots> \<le> 1/N * norm (\<gamma> p - x) + 1/N * norm (\<gamma> p - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2055
                        apply (intro add_mono mult_right_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2056
                        using ij \<open>N > 0\<close> by (auto simp: field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2057
                      also have "\<dots> = 2 / N * norm (\<gamma> p - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2058
                        by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2059
                      finally have no_le: "norm ((A i - A j) *v (\<gamma> p - x)) \<le> 2 / N * norm (\<gamma> p - x)" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2060
                      have "norm (?V i p - ?V j p) =
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2061
                            norm ((A i - A j) *v ((\<gamma> p - x) /\<^sub>R norm (\<gamma> p - x)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2062
                        by (simp add: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2063
                      also have "\<dots> = norm ((A i - A j) *v (\<gamma> p - x)) / norm (\<gamma> p - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2064
                        by (simp add: divide_inverse matrix_vector_mult_scaleR)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2065
                      also have "\<dots> \<le> 2 / N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2066
                        using no_le by (auto simp: divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2067
                      finally show "norm (?V i p - ?V j p) \<le> 2 / N" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2068
                    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2069
                    have "isCont (\<lambda>w. (norm(A i *v w - A j *v w) - 2 / N)) z"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2070
                      by (intro continuous_intros)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2071
                    from isCont_tendsto_compose [OF this z]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2072
                    have lim: "(\<lambda>w. norm (A i *v ((\<gamma> w - x) /\<^sub>R norm (\<gamma> w - x)) -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2073
                                    A j *v ((\<gamma> w - x) /\<^sub>R norm (\<gamma> w - x))) - 2 / N)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2074
                               \<longlonglongrightarrow> norm (A i *v z - A j *v z) - 2 / N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2075
                      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2076
                    have "dist (A i *v z) (A j *v z) \<le> 2 / N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2077
                      using tendsto_upperbound [OF lim even] by (auto simp: dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2078
                    with N show "dist (A i *v z) (A j *v z) < \<epsilon>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2079
                      by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2080
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2081
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2082
                then have "d \<bullet> z = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2083
                  using CA_eq d orthogonal_def by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2084
                then show False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2085
                  using \<open>0 < \<xi>\<close> \<open>\<xi> \<le> \<bar>d \<bullet> z\<bar>\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2086
              qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2087
              ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2088
                using dim_eq_full by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2089
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2090
            finally have "?CA = UNIV" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2091
            then have "Cauchy (\<lambda>n. (A n) *v axis j 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2092
              by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2093
            then obtain L where "(\<lambda>n. A n *v axis j 1) \<longlonglongrightarrow> L"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2094
              by (auto simp: Cauchy_convergent_iff convergent_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2095
            then have "(\<lambda>x. (A x *v axis j 1) $ i) \<longlonglongrightarrow> L $ i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2096
              by (rule tendsto_vec_nth)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2097
            then show "\<exists>a. (\<lambda>n. A n $ i $ j) \<longlonglongrightarrow> a"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2098
              by (force simp: vax)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2099
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2100
          then obtain B where B: "\<And>i j. (\<lambda>n. A n $ i $ j) \<longlonglongrightarrow> B $ i $ j"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2101
            by (auto simp: lambda_skolem)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2102
          have lin_df: "linear (f' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2103
               and lim_df: "((\<lambda>y. (1 / norm (y - x)) *\<^sub>R (f y - (f x + f' x (y - x)))) \<longlongrightarrow> 0) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2104
            using \<open>x \<in> S\<close> assms by (auto simp: has_derivative_within linear_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2105
          moreover have "(matrix (f' x) - B) *v w = 0" for w
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2106
          proof (rule lemma_partial_derivatives [of "( *v) (matrix (f' x) - B)"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2107
            show "linear (( *v) (matrix (f' x) - B))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2108
              by (rule matrix_vector_mul_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2109
            have "((\<lambda>y. ((f x + f' x (y - x)) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2110
              using tendsto_minus [OF lim_df] by (simp add: algebra_simps divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2111
            then show "((\<lambda>y. (matrix (f' x) - B) *v (y - x) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2112
            proof (rule Lim_transform)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2113
              have "((\<lambda>y. ((f y + B *v x - (f x + B *v y)) /\<^sub>R norm (y - x))) \<longlongrightarrow> 0) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2114
              proof (clarsimp simp add: Lim_within dist_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2115
                fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2116
                assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2117
                then obtain q::nat where "q \<noteq> 0" and qe2: "1/q < e/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2118
                  by (metis divide_pos_pos inverse_eq_divide real_arch_inverse zero_less_numeral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2119
                let ?g = "\<lambda>p. sum  (\<lambda>i. sum (\<lambda>j. abs((A p - B)$i$j)) UNIV) UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2120
                have "(\<lambda>k. onorm (\<lambda>y. (A k - B) *v y)) \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2121
                proof (rule Lim_null_comparison)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2122
                  show "\<forall>\<^sub>F k in sequentially. norm (onorm (\<lambda>y. (A k - B) *v y)) \<le> ?g k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2123
                  proof (rule eventually_sequentiallyI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2124
                    fix k :: "nat"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2125
                    assume "0 \<le> k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2126
                    have "0 \<le> onorm (( *v) (A k - B))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2127
                      by (simp add: linear_linear onorm_pos_le matrix_vector_mul_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2128
                    then show "norm (onorm (( *v) (A k - B))) \<le> (\<Sum>i\<in>UNIV. \<Sum>j\<in>UNIV. \<bar>(A k - B) $ i $ j\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2129
                      by (simp add: onorm_le_matrix_component_sum del: vector_minus_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2130
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2131
                next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2132
                  show "?g \<longlonglongrightarrow> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2133
                    using B Lim_null tendsto_rabs_zero_iff by (fastforce intro!: tendsto_null_sum)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2134
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2135
                with \<open>e > 0\<close> obtain p where "\<And>n. n \<ge> p \<Longrightarrow> \<bar>onorm (( *v) (A n - B))\<bar> < e/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2136
                  unfolding lim_sequentially by (metis diff_zero dist_real_def divide_pos_pos zero_less_numeral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2137
                then have pqe2: "\<bar>onorm (( *v) (A (p + q) - B))\<bar> < e/2" (*17 [`abs (onorm (\y. A (p + q) ** y - B ** y)) < e / &2`]*)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2138
                  using le_add1 by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2139
                show "\<exists>d>0. \<forall>y\<in>S. y \<noteq> x \<and> norm (y - x) < d \<longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2140
                           inverse (norm (y - x)) * norm (f y + B *v x - (f x + B *v y)) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2141
                proof (intro exI, safe)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2142
                  show "0 < \<delta>(p + q)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2143
                    by (simp add: \<delta>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2144
                next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2145
                  fix y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2146
                  assume y: "y \<in> S" "norm (y - x) < \<delta>(p + q)" and "y \<noteq> x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2147
                  have *: "\<lbrakk>norm(b - c) < e - d; norm(y - x - b) \<le> d\<rbrakk> \<Longrightarrow> norm(y - x - c) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2148
                    for b c d e x and y:: "real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2149
                    using norm_triangle_ineq2 [of "y - x - c" "y - x - b"] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2150
                  have "norm (f y - f x - B *v (y - x)) < e * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2151
                  proof (rule *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2152
                    show "norm (f y - f x - A (p + q) *v (y - x)) \<le> norm (y - x) / (Suc (p + q))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2153
                      using A [OF y] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2154
                    have "norm (A (p + q) *v (y - x) - B *v (y - x)) \<le> onorm(\<lambda>x. (A(p + q) - B) *v x) * norm(y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2155
                      by (metis linear_linear matrix_vector_mul_linear matrix_vector_mult_diff_rdistrib onorm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2156
                    also have "\<dots> < (e/2) * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2157
                      using \<open>y \<noteq> x\<close> pqe2 by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2158
                    also have "\<dots> \<le> (e - 1 / (Suc (p + q))) * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2159
                    proof (rule mult_right_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2160
                      have "1 / Suc (p + q) \<le> 1 / q"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2161
                        using \<open>q \<noteq> 0\<close> by (auto simp: divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2162
                      also have "\<dots> < e/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2163
                        using qe2 by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2164
                      finally show "e / 2 \<le> e - 1 / real (Suc (p + q))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2165
                        by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2166
                    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2167
                    finally show "norm (A (p + q) *v (y - x) - B *v (y - x)) < e * norm (y - x) - norm (y - x) / real (Suc (p + q))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2168
                      by (simp add: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2169
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2170
                  then show "inverse (norm (y - x)) * norm (f y + B *v x - (f x + B *v y)) < e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2171
                    using \<open>y \<noteq> x\<close> by (simp add: divide_simps algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2172
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2173
              qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2174
              then show "((\<lambda>y. (matrix (f' x) - B) *v (y - x) /\<^sub>R
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2175
                           norm (y - x) - (f x + f' x (y - x) - f y) /\<^sub>R norm (y - x)) \<longlongrightarrow> 0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2176
                          (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2177
                by (simp add: algebra_simps lin_df linear_diff matrix_vector_mul_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2178
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2179
          qed (use x in \<open>simp; auto simp: not_less\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2180
          ultimately have "f' x = ( *v) B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2181
            by (force simp: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2182
          show "matrix (f' x) $ m $ n \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2183
          proof (rule tendsto_upperbound [of "\<lambda>i. (A i $ m $ n)" _ sequentially])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2184
            show "(\<lambda>i. A i $ m $ n) \<longlonglongrightarrow> matrix (f' x) $ m $ n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2185
              by (simp add: B \<open>f' x = ( *v) B\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2186
            show "\<forall>\<^sub>F i in sequentially. A i $ m $ n \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2187
              by (simp add: Ab less_eq_real_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2188
          qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2189
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2190
          fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2191
          assume "x \<in> S" and b: "matrix (f' x) $ m $ n \<le> b" and "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2192
          then obtain d where "d>0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2193
            and d: "\<And>y. y\<in>S \<Longrightarrow> 0 < dist y x \<and> dist y x < d \<longrightarrow> norm (f y - f x - f' x (y - x)) / (norm (y - x))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2194
                  < e/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2195
            using f [OF \<open>x \<in> S\<close>] unfolding Deriv.has_derivative_at_within Lim_within
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2196
            by (auto simp: field_simps dest: spec [of _ "e/2"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2197
          let ?A = "matrix(f' x) - (\<chi> i j. if i = m \<and> j = n then e / 4 else 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2198
          obtain B where BRats: "\<And>i j. B$i$j \<in> \<rat>" and Bo_e6: "onorm(( *v) (?A - B)) < e/6"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2199
            using matrix_rational_approximation \<open>e > 0\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2200
            by (metis zero_less_divide_iff zero_less_numeral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2201
          show "\<exists>d>0. \<exists>A. A $ m $ n < b \<and> (\<forall>i j. A $ i $ j \<in> \<rat>) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2202
                (\<forall>y\<in>S. norm (y - x) < d \<longrightarrow> norm (f y - f x - A *v (y - x)) \<le> e * norm (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2203
          proof (intro exI conjI ballI allI impI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2204
            show "d>0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2205
              by (rule \<open>d>0\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2206
            show "B $ m $ n < b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2207
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2208
              have "\<bar>matrix (( *v) (?A - B)) $ m $ n\<bar> \<le> onorm (( *v) (?A - B))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2209
                using component_le_onorm [OF matrix_vector_mul_linear, of _ m n] by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2210
              then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2211
                using b Bo_e6 by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2212
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2213
            show "B $ i $ j \<in> \<rat>" for i j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2214
              using BRats by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2215
            show "norm (f y - f x - B *v (y - x)) \<le> e * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2216
              if "y \<in> S" and y: "norm (y - x) < d" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2217
            proof (cases "y = x")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2218
              case True then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2219
                by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2220
            next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2221
              case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2222
              have *: "norm(d' - d) \<le> e/2 \<Longrightarrow> norm(y - (x + d')) < e/2 \<Longrightarrow> norm(y - x - d) \<le> e" for d d' e and x y::"real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2223
                using norm_triangle_le [of "d' - d" "y - (x + d')"] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2224
              show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2225
              proof (rule *)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2226
                have split246: "\<lbrakk>norm y \<le> e / 6; norm(x - y) \<le> e / 4\<rbrakk> \<Longrightarrow> norm x \<le> e/2" if "e > 0" for e and x y :: "real^'n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2227
                  using norm_triangle_le [of y "x-y" "e/2"] \<open>e > 0\<close> by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2228
                have "linear (f' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2229
                  using True f has_derivative_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2230
                then have "norm (f' x (y - x) - B *v (y - x)) = norm ((matrix (f' x) - B) *v (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2231
                  by (metis matrix_vector_mul matrix_vector_mult_diff_rdistrib)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2232
                also have "\<dots> \<le> (e * norm (y - x)) / 2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2233
                proof (rule split246)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2234
                  have "norm ((?A - B) *v (y - x)) / norm (y - x) \<le> onorm(\<lambda>x. (?A - B) *v x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2235
                    by (simp add: le_onorm linear_linear matrix_vector_mul_linear)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2236
                  also have  "\<dots> < e/6"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2237
                    by (rule Bo_e6)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2238
                  finally have "norm ((?A - B) *v (y - x)) / norm (y - x) < e / 6" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2239
                  then show "norm ((?A - B) *v (y - x)) \<le> e * norm (y - x) / 6"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2240
                    by (simp add: divide_simps False)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2241
                  have "norm ((matrix (f' x) - B) *v (y - x) - ((?A - B) *v (y - x))) = norm ((\<chi> i j. if i = m \<and> j = n then e / 4 else 0) *v (y - x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2242
                    by (simp add: algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2243
                  also have "\<dots> = norm((e/4) *\<^sub>R (y - x)$n *\<^sub>R axis m (1::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2244
                  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2245
                    have "(\<Sum>j\<in>UNIV. (if i = m \<and> j = n then e / 4 else 0) * (y $ j - x $ j)) * 4 = e * (y $ n - x $ n) * axis m 1 $ i" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2246
                    proof (cases "i=m")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2247
                      case True then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2248
                        by (auto simp: if_distrib [of "\<lambda>z. z * _"] cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2249
                    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2250
                      case False then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2251
                        by (simp add: axis_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2252
                    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2253
                    then have "(\<chi> i j. if i = m \<and> j = n then e / 4 else 0) *v (y - x) = (e/4) *\<^sub>R (y - x)$n *\<^sub>R axis m (1::real)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2254
                      by (auto simp: vec_eq_iff matrix_vector_mult_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2255
                    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2256
                      by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2257
                  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2258
                  also have "\<dots> \<le> e * norm (y - x) / 4"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2259
                    using \<open>e > 0\<close> apply (simp add: norm_mult abs_mult)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2260
                    by (metis component_le_norm_cart vector_minus_component)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2261
                  finally show "norm ((matrix (f' x) - B) *v (y - x) - ((?A - B) *v (y - x))) \<le> e * norm (y - x) / 4" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2262
                  show "0 < e * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2263
                    by (simp add: False \<open>e > 0\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2264
                qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2265
                finally show "norm (f' x (y - x) - B *v (y - x)) \<le> (e * norm (y - x)) / 2" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2266
                show "norm (f y - (f x + f' x (y - x))) < (e * norm (y - x)) / 2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2267
                  using False d [OF \<open>y \<in> S\<close>] y by (simp add: dist_norm field_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2268
              qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2269
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2270
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2271
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2272
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2273
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2274
    show "negligible ?M"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2275
      using negligible_subset [OF nN MN] .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2276
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2277
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2278
    by (simp add: borel_measurable_vimage_halfspace_component_le sets_restrict_space_iff assms)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2279
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2280
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2281
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2282
theorem borel_measurable_det_Jacobian:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2283
 fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2284
  assumes S: "S \<in> sets lebesgue" and f: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2285
  shows "(\<lambda>x. det(matrix(f' x))) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2286
  unfolding det_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2287
  by (intro measurable) (auto intro: f borel_measurable_partial_derivatives [OF S])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2288
68001
0a2a1b6507c1 correction of TeX errors and other oversights
paulson <lp15@cam.ac.uk>
parents: 67999
diff changeset
  2289
text\<open>The localisation wrt S uses the same argument for many similar results.\<close>
0a2a1b6507c1 correction of TeX errors and other oversights
paulson <lp15@cam.ac.uk>
parents: 67999
diff changeset
  2290
(*See HOL Light's MEASURABLE_ON_LEBESGUE_MEASURABLE_PREIMAGE_BOREL, etc.*)
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2291
lemma borel_measurable_lebesgue_on_preimage_borel:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2292
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2293
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2294
  shows "f \<in> borel_measurable (lebesgue_on S) \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2295
         (\<forall>T. T \<in> sets borel \<longrightarrow> {x \<in> S. f x \<in> T} \<in> sets lebesgue)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2296
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2297
  have "{x. (if x \<in> S then f x else 0) \<in> T} \<in> sets lebesgue \<longleftrightarrow> {x \<in> S. f x \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2298
         if "T \<in> sets borel" for T
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2299
    proof (cases "0 \<in> T")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2300
      case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2301
      then have "{x \<in> S. f x \<in> T} = {x. (if x \<in> S then f x else 0) \<in> T} \<inter> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2302
                "{x. (if x \<in> S then f x else 0) \<in> T} = {x \<in> S. f x \<in> T} \<union> -S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2303
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2304
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2305
        by (metis (no_types, lifting) Compl_in_sets_lebesgue assms sets.Int sets.Un)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2306
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2307
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2308
      then have "{x. (if x \<in> S then f x else 0) \<in> T} = {x \<in> S. f x \<in> T}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2309
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2310
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2311
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2312
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2313
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2314
      unfolding borel_measurable_lebesgue_preimage_borel borel_measurable_UNIV [OF assms, symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2315
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2316
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2317
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2318
lemma sets_lebesgue_almost_borel:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2319
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2320
  obtains B N where "B \<in> sets borel" "negligible N" "B \<union> N = S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2321
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2322
  obtain T N N' where "S = T \<union> N" "N \<subseteq> N'" "N' \<in> null_sets lborel" "T \<in> sets borel"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2323
    using sets_completionE [OF assms] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2324
  then show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2325
    by (metis negligible_iff_null_sets negligible_subset null_sets_completionI that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2326
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2327
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2328
lemma double_lebesgue_sets:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2329
 assumes S: "S \<in> sets lebesgue" and T: "T \<in> sets lebesgue" and fim: "f ` S \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2330
 shows "(\<forall>U. U \<in> sets lebesgue \<and> U \<subseteq> T \<longrightarrow> {x \<in> S. f x \<in> U} \<in> sets lebesgue) \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2331
          f \<in> borel_measurable (lebesgue_on S) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2332
          (\<forall>U. negligible U \<and> U \<subseteq> T \<longrightarrow> {x \<in> S. f x \<in> U} \<in> sets lebesgue)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2333
         (is "?lhs \<longleftrightarrow> _ \<and> ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2334
  unfolding borel_measurable_lebesgue_on_preimage_borel [OF S]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2335
proof (intro iffI allI conjI impI, safe)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2336
  fix V :: "'b set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2337
  assume *: "\<forall>U. U \<in> sets lebesgue \<and> U \<subseteq> T \<longrightarrow> {x \<in> S. f x \<in> U} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2338
    and "V \<in> sets borel"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2339
  then have V: "V \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2340
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2341
  have "{x \<in> S. f x \<in> V} = {x \<in> S. f x \<in> T \<inter> V}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2342
    using fim by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2343
  also have "{x \<in> S. f x \<in> T \<inter> V} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2344
    using T V * le_inf_iff by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2345
  finally show "{x \<in> S. f x \<in> V} \<in> sets lebesgue" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2346
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2347
  fix U :: "'b set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2348
  assume "\<forall>U. U \<in> sets lebesgue \<and> U \<subseteq> T \<longrightarrow> {x \<in> S. f x \<in> U} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2349
         "negligible U" "U \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2350
  then show "{x \<in> S. f x \<in> U} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2351
    using negligible_imp_sets by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2352
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2353
  fix U :: "'b set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2354
  assume 1 [rule_format]: "(\<forall>T. T \<in> sets borel \<longrightarrow> {x \<in> S. f x \<in> T} \<in> sets lebesgue)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2355
     and 2 [rule_format]: "\<forall>U. negligible U \<and> U \<subseteq> T \<longrightarrow> {x \<in> S. f x \<in> U} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2356
     and "U \<in> sets lebesgue" "U \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2357
  then obtain C N where C: "C \<in> sets borel \<and> negligible N \<and> C \<union> N = U"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2358
    using sets_lebesgue_almost_borel
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2359
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2360
  then have "{x \<in> S. f x \<in> C} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2361
    by (blast intro: 1)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2362
  moreover have "{x \<in> S. f x \<in> N} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2363
    using C \<open>U \<subseteq> T\<close> by (blast intro: 2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2364
  moreover have "{x \<in> S. f x \<in> C \<union> N} = {x \<in> S. f x \<in> C} \<union> {x \<in> S. f x \<in> N}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2365
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2366
  ultimately show "{x \<in> S. f x \<in> U} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2367
    using C by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2368
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2369
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2370
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2371
subsection\<open>Simplest case of Sard's theorem (we don't need continuity of derivative)\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2372
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2373
lemma Sard_lemma00:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2374
  fixes P :: "'b::euclidean_space set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2375
  assumes "a \<ge> 0" and a: "a *\<^sub>R i \<noteq> 0" and i: "i \<in> Basis"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2376
    and P: "P \<subseteq> {x. a *\<^sub>R i \<bullet> x = 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2377
    and "0 \<le> m" "0 \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2378
 obtains S where "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2379
            and "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2380
            and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (DIM('b) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2381
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2382
  have "a > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2383
    using assms by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2384
  let ?v = "(\<Sum>j\<in>Basis. (if j = i then e else m) *\<^sub>R j)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2385
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2386
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2387
    have "- e \<le> x \<bullet> i" "x \<bullet> i \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2388
      if "t \<in> P" "norm (x - t) \<le> e" for x t
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2389
      using \<open>a > 0\<close> that Basis_le_norm [of i "x-t"] P i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2390
      by (auto simp: inner_commute algebra_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2391
    moreover have "- m \<le> x \<bullet> j" "x \<bullet> j \<le> m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2392
      if "norm x \<le> m" "t \<in> P" "norm (x - t) \<le> e" "j \<in> Basis" and "j \<noteq> i"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2393
      for x t j
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2394
      using that Basis_le_norm [of j x] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2395
    ultimately
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2396
    show "{z. norm z \<le> m \<and> (\<exists>t\<in>P. norm (z - t) \<le> e)} \<subseteq> cbox (-?v) ?v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2397
      by (auto simp: mem_box)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2398
    have *: "\<forall>k\<in>Basis. - ?v \<bullet> k \<le> ?v \<bullet> k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2399
      using \<open>0 \<le> m\<close> \<open>0 \<le> e\<close> by (auto simp: inner_Basis)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2400
    have 2: "2 ^ DIM('b) = 2 * 2 ^ (DIM('b) - Suc 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2401
      by (metis DIM_positive Suc_pred power_Suc)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2402
    show "measure lebesgue (cbox (-?v) ?v) \<le> 2 * e * (2 * m) ^ (DIM('b) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2403
      using \<open>i \<in> Basis\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2404
      by (simp add: content_cbox [OF *] prod.distrib prod.If_cases Diff_eq [symmetric] 2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2405
  qed blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2406
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2407
68001
0a2a1b6507c1 correction of TeX errors and other oversights
paulson <lp15@cam.ac.uk>
parents: 67999
diff changeset
  2408
text\<open>As above, but reorienting the vector (HOL Light's @text{GEOM\_BASIS\_MULTIPLE\_TAC})\<close>
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2409
lemma Sard_lemma0:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2410
  fixes P :: "(real^'n::{finite,wellorder}) set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2411
  assumes "a \<noteq> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2412
    and P: "P \<subseteq> {x. a \<bullet> x = 0}" and "0 \<le> m" "0 \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2413
  obtains S where "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2414
    and "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2415
    and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2416
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2417
  obtain T and k::'n where T: "orthogonal_transformation T" and a: "a = T (norm a *\<^sub>R axis k (1::real))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2418
    using rotation_rightward_line by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2419
  have Tinv [simp]: "T (inv T x) = x" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2420
    by (simp add: T orthogonal_transformation_surj surj_f_inv_f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2421
  obtain S where S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2422
    and subS: "{z. norm z \<le> m \<and> (\<exists>t \<in> T-`P. norm(z - t) \<le> e)} \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2423
    and mS: "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2424
  proof (rule Sard_lemma00 [of "norm a" "axis k (1::real)" "T-`P" m e])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2425
    have "norm a *\<^sub>R axis k 1 \<bullet> x = 0" if "T x \<in> P" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2426
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2427
      have "a \<bullet> T x = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2428
        using P that by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2429
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2430
        by (metis (no_types, lifting) T a orthogonal_orthogonal_transformation orthogonal_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2431
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2432
    then show "T -` P \<subseteq> {x. norm a *\<^sub>R axis k 1 \<bullet> x = 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2433
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2434
  qed (use assms T in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2435
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2436
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2437
    show "T ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2438
      using S measurable_orthogonal_image T by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2439
    have "{z. norm z \<le> m \<and> (\<exists>t\<in>P. norm (z - t) \<le> e)} \<subseteq> T ` {z. norm z \<le> m \<and> (\<exists>t\<in>T -` P. norm (z - t) \<le> e)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2440
    proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2441
      fix x t
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2442
      assume "norm x \<le> m" "t \<in> P" "norm (x - t) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2443
      then have "norm (inv T x) \<le> m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2444
        using orthogonal_transformation_inv [OF T] by (simp add: orthogonal_transformation_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2445
      moreover have "\<exists>t\<in>T -` P. norm (inv T x - t) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2446
      proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2447
        have "T (inv T x - inv T t) = x - t"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2448
          using T linear_diff orthogonal_transformation_def by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2449
        then have "norm (inv T x - inv T t) = norm (x - t)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2450
          by (metis T orthogonal_transformation_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2451
        then show "norm (inv T x - inv T t) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2452
          using \<open>norm (x - t) \<le> e\<close> by linarith
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2453
       next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2454
         show "inv T t \<in> T -` P"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2455
           using \<open>t \<in> P\<close> by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2456
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2457
      ultimately show "x \<in> T ` {z. norm z \<le> m \<and> (\<exists>t\<in>T -` P. norm (z - t) \<le> e)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2458
        by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2459
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2460
    then show "{z. norm z \<le> m \<and> (\<exists>t\<in>P. norm (z - t) \<le> e)} \<subseteq> T ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2461
      using image_mono [OF subS] by (rule order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2462
    show "measure lebesgue (T ` S) \<le> 2 * e * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2463
      using mS T by (simp add: S measure_orthogonal_image)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2464
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2465
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2466
68001
0a2a1b6507c1 correction of TeX errors and other oversights
paulson <lp15@cam.ac.uk>
parents: 67999
diff changeset
  2467
text\<open>As above, but translating the sets (HOL Light's @text{GEN\_GEOM\_ORIGIN\_TAC})\<close>
67998
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2468
lemma Sard_lemma1:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2469
  fixes P :: "(real^'n::{finite,wellorder}) set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2470
   assumes P: "dim P < CARD('n)" and "0 \<le> m" "0 \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2471
 obtains S where "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2472
            and "{z. norm(z - w) \<le> m \<and> (\<exists>t \<in> P. norm(z - w - t) \<le> e)} \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2473
            and "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2474
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2475
  obtain a where "a \<noteq> 0" "P \<subseteq> {x. a \<bullet> x = 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2476
    using lowdim_subset_hyperplane [of P] P span_inc by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2477
  then obtain S where S: "S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2478
    and subS: "{z. norm z \<le> m \<and> (\<exists>t \<in> P. norm(z - t) \<le> e)} \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2479
    and mS: "measure lebesgue S \<le> (2 * e) * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2480
    by (rule Sard_lemma0 [OF _ _ \<open>0 \<le> m\<close> \<open>0 \<le> e\<close>])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2481
  show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2482
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2483
    show "(+)w ` S \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2484
      by (metis measurable_translation S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2485
    show "{z. norm (z - w) \<le> m \<and> (\<exists>t\<in>P. norm (z - w - t) \<le> e)} \<subseteq> (+)w ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2486
      using subS by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2487
    show "measure lebesgue ((+)w ` S) \<le> 2 * e * (2 * m) ^ (CARD('n) - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2488
      by (metis measure_translation mS)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2489
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2490
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2491
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2492
lemma Sard_lemma2:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2493
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n::{finite,wellorder}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2494
  assumes mlen: "CARD('m) \<le> CARD('n)" (is "?m \<le> ?n")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2495
    and "B > 0" "bounded S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2496
    and derS: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2497
    and rank: "\<And>x. x \<in> S \<Longrightarrow> rank(matrix(f' x)) < CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2498
    and B: "\<And>x. x \<in> S \<Longrightarrow> onorm(f' x) \<le> B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2499
  shows "negligible(f ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2500
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2501
  have lin_f': "\<And>x. x \<in> S \<Longrightarrow> linear(f' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2502
    using derS has_derivative_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2503
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2504
  proof (clarsimp simp add: negligible_outer_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2505
    fix e :: "real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2506
    assume "e > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2507
    obtain c where csub: "S \<subseteq> cbox (- (vec c)) (vec c)" and "c > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2508
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2509
      obtain b where b: "\<And>x. x \<in> S \<Longrightarrow> norm x \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2510
        using \<open>bounded S\<close> by (auto simp: bounded_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2511
      show thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2512
      proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2513
        have "- \<bar>b\<bar> - 1 \<le> x $ i \<and> x $ i \<le> \<bar>b\<bar> + 1" if "x \<in> S" for x i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2514
          using component_le_norm_cart [of x i] b [OF that] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2515
        then show "S \<subseteq> cbox (- vec (\<bar>b\<bar> + 1)) (vec (\<bar>b\<bar> + 1))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2516
          by (auto simp: mem_box_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2517
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2518
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2519
    then have box_cc: "box (- (vec c)) (vec c) \<noteq> {}" and cbox_cc: "cbox (- (vec c)) (vec c) \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2520
      by (auto simp: interval_eq_empty_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2521
    obtain d where "d > 0" "d \<le> B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2522
             and d: "(d * 2) * (4 * B) ^ (?n - 1) \<le> e / (2*c) ^ ?m / ?m ^ ?m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2523
      apply (rule that [of "min B (e / (2*c) ^ ?m / ?m ^ ?m / (4 * B) ^ (?n - 1) / 2)"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2524
      using \<open>B > 0\<close> \<open>c > 0\<close> \<open>e > 0\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2525
      by (simp_all add: divide_simps min_mult_distrib_right)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2526
    have "\<exists>r. 0 < r \<and> r \<le> 1/2 \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2527
              (x \<in> S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2528
               \<longrightarrow> (\<forall>y. y \<in> S \<and> norm(y - x) < r
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2529
                       \<longrightarrow> norm(f y - f x - f' x (y - x)) \<le> d * norm(y - x)))" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2530
    proof (cases "x \<in> S")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2531
      case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2532
      then obtain r where "r > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2533
              and "\<And>y. \<lbrakk>y \<in> S; norm (y - x) < r\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2534
                       \<Longrightarrow> norm (f y - f x - f' x (y - x)) \<le> d * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2535
        using derS \<open>d > 0\<close> by (force simp: has_derivative_within_alt)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2536
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2537
        by (rule_tac x="min r (1/2)" in exI) simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2538
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2539
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2540
      then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2541
        by (rule_tac x="1/2" in exI) simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2542
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2543
    then obtain r where r12: "\<And>x. 0 < r x \<and> r x \<le> 1/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2544
            and r: "\<And>x y. \<lbrakk>x \<in> S; y \<in> S; norm(y - x) < r x\<rbrakk>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2545
                          \<Longrightarrow> norm(f y - f x - f' x (y - x)) \<le> d * norm(y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2546
      by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2547
    then have ga: "gauge (\<lambda>x. ball x (r x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2548
      by (auto simp: gauge_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2549
    obtain \<D> where \<D>: "countable \<D>" and sub_cc: "\<Union>\<D> \<subseteq> cbox (- vec c) (vec c)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2550
      and cbox: "\<And>K. K \<in> \<D> \<Longrightarrow> interior K \<noteq> {} \<and> (\<exists>u v. K = cbox u v)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2551
      and djointish: "pairwise (\<lambda>A B. interior A \<inter> interior B = {}) \<D>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2552
      and covered: "\<And>K. K \<in> \<D> \<Longrightarrow> \<exists>x \<in> S \<inter> K. K \<subseteq> ball x (r x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2553
      and close: "\<And>u v. cbox u v \<in> \<D> \<Longrightarrow> \<exists>n. \<forall>i::'m. v $ i - u $ i = 2*c / 2^n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2554
      and covers: "S \<subseteq> \<Union>\<D>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2555
      apply (rule covering_lemma [OF csub box_cc ga])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2556
      apply (auto simp: Basis_vec_def cart_eq_inner_axis [symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2557
      done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2558
    let ?\<mu> = "measure lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2559
    have "\<exists>T. T \<in> lmeasurable \<and> f ` (K \<inter> S) \<subseteq> T \<and> ?\<mu> T \<le> e / (2*c) ^ ?m * ?\<mu> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2560
      if "K \<in> \<D>" for K
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2561
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2562
      obtain u v where uv: "K = cbox u v"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2563
        using cbox \<open>K \<in> \<D>\<close> by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2564
      then have uv_ne: "cbox u v \<noteq> {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2565
        using cbox that by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2566
      obtain x where x: "x \<in> S \<inter> cbox u v" "cbox u v \<subseteq> ball x (r x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2567
        using \<open>K \<in> \<D>\<close> covered uv by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2568
      then have "dim (range (f' x)) < ?n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2569
        using rank_dim_range [of "matrix (f' x)"] lin_f' rank by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2570
      then obtain T where T: "T \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2571
            and subT: "{z. norm(z - f x) \<le> (2 * B) * norm(v - u) \<and> (\<exists>t \<in> range (f' x). norm(z - f x - t) \<le> d * norm(v - u))} \<subseteq> T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2572
            and measT: "?\<mu> T \<le> (2 * (d * norm(v - u))) * (2 * ((2 * B) * norm(v - u))) ^ (?n - 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2573
                        (is "_ \<le> ?DVU")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2574
        apply (rule Sard_lemma1 [of "range (f' x)" "(2 * B) * norm(v - u)" "d * norm(v - u)" "f x"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2575
        using \<open>B > 0\<close> \<open>d > 0\<close> by simp_all
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2576
      show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2577
      proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2578
        have "f ` (K \<inter> S) \<subseteq> {z. norm(z - f x) \<le> (2 * B) * norm(v - u) \<and> (\<exists>t \<in> range (f' x). norm(z - f x - t) \<le> d * norm(v - u))}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2579
          unfolding uv
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2580
        proof (clarsimp simp: mult.assoc, intro conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2581
          fix y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2582
          assume y: "y \<in> cbox u v" and "y \<in> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2583
          then have "norm (y - x) < r x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2584
            by (metis dist_norm mem_ball norm_minus_commute subsetCE x(2))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2585
          then have le_dyx: "norm (f y - f x - f' x (y - x)) \<le> d * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2586
            using r [of x y] x \<open>y \<in> S\<close> by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2587
          have yx_le: "norm (y - x) \<le> norm (v - u)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2588
          proof (rule norm_le_componentwise_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2589
            show "\<bar>(y - x) $ i\<bar> \<le> \<bar>(v - u) $ i\<bar>" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2590
            using x y by (force simp: mem_box_cart dest!: spec [where x=i])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2591
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2592
          have *: "\<lbrakk>norm(y - x - z) \<le> d; norm z \<le> B; d \<le> B\<rbrakk> \<Longrightarrow> norm(y - x) \<le> 2 * B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2593
            for x y z :: "real^'n::_" and d B
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2594
            using norm_triangle_ineq2 [of "y - x" z] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2595
          show "norm (f y - f x) \<le> 2 * (B * norm (v - u))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2596
          proof (rule * [OF le_dyx])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2597
            have "norm (f' x (y - x)) \<le> onorm (f' x) * norm (y - x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2598
              using onorm [of "f' x" "y-x"] by (meson IntE lin_f' linear_linear x(1))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2599
            also have "\<dots> \<le> B * norm (v - u)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2600
            proof (rule mult_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2601
              show "onorm (f' x) \<le> B"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2602
                using B x by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2603
            qed (use \<open>B > 0\<close> yx_le in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2604
            finally show "norm (f' x (y - x)) \<le> B * norm (v - u)" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2605
            show "d * norm (y - x) \<le> B * norm (v - u)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2606
              using \<open>B > 0\<close> by (auto intro: mult_mono [OF \<open>d \<le> B\<close> yx_le])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2607
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2608
          show "\<exists>t. norm (f y - f x - f' x t) \<le> d * norm (v - u)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2609
            apply (rule_tac x="y-x" in exI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2610
            using \<open>d > 0\<close> yx_le le_dyx mult_left_mono [where c=d]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2611
            by (meson order_trans real_mult_le_cancel_iff2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2612
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2613
        with subT show "f ` (K \<inter> S) \<subseteq> T" by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2614
        show "?\<mu> T \<le> e / (2*c) ^ ?m * ?\<mu> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2615
        proof (rule order_trans [OF measT])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2616
          have "?DVU = (d * 2 * (4 * B) ^ (?n - 1)) * norm (v - u)^?n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2617
            using \<open>c > 0\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2618
            apply (simp add: algebra_simps power_mult_distrib)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2619
            by (metis Suc_pred power_Suc zero_less_card_finite)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2620
          also have "\<dots> \<le> (e / (2*c) ^ ?m / (?m ^ ?m)) * norm(v - u) ^ ?n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2621
            by (rule mult_right_mono [OF d]) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2622
          also have "\<dots> \<le> e / (2*c) ^ ?m * ?\<mu> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2623
          proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2624
            have "u \<in> ball (x) (r x)" "v \<in> ball x (r x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2625
              using box_ne_empty(1) contra_subsetD [OF x(2)] mem_box(2) uv_ne by fastforce+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2626
            moreover have "r x \<le> 1/2"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2627
              using r12 by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2628
            ultimately have "norm (v - u) \<le> 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2629
              using norm_triangle_half_r [of x u 1 v]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2630
              by (metis (no_types, hide_lams) dist_commute dist_norm less_eq_real_def less_le_trans mem_ball)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2631
            then have "norm (v - u) ^ ?n \<le> norm (v - u) ^ ?m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2632
              by (simp add: power_decreasing [OF mlen])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2633
            also have "\<dots> \<le> ?\<mu> K * real (?m ^ ?m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2634
            proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2635
              obtain n where n: "\<And>i. v$i - u$i = 2 * c / 2^n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2636
                using close [of u v] \<open>K \<in> \<D>\<close> uv by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2637
              have "norm (v - u) ^ ?m \<le> (\<Sum>i\<in>UNIV. \<bar>(v - u) $ i\<bar>) ^ ?m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2638
                by (intro norm_le_l1_cart power_mono) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2639
              also have "\<dots> \<le> (\<Prod>i\<in>UNIV. v $ i - u $ i) * real CARD('m) ^ CARD('m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2640
                by (simp add: n field_simps \<open>c > 0\<close> less_eq_real_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2641
              also have "\<dots> = ?\<mu> K * real (?m ^ ?m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2642
                by (simp add: uv uv_ne content_cbox_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2643
              finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2644
            qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2645
            finally have *: "1 / real (?m ^ ?m) * norm (v - u) ^ ?n \<le> ?\<mu> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2646
              by (simp add: divide_simps)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2647
            show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2648
              using mult_left_mono [OF *, of "e / (2*c) ^ ?m"] \<open>c > 0\<close> \<open>e > 0\<close> by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2649
          qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2650
          finally show "?DVU \<le> e / (2*c) ^ ?m * ?\<mu> K" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2651
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2652
      qed (use T in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2653
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2654
    then obtain g where meas_g: "\<And>K. K \<in> \<D> \<Longrightarrow> g K \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2655
                    and sub_g: "\<And>K. K \<in> \<D> \<Longrightarrow> f ` (K \<inter> S) \<subseteq> g K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2656
                    and le_g: "\<And>K. K \<in> \<D> \<Longrightarrow> ?\<mu> (g K) \<le> e / (2*c)^?m * ?\<mu> K"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2657
      by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2658
    have le_e: "?\<mu> (\<Union>i\<in>\<F>. g i) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2659
      if "\<F> \<subseteq> \<D>" "finite \<F>" for \<F>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2660
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2661
      have "?\<mu> (\<Union>i\<in>\<F>. g i) \<le> (\<Sum>i\<in>\<F>. ?\<mu> (g i))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2662
        using meas_g \<open>\<F> \<subseteq> \<D>\<close> by (auto intro: measure_UNION_le [OF \<open>finite \<F>\<close>])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2663
      also have "\<dots> \<le> (\<Sum>K\<in>\<F>. e / (2*c) ^ ?m * ?\<mu> K)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2664
        using \<open>\<F> \<subseteq> \<D>\<close> sum_mono [OF le_g] by (meson le_g subsetCE sum_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2665
      also have "\<dots> = e / (2*c) ^ ?m * (\<Sum>K\<in>\<F>. ?\<mu> K)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2666
        by (simp add: sum_distrib_left)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2667
      also have "\<dots> \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2668
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2669
        have "\<F> division_of \<Union>\<F>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2670
        proof (rule division_ofI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2671
          show "K \<subseteq> \<Union>\<F>"  "K \<noteq> {}" "\<exists>a b. K = cbox a b" if "K \<in> \<F>" for K
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2672
            using \<open>K \<in> \<F>\<close> covered cbox \<open>\<F> \<subseteq> \<D>\<close> by (auto simp: Union_upper)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2673
          show "interior K \<inter> interior L = {}" if "K \<in> \<F>" and "L \<in> \<F>" and "K \<noteq> L" for K L
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2674
            by (metis (mono_tags, lifting) \<open>\<F> \<subseteq> \<D>\<close> pairwiseD djointish pairwise_subset that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2675
        qed (use that in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2676
        then have "sum ?\<mu> \<F> \<le> ?\<mu> (\<Union>\<F>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2677
          by (simp add: content_division)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2678
        also have "\<dots> \<le> ?\<mu> (cbox (- vec c) (vec c) :: (real, 'm) vec set)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2679
        proof (rule measure_mono_fmeasurable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2680
          show "\<Union>\<F> \<subseteq> cbox (- vec c) (vec c)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2681
            by (meson Sup_subset_mono sub_cc order_trans \<open>\<F> \<subseteq> \<D>\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2682
        qed (use \<open>\<F> division_of \<Union>\<F>\<close> lmeasurable_division in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2683
        also have "\<dots> = content (cbox (- vec c) (vec c) :: (real, 'm) vec set)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2684
          by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2685
        also have "\<dots> \<le> (2 ^ ?m * c ^ ?m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2686
          using \<open>c > 0\<close> by (simp add: content_cbox_if_cart)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2687
        finally have "sum ?\<mu> \<F> \<le> (2 ^ ?m * c ^ ?m)" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2688
        then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2689
          using \<open>e > 0\<close> \<open>c > 0\<close> by (auto simp: divide_simps mult_less_0_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2690
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2691
      finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2692
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2693
    show "\<exists>T. f ` S \<subseteq> T \<and> T \<in> lmeasurable \<and> ?\<mu> T \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2694
    proof (intro exI conjI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2695
      show "f ` S \<subseteq> UNION \<D> g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2696
        using covers sub_g by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2697
      show "UNION \<D> g \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2698
        by (rule fmeasurable_UN_bound [OF \<open>countable \<D>\<close> meas_g le_e])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2699
      show "?\<mu> (UNION \<D> g) \<le> e"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2700
        by (rule measure_UN_bound [OF \<open>countable \<D>\<close> meas_g le_e])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2701
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2702
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2703
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2704
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2705
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2706
theorem baby_Sard:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2707
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n::{finite,wellorder}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2708
  assumes mlen: "CARD('m) \<le> CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2709
    and der: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2710
    and rank: "\<And>x. x \<in> S \<Longrightarrow> rank(matrix(f' x)) < CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2711
  shows "negligible(f ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2712
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2713
  let ?U = "\<lambda>n. {x \<in> S. norm(x) \<le> n \<and> onorm(f' x) \<le> real n}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2714
  have "\<And>x. x \<in> S \<Longrightarrow> \<exists>n. norm x \<le> real n \<and> onorm (f' x) \<le> real n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2715
    by (meson linear order_trans real_arch_simple)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2716
  then have eq: "S = (\<Union>n. ?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2717
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2718
  have "negligible (f ` ?U n)" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2719
  proof (rule Sard_lemma2 [OF mlen])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2720
    show "0 < real n + 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2721
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2722
    show "bounded (?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2723
      using bounded_iff by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2724
    show "(f has_derivative f' x) (at x within ?U n)" if "x \<in> ?U n" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2725
      using der that by (force intro: has_derivative_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2726
  qed (use rank in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2727
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2728
    by (subst eq) (simp add: image_Union negligible_Union_nat)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2729
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2730
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2731
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2732
subsection\<open>A one-way version of change-of-variables not assuming injectivity. \<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2733
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2734
lemma integral_on_image_ubound_weak:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2735
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2736
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2737
      and f: "f \<in> borel_measurable (lebesgue_on (g ` S))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2738
      and nonneg_fg:  "\<And>x. x \<in> S \<Longrightarrow> 0 \<le> f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2739
      and der_g:   "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2740
      and det_int_fg: "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2741
      and meas_gim: "\<And>T. \<lbrakk>T \<subseteq> g ` S; T \<in> sets lebesgue\<rbrakk> \<Longrightarrow> {x \<in> S. g x \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2742
    shows "f integrable_on (g ` S) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2743
           integral (g ` S) f \<le> integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2744
         (is "_ \<and> _ \<le> ?b")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2745
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2746
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2747
  have cont_g: "continuous_on S g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2748
    using der_g has_derivative_continuous_on by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2749
  have [simp]: "space (lebesgue_on S) = S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2750
    by (simp add: S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2751
  have gS_in_sets_leb: "g ` S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2752
    apply (rule differentiable_image_in_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2753
    using der_g by (auto simp: S differentiable_def differentiable_on_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2754
  obtain h where nonneg_h: "\<And>n x. 0 \<le> h n x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2755
    and h_le_f: "\<And>n x. x \<in> S \<Longrightarrow> h n (g x) \<le> f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2756
    and h_inc: "\<And>n x. h n x \<le> h (Suc n) x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2757
    and h_meas: "\<And>n. h n \<in> borel_measurable lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2758
    and fin_R: "\<And>n. finite(range (h n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2759
    and lim: "\<And>x. x \<in> g ` S \<Longrightarrow> (\<lambda>n. h n x) \<longlonglongrightarrow> f x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2760
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2761
    let ?f = "\<lambda>x. if x \<in> g ` S then f x else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2762
    have "?f \<in> borel_measurable lebesgue \<and> (\<forall>x. 0 \<le> ?f x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2763
      by (auto simp: gS_in_sets_leb f nonneg_fg measurable_restrict_space_iff [symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2764
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2765
      apply (clarsimp simp add: borel_measurable_simple_function_limit_increasing)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2766
      apply (rename_tac h)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2767
      by (rule_tac h=h in that) (auto split: if_split_asm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2768
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2769
  have h_lmeas: "{t. h n (g t) = y} \<inter> S \<in> sets lebesgue" for y n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2770
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2771
    have "space (lebesgue_on (UNIV::(real,'n) vec set)) = UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2772
      by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2773
    then have "((h n) -`{y} \<inter> g ` S) \<in> sets (lebesgue_on (g ` S))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2774
      by (metis Int_commute borel_measurable_vimage h_meas image_eqI inf_top.right_neutral sets_restrict_space space_borel space_completion space_lborel)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2775
    then have "({u. h n u = y} \<inter> g ` S) \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2776
      using gS_in_sets_leb
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2777
      by (simp add: integral_indicator fmeasurableI2 sets_restrict_space_iff vimage_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2778
    then have "{x \<in> S. g x \<in> ({u. h n u = y} \<inter> g ` S)} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2779
      using meas_gim[of "({u. h n u = y} \<inter> g ` S)"] by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2780
    moreover have "{t. h n (g t) = y} \<inter> S = {x \<in> S. g x \<in> ({u. h n u = y} \<inter> g ` S)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2781
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2782
    ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2783
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2784
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2785
  have hint: "h n integrable_on g ` S \<and> integral (g ` S) (h n) \<le> integral S (\<lambda>x. ?D x * h n (g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2786
          (is "?INT \<and> ?lhs \<le> ?rhs")  for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2787
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2788
    let ?R = "range (h n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2789
    have hn_eq: "h n = (\<lambda>x. \<Sum>y\<in>?R. y * indicat_real {x. h n x = y} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2790
      by (simp add: indicator_def if_distrib fin_R cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2791
    have yind: "(\<lambda>t. y * indicator{x. h n x = y} t) integrable_on (g ` S) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2792
                (integral (g ` S) (\<lambda>t. y * indicator {x. h n x = y} t))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2793
                 \<le> integral S (\<lambda>t. \<bar>det (matrix (g' t))\<bar> * y * indicator {x. h n x = y} (g t))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2794
       if y: "y \<in> ?R" for y::real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2795
    proof (cases "y=0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2796
      case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2797
      then show ?thesis using gS_in_sets_leb integrable_0 by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2798
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2799
      case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2800
      with that have "y > 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2801
        using less_eq_real_def nonneg_h by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2802
      have "(\<lambda>x. if x \<in> {t. h n (g t) = y} then ?D x else 0) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2803
      proof (rule measurable_bounded_by_integrable_imp_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2804
        have "(\<lambda>x. ?D x) \<in> borel_measurable (lebesgue_on ({t. h n (g t) = y} \<inter> S))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2805
          apply (intro borel_measurable_abs borel_measurable_det_Jacobian [OF h_lmeas, where f=g])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2806
          by (meson der_g IntD2 has_derivative_within_subset inf_le2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2807
        then have "(\<lambda>x. if x \<in> {t. h n (g t) = y} \<inter> S then ?D x else 0) \<in> borel_measurable lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2808
          by (rule borel_measurable_If_I [OF _ h_lmeas])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2809
        then show "(\<lambda>x. if x \<in> {t. h n (g t) = y} then ?D x else 0) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2810
          by (simp add: if_if_eq_conj Int_commute borel_measurable_UNIV [OF S, symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2811
        show "(\<lambda>x. ?D x *\<^sub>R f (g x) /\<^sub>R y) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2812
          by (rule integrable_cmul) (use det_int_fg in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2813
        show "norm (if x \<in> {t. h n (g t) = y} then ?D x else 0) \<le> ?D x *\<^sub>R f (g x) /\<^sub>R y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2814
          if "x \<in> S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2815
          using nonneg_h [of n x] \<open>y > 0\<close> nonneg_fg [of x] h_le_f [of x n] that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2816
          by (auto simp: divide_simps ordered_semiring_class.mult_left_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2817
      qed (use S in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2818
      then have int_det: "(\<lambda>t. \<bar>det (matrix (g' t))\<bar>) integrable_on ({t. h n (g t) = y} \<inter> S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2819
        using integrable_restrict_Int by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2820
      have "(g ` ({t. h n (g t) = y} \<inter> S)) \<in> lmeasurable"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2821
        apply (rule measurable_differentiable_image [OF h_lmeas])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2822
         apply (blast intro: has_derivative_within_subset [OF der_g])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2823
        apply (rule int_det)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2824
        done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2825
      moreover have "g ` ({t. h n (g t) = y} \<inter> S) = {x. h n x = y} \<inter> g ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2826
        by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2827
      moreover have "measure lebesgue (g ` ({t. h n (g t) = y} \<inter> S))
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2828
                     \<le> integral ({t. h n (g t) = y} \<inter> S) (\<lambda>t. \<bar>det (matrix (g' t))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2829
        apply (rule measure_differentiable_image [OF h_lmeas _ int_det])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2830
        apply (blast intro: has_derivative_within_subset [OF der_g])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2831
        done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2832
      ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2833
        using \<open>y > 0\<close> integral_restrict_Int [of S "{t. h n (g t) = y}" "\<lambda>t. \<bar>det (matrix (g' t))\<bar> * y"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2834
        apply (simp add: integrable_on_indicator integrable_on_cmult_iff integral_indicator)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2835
        apply (simp add: indicator_def if_distrib cong: if_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2836
        done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2837
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2838
    have hn_int: "h n integrable_on g ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2839
      apply (subst hn_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2840
      using yind by (force intro: integrable_sum [OF fin_R])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2841
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2842
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2843
      have "?lhs = integral (g ` S) (\<lambda>x. \<Sum>y\<in>range (h n). y * indicat_real {x. h n x = y} x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2844
        by (metis hn_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2845
      also have "\<dots> = (\<Sum>y\<in>range (h n). integral (g ` S) (\<lambda>x. y * indicat_real {x. h n x = y} x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2846
        by (rule integral_sum [OF fin_R]) (use yind in blast)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2847
      also have "\<dots> \<le> (\<Sum>y\<in>range (h n). integral S (\<lambda>u. \<bar>det (matrix (g' u))\<bar> * y * indicat_real {x. h n x = y} (g u)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2848
        using yind by (force intro: sum_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2849
      also have "\<dots> = integral S (\<lambda>u. \<Sum>y\<in>range (h n). \<bar>det (matrix (g' u))\<bar> * y * indicat_real {x. h n x = y} (g u))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2850
      proof (rule integral_sum [OF fin_R, symmetric])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2851
        fix y assume y: "y \<in> ?R"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2852
        with nonneg_h have "y \<ge> 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2853
          by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2854
        show "(\<lambda>u. \<bar>det (matrix (g' u))\<bar> * y * indicat_real {x. h n x = y} (g u)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2855
        proof (rule measurable_bounded_by_integrable_imp_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2856
          have "(\<lambda>x. indicat_real {x. h n x = y} (g x)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2857
            using h_lmeas S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2858
            by (auto simp: indicator_vimage [symmetric] borel_measurable_indicator_iff sets_restrict_space_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2859
          then show "(\<lambda>u. \<bar>det (matrix (g' u))\<bar> * y * indicat_real {x. h n x = y} (g u)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2860
            by (intro borel_measurable_times borel_measurable_abs borel_measurable_const borel_measurable_det_Jacobian [OF S der_g])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2861
        next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2862
          fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2863
          assume "x \<in> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2864
          have "y * indicat_real {x. h n x = y} (g x) \<le> f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2865
            by (metis (full_types) \<open>x \<in> S\<close> h_le_f indicator_def mem_Collect_eq mult.right_neutral mult_zero_right nonneg_fg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2866
          with \<open>y \<ge> 0\<close> show "norm (?D x * y * indicat_real {x. h n x = y} (g x)) \<le> ?D x * f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2867
            by (simp add: abs_mult mult.assoc mult_left_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2868
        qed (use S det_int_fg in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2869
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2870
      also have "\<dots> = integral S (\<lambda>T. \<bar>det (matrix (g' T))\<bar> *
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2871
                                        (\<Sum>y\<in>range (h n). y * indicat_real {x. h n x = y} (g T)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2872
        by (simp add: sum_distrib_left mult.assoc)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2873
      also have "\<dots> = ?rhs"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2874
        by (metis hn_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2875
      finally show "integral (g ` S) (h n) \<le> ?rhs" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2876
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2877
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2878
  have le: "integral S (\<lambda>T. \<bar>det (matrix (g' T))\<bar> * h n (g T)) \<le> ?b" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2879
  proof (rule integral_le)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2880
    show "(\<lambda>T. \<bar>det (matrix (g' T))\<bar> * h n (g T)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2881
    proof (rule measurable_bounded_by_integrable_imp_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2882
      have "(\<lambda>T. \<bar>det (matrix (g' T))\<bar> *\<^sub>R h n (g T)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2883
      proof (intro borel_measurable_scaleR borel_measurable_abs borel_measurable_det_Jacobian \<open>S \<in> sets lebesgue\<close>)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2884
        have eq: "{x \<in> S. f x \<le> a} = (\<Union>b \<in> (f ` S) \<inter> atMost a. {x. f x = b} \<inter> S)" for f and a::real
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2885
          by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2886
        have "finite ((\<lambda>x. h n (g x)) ` S \<inter> {..a})" for a
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2887
          by (force intro: finite_subset [OF _ fin_R])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2888
        with h_lmeas [of n] show "(\<lambda>x. h n (g x)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2889
          apply (simp add: borel_measurable_vimage_halfspace_component_le \<open>S \<in> sets lebesgue\<close> sets_restrict_space_iff eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2890
          by (metis (mono_tags) SUP_inf sets.finite_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2891
      qed (use der_g in blast)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2892
      then show "(\<lambda>T. \<bar>det (matrix (g' T))\<bar> * h n (g T)) \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2893
        by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2894
      show "norm (?D x * h n (g x)) \<le> ?D x *\<^sub>R f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2895
        if "x \<in> S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2896
        by (simp add: h_le_f mult_left_mono nonneg_h that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2897
    qed (use S det_int_fg in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2898
    show "?D x * h n (g x) \<le> ?D x * f (g x)" if "x \<in> S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2899
      by (simp add: \<open>x \<in> S\<close> h_le_f mult_left_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2900
    show "(\<lambda>x. ?D x * f (g x)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2901
      using det_int_fg by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2902
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2903
  have "f integrable_on g ` S \<and> (\<lambda>k. integral (g ` S) (h k)) \<longlonglongrightarrow> integral (g ` S) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2904
  proof (rule monotone_convergence_increasing)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2905
    have "\<bar>integral (g ` S) (h n)\<bar> \<le> integral S (\<lambda>x. ?D x * f (g x))" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2906
    proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2907
      have "\<bar>integral (g ` S) (h n)\<bar> = integral (g ` S) (h n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2908
        using hint by (simp add: integral_nonneg nonneg_h)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2909
      also have "\<dots> \<le> integral S (\<lambda>x. ?D x * f (g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2910
        using hint le by (meson order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2911
      finally show ?thesis .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2912
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2913
    then show "bounded (range (\<lambda>k. integral (g ` S) (h k)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2914
      by (force simp: bounded_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2915
  qed (use h_inc lim hint in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2916
  moreover have "integral (g ` S) (h n) \<le> integral S (\<lambda>x. ?D x * f (g x))" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2917
    using hint by (blast intro: le order_trans)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2918
  ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2919
    by (auto intro: Lim_bounded_ereal)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2920
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2921
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2922
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2923
lemma integral_on_image_ubound_nonneg:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2924
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2925
  assumes nonneg_fg: "\<And>x. x \<in> S \<Longrightarrow> 0 \<le> f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2926
      and der_g:   "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2927
      and intS: "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2928
  shows "f integrable_on (g ` S) \<and> integral (g ` S) f \<le> integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2929
         (is "_ \<and> _ \<le> ?b")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2930
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2931
  let ?D = "\<lambda>x. det (matrix (g' x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2932
  define S' where "S' \<equiv> {x \<in> S. ?D x * f(g x) \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2933
  then have der_gS': "\<And>x. x \<in> S' \<Longrightarrow> (g has_derivative g' x) (at x within S')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2934
    by (metis (mono_tags, lifting) der_g has_derivative_within_subset mem_Collect_eq subset_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2935
  have "(\<lambda>x. if x \<in> S then \<bar>?D x\<bar> * f (g x) else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2936
    by (simp add: integrable_restrict_UNIV intS)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2937
  then have Df_borel: "(\<lambda>x. if x \<in> S then \<bar>?D x\<bar> * f (g x) else 0) \<in> borel_measurable lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2938
    using integrable_imp_measurable borel_measurable_UNIV_eq by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2939
  have S': "S' \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2940
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2941
    from Df_borel borel_measurable_vimage_open [of _ UNIV]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2942
    have "{x. (if x \<in> S then \<bar>?D x\<bar> * f (g x) else 0) \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2943
      if "open T" for T
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2944
      using that unfolding borel_measurable_UNIV_eq
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2945
      by (fastforce simp add: dest!: spec)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2946
    then have "{x. (if x \<in> S then \<bar>?D x\<bar> * f (g x) else 0) \<in> -{0}} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2947
      using open_Compl by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2948
    then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2949
      by (simp add: S'_def conj_ac split: if_split_asm cong: conj_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2950
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2951
  then have gS': "g ` S' \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2952
  proof (rule differentiable_image_in_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2953
    show "g differentiable_on S'"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2954
      using der_g unfolding S'_def differentiable_def differentiable_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2955
      by (blast intro: has_derivative_within_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2956
  qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2957
  have f: "f \<in> borel_measurable (lebesgue_on (g ` S'))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2958
  proof (clarsimp simp add: borel_measurable_vimage_open)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2959
    fix T :: "real set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2960
    assume "open T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2961
    have "{x \<in> g ` S'. f x \<in> T} = g ` {x \<in> S'. f(g x) \<in> T}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2962
      by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2963
    moreover have "g ` {x \<in> S'. f(g x) \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2964
    proof (rule differentiable_image_in_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2965
      let ?h = "\<lambda>x. \<bar>?D x\<bar> * f (g x) /\<^sub>R \<bar>?D x\<bar>"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2966
      have "(\<lambda>x. if x \<in> S' then \<bar>?D x\<bar> * f (g x) else 0) = (\<lambda>x. if x \<in> S then \<bar>?D x\<bar> * f (g x) else 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2967
        by (auto simp: S'_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2968
      also have "\<dots> \<in> borel_measurable lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2969
        by (rule Df_borel)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2970
      finally have *: "(\<lambda>x. \<bar>?D x\<bar> * f (g x)) \<in> borel_measurable (lebesgue_on S')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2971
        by (simp add: borel_measurable_If_D)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2972
      have "?h \<in> borel_measurable (lebesgue_on S')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2973
        by (intro * S' der_gS' borel_measurable_det_Jacobian measurable) (blast intro: der_gS')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2974
      moreover have "?h x = f(g x)" if "x \<in> S'" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2975
        using that by (auto simp: S'_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2976
      ultimately have "(\<lambda>x. f(g x)) \<in> borel_measurable (lebesgue_on S')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2977
        by (metis (no_types, lifting) measurable_lebesgue_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2978
      then show "{x \<in> S'. f (g x) \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2979
        by (simp add: \<open>S' \<in> sets lebesgue\<close> \<open>open T\<close> borel_measurable_vimage_open sets_restrict_space_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2980
      show "g differentiable_on {x \<in> S'. f (g x) \<in> T}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2981
        using der_g unfolding S'_def differentiable_def differentiable_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2982
        by (blast intro: has_derivative_within_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2983
    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2984
    ultimately have "{x \<in> g ` S'. f x \<in> T} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2985
      by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2986
    then show "{x \<in> g ` S'. f x \<in> T} \<in> sets (lebesgue_on (g ` S'))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2987
      by (simp add: \<open>g ` S' \<in> sets lebesgue\<close> sets_restrict_space_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2988
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2989
  have intS': "(\<lambda>x. \<bar>?D x\<bar> * f (g x)) integrable_on S'"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2990
    using intS
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2991
    by (rule integrable_spike_set) (auto simp: S'_def intro: empty_imp_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2992
  have lebS': "{x \<in> S'. g x \<in> T} \<in> sets lebesgue" if "T \<subseteq> g ` S'" "T \<in> sets lebesgue" for T
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2993
  proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2994
    have "g \<in> borel_measurable (lebesgue_on S')"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2995
      using der_gS' has_derivative_continuous_on S'
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2996
      by (blast intro: continuous_imp_measurable_on_sets_lebesgue)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2997
    moreover have "{x \<in> S'. g x \<in> U} \<in> sets lebesgue" if "negligible U" "U \<subseteq> g ` S'" for U
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2998
    proof (intro negligible_imp_sets negligible_differentiable_vimage that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  2999
      fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3000
      assume x: "x \<in> S'"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3001
      then have "linear (g' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3002
        using der_gS' has_derivative_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3003
      with x show "inj (g' x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3004
        by (auto simp: S'_def det_nz_iff_inj)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3005
    qed (use der_gS' in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3006
    ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3007
      using double_lebesgue_sets [OF S' gS' order_refl] that by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3008
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3009
  have int_gS': "f integrable_on g ` S' \<and> integral (g ` S') f \<le> integral S' (\<lambda>x. \<bar>?D x\<bar> * f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3010
    using integral_on_image_ubound_weak [OF S' f nonneg_fg der_gS' intS' lebS'] S'_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3011
  have "negligible (g ` {x \<in> S. det(matrix(g' x)) = 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3012
  proof (rule baby_Sard, simp_all)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3013
    fix x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3014
    assume x: "x \<in> S \<and> det (matrix (g' x)) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3015
    then show "(g has_derivative g' x) (at x within {x \<in> S. det (matrix (g' x)) = 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3016
      by (metis (no_types, lifting) der_g has_derivative_within_subset mem_Collect_eq subsetI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3017
    then show "rank (matrix (g' x)) < CARD('n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3018
      using det_nz_iff_inj matrix_vector_mul_linear x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3019
      by (fastforce simp add: less_rank_noninjective)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3020
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3021
  then have negg: "negligible (g ` S - g ` {x \<in> S. ?D x \<noteq> 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3022
    by (rule negligible_subset) (auto simp: S'_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3023
  have null: "g ` {x \<in> S. ?D x \<noteq> 0} - g ` S = {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3024
    by (auto simp: S'_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3025
  let ?F = "{x \<in> S. f (g x) \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3026
  have eq: "g ` S' = g ` ?F \<inter> g ` {x \<in> S. ?D x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3027
    by (auto simp: S'_def image_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3028
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3029
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3030
    have "((\<lambda>x. if x \<in> g ` ?F then f x else 0) integrable_on g ` {x \<in> S. ?D x \<noteq> 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3031
      using int_gS' eq integrable_restrict_Int [where f=f]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3032
      by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3033
    then have "f integrable_on g ` {x \<in> S. ?D x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3034
      by (auto simp: image_iff elim!: integrable_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3035
    then show "f integrable_on g ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3036
      apply (rule integrable_spike_set [OF _ empty_imp_negligible negligible_subset])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3037
      using negg null by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3038
    have "integral (g ` S) f = integral (g ` {x \<in> S. ?D x \<noteq> 0}) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3039
      using negg by (auto intro: negligible_subset integral_spike_set)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3040
    also have "\<dots> = integral (g ` {x \<in> S. ?D x \<noteq> 0}) (\<lambda>x. if x \<in> g ` ?F then f x else 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3041
      by (auto simp: image_iff intro!: integral_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3042
    also have "\<dots> = integral (g ` S') f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3043
      using  eq integral_restrict_Int by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3044
    also have "\<dots> \<le> integral S' (\<lambda>x. \<bar>?D x\<bar> * f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3045
      by (metis int_gS')
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3046
    also have "\<dots> \<le> ?b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3047
      by (rule integral_subset_le [OF _ intS' intS]) (use nonneg_fg S'_def in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3048
    finally show "integral (g ` S) f \<le> ?b" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3049
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3050
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3051
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3052
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3053
lemma absolutely_integrable_on_image_real:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3054
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real" and g :: "real^'n::_ \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3055
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3056
    and intS: "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3057
  shows "f absolutely_integrable_on (g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3058
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3059
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3060
  let ?N = "{x \<in> S. f (g x) < 0}" and ?P = "{x \<in> S. f (g x) > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3061
  have eq: "{x. (if x \<in> S then ?D x else 0) > 0} = {x \<in> S. ?D x > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3062
           "{x. (if x \<in> S then ?D x else 0) < 0} = {x \<in> S. ?D x < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3063
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3064
  have "?D integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3065
    using intS absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3066
  then have "(\<lambda>x. if x \<in> S then ?D x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3067
    by (simp add: integrable_restrict_UNIV)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3068
  then have D_borel: "(\<lambda>x. if x \<in> S then ?D x else 0) \<in> borel_measurable (lebesgue_on UNIV)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3069
    using integrable_imp_measurable borel_measurable_UNIV_eq by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3070
  then have Dlt: "{x \<in> S. ?D x < 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3071
    unfolding borel_measurable_vimage_halfspace_component_lt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3072
    by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3073
  from D_borel have Dgt: "{x \<in> S. ?D x > 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3074
    unfolding borel_measurable_vimage_halfspace_component_gt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3075
    by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3076
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3077
  have dfgbm: "?D \<in> borel_measurable (lebesgue_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3078
    using intS absolutely_integrable_on_def integrable_imp_measurable by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3079
  have der_gN: "(g has_derivative g' x) (at x within ?N)" if "x \<in> ?N" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3080
      using der_g has_derivative_within_subset that by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3081
  have "(\<lambda>x. - f x) integrable_on g ` ?N \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3082
         integral (g ` ?N) (\<lambda>x. - f x) \<le> integral ?N (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * - f (g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3083
  proof (rule integral_on_image_ubound_nonneg [OF _ der_gN])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3084
    have 1: "?D integrable_on {x \<in> S. ?D x < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3085
      using Dlt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3086
      by (auto intro: set_lebesgue_integral_eq_integral [OF set_integrable_subset] intS)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3087
    have "uminus \<circ> (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * - f (g x)) integrable_on ?N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3088
      by (simp add: o_def mult_less_0_iff empty_imp_negligible integrable_spike_set [OF 1])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3089
    then show "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * - f (g x)) integrable_on ?N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3090
      by (simp add: integrable_neg_iff o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3091
  qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3092
  then have "f integrable_on g ` ?N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3093
    by (simp add: integrable_neg_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3094
  moreover have "g ` ?N = {y \<in> g ` S. f y < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3095
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3096
  ultimately have "f integrable_on {y \<in> g ` S. f y < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3097
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3098
  then have N: "f absolutely_integrable_on {y \<in> g ` S. f y < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3099
    by (rule absolutely_integrable_absolutely_integrable_ubound) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3100
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3101
  have der_gP: "(g has_derivative g' x) (at x within ?P)" if "x \<in> ?P" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3102
      using der_g has_derivative_within_subset that by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3103
  have "f integrable_on g ` ?P \<and> integral (g ` ?P) f \<le> integral ?P ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3104
  proof (rule integral_on_image_ubound_nonneg [OF _ der_gP])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3105
    have "?D integrable_on {x \<in> S. 0 < ?D x}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3106
      using Dgt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3107
      by (auto intro: set_lebesgue_integral_eq_integral [OF set_integrable_subset] intS)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3108
    then show "?D integrable_on ?P"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3109
      apply (rule integrable_spike_set)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3110
      by (auto simp: zero_less_mult_iff empty_imp_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3111
  qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3112
  then have "f integrable_on g ` ?P"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3113
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3114
  moreover have "g ` ?P = {y \<in> g ` S. f y > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3115
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3116
  ultimately have "f integrable_on {y \<in> g ` S. f y > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3117
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3118
  then have P: "f absolutely_integrable_on {y \<in> g ` S. f y > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3119
    by (rule absolutely_integrable_absolutely_integrable_lbound) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3120
  have "(\<lambda>x. if x \<in> g ` S \<and> f x < 0 \<or> x \<in> g ` S \<and> 0 < f x then f x else 0) = (\<lambda>x. if x \<in> g ` S then f x else 0)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3121
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3122
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3123
    using absolutely_integrable_Un [OF N P] absolutely_integrable_restrict_UNIV [symmetric, where f=f]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3124
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3125
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3126
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3127
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3128
proposition absolutely_integrable_on_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3129
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3130
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3131
    and intS: "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3132
  shows "f absolutely_integrable_on (g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3133
  apply (rule absolutely_integrable_componentwise [OF absolutely_integrable_on_image_real [OF der_g]])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3134
  using absolutely_integrable_component [OF intS]  by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3135
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3136
proposition integral_on_image_ubound:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3137
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real" and g :: "real^'n::_ \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3138
  assumes"\<And>x. x \<in> S \<Longrightarrow> 0 \<le> f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3139
    and "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3140
    and "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3141
  shows "integral (g ` S) f \<le> integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3142
  using integral_on_image_ubound_nonneg [OF assms] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3143
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3144
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3145
subsection\<open>Change-of-variables theorem\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3146
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3147
text\<open>The classic change-of-variables theorem. We have two versions with quite general hypotheses,
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3148
the first that the transforming function has a continuous inverse, the second that the base set is
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3149
Lebesgue measurable.\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3150
lemma cov_invertible_nonneg_le:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3151
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real" and g :: "real^'n::_ \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3152
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3153
    and der_h: "\<And>y. y \<in> T \<Longrightarrow> (h has_derivative h' y) (at y within T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3154
    and f0: "\<And>y. y \<in> T \<Longrightarrow> 0 \<le> f y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3155
    and hg: "\<And>x. x \<in> S \<Longrightarrow> g x \<in> T \<and> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3156
    and gh: "\<And>y. y \<in> T \<Longrightarrow> h y \<in> S \<and> g(h y) = y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3157
    and id: "\<And>y. y \<in> T \<Longrightarrow> h' y \<circ> g'(h y) = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3158
  shows "f integrable_on T \<and> (integral T f) \<le> b \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3159
             (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3160
             integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3161
        (is "?lhs = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3162
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3163
  have Teq: "T = g`S" and Seq: "S = h`T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3164
    using hg gh image_iff by fastforce+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3165
  have gS: "g differentiable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3166
    by (meson der_g differentiable_def differentiable_on_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3167
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3168
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3169
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3170
    assume ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3171
    then have fT: "f integrable_on T" and intf: "integral T f \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3172
      by blast+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3173
    show ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3174
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3175
      let ?fgh = "\<lambda>x. \<bar>det (matrix (h' x))\<bar> * (\<bar>det (matrix (g' (h x)))\<bar> * f (g (h x)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3176
      have ddf: "?fgh x = f x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3177
        if "x \<in> T" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3178
      proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3179
        have "matrix (h' x) ** matrix (g' (h x)) = mat 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3180
          using that id matrix_compose
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3181
          by (metis der_g gh has_derivative_linear left_inverse_linear matrix_id_mat_1)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3182
        then have "\<bar>det (matrix (h' x))\<bar> * \<bar>det (matrix (g' (h x)))\<bar> = 1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3183
          by (metis abs_1 abs_mult det_I det_mul)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3184
        then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3185
          by (simp add: gh that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3186
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3187
      have "?D integrable_on (h ` T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3188
      proof (intro set_lebesgue_integral_eq_integral absolutely_integrable_on_image_real)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3189
        show "(\<lambda>x. ?fgh x) absolutely_integrable_on T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3190
        proof (subst absolutely_integrable_on_iff_nonneg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3191
          show "(\<lambda>x. ?fgh x) integrable_on T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3192
            using ddf fT integrable_eq by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3193
        qed (simp add: zero_le_mult_iff f0 gh)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3194
      qed (use der_h in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3195
      with Seq show "(\<lambda>x. ?D x) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3196
        by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3197
      have "integral S (\<lambda>x. ?D x) \<le> integral T (\<lambda>x. ?fgh x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3198
        unfolding Seq
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3199
      proof (rule integral_on_image_ubound)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3200
        show "(\<lambda>x. ?fgh x) integrable_on T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3201
        using ddf fT integrable_eq by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3202
      qed (use f0 gh der_h in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3203
      also have "\<dots> = integral T f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3204
        by (force simp: ddf intro: integral_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3205
      also have "\<dots> \<le> b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3206
        by (rule intf)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3207
      finally show "integral S (\<lambda>x. ?D x) \<le> b" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3208
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3209
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3210
    assume R: ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3211
    then have "f integrable_on g ` S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3212
      using der_g f0 hg integral_on_image_ubound_nonneg by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3213
    moreover have "integral (g ` S) f \<le> integral S (\<lambda>x. ?D x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3214
      by (rule integral_on_image_ubound [OF f0 der_g]) (use R Teq in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3215
    ultimately show ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3216
      using R by (simp add: Teq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3217
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3218
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3219
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3220
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3221
lemma cov_invertible_nonneg_eq:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3222
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real" and g :: "real^'n::_ \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3223
  assumes "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3224
      and "\<And>y. y \<in> T \<Longrightarrow> (h has_derivative h' y) (at y within T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3225
      and "\<And>y. y \<in> T \<Longrightarrow> 0 \<le> f y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3226
      and "\<And>x. x \<in> S \<Longrightarrow> g x \<in> T \<and> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3227
      and "\<And>y. y \<in> T \<Longrightarrow> h y \<in> S \<and> g(h y) = y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3228
      and "\<And>y. y \<in> T \<Longrightarrow> h' y \<circ> g'(h y) = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3229
  shows "((\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) has_integral b) S \<longleftrightarrow> (f has_integral b) T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3230
  using cov_invertible_nonneg_le [OF assms]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3231
  by (simp add: has_integral_iff) (meson eq_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3232
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3233
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3234
lemma cov_invertible_real:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3235
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real" and g :: "real^'n::_ \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3236
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3237
      and der_h: "\<And>y. y \<in> T \<Longrightarrow> (h has_derivative h' y) (at y within T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3238
      and hg: "\<And>x. x \<in> S \<Longrightarrow> g x \<in> T \<and> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3239
      and gh: "\<And>y. y \<in> T \<Longrightarrow> h y \<in> S \<and> g(h y) = y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3240
      and id: "\<And>y. y \<in> T \<Longrightarrow> h' y \<circ> g'(h y) = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3241
  shows "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3242
           integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)) = b \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3243
         f absolutely_integrable_on T \<and> integral T f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3244
         (is "?lhs = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3245
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3246
  have Teq: "T = g`S" and Seq: "S = h`T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3247
    using hg gh image_iff by fastforce+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3248
  let ?DP = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x)" and ?DN = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> * -f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3249
  have "+": "(?DP has_integral b) {x \<in> S. f (g x) > 0} \<longleftrightarrow> (f has_integral b) {y \<in> T. f y > 0}" for b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3250
  proof (rule cov_invertible_nonneg_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3251
    have *: "(\<lambda>x. f (g x)) -` Y \<inter> {x \<in> S. f (g x) > 0}
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3252
          = ((\<lambda>x. f (g x)) -` Y \<inter> S) \<inter> {x \<in> S. f (g x) > 0}" for Y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3253
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3254
    show "(g has_derivative g' x) (at x within {x \<in> S. f (g x) > 0})" if "x \<in> {x \<in> S. f (g x) > 0}" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3255
      using that der_g has_derivative_within_subset by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3256
    show "(h has_derivative h' y) (at y within {y \<in> T. f y > 0})" if "y \<in> {y \<in> T. f y > 0}" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3257
      using that der_h has_derivative_within_subset by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3258
  qed (use gh hg id in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3259
  have "-": "(?DN has_integral b) {x \<in> S. f (g x) < 0} \<longleftrightarrow> ((\<lambda>x. - f x) has_integral b) {y \<in> T. f y < 0}" for b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3260
  proof (rule cov_invertible_nonneg_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3261
    have *: "(\<lambda>x. - f (g x)) -` y \<inter> {x \<in> S. f (g x) < 0}
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3262
          = ((\<lambda>x. f (g x)) -` uminus ` y \<inter> S) \<inter> {x \<in> S. f (g x) < 0}" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3263
      using image_iff by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3264
    show "(g has_derivative g' x) (at x within {x \<in> S. f (g x) < 0})" if "x \<in> {x \<in> S. f (g x) < 0}" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3265
      using that der_g has_derivative_within_subset by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3266
    show "(h has_derivative h' y) (at y within {y \<in> T. f y < 0})" if "y \<in> {y \<in> T. f y < 0}" for y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3267
      using that der_h has_derivative_within_subset by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3268
  qed (use gh hg id in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3269
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3270
  proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3271
    assume LHS: ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3272
    have eq: "{x. (if x \<in> S then ?DP x else 0) > 0} = {x \<in> S. ?DP x > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3273
      "{x. (if x \<in> S then ?DP x else 0) < 0} = {x \<in> S. ?DP x < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3274
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3275
    have "?DP integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3276
      using LHS absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3277
    then have "(\<lambda>x. if x \<in> S then ?DP x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3278
      by (simp add: integrable_restrict_UNIV)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3279
    then have D_borel: "(\<lambda>x. if x \<in> S then ?DP x else 0) \<in> borel_measurable (lebesgue_on UNIV)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3280
      using integrable_imp_measurable borel_measurable_UNIV_eq by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3281
    then have SN: "{x \<in> S. ?DP x < 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3282
      unfolding borel_measurable_vimage_halfspace_component_lt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3283
      by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3284
    from D_borel have SP: "{x \<in> S. ?DP x > 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3285
      unfolding borel_measurable_vimage_halfspace_component_gt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3286
      by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3287
    have "?DP absolutely_integrable_on {x \<in> S. ?DP x > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3288
      using LHS by (fast intro!: set_integrable_subset [OF _, of _ S] SP)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3289
    then have aP: "?DP absolutely_integrable_on {x \<in> S. f (g x) > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3290
      by (rule absolutely_integrable_spike_set) (auto simp: zero_less_mult_iff empty_imp_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3291
    have "?DP absolutely_integrable_on {x \<in> S. ?DP x < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3292
      using LHS by (fast intro!: set_integrable_subset [OF _, of _ S] SN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3293
    then have aN: "?DP absolutely_integrable_on {x \<in> S. f (g x) < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3294
      by (rule absolutely_integrable_spike_set) (auto simp: mult_less_0_iff empty_imp_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3295
    have fN: "f integrable_on {y \<in> T. f y < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3296
             "integral {y \<in> T. f y < 0} f = integral {x \<in> S. f (g x) < 0} ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3297
      using "-" [of "integral {x \<in> S. f(g x) < 0} ?DN"] aN
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3298
      by (auto simp: set_lebesgue_integral_eq_integral has_integral_iff integrable_neg_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3299
    have faN: "f absolutely_integrable_on {y \<in> T. f y < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3300
      apply (rule absolutely_integrable_integrable_bound [where g = "\<lambda>x. - f x"])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3301
      using fN by (auto simp: integrable_neg_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3302
    have fP: "f integrable_on {y \<in> T. f y > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3303
             "integral {y \<in> T. f y > 0} f = integral {x \<in> S. f (g x) > 0} ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3304
      using "+" [of "integral {x \<in> S. f(g x) > 0} ?DP"] aP
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3305
      by (auto simp: set_lebesgue_integral_eq_integral has_integral_iff integrable_neg_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3306
    have faP: "f absolutely_integrable_on {y \<in> T. f y > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3307
      apply (rule absolutely_integrable_integrable_bound [where g = f])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3308
      using fP by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3309
    have fa: "f absolutely_integrable_on ({y \<in> T. f y < 0} \<union> {y \<in> T. f y > 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3310
      by (rule absolutely_integrable_Un [OF faN faP])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3311
    show ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3312
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3313
      have eq: "((if x \<in> T \<and> f x < 0 \<or> x \<in> T \<and> 0 < f x then 1 else 0) * f x)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3314
              = (if x \<in> T then 1 else 0) * f x" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3315
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3316
      show "f absolutely_integrable_on T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3317
        using fa by (simp add: indicator_def set_integrable_def eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3318
      have [simp]: "{y \<in> T. f y < 0} \<inter> {y \<in> T. 0 < f y} = {}" for T and f :: "(real^'n::_) \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3319
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3320
      have "integral T f = integral ({y \<in> T. f y < 0} \<union> {y \<in> T. f y > 0}) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3321
        by (intro empty_imp_negligible integral_spike_set) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3322
      also have "\<dots> = integral {y \<in> T. f y < 0} f + integral {y \<in> T. f y > 0} f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3323
        using fN fP by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3324
      also have "\<dots> = integral {x \<in> S. f (g x) < 0} ?DP + integral {x \<in> S. 0 < f (g x)} ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3325
        by (simp add: fN fP)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3326
      also have "\<dots> = integral ({x \<in> S. f (g x) < 0} \<union> {x \<in> S. 0 < f (g x)}) ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3327
        using aP aN by (simp add: set_lebesgue_integral_eq_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3328
      also have "\<dots> = integral S ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3329
        by (intro empty_imp_negligible integral_spike_set) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3330
      also have "\<dots> = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3331
        using LHS by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3332
      finally show "integral T f = b" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3333
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3334
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3335
    assume RHS: ?rhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3336
    have eq: "{x. (if x \<in> T then f x else 0) > 0} = {x \<in> T. f x > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3337
             "{x. (if x \<in> T then f x else 0) < 0} = {x \<in> T. f x < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3338
      by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3339
    have "f integrable_on T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3340
      using RHS absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3341
    then have "(\<lambda>x. if x \<in> T then f x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3342
      by (simp add: integrable_restrict_UNIV)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3343
    then have D_borel: "(\<lambda>x. if x \<in> T then f x else 0) \<in> borel_measurable (lebesgue_on UNIV)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3344
      using integrable_imp_measurable borel_measurable_UNIV_eq by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3345
    then have TN: "{x \<in> T. f x < 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3346
      unfolding borel_measurable_vimage_halfspace_component_lt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3347
      by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3348
    from D_borel have TP: "{x \<in> T. f x > 0} \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3349
      unfolding borel_measurable_vimage_halfspace_component_gt
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3350
      by (drule_tac x=0 in spec) (auto simp: eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3351
    have aint: "f absolutely_integrable_on {y. y \<in> T \<and> 0 < (f y)}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3352
               "f absolutely_integrable_on {y. y \<in> T \<and> (f y) < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3353
         and intT: "integral T f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3354
      using set_integrable_subset [of _ T] TP TN RHS
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3355
      by blast+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3356
    show ?lhs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3357
    proof
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3358
      have fN: "f integrable_on {v \<in> T. f v < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3359
        using absolutely_integrable_on_def aint by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3360
      then have DN: "(?DN has_integral integral {y \<in> T. f y < 0} (\<lambda>x. - f x)) {x \<in> S. f (g x) < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3361
        using "-" [of "integral {y \<in> T. f y < 0} (\<lambda>x. - f x)"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3362
        by (simp add: has_integral_neg_iff integrable_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3363
      have aDN: "?DP absolutely_integrable_on {x \<in> S. f (g x) < 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3364
        apply (rule absolutely_integrable_integrable_bound [where g = ?DN])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3365
        using DN hg by (fastforce simp: abs_mult integrable_neg_iff)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3366
      have fP: "f integrable_on {v \<in> T. f v > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3367
        using absolutely_integrable_on_def aint by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3368
      then have DP: "(?DP has_integral integral {y \<in> T. f y > 0} f) {x \<in> S. f (g x) > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3369
        using "+" [of "integral {y \<in> T. f y > 0} f"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3370
        by (simp add: has_integral_neg_iff integrable_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3371
      have aDP: "?DP absolutely_integrable_on {x \<in> S. f (g x) > 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3372
        apply (rule absolutely_integrable_integrable_bound [where g = ?DP])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3373
        using DP hg by (fastforce simp: integrable_neg_iff)+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3374
      have eq: "(if x \<in> S then 1 else 0) * ?DP x = (if x \<in> S \<and> f (g x) < 0 \<or> x \<in> S \<and> f (g x) > 0 then 1 else 0) * ?DP x" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3375
        by force
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3376
      have "?DP absolutely_integrable_on ({x \<in> S. f (g x) < 0} \<union> {x \<in> S. f (g x) > 0})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3377
        by (rule absolutely_integrable_Un [OF aDN aDP])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3378
      then show I: "?DP absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3379
        by (simp add: indicator_def eq set_integrable_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3380
      have [simp]: "{y \<in> S. f y < 0} \<inter> {y \<in> S. 0 < f y} = {}" for S and f :: "(real^'n::_) \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3381
        by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3382
      have "integral S ?DP = integral ({x \<in> S. f (g x) < 0} \<union> {x \<in> S. f (g x) > 0}) ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3383
        by (intro empty_imp_negligible integral_spike_set) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3384
      also have "\<dots> = integral {x \<in> S. f (g x) < 0} ?DP + integral {x \<in> S. 0 < f (g x)} ?DP"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3385
        using aDN aDP by (simp add: set_lebesgue_integral_eq_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3386
      also have "\<dots> = - integral {y \<in> T. f y < 0} (\<lambda>x. - f x) + integral {y \<in> T. f y > 0} f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3387
        using DN DP by (auto simp: has_integral_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3388
      also have "\<dots> = integral ({x \<in> T. f x < 0} \<union> {x \<in> T. 0 < f x}) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3389
        by (simp add: fN fP)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3390
      also have "\<dots> = integral T f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3391
        by (intro empty_imp_negligible integral_spike_set) auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3392
      also have "\<dots> = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3393
        using intT by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3394
      finally show "integral S ?DP = b" .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3395
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3396
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3397
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3398
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3399
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3400
lemma cv_inv_version3:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3401
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3402
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3403
    and der_h: "\<And>y. y \<in> T \<Longrightarrow> (h has_derivative h' y) (at y within T)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3404
    and hg: "\<And>x. x \<in> S \<Longrightarrow> g x \<in> T \<and> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3405
    and gh: "\<And>y. y \<in> T \<Longrightarrow> h y \<in> S \<and> g(h y) = y"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3406
    and id: "\<And>y. y \<in> T \<Longrightarrow> h' y \<circ> g'(h y) = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3407
  shows "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3408
             integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3409
         \<longleftrightarrow> f absolutely_integrable_on T \<and> integral T f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3410
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3411
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3412
  have "((\<lambda>x. \<bar>det (matrix (g' x))\<bar> * f(g x) $ i) absolutely_integrable_on S \<and> integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> * (f(g x) $ i)) = b $ i) \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3413
        ((\<lambda>x. f x $ i) absolutely_integrable_on T \<and> integral T (\<lambda>x. f x $ i) = b $ i)" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3414
    by (rule cov_invertible_real [OF der_g der_h hg gh id])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3415
  then have "?D absolutely_integrable_on S \<and> (?D has_integral b) S \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3416
        f absolutely_integrable_on T \<and> (f has_integral b) T"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3417
    unfolding absolutely_integrable_componentwise_iff [where f=f] has_integral_componentwise_iff [of f]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3418
              absolutely_integrable_componentwise_iff [where f="?D"] has_integral_componentwise_iff [of ?D]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3419
    by (auto simp: all_conj_distrib Basis_vec_def cart_eq_inner_axis [symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3420
           has_integral_iff set_lebesgue_integral_eq_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3421
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3422
    using absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3423
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3424
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3425
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3426
lemma cv_inv_version4:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3427
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3428
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S) \<and> invertible(matrix(g' x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3429
    and hg: "\<And>x. x \<in> S \<Longrightarrow> continuous_on (g ` S) h \<and> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3430
  shows "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3431
             integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3432
         \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3433
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3434
  have "\<forall>x. \<exists>h'. x \<in> S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3435
           \<longrightarrow> (g has_derivative g' x) (at x within S) \<and> linear h' \<and> g' x \<circ> h' = id \<and> h' \<circ> g' x = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3436
    using der_g matrix_invertible has_derivative_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3437
  then obtain h' where h':
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3438
    "\<And>x. x \<in> S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3439
           \<Longrightarrow> (g has_derivative g' x) (at x within S) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3440
               linear (h' x) \<and> g' x \<circ> (h' x) = id \<and> (h' x) \<circ> g' x = id"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3441
    by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3442
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3443
  proof (rule cv_inv_version3)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3444
    show "\<And>y. y \<in> g ` S \<Longrightarrow> (h has_derivative h' (h y)) (at y within g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3445
      using h' hg
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3446
      by (force simp: continuous_on_eq_continuous_within intro!: has_derivative_inverse_within)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3447
  qed (use h' hg in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3448
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3449
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3450
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3451
proposition has_absolute_integral_change_of_variables_invertible:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3452
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3453
  assumes der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3454
      and hg: "\<And>x. x \<in> S \<Longrightarrow> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3455
      and conth: "continuous_on (g ` S) h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3456
  shows "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and> integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3457
         f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3458
    (is "?lhs = ?rhs")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3459
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3460
  let ?S = "{x \<in> S. invertible (matrix (g' x))}" and ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3461
  have *: "?D absolutely_integrable_on ?S \<and> integral ?S ?D = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3462
           \<longleftrightarrow> f absolutely_integrable_on (g ` ?S) \<and> integral (g ` ?S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3463
  proof (rule cv_inv_version4)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3464
    show "(g has_derivative g' x) (at x within ?S) \<and> invertible (matrix (g' x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3465
      if "x \<in> ?S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3466
      using der_g that has_derivative_within_subset that by fastforce
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3467
    show "continuous_on (g ` ?S) h \<and> h (g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3468
      if "x \<in> ?S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3469
      using that continuous_on_subset [OF conth]  by (simp add: hg image_mono)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3470
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3471
  have "(g has_derivative g' x) (at x within {x \<in> S. rank (matrix (g' x)) < CARD('m)})" if "x \<in> S" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3472
    by (metis (no_types, lifting) der_g has_derivative_within_subset mem_Collect_eq subsetI that)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3473
  then have "negligible (g ` {x \<in> S. \<not> invertible (matrix (g' x))})"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3474
    by (auto simp: invertible_det_nz det_eq_0_rank intro: baby_Sard)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3475
  then have neg: "negligible {x \<in> g ` S. x \<notin> g ` ?S \<and> f x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3476
    by (auto intro: negligible_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3477
  have [simp]: "{x \<in> g ` ?S. x \<notin> g ` S \<and> f x \<noteq> 0} = {}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3478
    by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3479
  have "?D absolutely_integrable_on ?S \<and> integral ?S ?D = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3480
    \<longleftrightarrow> ?D absolutely_integrable_on S \<and> integral S ?D = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3481
    apply (intro conj_cong absolutely_integrable_spike_set_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3482
      apply(auto simp: integral_spike_set invertible_det_nz empty_imp_negligible neg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3483
    done
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3484
  moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3485
  have "f absolutely_integrable_on (g ` ?S) \<and> integral (g ` ?S) f = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3486
    \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3487
    by (auto intro!: conj_cong absolutely_integrable_spike_set_eq integral_spike_set neg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3488
  ultimately
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3489
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3490
    using "*" by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3491
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3492
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3493
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3494
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3495
lemma has_absolute_integral_change_of_variables_compact:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3496
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3497
  assumes "compact S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3498
      and der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3499
      and inj: "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3500
  shows "((\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3501
             integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3502
      \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3503
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3504
  obtain h where hg: "\<And>x. x \<in> S \<Longrightarrow> h(g x) = x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3505
    using inj by (metis the_inv_into_f_f)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3506
  have conth: "continuous_on (g ` S) h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3507
    by (metis \<open>compact S\<close> continuous_on_inv der_g has_derivative_continuous_on hg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3508
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3509
    by (rule has_absolute_integral_change_of_variables_invertible [OF der_g hg conth])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3510
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3511
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3512
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3513
lemma has_absolute_integral_change_of_variables_compact_family:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3514
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3515
  assumes compact: "\<And>n::nat. compact (F n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3516
      and der_g: "\<And>x. x \<in> (\<Union>n. F n) \<Longrightarrow> (g has_derivative g' x) (at x within (\<Union>n. F n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3517
      and inj: "inj_on g (\<Union>n. F n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3518
  shows "((\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on (\<Union>n. F n) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3519
             integral (\<Union>n. F n) (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3520
      \<longleftrightarrow> f absolutely_integrable_on (g ` (\<Union>n. F n)) \<and> integral (g ` (\<Union>n. F n)) f = b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3521
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3522
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3523
  let ?U = "\<lambda>n. \<Union>m\<le>n. F m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3524
  let ?lift = "vec::real\<Rightarrow>real^1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3525
  have F_leb: "F m \<in> sets lebesgue" for m
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3526
    by (simp add: compact borel_compact)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3527
  have iff: "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f (g x)) absolutely_integrable_on (?U n) \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3528
             integral (?U n) (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f (g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3529
         \<longleftrightarrow> f absolutely_integrable_on (g ` (?U n)) \<and> integral (g ` (?U n)) f = b" for n b and f :: "real^'m::_ \<Rightarrow> real^'k"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3530
  proof (rule has_absolute_integral_change_of_variables_compact)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3531
    show "compact (?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3532
      by (simp add: compact compact_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3533
    show "(g has_derivative g' x) (at x within (?U n))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3534
      if "x \<in> ?U n" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3535
      using that by (blast intro!: has_derivative_within_subset [OF der_g])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3536
    show "inj_on g (?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3537
      using inj by (auto simp: inj_on_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3538
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3539
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3540
    unfolding image_UN
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3541
  proof safe
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3542
    assume DS: "?D absolutely_integrable_on (\<Union>n. F n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3543
      and b: "b = integral (\<Union>n. F n) ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3544
    have DU: "\<And>n. ?D absolutely_integrable_on (?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3545
             "(\<lambda>n. integral (?U n) ?D) \<longlonglongrightarrow> integral (\<Union>n. F n) ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3546
      using integral_countable_UN [OF DS F_leb] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3547
    with iff have fag: "f absolutely_integrable_on g ` (?U n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3548
      and fg_int: "integral (\<Union>m\<le>n. g ` F m) f = integral (?U n) ?D" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3549
      by (auto simp: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3550
    let ?h = "\<lambda>x. if x \<in> (\<Union>m. g ` F m) then norm(f x) else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3551
    have "(\<lambda>x. if x \<in> (\<Union>m. g ` F m) then f x else 0) absolutely_integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3552
    proof (rule dominated_convergence_absolutely_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3553
      show "(\<lambda>x. if x \<in> (\<Union>m\<le>k. g ` F m) then f x else 0) absolutely_integrable_on UNIV" for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3554
        unfolding absolutely_integrable_restrict_UNIV
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3555
        using fag by (simp add: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3556
      let ?nf = "\<lambda>n x. if x \<in> (\<Union>m\<le>n. g ` F m) then norm(f x) else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3557
      show "?h integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3558
      proof (rule monotone_convergence_increasing [THEN conjunct1])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3559
        show "?nf k integrable_on UNIV" for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3560
          using fag
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3561
          unfolding integrable_restrict_UNIV absolutely_integrable_on_def by (simp add: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3562
        { fix n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3563
          have "(norm \<circ> ?D) absolutely_integrable_on ?U n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3564
            by (intro absolutely_integrable_norm DU)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3565
          then have "integral (g ` ?U n) (norm \<circ> f) = integral (?U n) (norm \<circ> ?D)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3566
            using iff [of n "vec \<circ> norm \<circ> f" "integral (?U n) (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R (?lift \<circ> norm \<circ> f) (g x))"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3567
            unfolding absolutely_integrable_on_1_iff integral_on_1_eq by (auto simp: o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3568
        }
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3569
        moreover have "bounded (range (\<lambda>k. integral (?U k) (norm \<circ> ?D)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3570
          unfolding bounded_iff
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3571
        proof (rule exI, clarify)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3572
          fix k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3573
          show "norm (integral (?U k) (norm \<circ> ?D)) \<le> integral (\<Union>n. F n) (norm \<circ> ?D)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3574
            unfolding integral_restrict_UNIV [of _ "norm \<circ> ?D", symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3575
          proof (rule integral_norm_bound_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3576
            show "(\<lambda>x. if x \<in> UNION {..k} F then (norm \<circ> ?D) x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3577
              "(\<lambda>x. if x \<in> (\<Union>n. F n) then (norm \<circ> ?D) x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3578
              using DU(1) DS
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3579
              unfolding absolutely_integrable_on_def o_def integrable_restrict_UNIV by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3580
          qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3581
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3582
        ultimately show "bounded (range (\<lambda>k. integral UNIV (?nf k)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3583
          by (simp add: integral_restrict_UNIV image_UN [symmetric] o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3584
      next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3585
        show "(\<lambda>k. if x \<in> (\<Union>m\<le>k. g ` F m) then norm (f x) else 0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3586
              \<longlonglongrightarrow> (if x \<in> (\<Union>m. g ` F m) then norm (f x) else 0)" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3587
          by (force intro: Lim_eventually eventually_sequentiallyI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3588
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3589
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3590
      show "(\<lambda>k. if x \<in> (\<Union>m\<le>k. g ` F m) then f x else 0)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3591
            \<longlonglongrightarrow> (if x \<in> (\<Union>m. g ` F m) then f x else 0)" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3592
      proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3593
        fix m y
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3594
        assume "y \<in> F m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3595
        show "(\<lambda>k. if \<exists>x\<in>{..k}. g y \<in> g ` F x then f (g y) else 0) \<longlonglongrightarrow> f (g y)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3596
          using \<open>y \<in> F m\<close> by (force intro: Lim_eventually eventually_sequentiallyI [of m])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3597
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3598
    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3599
    then show fai: "f absolutely_integrable_on (\<Union>m. g ` F m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3600
      using absolutely_integrable_restrict_UNIV by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3601
    show "integral ((\<Union>x. g ` F x)) f = integral (\<Union>n. F n) ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3602
    proof (rule LIMSEQ_unique)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3603
      show "(\<lambda>n. integral (?U n) ?D) \<longlonglongrightarrow> integral (\<Union>x. g ` F x) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3604
        unfolding fg_int [symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3605
      proof (rule integral_countable_UN [OF fai])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3606
        show "g ` F m \<in> sets lebesgue" for m
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3607
        proof (rule differentiable_image_in_sets_lebesgue [OF F_leb])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3608
          show "g differentiable_on F m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3609
            by (meson der_g differentiableI UnionI differentiable_on_def differentiable_on_subset rangeI subsetI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3610
        qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3611
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3612
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3613
      show "(\<lambda>n. integral (?U n) ?D) \<longlonglongrightarrow> integral (\<Union>n. F n) ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3614
        by (rule DU)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3615
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3616
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3617
    assume fs: "f absolutely_integrable_on (\<Union>x. g ` F x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3618
      and b: "b = integral ((\<Union>x. g ` F x)) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3619
    have gF_leb: "g ` F m \<in> sets lebesgue" for m
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3620
    proof (rule differentiable_image_in_sets_lebesgue [OF F_leb])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3621
      show "g differentiable_on F m"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3622
        using der_g unfolding differentiable_def differentiable_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3623
        by (meson Sup_upper UNIV_I UnionI has_derivative_within_subset image_eqI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3624
    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3625
    have fgU: "\<And>n. f absolutely_integrable_on (\<Union>m\<le>n. g ` F m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3626
      "(\<lambda>n. integral (\<Union>m\<le>n. g ` F m) f) \<longlonglongrightarrow> integral (\<Union>m. g ` F m) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3627
      using integral_countable_UN [OF fs gF_leb] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3628
    with iff have DUn: "?D absolutely_integrable_on ?U n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3629
      and D_int: "integral (?U n) ?D = integral (\<Union>m\<le>n. g ` F m) f" for n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3630
      by (auto simp: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3631
    let ?h = "\<lambda>x. if x \<in> (\<Union>n. F n) then norm(?D x) else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3632
    have "(\<lambda>x. if x \<in> (\<Union>n. F n) then ?D x else 0) absolutely_integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3633
    proof (rule dominated_convergence_absolutely_integrable)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3634
      show "(\<lambda>x. if x \<in> ?U k then ?D x else 0) absolutely_integrable_on UNIV" for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3635
        unfolding absolutely_integrable_restrict_UNIV using DUn by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3636
      let ?nD = "\<lambda>n x. if x \<in> ?U n then norm(?D x) else 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3637
      show "?h integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3638
      proof (rule monotone_convergence_increasing [THEN conjunct1])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3639
        show "?nD k integrable_on UNIV" for k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3640
          using DUn
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3641
          unfolding integrable_restrict_UNIV absolutely_integrable_on_def by (simp add: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3642
        { fix n::nat
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3643
          have "(norm \<circ> f) absolutely_integrable_on (\<Union>m\<le>n. g ` F m)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3644
            apply (rule absolutely_integrable_norm)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3645
            using fgU by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3646
          then have "integral (?U n) (norm \<circ> ?D) = integral (g ` ?U n) (norm \<circ> f)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3647
            using iff [of n "?lift \<circ> norm \<circ> f" "integral (g ` ?U n) (?lift \<circ> norm \<circ> f)"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3648
            unfolding absolutely_integrable_on_1_iff integral_on_1_eq image_UN by (auto simp: o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3649
        }
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3650
        moreover have "bounded (range (\<lambda>k. integral (g ` ?U k) (norm \<circ> f)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3651
          unfolding bounded_iff
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3652
        proof (rule exI, clarify)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3653
          fix k
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3654
          show "norm (integral (g ` ?U k) (norm \<circ> f)) \<le> integral (g ` (\<Union>n. F n)) (norm \<circ> f)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3655
            unfolding integral_restrict_UNIV [of _ "norm \<circ> f", symmetric]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3656
          proof (rule integral_norm_bound_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3657
            show "(\<lambda>x. if x \<in> g ` ?U k then (norm \<circ> f) x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3658
                 "(\<lambda>x. if x \<in> g ` (\<Union>n. F n) then (norm \<circ> f) x else 0) integrable_on UNIV"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3659
              using fgU fs
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3660
              unfolding absolutely_integrable_on_def o_def integrable_restrict_UNIV
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3661
              by (auto simp: image_UN)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3662
          qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3663
        qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3664
        ultimately show "bounded (range (\<lambda>k. integral UNIV (?nD k)))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3665
          unfolding integral_restrict_UNIV image_UN [symmetric] o_def by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3666
      next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3667
        show "(\<lambda>k. if x \<in> ?U k then norm (?D x) else 0) \<longlonglongrightarrow> (if x \<in> (\<Union>n. F n) then norm (?D x) else 0)" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3668
          by (force intro: Lim_eventually eventually_sequentiallyI)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3669
      qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3670
    next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3671
      show "(\<lambda>k. if x \<in> ?U k then ?D x else 0) \<longlonglongrightarrow> (if x \<in> (\<Union>n. F n) then ?D x else 0)" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3672
      proof clarsimp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3673
        fix n
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3674
        assume "x \<in> F n"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3675
        show "(\<lambda>m. if \<exists>j\<in>{..m}. x \<in> F j then ?D x else 0) \<longlonglongrightarrow> ?D x"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3676
          using \<open>x \<in> F n\<close> by (auto intro!: Lim_eventually eventually_sequentiallyI [of n])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3677
      qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3678
    qed auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3679
    then show Dai: "?D absolutely_integrable_on (\<Union>n. F n)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3680
      unfolding absolutely_integrable_restrict_UNIV by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3681
    show "integral (\<Union>n. F n) ?D = integral ((\<Union>x. g ` F x)) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3682
    proof (rule LIMSEQ_unique)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3683
      show "(\<lambda>n. integral (\<Union>m\<le>n. g ` F m) f) \<longlonglongrightarrow> integral (\<Union>x. g ` F x) f"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3684
        by (rule fgU)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3685
      show "(\<lambda>n. integral (\<Union>m\<le>n. g ` F m) f) \<longlonglongrightarrow> integral (\<Union>n. F n) ?D"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3686
        unfolding D_int [symmetric] by (rule integral_countable_UN [OF Dai F_leb])
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3687
    qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3688
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3689
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3690
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3691
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3692
proposition has_absolute_integral_change_of_variables:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3693
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3694
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3695
    and der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3696
    and inj: "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3697
  shows "(\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3698
           integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3699
     \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3700
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3701
  obtain C N where "fsigma C" "negligible N" and CNS: "C \<union> N = S" and "disjnt C N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3702
    using lebesgue_set_almost_fsigma [OF S] .
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3703
  then obtain F :: "nat \<Rightarrow> (real^'m::_) set"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3704
    where F: "range F \<subseteq> Collect compact" and Ceq: "C = Union(range F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3705
    using fsigma_Union_compact by metis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3706
  let ?D = "\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f (g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3707
  have "?D absolutely_integrable_on C \<and> integral C ?D = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3708
    \<longleftrightarrow> f absolutely_integrable_on (g ` C) \<and> integral (g ` C) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3709
    unfolding Ceq
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3710
  proof (rule has_absolute_integral_change_of_variables_compact_family)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3711
    fix n x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3712
    assume "x \<in> UNION UNIV F"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3713
    then show "(g has_derivative g' x) (at x within UNION UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3714
      using Ceq \<open>C \<union> N = S\<close> der_g has_derivative_within_subset by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3715
  next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3716
    have "UNION UNIV F \<subseteq> S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3717
      using Ceq \<open>C \<union> N = S\<close> by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3718
    then show "inj_on g (UNION UNIV F)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3719
      using inj by (meson inj_on_subset)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3720
  qed (use F in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3721
  moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3722
  have "?D absolutely_integrable_on C \<and> integral C ?D = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3723
    \<longleftrightarrow> ?D absolutely_integrable_on S \<and> integral S ?D = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3724
  proof (rule conj_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3725
    have neg: "negligible {x \<in> C - S. ?D x \<noteq> 0}" "negligible {x \<in> S - C. ?D x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3726
      using CNS by (blast intro: negligible_subset [OF \<open>negligible N\<close>])+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3727
    then show "(?D absolutely_integrable_on C) = (?D absolutely_integrable_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3728
      by (rule absolutely_integrable_spike_set_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3729
    show "(integral C ?D = b) \<longleftrightarrow> (integral S ?D = b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3730
      using integral_spike_set [OF neg] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3731
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3732
  moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3733
  have "f absolutely_integrable_on (g ` C) \<and> integral (g ` C) f = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3734
    \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3735
  proof (rule conj_cong)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3736
    have "g differentiable_on N"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3737
      by (metis CNS der_g differentiable_def differentiable_on_def differentiable_on_subset sup.cobounded2)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3738
    with \<open>negligible N\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3739
    have neg_gN: "negligible (g ` N)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3740
      by (blast intro: negligible_differentiable_image_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3741
    have neg: "negligible {x \<in> g ` C - g ` S. f x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3742
              "negligible {x \<in> g ` S - g ` C. f x \<noteq> 0}"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3743
      using CNS by (blast intro: negligible_subset [OF neg_gN])+
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3744
    then show "(f absolutely_integrable_on g ` C) = (f absolutely_integrable_on g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3745
      by (rule absolutely_integrable_spike_set_eq)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3746
    show "(integral (g ` C) f = b) \<longleftrightarrow> (integral (g ` S) f = b)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3747
      using integral_spike_set [OF neg] by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3748
  qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3749
  ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3750
    by simp
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3751
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3752
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3753
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3754
corollary absolutely_integrable_change_of_variables:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3755
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3756
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3757
    and "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3758
    and "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3759
  shows "f absolutely_integrable_on (g ` S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3760
     \<longleftrightarrow> (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3761
  using assms has_absolute_integral_change_of_variables by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3762
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3763
corollary integral_change_of_variables:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3764
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3765
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3766
    and der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3767
    and inj: "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3768
    and disj: "(f absolutely_integrable_on (g ` S) \<or>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3769
        (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3770
  shows "integral (g ` S) f = integral S (\<lambda>x. \<bar>det (matrix (g' x))\<bar> *\<^sub>R f(g x))"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3771
  using has_absolute_integral_change_of_variables [OF S der_g inj] disj
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3772
  by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3773
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3774
lemma has_absolute_integral_change_of_variables_1:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3775
  fixes f :: "real \<Rightarrow> real^'n::{finite,wellorder}" and g :: "real \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3776
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3777
    and der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_vector_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3778
    and inj: "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3779
  shows "(\<lambda>x. \<bar>g' x\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3780
           integral S (\<lambda>x. \<bar>g' x\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3781
     \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3782
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3783
  let ?lift = "vec :: real \<Rightarrow> real^1"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3784
  let ?drop = "(\<lambda>x::real^1. x $ 1)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3785
  have S': "?lift ` S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3786
    by (auto intro: differentiable_image_in_sets_lebesgue [OF S] differentiable_vec)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3787
  have "((\<lambda>x. vec (g (x $ 1))) has_derivative ( *\<^sub>R) (g' z)) (at (vec z) within ?lift ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3788
    if "z \<in> S" for z
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3789
    using der_g [OF that]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3790
    by (simp add: has_vector_derivative_def has_derivative_vector_1)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3791
  then have der': "\<And>x. x \<in> ?lift ` S \<Longrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3792
        (?lift \<circ> g \<circ> ?drop has_derivative ( *\<^sub>R) (g' (?drop x))) (at x within ?lift ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3793
    by (auto simp: o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3794
  have inj': "inj_on (vec \<circ> g \<circ> ?drop) (vec ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3795
    using inj by (simp add: inj_on_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3796
  let ?fg = "\<lambda>x. \<bar>g' x\<bar> *\<^sub>R f(g x)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3797
  have "((\<lambda>x. ?fg x $ i) absolutely_integrable_on S \<and> ((\<lambda>x. ?fg x $ i) has_integral b $ i) S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3798
    \<longleftrightarrow> (\<lambda>x. f x $ i) absolutely_integrable_on g ` S \<and> ((\<lambda>x. f x $ i) has_integral b $ i) (g ` S))" for i
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3799
    using has_absolute_integral_change_of_variables [OF S' der' inj', of "\<lambda>x. ?lift(f (?drop x) $ i)" "?lift (b$i)"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3800
    unfolding integrable_on_1_iff integral_on_1_eq absolutely_integrable_on_1_iff absolutely_integrable_drop absolutely_integrable_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3801
    by (auto simp: image_comp o_def integral_vec1_eq has_integral_iff)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3802
  then have "?fg absolutely_integrable_on S \<and> (?fg has_integral b) S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3803
         \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> (f has_integral b) (g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3804
    unfolding has_integral_componentwise_iff [where y=b]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3805
           absolutely_integrable_componentwise_iff [where f=f]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3806
           absolutely_integrable_componentwise_iff [where f = ?fg]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3807
    by (force simp: Basis_vec_def cart_eq_inner_axis)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3808
  then show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3809
    using absolutely_integrable_on_def by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3810
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3811
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3812
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3813
corollary absolutely_integrable_change_of_variables_1:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3814
  fixes f :: "real \<Rightarrow> real^'n::{finite,wellorder}" and g :: "real \<Rightarrow> real"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3815
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3816
    and der_g: "\<And>x. x \<in> S \<Longrightarrow> (g has_vector_derivative g' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3817
    and inj: "inj_on g S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3818
  shows "(f absolutely_integrable_on g ` S \<longleftrightarrow>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3819
             (\<lambda>x. \<bar>g' x\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3820
  using has_absolute_integral_change_of_variables_1 [OF assms] by auto
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3821
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3822
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3823
subsection\<open>Change of variables for integrals: special case of linear function\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3824
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3825
lemma has_absolute_integral_change_of_variables_linear:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3826
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3827
  assumes "linear g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3828
  shows "(\<lambda>x. \<bar>det (matrix g)\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S \<and>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3829
           integral S (\<lambda>x. \<bar>det (matrix g)\<bar> *\<^sub>R f(g x)) = b
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3830
     \<longleftrightarrow> f absolutely_integrable_on (g ` S) \<and> integral (g ` S) f = b"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3831
proof (cases "det(matrix g) = 0")
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3832
  case True
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3833
  then have "negligible(g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3834
    using assms det_nz_iff_inj negligible_linear_singular_image by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3835
  with True show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3836
    by (auto simp: absolutely_integrable_on_def integrable_negligible integral_negligible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3837
next
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3838
  case False
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3839
  then obtain h where h: "\<And>x. x \<in> S \<Longrightarrow> h (g x) = x" "linear h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3840
    using assms det_nz_iff_inj linear_injective_isomorphism by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3841
  show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3842
  proof (rule has_absolute_integral_change_of_variables_invertible)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3843
    show "(g has_derivative g) (at x within S)" for x
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3844
      by (simp add: assms linear_imp_has_derivative)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3845
    show "continuous_on (g ` S) h"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3846
      using continuous_on_eq_continuous_within has_derivative_continuous linear_imp_has_derivative h by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3847
  qed (use h in auto)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3848
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3849
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3850
lemma absolutely_integrable_change_of_variables_linear:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3851
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3852
  assumes "linear g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3853
  shows "(\<lambda>x. \<bar>det (matrix g)\<bar> *\<^sub>R f(g x)) absolutely_integrable_on S
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3854
     \<longleftrightarrow> f absolutely_integrable_on (g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3855
  using assms has_absolute_integral_change_of_variables_linear by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3856
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3857
lemma absolutely_integrable_on_linear_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3858
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3859
  assumes "linear g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3860
  shows "f absolutely_integrable_on (g ` S)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3861
     \<longleftrightarrow> (f \<circ> g) absolutely_integrable_on S \<or> det(matrix g) = 0"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3862
  unfolding assms absolutely_integrable_change_of_variables_linear [OF assms, symmetric] absolutely_integrable_on_scaleR_iff
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3863
  by (auto simp: set_integrable_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3864
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3865
lemma integral_change_of_variables_linear:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3866
  fixes f :: "real^'m::{finite,wellorder} \<Rightarrow> real^'n" and g :: "real^'m::_ \<Rightarrow> real^'m::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3867
  assumes "linear g"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3868
      and "f absolutely_integrable_on (g ` S) \<or> (f \<circ> g) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3869
    shows "integral (g ` S) f = \<bar>det (matrix g)\<bar> *\<^sub>R integral S (f \<circ> g)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3870
proof -
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3871
  have "((\<lambda>x. \<bar>det (matrix g)\<bar> *\<^sub>R f (g x)) absolutely_integrable_on S) \<or> (f absolutely_integrable_on g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3872
    using absolutely_integrable_on_linear_image assms by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3873
  moreover
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3874
  have ?thesis if "((\<lambda>x. \<bar>det (matrix g)\<bar> *\<^sub>R f (g x)) absolutely_integrable_on S)" "(f absolutely_integrable_on g ` S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3875
    using has_absolute_integral_change_of_variables_linear [OF \<open>linear g\<close>] that
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3876
    by (auto simp: o_def)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3877
  ultimately show ?thesis
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3878
    using absolutely_integrable_change_of_variables_linear [OF \<open>linear g\<close>]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3879
    by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3880
qed
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3881
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3882
subsection\<open>Change of variable for measure\<close>
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3883
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3884
lemma has_measure_differentiable_image:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3885
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3886
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3887
      and "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3888
      and "inj_on f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3889
  shows "f ` S \<in> lmeasurable \<and> measure lebesgue (f ` S) = m
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3890
     \<longleftrightarrow> ((\<lambda>x. \<bar>det (matrix (f' x))\<bar>) has_integral m) S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3891
  using has_absolute_integral_change_of_variables [OF assms, of "\<lambda>x. (1::real^1)" "vec m"]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3892
  unfolding absolutely_integrable_on_1_iff integral_on_1_eq integrable_on_1_iff absolutely_integrable_on_def
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3893
  by (auto simp: has_integral_iff lmeasurable_iff_integrable_on lmeasure_integral)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3894
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3895
lemma measurable_differentiable_image_eq:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3896
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3897
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3898
      and "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3899
      and "inj_on f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3900
  shows "f ` S \<in> lmeasurable \<longleftrightarrow> (\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3901
  using has_measure_differentiable_image [OF assms]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3902
  by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3903
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3904
lemma measurable_differentiable_image_alt:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3905
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3906
  assumes "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3907
    and "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3908
    and "inj_on f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3909
  shows "f ` S \<in> lmeasurable \<longleftrightarrow> (\<lambda>x. \<bar>det (matrix (f' x))\<bar>) absolutely_integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3910
  using measurable_differentiable_image_eq [OF assms]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3911
  by (simp only: absolutely_integrable_on_iff_nonneg)
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3912
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3913
lemma measure_differentiable_image_eq:
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3914
  fixes f :: "real^'n::{finite,wellorder} \<Rightarrow> real^'n::_"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3915
  assumes S: "S \<in> sets lebesgue"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3916
    and der_f: "\<And>x. x \<in> S \<Longrightarrow> (f has_derivative f' x) (at x within S)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3917
    and inj: "inj_on f S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3918
    and intS: "(\<lambda>x. \<bar>det (matrix (f' x))\<bar>) integrable_on S"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3919
  shows "measure lebesgue (f ` S) = integral S (\<lambda>x. \<bar>det (matrix (f' x))\<bar>)"
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3920
  using measurable_differentiable_image_eq [OF S der_f inj]
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3921
        assms has_measure_differentiable_image by blast
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3922
73a5a33486ee Change of variables proof
paulson <lp15@cam.ac.uk>
parents:
diff changeset
  3923
end