vermaseren / form

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

Match powers of CFunctions #92

Closed jodavies closed 7 years ago

jodavies commented 8 years ago

Is there any particular reason why one cannot match powers of CFunctions as in

CFunction f;
Symbol x,n;

Local test = f + f^2;

Identify f^n? = x^n;

Print +s;
.end

?

You can of course match numeric powers as in

Identify f^2 = x^2;

say.

tueda commented 8 years ago

I guess: Short answer: Functions are different from symbols. Long answer: Because of different internal data format of functions and symbols, their pattern matchings are implemented differently, although maybe one could implement f^n? also for functions as the same way as symbols. Actually, you can see their internal representations as:

S f;
S x,n;
L F = f + f^2;
P "%r";
.end

which prints

8  1  4  20  1  1  1  3  
8  1  4  20  2  1  1  3 

The first number 8 means the term consists of 8 words. The following 1 4 means symbols with 4 words. So 1 4 20 1 is f and 1 4 20 2 is f^2. The last 3 words are for the coefficient 1/1 whose size is 3 words. On the other hand, for functions,

CF f;
S x,n;
L F = f + f^2;
P "%r";
.end

prints

7  150  3  0  1  1  3  
10  150  3  0  150  3  0  1  1  3  

For the second term, you can see 150 3 0 150 3 0, which is f*f, which is different from how powers of symbols are represented.

vermaseren commented 8 years ago

Hi Josh

Of course there is a reason :-) The powers of Cfunctions are only cosmetic. Internally they are stored as f_f_ff…_f. It is just that the printing routine can figure this out and so can the reading routine. If you say id f^2 = this is translated during execution as id f_f = which is something that can match. f^n? will be translated as (f)^(n?) and such eventuality just does not exist in the pattern matcher. And I am not going to build it either, because there is a workaround: id f = f(1); repeat id f(n1?)*f(n2?) = f(n1+n2); id f(n?) = x^n; or whatever. It would be quite an amount of work to bult this in properly and considering the shortage of manpower I think it is better to spend it on things that have no easy workaround. See for instance the recent addition of the all option in the id statement. That took more than a week, but it is definitely worth it. (see also my talk in Loops and Legs 2016).

OK, maybe this is not the reason you were looking for but at least now you have the whole story. If you would like to implement this yourself, in my eyes the easiest way would be to increase FUNHEAD by one and use the extra space for the power. Then you have to make sure you do not break anything, and then you can add your code. Of course you have to make the Normalize routine such that it indeed collects those powers, modify things like the printing routines, and a few more things. I guess by now you see why I am not hopping up and down to get started. But it would have been nice if I would have realized this from the start.

Cheers

Jos

On 4 mei 2016, at 19:43, jodavies notifications@github.com wrote:

Is there any particular reason why one cannot match powers of CFunctions as in

CFunction f; Symbol x,n;

Local test = f + f^2;

Identify f^n? = x^n;

Print +s; .end ?

You can of course match numeric powers as in

Identify f^2 = x^2; say.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/vermaseren/form/issues/92

jodavies commented 8 years ago

Thanks.

Presumably this could save quite a bit of memory for expressions which contain many high powers of cfunctions... although your workaround, inserted at the right place in the form script, would have the same effect.

This is a task I would consider attempting at the end of the summer (after I have finished my thesis...). Indeed, I was hoping to speak to you at some point (maybe I will visit in the summer?) about contributing to form development.

vermaseren commented 8 years ago

Hi Josh,

That sounds quite nice. Probably we can organize something, but it is better if you finish your thesis first.

Jos

On 4 mei 2016, at 20:27, jodavies notifications@github.com wrote:

Thanks.

Presumably this could save quite a bit of memory for expressions which contain many high powers of cfunctions... although your workaround, inserted at the right place in the form script, would have the same effect.

This is a task I would consider attempting at the end of the summer (after I have finished my thesis...). Indeed, I was hoping to speak to you at some point (maybe I will visit in the summer?) about contributing to form development.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/vermaseren/form/issues/92#issuecomment-216957115