@@ -5,6 +5,7 @@ Authors: Zhouhang Zhou
5
5
-/
6
6
import algebra.quadratic_discriminant
7
7
import analysis.special_functions.pow
8
+ import tactic.apply_fun
8
9
import tactic.monotonicity
9
10
10
11
@@ -193,6 +194,59 @@ lemma parallelogram_law_with_norm {x y : α} :
193
194
∥x + y∥ * ∥x + y∥ + ∥x - y∥ * ∥x - y∥ = 2 * (∥x∥ * ∥x∥ + ∥y∥ * ∥y∥) :=
194
195
by { simp only [(inner_self_eq_norm_square _).symm], exact parallelogram_law }
195
196
197
+ /-- The inner product, in terms of the norm. -/
198
+ lemma inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : α) :
199
+ inner x y = (∥x + y∥ * ∥x + y∥ - ∥x∥ * ∥x∥ - ∥y∥ * ∥y∥) / 2 :=
200
+ begin
201
+ rw norm_add_mul_self,
202
+ ring
203
+ end
204
+
205
+ /-- The inner product, in terms of the norm. -/
206
+ lemma inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : α) :
207
+ inner x y = (∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ - ∥x - y∥ * ∥x - y∥) / 2 :=
208
+ begin
209
+ rw norm_sub_mul_self,
210
+ ring
211
+ end
212
+
213
+ /-- The inner product, in terms of the norm. -/
214
+ lemma inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : α) :
215
+ inner x y = (∥x + y∥ * ∥x + y∥ - ∥x - y∥ * ∥x - y∥) / 4 :=
216
+ begin
217
+ rw [norm_add_mul_self, norm_sub_mul_self],
218
+ ring
219
+ end
220
+
221
+ /-- Pythagorean theorem, if-and-only-if vector inner product form. -/
222
+ lemma norm_add_square_eq_norm_square_add_norm_square_iff_inner_eq_zero (x y : α) :
223
+ ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ inner x y = 0 :=
224
+ begin
225
+ rw [norm_add_mul_self, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],
226
+ norm_num
227
+ end
228
+
229
+ /-- Pythagorean theorem, vector inner product form. -/
230
+ lemma norm_add_square_eq_norm_square_add_norm_square {x y : α} (h : inner x y = 0 ) :
231
+ ∥x + y∥ * ∥x + y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=
232
+ (norm_add_square_eq_norm_square_add_norm_square_iff_inner_eq_zero x y).2 h
233
+
234
+ /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
235
+ inner product form. -/
236
+ lemma norm_sub_square_eq_norm_square_add_norm_square_iff_inner_eq_zero (x y : α) :
237
+ ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ ↔ inner x y = 0 :=
238
+ begin
239
+ rw [norm_sub_mul_self, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,
240
+ mul_eq_zero],
241
+ norm_num
242
+ end
243
+
244
+ /-- Pythagorean theorem, subtracting vectors, vector inner product
245
+ form. -/
246
+ lemma norm_sub_square_eq_norm_square_add_norm_square {x y : α} (h : inner x y = 0 ) :
247
+ ∥x - y∥ * ∥x - y∥ = ∥x∥ * ∥x∥ + ∥y∥ * ∥y∥ :=
248
+ (norm_sub_square_eq_norm_square_add_norm_square_iff_inner_eq_zero x y).2 h
249
+
196
250
/-- An inner product space forms a normed group w.r.t. its associated norm. -/
197
251
@[priority 100 ] -- see Note [lower instance priority]
198
252
instance inner_product_space_is_normed_group : normed_group α :=
@@ -225,6 +279,165 @@ instance inner_product_space_is_normed_space : normed_space ℝ α :=
225
279
exact mul_nonneg (abs_nonneg _) (sqrt_nonneg _)
226
280
end }
227
281
282
+ /-- The inner product of two vectors, divided by the product of their
283
+ norms, has absolute value at most 1. -/
284
+ lemma abs_inner_div_norm_mul_norm_le_one (x y : α) : abs (inner x y / (∥x∥ * ∥y∥)) ≤ 1 :=
285
+ begin
286
+ rw abs_div,
287
+ by_cases h : 0 = abs (∥x∥ * ∥y∥),
288
+ { rw [←h, div_zero],
289
+ norm_num },
290
+ { apply div_le_of_le_mul (lt_of_le_of_ne (ge_iff_le.mp (abs_nonneg (∥x∥ * ∥y∥))) h),
291
+ convert abs_inner_le_norm x y using 1 ,
292
+ rw [abs_mul, abs_of_nonneg (norm_nonneg x), abs_of_nonneg (norm_nonneg y), mul_one] }
293
+ end
294
+
295
+ /-- The inner product of a vector with a multiple of itself. -/
296
+ lemma inner_smul_self_left (x : α) (r : ℝ) : inner (r • x) x = r * (∥x∥ * ∥x∥) :=
297
+ by rw [inner_smul_left, ←inner_self_eq_norm_square]
298
+
299
+ /-- The inner product of a vector with a multiple of itself. -/
300
+ lemma inner_smul_self_right (x : α) (r : ℝ) : inner x (r • x) = r * (∥x∥ * ∥x∥) :=
301
+ by rw [inner_smul_right, ←inner_self_eq_norm_square]
302
+
303
+ /-- The inner product of a nonzero vector with a nonzero multiple of
304
+ itself, divided by the product of their norms, has absolute value
305
+ 1. -/
306
+ lemma abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul
307
+ {x : α} {r : ℝ} (hx : x ≠ 0 ) (hr : r ≠ 0 ) : abs (inner x (r • x) / (∥x∥ * ∥r • x∥)) = 1 :=
308
+ begin
309
+ rw [inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ∥x∥, mul_comm _ (abs r),
310
+ mul_assoc, abs_div, abs_mul r, abs_mul (abs r), abs_abs, div_self],
311
+ exact mul_ne_zero (λ h, hr (eq_zero_of_abs_eq_zero h))
312
+ (λ h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero (eq_zero_of_abs_eq_zero h))))
313
+ end
314
+
315
+ /-- The inner product of a nonzero vector with a positive multiple of
316
+ itself, divided by the product of their norms, has value 1. -/
317
+ lemma inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul
318
+ {x : α} {r : ℝ} (hx : x ≠ 0 ) (hr : 0 < r) : inner x (r • x) / (∥x∥ * ∥r • x∥) = 1 :=
319
+ begin
320
+ rw [inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ∥x∥, mul_comm _ (abs r),
321
+ mul_assoc, abs_of_nonneg (le_of_lt hr), div_self],
322
+ exact mul_ne_zero (ne_of_gt hr)
323
+ (λ h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))
324
+ end
325
+
326
+ /-- The inner product of a nonzero vector with a negative multiple of
327
+ itself, divided by the product of their norms, has value -1. -/
328
+ lemma inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul
329
+ {x : α} {r : ℝ} (hx : x ≠ 0 ) (hr : r < 0 ) : inner x (r • x) / (∥x∥ * ∥r • x∥) = -1 :=
330
+ begin
331
+ rw [inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ∥x∥, mul_comm _ (abs r),
332
+ mul_assoc, abs_of_neg hr, ←neg_mul_eq_neg_mul, div_neg_eq_neg_div, div_self],
333
+ exact mul_ne_zero (ne_of_lt hr)
334
+ (λ h, hx (norm_eq_zero.1 (eq_zero_of_mul_self_eq_zero h)))
335
+ end
336
+
337
+ /-- The inner product of two vectors, divided by the product of their
338
+ norms, has absolute value 1 if and only if they are nonzero and one is
339
+ a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
340
+ lemma abs_inner_div_norm_mul_norm_eq_one_iff (x y : α) :
341
+ abs (inner x y / (∥x∥ * ∥y∥)) = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r ≠ 0 ∧ y = r • x) :=
342
+ begin
343
+ split,
344
+ { intro h,
345
+ have hx0 : x ≠ 0 ,
346
+ { intro hx0,
347
+ rw [hx0, inner_zero_left, zero_div] at h,
348
+ norm_num at h,
349
+ exact h },
350
+ refine and.intro hx0 _,
351
+ set r := inner x y / (∥x∥ * ∥x∥) with hr,
352
+ use r,
353
+ set t := y - r • x with ht,
354
+ have ht0 : inner x t = 0 ,
355
+ { rw [ht, inner_sub_right, inner_smul_right, hr, ←inner_self_eq_norm_square,
356
+ div_mul_cancel _ (λ h, hx0 (inner_self_eq_zero.1 h)), sub_self] },
357
+ rw [←sub_add_cancel y (r • x), ←ht, inner_add_right, ht0, zero_add, inner_smul_right,
358
+ inner_self_eq_norm_square, ←mul_assoc, mul_comm,
359
+ mul_div_mul_left _ _ (λ h, hx0 (norm_eq_zero.1 h)), abs_div, abs_mul,
360
+ abs_of_nonneg (norm_nonneg _), abs_of_nonneg (norm_nonneg _), ←real.norm_eq_abs,
361
+ ←norm_smul] at h,
362
+ have hr0 : r ≠ 0 ,
363
+ { intro hr0,
364
+ rw [hr0, zero_smul, norm_zero, zero_div] at h,
365
+ norm_num at h },
366
+ refine and.intro hr0 _,
367
+ have h2 : ∥r • x∥ ^ 2 = ∥t + r • x∥ ^ 2 ,
368
+ { congr' 1 ,
369
+ refine eq_of_div_eq_one _ _ h,
370
+ intro h0,
371
+ rw [h0, div_zero] at h,
372
+ norm_num at h },
373
+ rw [pow_two, pow_two, ←inner_self_eq_norm_square, ←inner_self_eq_norm_square,
374
+ inner_add_add_self] at h2,
375
+ conv_rhs at h2 {
376
+ congr,
377
+ congr,
378
+ skip,
379
+ rw [inner_smul_right, inner_comm, ht0, mul_zero, mul_zero]
380
+ },
381
+ symmetry' at h2,
382
+ rw [add_zero, add_left_eq_self, inner_self_eq_zero] at h2,
383
+ rw h2 at ht,
384
+ exact eq_of_sub_eq_zero ht.symm },
385
+ { intro h,
386
+ rcases h with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,
387
+ rw hy,
388
+ exact abs_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }
389
+ end
390
+
391
+ /-- The inner product of two vectors, divided by the product of their
392
+ norms, has value 1 if and only if they are nonzero and one is
393
+ a positive multiple of the other. -/
394
+ lemma inner_div_norm_mul_norm_eq_one_iff (x y : α) :
395
+ inner x y / (∥x∥ * ∥y∥) = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), 0 < r ∧ y = r • x) :=
396
+ begin
397
+ split,
398
+ { intro h,
399
+ have ha := h,
400
+ apply_fun abs at ha,
401
+ norm_num at ha,
402
+ rcases (abs_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,
403
+ use [hx, r],
404
+ refine and.intro _ hy,
405
+ by_contradiction hrneg,
406
+ rw hy at h,
407
+ rw inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx
408
+ (lt_of_le_of_ne' (le_of_not_lt hrneg) hr) at h,
409
+ norm_num at h },
410
+ { intro h,
411
+ rcases h with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,
412
+ rw hy,
413
+ exact inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }
414
+ end
415
+
416
+ /-- The inner product of two vectors, divided by the product of their
417
+ norms, has value -1 if and only if they are nonzero and one is
418
+ a negative multiple of the other. -/
419
+ lemma inner_div_norm_mul_norm_eq_neg_one_iff (x y : α) :
420
+ inner x y / (∥x∥ * ∥y∥) = -1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r < 0 ∧ y = r • x) :=
421
+ begin
422
+ split,
423
+ { intro h,
424
+ have ha := h,
425
+ apply_fun abs at ha,
426
+ norm_num at ha,
427
+ rcases (abs_inner_div_norm_mul_norm_eq_one_iff x y).1 ha with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,
428
+ use [hx, r],
429
+ refine and.intro _ hy,
430
+ by_contradiction hrpos,
431
+ rw hy at h,
432
+ rw inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx
433
+ (lt_of_le_of_ne' (le_of_not_lt hrpos) hr.symm) at h,
434
+ norm_num at h },
435
+ { intro h,
436
+ rcases h with ⟨hx, ⟨r, ⟨hr, hy⟩⟩⟩,
437
+ rw hy,
438
+ exact inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul hx hr }
439
+ end
440
+
228
441
end norm
229
442
230
443
-- TODO [Lean 3.15]: drop some of these `show`s
0 commit comments