vermaseren / form

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

Nested bracket #301

Closed gkdgoutam closed 5 years ago

gkdgoutam commented 5 years ago

Hi, not an issue but a small curiosity. I wanted to ask experts if a nested bracket is possible in Form output.

An example is like this:

L exp= (3*CA*CF + 5*CA*CF*zeta2 + 17*zeta3*NF*CF);
b CA,CF,NF;
Print +s exp;

This will give me output

+ CA*CF*( + 3 + 5*zeta2 ) 
+ CF*NF*( + 17*zeta3);

But I was wondering if this is also possible to take zeta bracket in a nested way so that I will have

CA*CF*( 
+ 3
+ zeta2*(5)
)
+ CF*NF*(
+ zeta3*(17)
)

PS. apologies if this is not the right platform to ask.

vermaseren commented 5 years ago

Hi,

I have several times started on an implementation, thinking it would be trivial, but every time I ran into some complications, and due to other activities had to stop it. The internal notation of the terms does allow it though. The bracket separator (separates the parts outside from the part inside) has a space for a bracket level, already from the beginning. The sorting routines can handle it also. The main problems are: syntax (how to declare) and taking the terms apart into their verious levels. Then there is also the problem of selecting the contents of a bracket as in F[x^2] when F is an expression. The syntax for that needs also some thinking. Plus that it becomes rather messy for the bracketindex as well. As you see, at first it looks trivial, but….. My guess is that it would be a project for a couple of days full time, which are hard to find.

Jos

On 24 Nov 2018, at 08:07, gkdgoutam notifications@github.com wrote:

Hi, not an issue but a small curiosity. I wanted to ask experts if a nested bracket is possible in Form output.

An example is like this:

L exp= (3CACF + 5CACFzeta2 + 17zeta3NFCF); b CA,CF,NF; Print +s exp; This will give me output

  • CACF( + 3 + 5*zeta2 )
  • CFNF( + 17*zeta3); But I was wondering if this is also possible to take zeta bracket in a nested way so that I will have

CACF(

  • 3
  • zeta2*(5) )
  • CFNF(
  • zeta3*(17) ) PS. apologies if this is not the right platform to ask.

— 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/301, or mute the thread https://github.com/notifications/unsubscribe-auth/AFLxEtOap1s3_Z1MD9X8nyM6_iVzr0q4ks5uyH-lgaJpZM4YxLc_.

jodavies commented 5 years ago

You can get close to what you want with the following,

Bracket CA,CF,NF,zeta2,zeta3;
.sort                        
Collect dum_;                
Bracket CA,CF,NF;            

maybe with some

If (Count(zeta2,1,zeta3,1)==0) Identify dum_(x?) = x;

to remove the unnecessary brackets.

Thanks, Josh,

vermaseren commented 5 years ago

Yes, I forgot. That was precisely what the function dum_ was made for.

Thanks

Jos

On 25 Nov 2018, at 17:25, jodavies notifications@github.com wrote:

You can get close to what you want with the following,

Bracket CA,CF,NF,zeta2,zeta3; .sort
Collect dum_;
Bracket CA,CF,NF;
maybe with some

If (Count(zeta2,1,zeta3,1)==0) Identify dum_(x?) = x; to remove the unnecessary brackets.

Thanks, Josh,

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

gkdgoutam commented 5 years ago

Thanks. I also wanted to ask one more question related to this. Apart from the format is there anything for output optimisation? Particularly I could not find any easier way if I can print the output in a reverse order than the normal one.

vermaseren commented 5 years ago

Printing the output in reverse form does not exist. There exists however the #reverseinclude that can do reverse reading of the input. Maybe you can make that work for you?

Jos

On 26 Nov 2018, at 02:45, gkdgoutam notifications@github.com wrote:

Thanks. I also wanted to ask one more question related to this. Apart from the format is there anything for output optimisation? Particularly I could not find any easier way if I can print the output in a reverse order than the normal one.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/301#issuecomment-441458308, or mute the thread https://github.com/notifications/unsubscribe-auth/AFLxEm5MzdElkmV-gM35GtWPIrK8e1lEks5uytdGgaJpZM4YxLc_.

gkdgoutam commented 5 years ago

Thanks. I found one which kind of work. On HighFirst or Off LowFirst. I have checked for a test program it works. But for this solution with nested bracket it does not in the sense that if I want constant term to be first and the higher powers of variables it does not work. What it does it writes in ascending order but the constant is put at the last. If I do the opposite it works perfectly. In short I can not bring the constant piece at the very first. Any way I will try to make it work. Thanks anyway.

tueda commented 5 years ago

When I really need to control the term ordering in detail, I would introduce a kind of "dummy" function controlling the ordering and then textually remove it from the output by another scripting language. For example, the following FORM program (test.frm)

S ca,cf,nf;
S z2,...,z5;

L test = (1 + ca + cf + nf)^2 * (1 + z2 +...+ z5)^2;
.sort

* Sort by transcendentality; for simplicity, I don't care about the ordering
* for terms in the same level and just accept what FORM gives me. You can
* introduce a more complicated "order" function with more than one arguments.
S x,n1,n2;
CF order;
multiply order(0);
id z2 = z2 * x^2;
id z3 = z3 * x^3;
id z4 = z4 * x^4;
id z5 = z5 * x^5;
repeat id x^n1?!{0,} * order(n2?) = order(n1+n2);

P +s;
.end

and a sed script (test.sed)

s/\*order(.*)//
s/order(.*)\*//
s/order(.*)/1/

which can be run as

form test.frm | sed -f test.sed

It might be combined with other techniques (Bracket, Collect etc.).

gkdgoutam commented 5 years ago

Thanks. I also had similar plans i.e. multiply by dummy flag and remove those in using shell script. Thanks you.