Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(linear_algebra/{cross_product,vectors}): cross product #11181

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
448ef4d
feat(linear_algebra/cross_product)
madvorak Jan 1, 2022
06d1895
refactor(linear_algebra/vectors): unused argument
madvorak Jan 1, 2022
ed2a8bf
Update src/linear_algebra/cross_product.lean
madvorak Jan 3, 2022
408677e
feat(linear_algebra/cross_product): added the jacobi identity; small …
madvorak Jan 3, 2022
924004d
refactor(linear_algebra/cross_product): shortened proof of the Jacobi…
madvorak Jan 3, 2022
85cd4ff
feat(linear_algebra/cross_product): cross product is a lie ring
madvorak Jan 4, 2022
cffd9c7
feat(linear_algebra/cross_product): improved comments about the lie ring
madvorak Jan 4, 2022
d95f2bc
refactor(linear_algebra/vectors): redundant parentheses removed
madvorak Jan 4, 2022
4dec7d4
Merge branch 'master' into madvorak_cross_product
madvorak Jan 5, 2022
45ee22c
refactor(linear_algebra/vectors): proofs by rewrite
madvorak Jan 6, 2022
ba3e4d8
refactor(data/matrix/notation): moved lemmata about vec2 and vec3
madvorak Jan 6, 2022
e97767f
refactor(data/matrix/notation): variable names more consistent
madvorak Jan 6, 2022
78f8546
refactor(data/matrix/notation): symbol for explicit dot product changed
madvorak Jan 6, 2022
f7b3d22
doc(data/matrix/notation): fix doc for the new notation of explicit v…
madvorak Jan 6, 2022
a2d8b2b
Update src/linear_algebra/cross_product.lean
madvorak Jan 6, 2022
0d5610e
feat(linear_algebra/cross_product): lie_lie
madvorak Jan 6, 2022
1105db4
refactor(linear_algebra/cross_product): third form of the lie propert…
madvorak Jan 6, 2022
cdffc61
fix(data/matrix/notation): removed unnecessary instance
madvorak Jan 6, 2022
e72bdef
Merge remote-tracking branch 'origin/master' into madvorak_cross_product
madvorak Jan 8, 2022
afc8397
refactor(linear_algebra/cross_product): wip
madvorak Jan 8, 2022
7b98d25
fix(linear_algebra/cross_product): problem with has_add vs add_semigr…
madvorak Jan 9, 2022
611856f
refactor(linear_algebra/cross_product): cross product multilinearity …
madvorak Jan 9, 2022
9a61907
refactor(data/matrix/notation): lemmata (not) used in linear_algebra/…
madvorak Jan 9, 2022
8667dfc
refactor(data/matrix/notation)
madvorak Jan 9, 2022
514803f
refactor(linear_algebra/cross_product): slightly increased priority o…
madvorak Jan 9, 2022
b96633d
refactor(linear_algebra/cross_product): performance improvement
madvorak Jan 9, 2022
8adea54
feat(linear_algebra/cross_product): theorem cross_dot_cross
madvorak Jan 9, 2022
20b4398
doc(linear_algebra/cross_product): docstring for cross_dot_cross
madvorak Jan 11, 2022
c42838e
Apply suggestions from code review
madvorak Jan 12, 2022
c6cce40
refactor(linear_algebra/cross_product): full name cross_product only …
madvorak Jan 12, 2022
95e06ca
add cross product to docs/undergrad.yaml
jcommelin Jan 12, 2022
1b89fb9
Merge remote-tracking branch 'origin/master' into madvorak_cross_product
madvorak Jan 12, 2022
5c36153
fix(linear_algebra/cross_product): simp with smul after merge
madvorak Jan 13, 2022
7a68101
refactor(linear_algebra/cross_product): cleaner and faster def cross_…
madvorak Jan 13, 2022
d2c3cee
refactor(linear_algebra/cross_product): little changes
madvorak Jan 13, 2022
6e1d89d
docs(linear_algebra/cross_product): Jacobi identity was renamed
madvorak Jan 13, 2022
f2eb08c
Update src/linear_algebra/cross_product.lean
jcommelin Jan 13, 2022
dde823a
fix(linear_algebra/cross_product): line too long
madvorak Jan 13, 2022
73bdd43
Merge branch 'madvorak_cross_product' of https://github.com/leanprove…
madvorak Jan 13, 2022
6660261
refactor(linear_algebra/cross_product): the problematic line was in a…
madvorak Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 134 additions & 0 deletions src/linear_algebra/cross_product.lean
@@ -0,0 +1,134 @@
/-
Copyright (c) 2021 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak, Kyle Miller, Eric Wieser
-/

import linear_algebra.bilinear_map
import linear_algebra.matrix.determinant
import linear_algebra.vectors
import algebra.lie.basic

/-!
# Cross products

This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring.

## Main definitions

* `cross_product` is the cross product of pairs of vectors in $R^3$.

## Main results

* `triple_product_eq_det`
* `jacobi_identity`

## Notation

The locale `vectors` gives the following notation:

* `×₃` for the cross product

## Tags

crossproduct
-/

open_locale vectors

variables {R : Type*} [comm_ring R]

/-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/
def cross_product : (fin 3 → R) →ₗ[R] (fin 3 → R) →ₗ[R] (fin 3 → R) :=
begin
apply linear_map.mk₂ R (λ (a b : fin 3 → R),
![ (a 1)*(b 2) - (a 2)*(b 1) ,
(a 2)*(b 0) - (a 0)*(b 2) ,
(a 0)*(b 1) - (a 1)*(b 0) ]);
intros;
simp only [vec3_add,
pi.add_apply, smul_eq_mul, matrix.smul_cons, matrix.smul_empty, pi.smul_apply];
apply vec3_eq;
ring,
end
madvorak marked this conversation as resolved.
Show resolved Hide resolved

localized "infixl ` ×₃ `: 68 := cross_product" in vectors

lemma cross_product_apply (a b : fin 3 → R) :
a ×₃ b =
![ (a 1)*(b 2) - (a 2)*(b 1) ,
(a 2)*(b 0) - (a 0)*(b 2) ,
(a 0)*(b 1) - (a 1)*(b 0) ] :=
rfl

lemma cross_product_anticomm (v w : fin 3 → R) :
madvorak marked this conversation as resolved.
Show resolved Hide resolved
- (v ×₃ w) = w ×₃ v :=
by simp [cross_product_apply, mul_comm]

lemma cross_product_anticomm' (v w : fin 3 → R) :
v ×₃ w + w ×₃ v = 0 :=
by rw [add_eq_zero_iff_eq_neg, cross_product_anticomm]

lemma cross_product_self (v : fin 3 → R) :
madvorak marked this conversation as resolved.
Show resolved Hide resolved
v ×₃ v = 0 :=
by simp [cross_product_apply, mul_comm]

/-- The cross product of two vectors is perpendicular to the first vector. -/
lemma dot_self_cross_product (v w : fin 3 → R) :
madvorak marked this conversation as resolved.
Show resolved Hide resolved
v ⬝ (v ×₃ w) = 0 :=
by simp [cross_product_apply, vec3_dot_product, mul_sub, mul_assoc, mul_left_comm]

/-- The cross product of two vectors is perpendicular to the second vector. -/
lemma dot_cross_product_self (v w : fin 3 → R) :
madvorak marked this conversation as resolved.
Show resolved Hide resolved
w ⬝ (v ×₃ w) = 0 :=
by rw [← cross_product_anticomm, matrix.dot_product_neg, dot_self_cross_product, neg_zero]

/-- Cyclic permutations preserve the triple product. See also `triple_product_eq_det`. -/
lemma triple_product_permutation (u v w : fin 3 → R) :
u ⬝ (v ×₃ w) = v ⬝ (w ×₃ u) :=
begin
simp only [cross_product_apply, vec3_dot_product,
matrix.head_cons, matrix.cons_vec_bit0_eq_alt0, matrix.empty_append, matrix.cons_val_one,
matrix.cons_vec_alt0, matrix.cons_append, matrix.cons_val_zero],
ring,
end

/-- The triple product of `u`, `v`, and `w` is equal to the determinant of the matrix
with those vectors as its rows. -/
theorem triple_product_eq_det (u v w : fin 3 → R) :
u ⬝ (v ×₃ w) = matrix.det ![u, v, w] :=
begin
simp only [vec3_dot_product, cross_product_apply, matrix.det_fin_three,
matrix.head_cons, matrix.cons_vec_bit0_eq_alt0, matrix.empty_vec_alt0, matrix.cons_vec_alt0,
matrix.vec_head_vec_alt0, fin.fin_append_apply_zero, matrix.empty_append, matrix.cons_append,
matrix.cons_val', matrix.cons_val_one, matrix.cons_val_zero],
ring,
end

/-- The cross product satisfies the Leibniz lie property
`∀ (x y z : L) : ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆` from `algebra.lie.basic.lie_ring`.
It is equivalent to the Jacobi identity in the presence of the other Lie ring axioms. -/
lemma leibniz_cross (u v w : fin 3 → R) :
u ×₃ (v ×₃ w) = (u ×₃ v) ×₃ w + v ×₃ (u ×₃ w) :=
begin
dsimp only [has_bracket.bracket, cross_product_apply],
madvorak marked this conversation as resolved.
Show resolved Hide resolved
ext i,
fin_cases i; norm_num; ring,
end

/-- The three-dimensional vectors together with the operations + and ×₃ form a Lie ring. -/
madvorak marked this conversation as resolved.
Show resolved Hide resolved
def cross_product.lie_ring : lie_ring (fin 3 → R) :=
{ bracket := λ u v, u ×₃ v,
add_lie := linear_map.map_add₂ _,
lie_add := λ u, linear_map.map_add _,
lie_self := cross_product_self,
leibniz_lie := leibniz_cross,
..pi.add_comm_group }

local attribute [instance] cross_product.lie_ring

/-- For a cross product of three vectors, their sum over the three even permutations is equal
to the zero vector. -/
theorem jacobi_identity (u v w : fin 3 → R) :
madvorak marked this conversation as resolved.
Show resolved Hide resolved
u ×₃ (v ×₃ w) + v ×₃ (w ×₃ u) + w ×₃ (u ×₃ v) = 0 :=
lie_jacobi u v w
madvorak marked this conversation as resolved.
Show resolved Hide resolved
madvorak marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 56 additions & 0 deletions src/linear_algebra/vectors.lean
@@ -0,0 +1,56 @@
/-
madvorak marked this conversation as resolved.
Show resolved Hide resolved
Copyright (c) 2021 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak, Kyle Miller
-/

import data.matrix.basic
import data.matrix.notation
import tactic.fin_cases

/-!
# Vectors

This module provides lemmata to more easily manipulate explicit vectors in $R^2$ and $R^3$
for $R$ a commutative ring.

## Notation

The locale `vectors` gives the following notation:

* `⬝` for dot products

## Tags

vectors
-/

variable {R : Type*}

lemma vec2_eq {a₀ a₁ b₀ b₁ : R} (h₀ : a₀ = b₀) (h₁ : a₁ = b₁) :
![a₀, a₁] = ![b₀, b₁] :=
by { ext x, fin_cases x; assumption }

lemma vec3_eq {a₀ a₁ a₂ b₀ b₁ b₂ : R} (h₀ : a₀ = b₀) (h₁ : a₁ = b₁) (h₂ : a₂ = b₂) :
![a₀, a₁, a₂] = ![b₀, b₁, b₂] :=
by { ext x, fin_cases x; assumption }

variable [comm_ring R]

lemma vec2_add {a₀ a₁ b₀ b₁ : R} :
![a₀, a₁] + ![b₀, b₁] = ![a₀ + b₀, a₁ + b₁] :=
by { ext x, fin_cases x; refl }
madvorak marked this conversation as resolved.
Show resolved Hide resolved

lemma vec3_add {a₀ a₁ a₂ b₀ b₁ b₂ : R} :
![a₀, a₁, a₂] + ![b₀, b₁, b₂] = ![a₀ + b₀, a₁ + b₁, a₂ + b₂] :=
by { ext x, fin_cases x; refl }
madvorak marked this conversation as resolved.
Show resolved Hide resolved

localized "infix ` ⬝ ` : 67 := matrix.dot_product" in vectors

lemma vec2_dot_product (v w : fin 2 → R) :
v ⬝ w = v 0 * w 0 + v 1 * w 1 :=
by simp [matrix.dot_product, add_assoc, fin.sum_univ_succ]

lemma vec3_dot_product (v w : fin 3 → R) :
v ⬝ w = v 0 * w 0 + v 1 * w 1 + v 2 * w 2 :=
by simp [matrix.dot_product, add_assoc, fin.sum_univ_succ]
madvorak marked this conversation as resolved.
Show resolved Hide resolved