Cross¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Cross[a, b]
gives the vector cross product of two length-3 vectors.
Cross[a1, a2, ..., a(n-1)]
gives the generalized (n-1)-fold cross product in n dimensions, i.e. the unique vector orthogonal to all inputs whose components are the signed cofactor minors of the matrix [a1; a2; ...; en].
Examples (9)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (4)¶
In[1]:= Cross[{1, 2, -1}, {-1, 1, 0}]
Out[1]= {1, 1, 3}
In[2]:= Cross[{1, Sqrt[3]}]
Out[2]= {-Sqrt[3], 1}
In[3]:= Cross[{3.2, 4.2, 5.2}, {0.75, 0.09, 0.06}]
Out[3]= {-0.216, 3.708, -2.862}
In[4]:= Cross[{1.3 + I, 2, 3 - 2 I}, {6. + I, 4, 5 - 7 I}]
Out[4]= {-2 - 6*I, 6.5 - 4.9*I, -6.8 + 2.0*I}
Applications (5)¶
In[5]:= Cross[{1,0,0},{0,1,0}]
Out[5]= {0, 0, 1}
In[6]:= Cross[{a1,a2,a3},{b1,b2,b3}]
Out[6]= {-a3 b2 + a2 b3, -(-a3 b1 + a1 b3), -a2 b1 + a1 b2}
In[7]:= Cross[{2,1,-1},{1,-1,2}]
Out[7]= {1, -5, -3}
In[8]:= Cross[{1,2}]
Out[8]= {-2, 1}
In[9]:= Cross[{1,2,3,4},{5,6,7,8},{9,10,11,13}]
Out[9]= {4, -8, 4, 0}
Algorithm¶
Generalised cross product.
Cross[v1, ..., v(n-1)] for n-dimensional vectors v_i returns the vector
the minor obtained by deleting the i-th column from the matrix of stacked rows.
Implementation notes¶
Algorithm. builtin_cross implements the generalised cross product. Given m = n-1 input vectors of length n (each must be a List of equal length, exactly one less than the number of arguments ā otherwise it emits Cross::nonn1 and returns NULL), the i-th component of the result is the signed minor obtained by stacking the input rows and deleting column i. Each minor is evaluated by laplace_det (shared with Det), and a sign (-1)^(m+i) is applied by wrapping the determinant in Times[-1, ā¦] and calling eval_and_free. The classic 3-vector case Cross[u, v] is the m = 2, n = 3 instance.
Data structures. Each minor is assembled into a flat Expr** array of m*m element pointers (borrowed from the input vectors, not copied) and passed to laplace_det with an explicit column-index list. Entries flow through symbolically, so the result is exact/symbolic whenever the inputs are. The output is a List of n components.
Protected.- Returns the cross product or totally antisymmetric product of $n-1$ vectors of length $n$.
- Works for symbolic and numerical inputs.
- Outputs
Cross::nonn1error message if inputs are not equal-length vectors or if the number of arguments is not one less than their length.
Attributes: Protected.
References¶
- Source:
src/linalg/cross.c - Specification:
docs/spec/builtins/linear-algebra.md - Tests:
tests/test_compile_linalg.c - Tests:
tests/test_distribute.c - Tests:
tests/test_linalg.c - Tests:
tests/test_ndarray_linalg.c
Notes & additional examples¶
Notes¶
Cross[a, b] is the usual 3-vector cross product, returned in fully symbolic cofactor form so it works for indeterminate components. The general Cross[a1, ..., a(n-1)] form gives the unique vector in n dimensions orthogonal to all n-1 inputs, computed as the signed cofactor minors of the matrix whose remaining row is the basis vectors ā so Cross[{1,2}] in the plane returns the 90-degree rotation {-2, 1}, and three 4-vectors yield a fourth vector perpendicular to all of them.