mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 05:01:24 +00:00
[gatest] Add a commutesWith method to blades
It came about from a discussion in the bivector discord about programmatic testing for blade commutativity and why no texts talked about it. I came up with an idea that turned out not to work (I guess I'd overthought how count_flips works). In the end, I decided to keep it, and simplified metric's sign check.
This commit is contained in:
parent
f0e770b972
commit
c038670114
4 changed files with 55 additions and 8 deletions
|
@ -21,6 +21,8 @@
|
||||||
-(unsigned) mask;
|
-(unsigned) mask;
|
||||||
-(double) scale;
|
-(double) scale;
|
||||||
-(string) name;
|
-(string) name;
|
||||||
|
-(int) commutesWith:(BasisBlade *) b;
|
||||||
|
-(int) commutesWith:(BasisBlade *) b metric:(Metric *)m;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif//__basisblade_h
|
#endif//__basisblade_h
|
||||||
|
|
|
@ -103,4 +103,17 @@
|
||||||
{
|
{
|
||||||
return sprintf ("%g%s", scale, [self name]);
|
return sprintf ("%g%s", scale, [self name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(int) commutesWith:(BasisBlade *) b metric:(Metric *)m
|
||||||
|
{
|
||||||
|
int sign1 = count_flips (mask, b.mask) & 1;
|
||||||
|
int sign2 = count_flips (b.mask, mask) & 1;
|
||||||
|
return sign1 == sign2 || (m && ![m apply:mask, b.mask]);
|
||||||
|
}
|
||||||
|
|
||||||
|
-(int) commutesWith:(BasisBlade *) b
|
||||||
|
{
|
||||||
|
return [self commutesWith: b metric:nil];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -43,6 +43,44 @@ basic_test (void)
|
||||||
// printf ("d: %@\n", d);
|
// printf ("d: %@\n", d);
|
||||||
|
|
||||||
arp_end ();
|
arp_end ();
|
||||||
|
|
||||||
|
arp_start ();
|
||||||
|
{
|
||||||
|
auto ab = [a outerProduct:b];
|
||||||
|
auto ac = [a outerProduct:c];
|
||||||
|
auto ad = [a outerProduct:d];
|
||||||
|
auto bc = [b outerProduct:c];
|
||||||
|
auto bd = [b outerProduct:d];
|
||||||
|
auto cd = [c outerProduct:d];
|
||||||
|
auto abc = [ab outerProduct:c];
|
||||||
|
auto bcd = [bc outerProduct:d];
|
||||||
|
auto cda = [cd outerProduct:a];
|
||||||
|
auto dab = [d outerProduct:ab];
|
||||||
|
auto abcd = [abc outerProduct:d];
|
||||||
|
printf ("a, bcd: %d\n", [a commutesWith:bcd]);
|
||||||
|
printf ("b, bcd: %d\n", [b commutesWith:bcd]);
|
||||||
|
printf ("c, bcd: %d\n", [c commutesWith:bcd]);
|
||||||
|
printf ("d, bcd: %d\n", [d commutesWith:bcd]);
|
||||||
|
printf ("bcd, a: %d\n", [bcd commutesWith:a]);
|
||||||
|
printf ("bcd, b: %d\n", [bcd commutesWith:b]);
|
||||||
|
printf ("bcd, c: %d\n", [bcd commutesWith:c]);
|
||||||
|
printf ("bcd, d: %d\n", [bcd commutesWith:d]);
|
||||||
|
|
||||||
|
printf ("ab, bcd: %d\n", [ab commutesWith:bcd]);
|
||||||
|
printf ("ac, bcd: %d\n", [ac commutesWith:bcd]);
|
||||||
|
printf ("ad, bcd: %d\n", [ad commutesWith:bcd]);
|
||||||
|
printf ("bc, bcd: %d\n", [bc commutesWith:bcd]);
|
||||||
|
printf ("bd, bcd: %d\n", [bd commutesWith:bcd]);
|
||||||
|
printf ("cd, bcd: %d\n", [cd commutesWith:bcd]);
|
||||||
|
|
||||||
|
printf ("ab, bc: %d\n", [ab commutesWith:bc]);
|
||||||
|
printf ("ac, bc: %d\n", [ac commutesWith:bc]);
|
||||||
|
printf ("ad, bc: %d\n", [ad commutesWith:bc]);
|
||||||
|
printf ("bc, bc: %d\n", [bc commutesWith:bc]);
|
||||||
|
printf ("bd, bc: %d\n", [bd commutesWith:bc]);
|
||||||
|
printf ("cd, bc: %d\n", [cd commutesWith:bc]);
|
||||||
|
}
|
||||||
|
arp_end ();
|
||||||
#if 0
|
#if 0
|
||||||
arp_start ();
|
arp_start ();
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "metric.h"
|
#include "metric.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
@implementation Metric
|
@implementation Metric
|
||||||
+(Metric *)R:(int)p, int m, int z
|
+(Metric *)R:(int)p, int m, int z
|
||||||
|
@ -13,14 +14,7 @@
|
||||||
static double
|
static double
|
||||||
count_minus (unsigned minus)
|
count_minus (unsigned minus)
|
||||||
{
|
{
|
||||||
double s = 1;
|
return count_bits (minus) & 1 ? -1 : 1;
|
||||||
while (minus) {
|
|
||||||
if (minus & 1) {
|
|
||||||
s = -s;
|
|
||||||
}
|
|
||||||
minus >>= 1;
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double)apply:(unsigned) a, unsigned b
|
-(double)apply:(unsigned) a, unsigned b
|
||||||
|
|
Loading…
Reference in a new issue