Kumar
Kumar

Reputation: 87

make sub-expressions based on addition(+) operator MAPLE

Arbitrary expression be

test := a*b*c+x+a*y+c*z;

output := SomeCommand(test, `+`);
output
      [a*b*c,x,a*y,c*z];

Is there any command to do it as a expression.

I did this by converting it into string and using StringSplit command. converting each element from list to expression and in for loop.

test := convert(test, string)
with(StringTools):
output:=StringSplit(test, "+")
     ["a*b*c", "a*y", "c*z", "x"]
InertForm:-Parse(output[1])

value(output[1])
    a*b*c

but, My interest is to get this done as a expression. is there any possibility??

Upvotes: 1

Views: 78

Answers (1)

acer
acer

Reputation: 7246

You're question has input but no output. You should observe that the expression that you've assigned to test may have its addends stored in a different order from which they are typed in the input.

It is possible to pick off the addends of a sum, and put them in a list. The very simple code for this is below.

The order in which the addends appear in the list match the order in which they are stored internally.

restart;

f := proc(expr)
   if type(expr, `+`) then
      [op(expr)];
   else
      expr;
   end if;
end proc:

test := a*b*c+x+a*y+c*z;

             test := a b c + a y + c z + x

f( test );
                  [a b c, a y, c z, x]

Are you the same fellow who's asked all these (somewhat related) questions? Or taking the same course? Q1 Q2 Q3 Q4 If so then could you just tell use what you're really trying to accomplish?

Upvotes: 2

Related Questions