Skip to content

Commit ac75274

Browse files
committed
Additional duality check, minor docs improvement
1 parent 0a08d05 commit ac75274

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ where
293293
}
294294
}
295295

296-
///Exponent of a multivector computed using Taylor series.
296+
/// Exponent of a multivector computed using Taylor series.
297297
pub fn exp(&self) -> Self
298298
where
299299
T: Norm + From<f64>,
@@ -376,7 +376,7 @@ where
376376
ret
377377
}
378378

379-
/// Hodge dual of a multivector, signature-agnostic.
379+
/// Hodge dual of a multivector.
380380
///
381381
/// For any k-blade, `b.dual() * b` is a pseudoscalar.
382382
pub fn dual(&self) -> Self {
@@ -394,7 +394,7 @@ where
394394
ret
395395
}
396396

397-
/// Hodge dual of a multivector, signature-agnostic.
397+
/// Alternative Hodge dual of a multivector, such that `a.dual().undual() == a` for any `a`.
398398
///
399399
/// For any k-blade, `b * b.undual()` is a pseudoscalar.
400400
pub fn undual(&self) -> Self {

tests/unit.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,22 @@ fn dual_test() {
503503
);
504504
assert_eq!((&t + &x), (&t + &x).dual().undual());
505505
assert_eq!((&t + &x), (&t + &x).undual().dual());
506+
507+
// Check consistency with Grassmann.jl (up to a sign)
508+
declare_algebra!(TestA, [+,+,+,-,-,0,0]);
509+
let e = TestA::basis::<f32>();
510+
let [v1, v2, v3, v4, v5, v6, v7] = &e;
511+
let a = -v3 * 5. + v1 * v5 * v6 - v1 * v4 * v6 * v7
512+
+ v2 * v3 * v6 * v7
513+
+ v2 * v4 * v5 * v6 * v7 * 4.
514+
+ v1 * v2 * v3 * v4 * v5 * v6 * 2.;
515+
println!("{}", a.dual());
516+
let expected = -(v7 * 2. - v1 * v3 * 4. + v1 * v4 * v5 - v2 * v3 * v5 + v2 * v3 * v4 * v7
517+
- v1 * v2 * v4 * v5 * v6 * v7 * 5.);
518+
println!("{}", expected);
519+
assert_eq!(a.dual(), expected);
520+
assert_eq!(a.undual().dual(), a);
521+
assert_eq!(a, expected.undual());
506522
}
507523

508524
#[test]

0 commit comments

Comments
 (0)