5976 Reputation

17 Badges

9 years, 146 days

MaplePrimes Activity

These are questions asked by nm

I need to check if an expression is polynomial in but with coefficients that are either symbolic, or do not include the complex numebr I.

The problem is that maple considers integers and reals complex also.   

type(1,complex) gives true. so I can't use


Since this gives false. 

I could instead list all the types to be accepted using Or, like this


But I might overlook something if I have to enumerate every type accepted. It is easier to just exclude complex numbers. 

What is the correct way to tell Maple to check if expression is polynomial in where coefficients do not have the complex I in them? It it ok if the coefficient are any other numeric value, or a known Maple constant, or a parameter (symbol). I just want to exclude complex numbers.

I know I could do this

if not has(the_poly,I) then
   print("not allowed");

But I wanted to learn how to make a type which excludes complex numbers.

Maple 2021.1

Given an expressions such as 


I want to use indets to find only the mathematical functions in it, and also symbol but only x symbol in this above. I can do the following to find the mathematical functions and symbols, but I do not know how to tell it to find type symbol which happend to be x. Since x is not a type.

lis:=indets(expr,  Or( And(type_1),  type_2 ))

Which gives

But I really wanted this output

I know I can post process the outout using has or remove, to remove symbol y. But is it possible to do that using indets? something similar to specfunc but specsymbol ? I looked at the help page for Definition of a Structured Type in Maple but do not see anything there so far.

I tried

lis:=indets(expr,  Or( And(type_1),  And(type_2) ))

but it gives same output.



given one equation where both sides are polynomials in one variable x, like this


And we want to solve for the coefficients on the LHS, which are c1,c2,c3.  By hand, this is solved by expanding both sides, and then comparing the coefficient of each power of x. This generates 3 equations (in this example) and then these are solved for c1,c2,c3.

Is there a way to automatically do this in Maple without the user having to do the first manual step of generating the equations needed to solve for c1,c2,c3?



              {c1 = -4, c2 = 3, c3 = 0}

But It will be nice if there is a command in Maple which will do it starting from the first equation. Ofcourse one has to tell Maple what to solve for. PDEtools:-Solve(eq,[c1,c2,c3]); or solve(eq,[c1,c2,c3]) does not work, because Maple does not know it needs to expand and compare coefficients as we do by hand.

It is not hard to write code to generate these equations, but I am asking if there is already a command in Maple which somehow does it automatically. I looked at SolveTools, but did not spot something yet there.


Ok, I think this is easy to do. I found a command


{c1 = -4, c2 = 3, c3 = 0}



There is code at Maple app center  here  called "A Simple Expression Parser" which generates the actual tree structure of an expression. I tested it a little and it seems to work correctly on what I tried so far.

My question if some Graph expert could take the output of the above and generate an actual tree graph from it, to make it easier to see, similar to Mathematica TreeForm command which would make it much more useful.

I will show 2 examples, and the code from the above application and what the final graph should look like,. The code is (formatted a little to make it easier to read)

#code from https://www.maplesoft.com/applications/view.aspx?SID=4808
Op := proc(x) 
    if 1 < nops(x) and not type(x, function) then 
       [whattype(x), op(x)]; 
    elif type(x, function) then 
       [op(0, x), op(x)]; 
end proc;

Parse := proc(expr) 
   local tmp, i; 
   tmp := Op(expr); 
   for i from 2 to nops(tmp) do 
       if 1 < nops(tmp[i]) or type(tmp[i], function) then 
          tmp := subsop(i = Parse(tmp[i]), tmp); 
       end if; 
end proc;

ps. I do not think using name Parse above is good idea, since I see it is an inert form of Maple build in command.

Now, lets look at this

first example 

expr:=sin(x)+x*y + 1/x;

The above says the tree is rooted at `+` with three branches. The first is sin(x), the second is a tree rooted at `*` with two leafs x,y, and the third branch is roots at `^` with two leafs x,-1. Physically it looks like this

Second example

expr := sin(x)*(x + y) + 1/x;

Which physically will look like

So it is possible in theory to make a TreeForm command in Maple, using this Parse() command. May be using Graph package in Maple? by reading the output from the Parse() command, and generating nodes and arcs along the way.

How hard will such a task be? I never used the Maple 's Graph package.  

Could may be  someone may be give this an attempt? I never understood why Maple do not have a build in similar command to TreeForm. It is very useful to understanding expressions.


Why does Maple write





4 5 6 7 8 9 10 Last Page 6 of 120