Geometric algebra: Difference between revisions
rewriting. Back to verifying axioms.
m (J: with all the contradictions in the verbiage, who knows what's better or not...) |
(rewriting. Back to verifying axioms.) |
||
Line 11:
</math>
The product operation in
There are a few simple examples of geometric algebras. A trivial one for instance is simply <math>\R</math>, where <math>\mathcal{V} = \R</math>. The complex numbers also form a geometric algebra, where the vector space is the one-dimensional space of all purely imaginary numbers. An other example is the space of [[Quaternion type|quaternions]], where the vector space is the three-dimensional space of all linear combinations of <math>(i, j, k)</math>.
The purpose of this task is to implement a geometric algebra with a vector space <math>\mathcal{V}</math> of dimension ''n'' of at least five, but for extra-credit you can implement a version with ''n'' arbitrary large. Using a dimension five is useful as it is the dimension required for the so-called ''conformal model'' which will be the subject of a derived task.
To ensure the unicity of the solution (that is, up to some isomorphism), we will also restrict ourselves to the so-called euclidean case, where the square of a non-zero vector is positive:
<math>\forall\mathbf{x}\in\mathcal{V},\, \mathbf{x}\neq 0 \implies\mathbf{x}^2 > 0</math>.
You can of course, for extra credit, implement the general case. This would require the definition of a parameter for the ''signature'' of the metric.
In order to show that your solution uses a vector space of dimension at least five, you will create a function <tt>n -> e(n)</tt> such that the vectors <tt>e(0), e(1), e(2), e(3), e(4)</tt> are linearly independent. To do so you will make them orthonormal with the following [[wp:scalar product|scalar product]]:
<math>\mathbf{x}\cdot\mathbf{y} = (\mathbf{x}\mathbf{y} + \mathbf{y}\mathbf{x})/2</math>
The fact that this so-called ''inner product'' defines a scalar product is a consequence of the fourth axiom. To see it one just needs to notice the relation:
<math>\mathbf{x}\mathbf{y} + \mathbf{y}\mathbf{x} = (\mathbf{x} + \mathbf{y})^2 - \mathbf{x}^2 - \mathbf{y}^2</math>
Once you'll have shown that your vector space is at least of dimension five, you will show that the axioms are satisfied. For this purpose you will pick three random multivectors ''a'', ''b'' and ''c'', along with a random vector <math>\mathbf{x}</math>.
Producing a random vector is easy. Just use a pseudo-random generation function <tt>rand</tt> and create a vector:
<math>\mathrm{randomVector}() = \sum_{i=0}^4 \mathrm{rand}() \mathbf{e}_i</math>
Producing a random multivector is slightly more involved. It is known that when the dimension of <math>\mathcal{V}</math> is ''n'', then the dimension of the algebra (seen as a vector space with its natural scalar multiplication) is 2<sup>n</sup>. This means that for n=5 there is a basis of 2<sup>5</sup> = 32 basis multivectors from which any multivector can be written as a linear combination. Create such a basis <math>m_0, m_1,\ldots,m_{31}</math> along with a function producting a random multivector:
<math>\mathrm{randomMultivector}() = \sum_{i=0}^{31} \mathrm{rand}() m_i</math>
To summarize, to solve this task you will:
* define the inner product of two vectors : <math>\mathbf{x}\cdot\mathbf{y} = (\mathbf{xy} + \mathbf{yx})/2</math>.
* define the function <tt>e</tt>
* verify the orthonormality <math>\mathbf{e}_i\cdot\mathbf{e}_j = \delta_{i,j}</math> for i, j in <math>\{0, 1, 2, 3, 4\}</math>.
* create a function returning a random multivector
* create a function returning a random vector
* verify the axioms for three rarndom multivectors ''a'', ''b'', ''c'' and a random vector '''x'''.
Optionally, you will repeat the last step a large number of times, in order to increase confidence in the result.
=={{header|EchoLisp}}==
Line 561 ⟶ 573:
<lang perl6>use MultiVector;
use Test;
plan 29;
my @e = map &e, ^5;
for ^5 X ^5 -> ($i, $j) {
my $s = $i == $j ?? 1 !! 0;
ok @e[$i] cdot @e[$j] == $s, "e$i cdot e$j = $s";
}
sub random {
[+] map {
MultiVector.new:
:blades(my Real %{UInt} = $_ => rand.round(.01))
}, (^32).pick(5);
}
my
ok ($a*$b)*$c == $a*($b*$c), 'associativity';
ok $a*($b + $c) == $a*$b + $a*$c, 'left distributivity';
ok ($a + $b)*$c == $a*$c + $b*$c, 'right distributivity';
my @coeff = (.5 - rand) xx 4;
my $v = [+] @coeff Z* map &e, ^4;
ok ($v**2).narrow ~~ Real, 'contraction';</lang>
{{out}}
<pre>1..
ok 1 - e0 cdot e0 = 1
ok 2 - e0 cdot e1 = 0
ok 3 - e0 cdot e2 = 0
ok 4 - e0 cdot e3 = 0
ok 5 - e0 cdot e4 = 0
ok 6 - e1 cdot e0 = 0
ok 7 - e1 cdot e1 = 1
ok 8 - e1 cdot e2 = 0
ok 9 - e1 cdot e3 = 0
ok 10 - e1 cdot e4 = 0
ok 11 -
ok 12 -
ok 13 -
ok 14 - e2 cdot e3 = 0
ok 15 - e2 cdot e4 = 0
ok 16 - e3 cdot e0 = 0
ok 17 - e3 cdot e1 = 0
ok 18 - e3 cdot e2 = 0
ok 19 - e3 cdot e3 = 1
ok 20 - e3 cdot e4 = 0
ok 21 - e4 cdot e0 = 0
ok 22 - e4 cdot e1 = 0
ok 23 - e4 cdot e2 = 0
ok 24 - e4 cdot e3 = 0
ok 25 - e4 cdot e4 = 1
ok 26 - associativity
ok 27 - left distributivity
ok 28 - right distributivity
ok 29 - contraction</pre>
|