vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
1.14k stars 136 forks source link

Pattern with index and set restriction matches to number #153

Closed benruijl closed 7 years ago

benruijl commented 7 years ago

The following id statement matches even though it shouldn't:

#-
I mu1,mu2,mu3;
CF f;
Set indices:mu1,mu2,mu3;

L F = f(132); * only happens for certain numbers!
id f(mu1?indices) = 1; * matches...

Print +s;
.end
tueda commented 7 years ago

As you may imagine

On code;
I mu1,mu2,mu3;
.end

prints

 Indices
   iarg_(129) mu1(130) mu2(131) mu3(132)
tueda commented 7 years ago

A (silly) workaround is putting

#:constindex 10000
tueda commented 7 years ago

To me, the problem (also in #149) is resolved if we forbid a small number function argument that is not in the range of fixed indices matching with any indices at function.c:1242:

diff --git a/sources/function.c b/sources/function.c
index 7ec75dd..87fc8f0 100644
--- a/sources/function.c
+++ b/sources/function.c
@@ -1239,7 +1239,8 @@ IndAll:                           i = m[1] - WILDOFFSET;
                        else if ( *m == -ARGWILD ) goto ArgAll;
                        else if ( *m == -INDEX && m[1] >= AM.OffsetIndex+WILDOFFSET
                        && m[1] < AM.OffsetIndex+(WILDOFFSET<<1) ) {
-                               if ( *t == -VECTOR || *t == -SNUMBER ) goto IndAll;
+                               if ( *t == -VECTOR ) goto IndAll;
+                               if ( *t == -SNUMBER && t[1] >= 0 && t[1] < AM.OffsetIndex ) goto IndAll;
                                if ( *t == -MINVECTOR ) {
                                        i = m[1] - WILDOFFSET;
                                        AN.argaddress = AT.MinVecArg;

Am I right? I'm still not sure about the fixed indices...

vermaseren commented 7 years ago

Hi Takahiro,

That sounds about right. It is probably just a simple if somewhere in the code. I am a bit too busy with the colors at the moment. There is a nontrivial bug, either in color.h or in FORM. This is far more serious.

Jos

On 28 nov. 2016, at 13:49, Takahiro Ueda notifications@github.com wrote:

To me, the problem (also in #149 https://github.com/vermaseren/form/issues/149) is resolved if we forbid a small number function argument that is not in the range of fixed indices matching with any indices at function.c:1242 https://github.com/vermaseren/form/blob/6fe5632f513100fcabdc4c7fb002609b1bf8efea/sources/function.c#L1242:

diff --git a/sources/function.c b/sources/function.c index 7ec75dd..87fc8f0 100644 --- a/sources/function.c +++ b/sources/function.c @@ -1239,7 +1239,8 @@ IndAll: i = m[1] - WILDOFFSET; else if ( m == -ARGWILD ) goto ArgAll; else if ( m == -INDEX && m[1] >= AM.OffsetIndex+WILDOFFSET && m[1] < AM.OffsetIndex+(WILDOFFSET<<1) ) {

  • if ( t == -VECTOR || t == -SNUMBER ) goto IndAll;
  • if ( *t == -VECTOR ) goto IndAll;
  • if ( t == -SNUMBER && t[1] >= 0 && t[1] < AM.OffsetIndex ) goto IndAll; if ( t == -MINVECTOR ) { i = m[1] - WILDOFFSET; AN.argaddress = AT.MinVecArg; Am I right? I'm still not sure about the fixed indices...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/153#issuecomment-263263281, or mute the thread https://github.com/notifications/unsubscribe-auth/AFLxEpAEEjq_07JGTs64VYynEs4X4C2Sks5rCs3tgaJpZM4K84aJ.

tueda commented 7 years ago

Hi Jos,

OK. I will commit this patch, which fixes at least these cases. We will see if there are more related bugs.