Skip to content

Commit 41a1007

Browse files
authored
[ISSUE-77] Add cross product (#101)
1 parent 08520fd commit 41a1007

7 files changed

Lines changed: 108 additions & 42 deletions

File tree

.config/cspell.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dictionaries:
4949
- web-services
5050
- custom-dict-acronyms
5151
- custom-dict-names
52+
- custom-dict-other
5253
- custom-dict-words-en
5354
- custom-dict-words-es
5455

@@ -70,6 +71,8 @@ dictionaryDefinitions:
7071
path: "./custom-dict-acronyms.txt"
7172
- name: custom-dict-names
7273
path: "./custom-dict-names.txt"
74+
- name: custom-dict-other
75+
path: "./custom-dict-other.txt"
7376
- name: custom-dict-words-en
7477
path: "./custom-dict-words-en.txt"
7578
- name: custom-dict-words-es

.config/custom-dict-names.txt

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,63 @@
1-
fibonacci
2-
Fibonacci
3-
jnonino
4-
Liskov
5-
6-
7-
81
Aguilar
92
Alahyari
103
AMACOM
114
Apress
125
Arie
136
Artech
14-
157
Badgett
168
Basili
179
Beedle
1810
Bennekum
19-
bmatrix
2011
Boehm
2112
Boersma
2213
Booch
2314
Brookshear
24-
2515
Chacon
2616
Charette
2717
Christel
2818
Codecademy
29-
codeimporter
3019
Coghlan
3120
Cormen
32-
3321
Deitel
34-
3522
Easterbrook
36-
elif
3723
Eloranta
3824
Erlikh
3925
ESEM
4026
Euromicro
41-
4227
Fewster
28+
fibonacci
4329
franca
44-
4530
Gagne
4631
Grenning
4732
Grinberg
48-
4933
Hannes
5034
Hapke
5135
Harvill
5236
Hennessy
53-
hextra
5437
Highsmith
5538
Hiva
5639
Holmstrom
57-
5840
Ifrah
5941
infty
6042
Itkonen
61-
6243
Jalote
6344
Jaskiel
6445
jnonino
6546
Jouni
6647
Joyanes
6748
Juha
68-
6949
Kaner
7050
Kazman
7151
Kerzner
7252
Kimmo
7353
Krivy
74-
7554
Laplante
7655
Leanpub
7756
Leiserson
7857
Leppanen
7958
Lianping
8059
Liraz
8160
Liskov
82-
8361
Maberly
8462
Makinen
8563
Mannisto
@@ -88,46 +66,35 @@ Marick
8866
Markku
8967
Markkula
9068
Marko
91-
mathbb
92-
mathbf
9369
Matthes
9470
Matyas
9571
Mika
9672
Mikolov
9773
Moroney
98-
9974
Nonino
10075
Numpy
10176
Nuseibeh
10277
NXOR
103-
10478
Oivo
10579
Olsson
10680
OOPSLA
10781
Oram
108-
10982
Packt
11083
Pagels
11184
Parnas
11285
Pekka
11386
Pfleeger
11487
Pilar
115-
pmatrix
11688
Pulkkinen
117-
Pylint
118-
pytest
119-
12089
Raoul
12190
Rashka
12291
Replit
12392
Rossum
12493
Rumbaugh
125-
12694
Sams
12795
Schwaber
12896
SDLC
12997
Sebesta
130-
sectioncards
13198
Siewiorek
13299
Silberschatz
133100
Simo
@@ -136,20 +103,12 @@ Sommerville
136103
Stolt
137104
Straub
138105
Swarz
139-
140106
Turula
141-
142107
UMAP
143-
144108
Veli
145109
Vlissides
146-
147110
WESCON
148111
Wiegers
149-
wsgi
150-
151112
XNOR
152-
153113
Yourdon
154-
155114
Zelkowitz

.config/custom-dict-other.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bmatrix
2+
codeimporter
3+
elif
4+
hextra
5+
mathbb
6+
mathbf
7+
pmatrix
8+
pylint
9+
pytest
10+
sectioncards
11+
vmatrix
12+
wsgi

.config/custom-dict-words-en.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
anticommutativity
12
explainability
23
regulariser
34
sidelining

.config/custom-dict-words-es.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
anticonmutatividad
12
aprendé
23
autocompletado
34
bayesianos
45
contrastivo
56
convolucionales
7+
curvá
68
dejá
79
descripto
810
dimensionalidad

content/ai/math/algebra/vectors/index.en.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,51 @@ $$
260260
works precisely because of this geometry. Semantic relationships are encoded as *directions* in vector space, and finding `queen` means finding the vector whose cosine similarity to the query vector is maximized. Every modern embedding model (BERT, GPT, sentence-transformers) inherits this geometric philosophy. Next time you read something about word representation in vector spaces, remember they are talking about the same geometry we just derived.
261261
{{< /callout >}}
262262

263+
### The cross product
264+
265+
The dot product takes two vectors and returns a **scalar**. The **cross product** takes two vectors in \(\mathbb{R}^3\) and returns a **vector**, one that is perpendicular to both inputs. It is defined only in three (and seven) dimensions, which makes it more geometrically specialised than the dot product.
266+
267+
Given \(\mathbf{u} = [u_1, u_2, u_3]^T\) and \(\mathbf{v} = [v_1, v_2, v_3]^T\), the cross product \(\mathbf{u} \times \mathbf{v}\) is computed by expanding the following symbolic determinant:
268+
269+
$$
270+
\mathbf{u} \times \mathbf{v} = \begin{vmatrix} \mathbf{e}_1 & \mathbf{e}_2 & \mathbf{e}_3 \\ u_1 & u_2 & u_3 \\ v_1 & v_2 & v_3 \end{vmatrix}
271+
$$
272+
273+
Expanding along the first row:
274+
275+
$$
276+
\mathbf{u} \times \mathbf{v} = \mathbf{e}_1(u_2 v_3 - u_3 v_2) - \mathbf{e}_2(u_1 v_3 - u_3 v_1) + \mathbf{e}_3(u_1 v_2 - u_2 v_1)
277+
$$
278+
279+
$$
280+
\boxed{\mathbf{u} \times \mathbf{v} = \begin{bmatrix} u_2 v_3 - u_3 v_2 \\ u_3 v_1 - u_1 v_3 \\ u_1 v_2 - u_2 v_1 \end{bmatrix}}
281+
$$
282+
283+
{{< callout type="info" >}}
284+
In plain English: each component of the result is a \(2 \times 2\) determinant built from the other two components of the inputs. The pattern is cyclic: \((2,3)\), \((3,1)\), \((1,2)\).
285+
{{< /callout >}}
286+
287+
**Two geometric facts define the cross product completely**:
288+
289+
**Direction:** \(\mathbf{u} \times \mathbf{v}\) is always orthogonal to both \(\mathbf{u}\) and \(\mathbf{v}\). You can verify this directly: \((\mathbf{u} \times \mathbf{v}) \cdot \mathbf{u} = 0\) and \((\mathbf{u} \times \mathbf{v}) \cdot \mathbf{v} = 0\). The orientation follows the **right-hand rule**: curl the fingers of your right hand from \(\mathbf{u}\) toward \(\mathbf{v}\), and your thumb points in the direction of \(\mathbf{u} \times \mathbf{v}\).
290+
291+
**Magnitude:** The length of the result equals the area of the parallelogram spanned by \(\mathbf{u}\) and \(\mathbf{v}\), which can be expressed as:
292+
293+
$$\|\mathbf{u} \times \mathbf{v}\| = \|\mathbf{u}\|\|\mathbf{v}\|\sin\theta$$
294+
295+
296+
{{< callout type="info" >}}
297+
When \(\mathbf{u}\) and \(\mathbf{v}\) are parallel (\(\theta = 0°\)), the parallelogram is flat and the cross product is the zero vector. When they are perpendicular (\(\theta = 90°\)), the parallelogram has maximum area and \(\|\mathbf{u} \times \mathbf{v}\|\) is maximised. This is the exact opposite behaviour to the dot product, which is maximised when vectors are parallel and zero when perpendicular.
298+
{{< /callout >}}
299+
300+
**Key algebraic property, anticommutativity**:
301+
302+
$$
303+
\mathbf{u} \times \mathbf{v} = -(\mathbf{v} \times \mathbf{u})
304+
$$
305+
306+
Swapping the order flips the sign and the direction. This means the cross product is **not commutative**, unlike the dot product.
307+
263308
## Python implementation
264309

265310
Let's implement everything from scratch, first in pure Python, then verify with NumPy.

content/ai/math/algebra/vectors/index.es.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,50 @@ $$
259259
funciona precisamente gracias a esta geometría. Las relaciones semánticas se codifican como *direcciones* en el espacio vectorial, y encontrar `reina` significa hallar el vector con mayor similitud coseno al vector de consulta. Todo modelo de embedding moderno (BERT, GPT, sentence-transformers) hereda esta filosofía geométrica. La siguiente vez que leas sobre ***"espacios de representación"*** en un paper de IA, recuerda: están hablando literalmente de la geometría que acabas de derivar.
260260
{{< /callout >}}
261261

262+
### El producto vectorial (producto cruz)
263+
264+
El producto punto toma dos vectores y devuelve un **escalar**. El **producto vectorial** toma dos vectores en \(\mathbb{R}^3\) y devuelve un **vector**, uno que es perpendicular a ambas entradas. Está definido únicamente en tres (y siete) dimensiones, lo que lo hace más especializado geométricamente que el producto punto.
265+
266+
Dados \(\mathbf{u} = [u_1, u_2, u_3]^T\) y \(\mathbf{v} = [v_1, v_2, v_3]^T\), el producto vectorial \(\mathbf{u} \times \mathbf{v}\) se calcula expandiendo el siguiente determinante simbólico:
267+
268+
$$
269+
\mathbf{u} \times \mathbf{v} = \begin{vmatrix} \mathbf{e}_1 & \mathbf{e}_2 & \mathbf{e}_3 \\ u_1 & u_2 & u_3 \\ v_1 & v_2 & v_3 \end{vmatrix}
270+
$$
271+
272+
Expandiendo por la primera fila:
273+
274+
$$
275+
\mathbf{u} \times \mathbf{v} = \mathbf{e}_1(u_2 v_3 - u_3 v_2) - \mathbf{e}_2(u_1 v_3 - u_3 v_1) + \mathbf{e}_3(u_1 v_2 - u_2 v_1)
276+
$$
277+
278+
$$
279+
\boxed{\mathbf{u} \times \mathbf{v} = \begin{bmatrix} u_2 v_3 - u_3 v_2 \\ u_3 v_1 - u_1 v_3 \\ u_1 v_2 - u_2 v_1 \end{bmatrix}}
280+
$$
281+
282+
{{< callout type="info" >}}
283+
En términos sencillos: cada componente del resultado es un determinante \(2 \times 2\) construido a partir de las otras dos componentes de las entradas. El patrón es cíclico: \((2,3)\), \((3,1)\), \((1,2)\).
284+
{{< /callout >}}
285+
286+
Dos propiedades geométricas definen el producto vectorial por completo:
287+
- **Dirección:** \(\mathbf{u} \times \mathbf{v}\) es siempre ortogonal tanto a \(\mathbf{u}\) como a \(\mathbf{v}\). Podés verificarlo directamente: \((\mathbf{u} \times \mathbf{v}) \cdot \mathbf{u} = 0\) y \((\mathbf{u} \times \mathbf{v}) \cdot \mathbf{v} = 0\). La orientación sigue la **regla de la mano derecha**: curvá los dedos de tu mano derecha desde \(\mathbf{u}\) hacia \(\mathbf{v}\), y el pulgar apunta en la dirección de \(\mathbf{u} \times \mathbf{v}\).
288+
289+
**Magnitud:** La longitud del resultado es igual al área del paralelogramo generado por \(\mathbf{u}\) y \(\mathbf{v}\):
290+
$$
291+
\|\mathbf{u} \times \mathbf{v}\| = \|\mathbf{u}\|\|\mathbf{v}\|\sin\theta
292+
$$
293+
294+
{{< callout type="info" >}}
295+
Cuando \(\mathbf{u}\) y \(\mathbf{v}\) son paralelos (\(\theta = 0°\)), el paralelogramo es plano y el producto vectorial es el vector cero. Cuando son perpendiculares (\(\theta = 90°\)), el paralelogramo tiene área máxima y \(\|\mathbf{u} \times \mathbf{v}\|\) se maximiza. Este comportamiento es exactamente opuesto al del producto punto, que se maximiza cuando los vectores son paralelos y vale cero cuando son perpendiculares.
296+
{{< /callout >}}
297+
298+
**Propiedad algebraica clave, anticonmutatividad**:
299+
300+
$$
301+
\mathbf{u} \times \mathbf{v} = -(\mathbf{v} \times \mathbf{u})
302+
$$
303+
304+
Intercambiar el orden invierte el signo y la dirección. Esto significa que el producto vectorial **no es conmutativo**, a diferencia del producto punto.
305+
262306
## Implementación en Python
263307

264308
Implementamos todo desde cero: primero en Python puro para ver la mecánica, luego verificamos con NumPy.

0 commit comments

Comments
 (0)