Skip to content

Commit 8abec49

Browse files
committed
Fix sign error for wildcard powers of dotproducts involving negative vectors
Fixes #544
1 parent 4cb5be4 commit 8abec49

File tree

2 files changed

+115
-2
lines changed

2 files changed

+115
-2
lines changed

check/fixes.frm

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,91 @@ P F;
30483048
assert succeeded?
30493049
assert result("F") =~ expr("0")
30503050
*--#] Issue525 :
3051+
*--#[ Issue544 :
3052+
#-
3053+
Off Statistics;
3054+
3055+
Symbol x;
3056+
Vector D,p,q;
3057+
CFunction tag;
3058+
CFunction f,g,h,i,j,k,l,m;
3059+
CFunction F,G,H,I,J,K,L,M;
3060+
3061+
#define N "3"
3062+
3063+
Local test =
3064+
#do i = -`N',`N'
3065+
+ f(p,`i')
3066+
+ f(-q,`i')
3067+
+ f(p,q,`i')
3068+
+ f(-p,q,`i')
3069+
+ f(p,-q,`i')
3070+
+ f(-p,-q,`i')
3071+
#enddo
3072+
;
3073+
3074+
* Use tags to make sure the cancellation is unique
3075+
Identify f(?a) =
3076+
+ (f(?a) - F(?a)) * tag(f,?a)
3077+
+ (g(?a) - G(?a)) * tag(g,?a)
3078+
+ (h(?a) - H(?a)) * tag(h,?a)
3079+
+ (i(?a) - I(?a)) * tag(i,?a)
3080+
+ (j(?a) - J(?a)) * tag(j,?a)
3081+
+ (k(?a) - K(?a)) * tag(k,?a)
3082+
+ (l(?a) - L(?a)) * tag(l,?a)
3083+
+ (m(?a) - M(?a)) * tag(m,?a)
3084+
;
3085+
.sort
3086+
3087+
Identify f(p?,x?) = D.p^x;
3088+
Identify f(p?,q?,x?) = p.q^x;
3089+
Identify g(p?,x?) = D.p^-x;
3090+
Identify g(p?,q?,x?) = p.q^-x;
3091+
3092+
Identify h(p?,x?) = (D.p)^x;
3093+
Identify h(p?,q?,x?) = (p.q)^x;
3094+
Identify i(p?,x?) = D.p^(x);
3095+
Identify i(p?,q?,x?) = p.q^(x);
3096+
3097+
* And with - signs on the pattern vector:
3098+
Identify j(-p?,x?) = D.p^x;
3099+
Identify j(-p?,-q?,x?) = p.q^x;
3100+
Identify k(-p?,x?) = D.p^-x;
3101+
Identify k(-p?,-q?,x?) = p.q^-x;
3102+
3103+
Identify l(-p?,x?) = (D.p)^x;
3104+
Identify l(-p?,-q?,x?) = (p.q)^x;
3105+
Identify m(-p?,x?) = D.p^(x);
3106+
Identify m(-p?,-q?,x?) = p.q^(x);
3107+
3108+
* Cancel all terms, with no pattern for the power
3109+
#do i = -`N',`N'
3110+
Identify F(p?,`i') = D.p^`i';
3111+
Identify F(p?,q?,`i') = p.q^`i';
3112+
Identify G(p?,`i') = D.p^-`i';
3113+
Identify G(p?,q?,`i') = p.q^-`i';
3114+
3115+
Identify H(p?,`i') = (D.p)^`i';
3116+
Identify H(p?,q?,`i') = (p.q)^`i';
3117+
Identify I(p?,`i') = D.p^(`i');
3118+
Identify I(p?,q?,`i') = p.q^(`i');
3119+
3120+
Identify J(-p?,`i') = D.p^`i';
3121+
Identify J(-p?,-q?,`i') = p.q^`i';
3122+
Identify K(-p?,`i') = D.p^-`i';
3123+
Identify K(-p?,-q?,`i') = p.q^-`i';
3124+
3125+
Identify L(-p?,`i') = (D.p)^`i';
3126+
Identify L(-p?,-q?,`i') = (p.q)^`i';
3127+
Identify M(-p?,`i') = D.p^(`i');
3128+
Identify M(-p?,-q?,`i') = p.q^(`i');
3129+
#enddo
3130+
3131+
Print +s;
3132+
.end
3133+
assert succeeded?
3134+
assert result("test") =~ expr("0")
3135+
*--#] Issue544 :
30513136
*--#[ Issue563 :
30523137
#: SubTermsInSmall 50
30533138

sources/wildcard.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ Seven:;
306306
while ( t < u ) {
307307
*m = *t;
308308
subcount = 0;
309+
/* Process the first vector of the DOTPRODUCT */
309310
for ( si = 0; si < setflag; si += 2 ) {
310311
if ( t == temp + setlist[si] ) goto ss2;
311312
}
@@ -316,7 +317,17 @@ Seven:;
316317
*m = s[3]; dirty = 1; break;
317318
}
318319
if ( *s == VECTOMIN ) {
319-
*m = s[3]; dirty = 1; sgn += t[2]; break;
320+
*m = s[3];
321+
dirty = 1;
322+
if ( ( ABS(t[2]) - 2*MAXPOWER ) < 0 ) {
323+
/* The power is a number */
324+
sgn += t[2];
325+
}
326+
else {
327+
/* The power is a wildcard. Put a -, resolve later. */
328+
sgn++;
329+
}
330+
break;
320331
}
321332
if ( *s == VECTOSUB ) {
322333
*m = s[3]; dirty = 1; subcount = 1; break;
@@ -327,6 +338,7 @@ Seven:;
327338
ss2:
328339
*++m = *++t;
329340
s = subs;
341+
/* Process the second vector of the DOTPRODUCT */
330342
for ( si = 0; si < setflag; si += 2 ) {
331343
if ( t == temp + setlist[si] ) goto ss3;
332344
}
@@ -336,7 +348,17 @@ Seven:;
336348
*m = s[3]; dirty = 1; break;
337349
}
338350
if ( *s == VECTOMIN ) {
339-
*m = s[3]; dirty = 1; sgn += t[1]; break;
351+
*m = s[3];
352+
dirty = 1;
353+
if ( ( ABS(t[1]) - 2*MAXPOWER ) < 0 ) {
354+
/* The power is a number */
355+
sgn += t[1];
356+
}
357+
else {
358+
/* The power is a wildcard. Put a -, resolve later. */
359+
sgn++;
360+
}
361+
break;
340362
}
341363
if ( *s == VECTOSUB ) {
342364
*m = s[3]; dirty = 1; subcount += 2; break;
@@ -345,12 +367,18 @@ Seven:;
345367
s += s[1];
346368
}
347369
ss3: *++m = *++t;
370+
/* Process the power */
348371
if ( ( ABS(*t) - 2*MAXPOWER ) < 0 ) goto RegPow;
349372
s = subs;
350373
for ( j = 0; j < i; j++ ) {
351374
if ( ( ABS(*t) - 2*MAXPOWER ) == s[2] ) {
352375
if ( *s == SYMTONUM ) {
353376
*m = s[3];
377+
/* Since the power is a wildcard, sgn is 0,1,2 depending whether
378+
there were 0,1,2 VECTOMIN in the DOTPRODUCT. Multiply by the
379+
power, which is positive currently. */
380+
sgn *= *m;
381+
/* Now flip the sign of the power, if the wildcard came with a - */
354382
if ( *t < 0 ) *m = -*m;
355383
dirty = 1;
356384
break;

0 commit comments

Comments
 (0)