Core¶
The mathematical kernel of Versor.
Algebra¶
CliffordAlgebra
¶
Differentiable Clifford algebra kernel with memory-optimized blocked accumulation.
Handles geometric product, grade projection, and rotor operations.
Supports degenerate (null) dimensions via the r parameter:
Cl(p, q, r) has p positive, q negative, and r null
basis vectors (e_i^2 = 0).
Attributes:
| Name | Type | Description |
|---|---|---|
p |
int
|
Positive signature dimensions. |
q |
int
|
Negative signature dimensions. |
r |
int
|
Degenerate (null) dimensions. |
n |
int
|
Total dimensions (p + q + r). |
dim |
int
|
Total basis elements (2^n). |
device |
str
|
Computation device. |
Source code in core/algebra.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
num_grades
property
¶
Counts the number of grades (n + 1).
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of grades. |
__init__(p, q=0, r=0, device='cuda')
¶
Initialize the algebra and cache the Cayley table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
int
|
Positive dimensions (+1). |
required |
q
|
int
|
Negative dimensions (-1). Defaults to 0. |
0
|
r
|
int
|
Degenerate dimensions (0). Defaults to 0. |
0
|
device
|
str
|
The device on which computations are performed. Defaults to 'cuda'. |
'cuda'
|
Source code in core/algebra.py
embed_vector(vectors)
¶
Injects vectors into the Grade-1 subspace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vectors
|
Tensor
|
Raw vectors [..., n]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Multivector coefficients [..., dim]. |
Source code in core/algebra.py
get_grade_norms(mv)
¶
Calculates norms per grade. Useful for invariant features.
Vectorized via scatter_add -- no Python loops over grades.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Input multivector [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Grade norms [..., num_grades]. |
Source code in core/algebra.py
geometric_product(A, B)
¶
Computes the Geometric Product.
Uses vectorized gather + broadcast multiply + sum. No Python loops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Tensor
|
Left operand [..., Dim]. |
required |
B
|
Tensor
|
Right operand [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: The product AB [..., Dim]. |
Source code in core/algebra.py
ensure_device(device)
¶
Move cached tables to the given device if not already there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
Target device. |
required |
Source code in core/algebra.py
grade_projection(mv, grade)
¶
Isolates a specific grade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Multivector [..., Dim]. |
required |
grade
|
int
|
Target grade. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Projected multivector [..., Dim]. |
Source code in core/algebra.py
reverse(mv)
¶
Computes the reversion. The Clifford conjugate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Input multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Reversed multivector [..., Dim]. |
Source code in core/algebra.py
wedge(A, B)
¶
Computes the wedge (outer) product: A ^ B = (AB - BA)/2.
Single-pass implementation using precomputed antisymmetric signs.
Reference
Pence, T., Yamada, D., & Singh, V. (2025). "Composing Linear Layers from Irreducibles." arXiv:2507.11688v1 [cs.LG]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Tensor
|
Left operand [..., dim]. |
required |
B
|
Tensor
|
Right operand [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Wedge product A ^ B [..., dim]. |
Source code in core/algebra.py
right_contraction(A, B)
¶
Computes the right contraction: A _| B.
Fast path for bivector-vector case using precomputed skew-symmetric action matrices (avoids full geometric product + grade projection).
Reference
Pence, T., Yamada, D., & Singh, V. (2025). "Composing Linear Layers from Irreducibles." arXiv:2507.11688v1 [cs.LG], Algorithm 2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Tensor
|
Left operand (bivector) [..., dim]. |
required |
B
|
Tensor
|
Right operand (vector) [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Right contraction A _| B [..., dim]. |
Source code in core/algebra.py
inner_product(A, B)
¶
Computes the inner product: A . B = (AB + BA)/2.
Single-pass implementation using precomputed symmetric signs.
Reference
Pence, T., Yamada, D., & Singh, V. (2025). "Composing Linear Layers from Irreducibles." arXiv:2507.11688v1 [cs.LG]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
Tensor
|
Left operand [..., dim]. |
required |
B
|
Tensor
|
Right operand [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Inner product A . B [..., dim]. |
Source code in core/algebra.py
blade_inverse(blade)
¶
Compute the inverse of a blade: B^{-1} = B_rev / _0.
Works for any simple blade (non-degenerate). For null blades the scalar denominator is clamped to avoid division by zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blade
|
Tensor
|
Blade multivector [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Inverse blade [..., dim]. |
Source code in core/algebra.py
blade_project(mv, blade)
¶
Project multivector onto blade subspace: (mv . B) B^{-1}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Multivector to project [..., dim]. |
required |
blade
|
Tensor
|
Blade defining the subspace [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Projected multivector [..., dim]. |
Source code in core/algebra.py
blade_reject(mv, blade)
¶
Reject multivector from blade subspace: mv - proj_B(mv).
The orthogonal complement of the projection onto blade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Multivector to reject [..., dim]. |
required |
blade
|
Tensor
|
Blade defining the subspace [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Rejected multivector [..., dim]. |
Source code in core/algebra.py
grade_involution(mv)
¶
Grade involution (main involution): x_hat = sum (-1)^k
Flips sign of all odd-grade components, preserves even-grade. This is an algebra automorphism: (AB)^ = A_hat B_hat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Input multivector [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Involuted multivector [..., dim]. |
Source code in core/algebra.py
exp(mv)
¶
Exponentiates a bivector to produce a rotor via closed-form.
Three signature regimes
- Elliptic (B^2 < 0): exp(B) = cos(th) + sin(th)/th * B
- Hyperbolic (B^2 > 0): exp(B) = cosh(th) + sinh(th)/th * B
- Parabolic (B^2 ~ 0): exp(B) ~ 1 + B
For n <= 3 every bivector is simple, so the closed-form is exact.
For n >= 4 the closed-form is exact for simple bivectors and a
first-order approximation for non-simple ones. Use
exp_decomposed() when exact non-simple handling is needed
(inference only -- see core.decomposition).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Pure bivector [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Rotor exp(mv) [..., dim]. |
Source code in core/algebra.py
exp_decomposed(mv, **kwargs)
¶
Exponentiates a bivector via decomposition into simple components.
Decomposes a general bivector into a sum of simple (blade) bivectors using GA power iteration, exponentiates each in closed form, then composes via geometric product. Exact for all bivectors, but the power iteration loop is not differentiable through its normalization steps. During training the loop is detached and gradients flow only through the final closed-form exp + composition.
Reference
Pence, T., Yamada, D., & Singh, V. (2025). "Composing Linear Layers from Irreducibles." arXiv:2507.11688v1 [cs.LG]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
Pure bivector [..., dim]. |
required |
**kwargs
|
dict
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Rotor exp(mv) [..., dim]. |
Source code in core/algebra.py
Conformal Algebra¶
ConformalAlgebra
¶
Helper for CGA. Handles Conformal Geometric Algebra operations.
Maps Euclidean R^n to Null Cone in R^{n+1, 1}.
Attributes:
| Name | Type | Description |
|---|---|---|
d |
int
|
Euclidean dimension. |
algebra |
CliffordAlgebra
|
The higher dimensional algebra. |
e_o |
Tensor
|
Origin basis vector (null). |
e_inf |
Tensor
|
Infinity basis vector (null). |
device |
str
|
Computation device. |
Source code in core/cga.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__(euclidean_dim=3, device='cpu')
¶
Sets up the CGA stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
euclidean_dim
|
int
|
Physical dimension d. |
3
|
device
|
str
|
Computation device. |
'cpu'
|
Source code in core/cga.py
to_cga(x)
¶
Embeds Euclidean points into the conformal null cone.
P(x) = x + 0.5 * x^2 * e_inf + e_o.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Euclidean points [Batch, d]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Conformal points [Batch, 2^n]. |
Source code in core/cga.py
from_cga(P)
¶
Projects conformal points back to Euclidean space.
Normalization: P -> P / (-P . e_inf).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Tensor
|
Conformal points [Batch, 2^n]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Euclidean coordinates [Batch, d]. |
Source code in core/cga.py
Multivector¶
Multivector
¶
Object-oriented multivector wrapper with operator overloading.
Attributes:
| Name | Type | Description |
|---|---|---|
algebra |
CliffordAlgebra
|
The backend. |
tensor |
Tensor
|
The raw data [..., Dim]. |
Source code in core/multivector.py
__init__(algebra, tensor)
¶
Wraps the tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
tensor
|
Tensor
|
Coefficients. |
required |
from_vectors(algebra, vectors)
classmethod
¶
Promotes vectors to multivectors (Grade 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
vectors
|
Tensor
|
Vectors [Batch, n]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Multivector |
Multivector
|
The wrapper. |
Source code in core/multivector.py
norm()
¶
exp()
¶
Metric¶
metric
¶
Metric definitions for Clifford algebras.
Provides distances, norms, and inner products that respect the metric signature.
inner_product(algebra, A, B)
¶
Compute the scalar product via projection onto grade 0.
Computes _0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector [Batch, Dim]. |
required |
B
|
Tensor
|
Second multivector [Batch, Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Scalar part [Batch, 1]. |
Source code in core/metric.py
induced_norm(algebra, A)
¶
Compute the induced norm respecting the metric signature.
Computes ||A|| = sqrt(|_0|).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [Batch, Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Norm [Batch, 1]. |
Source code in core/metric.py
geometric_distance(algebra, A, B)
¶
Computes geometric distance.
dist(A, B) = ||A - B||.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector. |
required |
B
|
Tensor
|
Second multivector. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Distance. |
Source code in core/metric.py
grade_purity(algebra, A, grade)
¶
Checks the purity of the grade by examining coefficient energy.
Purity = ||_k||^2 / ||A||^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [..., Dim]. |
required |
grade
|
int
|
Target grade. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Purity score [0, 1]. |
Source code in core/metric.py
mean_active_grade(algebra, A)
¶
Average grade. Identifies the grade where the majority of the energy resides.
Mean Grade = Sum(k * ||_k||^2) / ||A||^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Average grade index. |
Source code in core/metric.py
clifford_conjugate(algebra, mv)
¶
Clifford conjugation (bar involution).
Combines reversion with grade involution
A_bar_k = (-1)^k * (-1)^{k(k-1)/2} * A_k
This is the natural *-involution on Cl(p,q). Useful for algebraic computations (e.g., spinor norms, Lipschitz groups).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
mv
|
Tensor
|
Multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Conjugated multivector [..., Dim]. |
Source code in core/metric.py
hermitian_inner_product(algebra, A, B)
¶
Hermitian inner product on Cl(p,q):
_H = Sum_I (conj_sign_I * metric_sign_I) * a_I * b_I
Uses precomputed sign arrays so that the result equals the scalar part of the geometric product of the Clifford conjugate of A with B. For Euclidean algebras (q=0), all signs are +1 and this reduces to the simple coefficient inner product Sum a_I b_I.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector [..., Dim]. |
required |
B
|
Tensor
|
Second multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar inner product [..., 1]. |
Source code in core/metric.py
hermitian_norm(algebra, A)
¶
Hermitian norm: ||A||_H = sqrt(|_H|).
Always real and non-negative for any signature. Uses abs() since the signed inner product can produce negative self-products in mixed-signature algebras.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Norm [..., 1]. Always >= 0. |
Source code in core/metric.py
hermitian_distance(algebra, A, B)
¶
Hermitian distance: d_H(A, B) = ||A - B||_H.
Positive-definite metric distance for any signature. Satisfies: non-negativity, symmetry, triangle inequality, identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector [..., Dim]. |
required |
B
|
Tensor
|
Second multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Distance [..., 1]. Always >= 0. |
Source code in core/metric.py
hermitian_angle(algebra, A, B)
¶
Hermitian angle between multivectors.
cos(theta) = _H / (||A||_H * ||B||_H)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector [..., Dim]. |
required |
B
|
Tensor
|
Second multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Angle in radians [..., 1]. |
Source code in core/metric.py
grade_hermitian_norm(algebra, A, grade)
¶
Hermitian norm restricted to a single grade.
||k||_H = sqrt(Sum{I: |I|=k} a_I**2)
Measures the energy contribution of a specific grade in a signature-independent way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [..., Dim]. |
required |
grade
|
int
|
Target grade. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Grade-specific norm [..., 1]. |
Source code in core/metric.py
hermitian_grade_spectrum(algebra, A)
¶
Full Hermitian grade spectrum.
Returns |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Grade energies [..., n+1]. Each entry >= 0. |
Source code in core/metric.py
signature_trace_form(algebra, A, B)
¶
Signature-aware trace form: <~A B>_0.
The standard Clifford algebra scalar product. NOT positive-definite in mixed signatures. Use hermitian_inner_product for optimization.
This form is signature-aware and useful for: - Rotor normalization (R~R = 1) - Versor validation - Spinor norm computation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
First multivector [..., Dim]. |
required |
B
|
Tensor
|
Second multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar trace form [..., 1]. Can be negative in mixed signatures. |
Source code in core/metric.py
signature_norm_squared(algebra, A)
¶
Signature-aware squared norm: _0.
Can be negative in mixed-signature algebras. Returns the raw value without absolute value, preserving causal structure information.
For Cl(n,0): always non-negative. For Cl(p,q) with q>0: sign encodes causal character.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
A
|
Tensor
|
Multivector [..., Dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Signed squared norm [..., 1]. |
Source code in core/metric.py
Decomposition¶
decomposition
¶
Bivector decomposition via GA power iteration.
Decomposes a general bivector into simple (blade) components that can each be exponentiated with the closed-form formula.
Reference
Pence, T., Yamada, D., & Singh, V. (2025). "Composing Linear Layers from Irreducibles." arXiv:2507.11688v1 [cs.LG]
ga_power_iteration(algebra, b, v_init=None, threshold=1e-06, max_iterations=100)
¶
Find the dominant simple bivector component via power iteration.
Implements Algorithm 2 from Pence et al. (2025). Iterates
v <- (b _| v) / ||b _| v|| until convergence, then recovers
the simple projection b_s = sigma * (u ^ v).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
CliffordAlgebra instance. |
required |
b
|
Tensor
|
Bivector to decompose [..., dim]. |
required |
v_init
|
Optional[Tensor]
|
Initial grade-1 vector (random if None). |
None
|
threshold
|
float
|
Convergence tolerance on |
1e-06
|
max_iterations
|
int
|
Iteration cap. |
100
|
Returns:
| Type | Description |
|---|---|
Tensor
|
(b_s, v) where b_s is the simple projection and v the converged |
Tensor
|
vector, both shaped [..., dim]. |
Source code in core/decomposition.py
differentiable_invariant_decomposition(algebra, b, k=None, threshold=1e-06, max_iterations=100)
¶
Decompose a bivector into simple components via greedy projection.
Implements Algorithm 1 from Pence et al. (2025). Iteratively extracts the dominant simple component and subtracts it from the residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
CliffordAlgebra instance. |
required |
b
|
Tensor
|
Bivector [..., dim]. |
required |
k
|
Optional[int]
|
Number of components (auto = n(n-1)/2 if None). |
None
|
threshold
|
float
|
Stop when residual norm falls below this. |
1e-06
|
max_iterations
|
int
|
Per-component power iteration cap. |
100
|
Returns:
| Type | Description |
|---|---|
(decomp, vectors)
|
lists of simple bivectors and their |
List[Tensor]
|
associated vectors. |
Source code in core/decomposition.py
exp_simple_bivector(algebra, b)
¶
Closed-form exponential of a simple bivector.
Delegates to algebra._exp_bivector_closed which handles all
three signature regimes (elliptic, hyperbolic, parabolic).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
CliffordAlgebra instance. |
required |
b
|
Tensor
|
Simple bivector [..., dim]. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Rotor exp(b) [..., dim]. |
Source code in core/decomposition.py
exp_decomposed(algebra, b, use_decomposition=True, k=None, threshold=1e-06, max_iterations=100)
¶
Exponentiate a bivector via decomposition into simple components.
When use_decomposition is True the bivector is decomposed into
simple blades (via differentiable_invariant_decomposition), each
is exponentiated in closed form, and the rotors are composed via
geometric product.
During training the power iteration loop is detached (run in forward-only mode) so that gradients do not flow through the normalization divisions. Gradients instead flow through the closed-form exp of each component and the final GP composition. This is stable for all bivector magnitudes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
CliffordAlgebra instance. |
required |
b
|
Tensor
|
Bivector [..., dim]. |
required |
use_decomposition
|
bool
|
Enable decomposition (False -> |
True
|
k
|
Optional[int]
|
Number of simple components (auto if None). |
None
|
threshold
|
float
|
Convergence threshold. |
1e-06
|
max_iterations
|
int
|
Power iteration cap. |
100
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Rotor exp(b) [..., dim]. |
Source code in core/decomposition.py
Signature Search¶
MetricSearch
¶
Learns optimal (p, q, r) signature via GBN probe training and bivector energy analysis.
Trains small single-rotor GBN probes on conformally-lifted data using coherence + curvature as the loss. After training, reads the learned bivector energy distribution to infer the optimal signature.
Multiple probes with biased initialization combat local minima.
Source code in core/search.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
__init__(device='cpu', num_probes=6, probe_epochs=80, probe_lr=0.005, probe_channels=4, k=8, energy_threshold=0.05, curvature_weight=0.3, sparsity_weight=0.01, max_workers=None, micro_batch_size=None, early_stop_patience=0)
¶
Initialize Metric Search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str
|
Computation device. |
'cpu'
|
num_probes
|
int
|
Number of parallel probes to train. |
6
|
probe_epochs
|
int
|
Epochs per probe training. |
80
|
probe_lr
|
float
|
Learning rate for probes. |
0.005
|
probe_channels
|
int
|
Channels in probe models. |
4
|
k
|
int
|
Nearest neighbors for flow analysis. |
8
|
energy_threshold
|
float
|
Energy cutoff for active base vectors. |
0.05
|
curvature_weight
|
float
|
Curvature penalty in probe loss. |
0.3
|
sparsity_weight
|
float
|
Sparsity penalty in probe loss. |
0.01
|
max_workers
|
int
|
Max threads for parallel training. |
None
|
micro_batch_size
|
int
|
If set, train probes on random micro-batches of this size each epoch instead of full data. |
None
|
early_stop_patience
|
int
|
Stop probe training if best loss has not improved for this many epochs. 0 disables early stopping. |
0
|
Source code in core/search.py
search(data)
¶
Returns optimal (p, q, r) signature for the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Input data [N, D]. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int, int]
|
Tuple[int, int, int]: Optimal signature (p, q, r). |
Source code in core/search.py
search_detailed(data)
¶
Returns signature and full diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Input data [N, D]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Diagnostics with 'signature', 'coherence', 'curvature', 'energy_breakdown', 'per_probe_results'. |
Source code in core/search.py
GeodesicFlow
¶
Geodesic flow analysis in Clifford algebra.
Interprets data points as grade-1 multivectors and computes the flow field - a bivector at each point that encodes the direction of shortest algebraic paths to its k-nearest neighbours.
The flow is computed as the mean of connection bivectors:
B_ij = <x_i . ~x_j>_2 (grade-2 part of the geometric product)
This bivector encodes the rotational "turn" needed to map x_i toward x_j, analogous to the parallel transport connection on a Lie group.
The coherence and curvature of this field reveal whether the data has causal (directional) structure:
- High coherence, low curvature -> the flow is smooth and aligned in one direction. Causality is visible.
- Low coherence, high curvature -> the flow is fragmented and collides with itself. The signal is dominated by noise.
Source code in core/search.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |
__init__(algebra, k=8)
¶
Initialize Geodesic Flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algebra
|
CliffordAlgebra
|
The algebra instance. |
required |
k
|
int
|
Number of nearest neighbours for the flow field. |
8
|
Source code in core/search.py
flow_bivectors(mv)
¶
Computes the mean flow bivector at each data point.
For each point x_i, aggregates the unit connection bivectors to its k-nearest neighbours:
B_i = mean_j { unit( <x_i . ~x_j>_2 ) }
.. note::
For perfectly symmetric data (e.g. a closed circle) the mean
cancels to zero - which is geometrically correct since there is
no preferred flow direction. Use :meth:coherence to measure
structure without this cancellation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: |
Source code in core/search.py
coherence(mv)
¶
Measures concentration of connection bivectors within each neighbourhood.
For each point, computes the mean absolute cosine similarity between all pairs of its k connection bivectors. This captures how consistently the neighbourhood connections lie on the same rotation plane.
- 1.0: all connections at every point are parallel or anti-parallel (maximally structured).
- 1/num_bivectors (~= baseline): connections point in random directions.
.. note:: In Cl(2,0) the grade-2 space is 1-dimensional (only e_12), so coherence is trivially 1.0 for any data - use at least Cl(3,0) for meaningful discrimination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Coherence score in [0, 1]. |
Source code in core/search.py
curvature(mv)
¶
Measures how much connection structure changes across the manifold.
Computes the mean dissimilarity of connection bivectors between neighbouring pairs of points:
dissimilarity(i, j) = 1 - mean_abs_cos( {B_ia}, {B_jb} )
where {B_ia} is the set of k unit connection bivectors at point i and {B_jb} at point j, and mean_abs_cos is the cross-set absolute cosine similarity.
- 0.0: all neighbouring points have the same connection structure (flat geodesics, smooth manifold).
- High: the connection direction changes rapidly between neighbours (high curvature, fragmented flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mv
|
Tensor
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Curvature score in [0, 1]. |
Source code in core/search.py
interpolate(a, b, steps=10)
¶
Interpolates along the geodesic from a to b.
Uses the Lie group exponential map on the transition element:
T = a_inv . b
log(T) ~= <T - 1>_2 (grade-2 approximation for small angles)
gamma(t) = a . exp(t . log(T))
Exact when a and b are close; a first-order approximation otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Tensor
|
Start multivector |
required |
b
|
Tensor
|
End multivector |
required |
steps
|
int
|
Number of interpolation steps (including endpoints). |
10
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: |
Source code in core/search.py
causal_report(data)
¶
Full geodesic flow analysis with a causal interpretation.
Embeds data, computes coherence and curvature, and returns a human-readable verdict:
- Causal: coherence > 0.5 and curvature < 0.5 -> flow is smooth and aligned in one direction.
- Noisy: otherwise -> flow is fragmented and collides with itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
report with keys |
Source code in core/search.py
DimensionLifter
¶
Tests whether lifting data to a higher-dimensional algebra reveals structure.
The hypothesis: data living on an n-dimensional manifold may possess latent structure that only becomes visible in Cl(n+1, q) or Cl(n, q+1).
Lifting appends extra coordinates to the grade-1 embedding:
- Positive lift
Cl(p, q) -> Cl(p+1, q): adds a spacelike dimension. The extra coordinate is set to 1 (projective / homogeneous lift). - Null lift
Cl(p, q) -> Cl(p, q+1): adds a timelike dimension. The extra coordinate is set to 0 (null vector lift for conformal-like embeddings).
After lifting, geodesic flow coherence is re-measured. An improvement indicates that the extra dimension captures hidden geometric structure.
Source code in core/search.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
__init__(device='cpu')
¶
Initialize Dimension Lifter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str
|
Computation device. |
'cpu'
|
lift(data, target_algebra, fill=1.0)
¶
Lifts data into the grade-1 subspace of a higher-dimensional algebra.
Pads each data vector with fill values in the new dimensions,
then embeds as a grade-1 multivector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
|
required |
target_algebra
|
CliffordAlgebra
|
Target algebra with n >= d. |
required |
fill
|
float
|
Coordinate value for the new dimensions. Use 1.0 for a projective (homogeneous) lift, 0.0 for a null-vector (conformal) lift. |
1.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: |
Source code in core/search.py
test(data, p, q, k=8)
¶
Compares geodesic flow coherence before and after dimension lifting.
Tests three algebras in parallel:
- Original Cl(p, q): baseline coherence and curvature.
- Positive lift Cl(p+1, q): spacelike extra dimension, fill=1.
- Null lift Cl(p, q+1): timelike extra dimension, fill=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
|
required |
p
|
int
|
Original positive signature. |
required |
q
|
int
|
Original negative signature. |
required |
k
|
int
|
Nearest neighbours for geodesic flow. |
8
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
results with keys |
Source code in core/search.py
format_report(results)
¶
Renders a lifting test result as a human-readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Dict
|
Output of :meth: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Multi-line report. |