nm

8552 Reputation

19 Badges

12 years, 353 days

MaplePrimes Activity


These are questions asked by nm

Should Maple hangs when one quits a debugger in the middle of debugging session, and there is a call to the same function with a DEBUG break point in it next?

For example

restart;
foo:=proc()
  local x;
  DEBUG();
  x:=x+1
end proc;

And now in the next same execution group, I had

> foo(); #quitting debugger here makes Maple hangs/freeze

  foo();

 

When evaluating the above, the debugger comes up as expected when first call to foo() is made.

When quitting the debugger either by hitting Quit or by hitting the close red X at top right corner, Maple now hangs. I was expecting the debugger to come up again for the second call to foo().  

It seems closing the debugger window like this for some reason is not handled correctly. Even if the user is not supposed to do this, Maple should not just freeze like this.

Nothing I do causes it to unfreeze. Clicking on the ! button does nothing. Only way is to either kill Maple from task manager or close all of Maple if possible and sometimes this does not even work, ending possibly losing work done on other open worksheets.

Maple should be more robust that this. Does this happen on other platforms?

This problem does not happen if the calls were each in a separate execution group in the worksheet. Like this

> foo();

> foo();

Using Maple 2021.2 on windows 10.

I am looking for a robust way to factor an expression (if applicable) to become    x^n*(rest)  as we do it by hand.

edit The input will only be of type `+` and I am looking for a way extract a common factor to convert the input to term^n*(rest) where term is the common factor to pull out.

For example, given  x^2*Y+x and the symbol is given as x  the result will be x*(x*Y+1) and if the input is Y^2*x^3-x^3 then the output is x^3*(Y^2-1) and if there is no common factor x to pull out from all the terms, the output will be the same as the input.

I tried many commands and options, but can't find one method that works all the time for all cases.

For example for   x^2*Y+x  the command factor(x^2*Y+x) gives (Y - 1)*(Y + 1)*x^3 which is not what I want. There is no option to factor to give the name to factor on. And I did not know how to use the last argument of function to do that.

But here simplify(x^2*Y+x) happened to work on this and gives (Y^2 - 1)*x^3 but simplify does not work on first example. simplify(x^2*Y+x) returns the same expression back. So simplify is not reliable to use.

I tried collect, with options factor and simplify. Again, they work on one examples but not others. 

collect(x^2*Y+x,x); does not do it. But collect(Y^2*x^3-x^3,x); works and returns (Y^2 - 1)*x^3 which is what I want.

The problem is that I do not know what the expression looks like. I just know the name and want to find if there is a common to any power that can be pulled out to rewite the expression as x^n*(rest) where is an integer or rational number depending.

This seems like a simple problem. But can't find a Maple command for.   I could ofcourse program it by brute force. Go over each term in the expression, check if each term has a free to any power in it multiplied by something else, then collect all these x^n term in a list. At end find the which is raised to lowest power, and then divide the whole expression by it. 

Here is another way I can also try:  Use factor and also collect and also simplify. One at a time. Each time I check if the result is of type `*` but not a division! (check that denom is 1). If so, Then check if result has two operands only. If so, check if op(1,result) is for form x^anything. If so, then one of these cases worked.  Need to try this now to see if it will work on all cases I have. 

Is there a better way to do this in Maple? It has to work on all expresions f(x) without knowing what the expression looks like.

update

I've updated the test cases and included all algorithms given to compare. It is hard in Maple to make a nice table to present results and keep math formatting below.

restart;
makegrid := proc(M::Matrix)#https://www.mapleprimes.com/questions/202902-How-To-Create-Table-Like-Output-For
  uses DocumentTools:-Layout;
  local i,j,m,n,wks;
  m,n := op(1,M);
  wks := Worksheet(Table(alignment=center,width=20,
                         seq(Column(),j=1..n),
                         seq(Row(seq(Cell(Textfield(sprintf("%a",M[i,j]))),
                                     j=1..n)),i=1..m)));
  DocumentTools:-InsertContent(wks);
end proc:

acer_V1_common_factor := proc(x::algebraic, ee::algebraic)
  local p, d := gcd(ee, x^frontend(degree,[ee,x]),'p');
  d * p;
end proc:

acer_V2_common_factor := proc(x, ee) local d, t;
  if ee::`+` then
    t := max(map(proc(u) local r:=frontend(degree,[u,x]);
                         `if`(r::numeric,r,0); end proc,[op(ee)]));
    d := gcd(numer(ee),x^t);
    d*map(u->u/d,ee);
  else ee; end if;
end proc:

dharr_common_factor:=proc(x,z)
  local xn:=x^ldegree(collect(z,x),x);
  if rem(z,xn,x)=0 then xn*quo(z,xn,x) else z end if;
end proc:

me_common_factor:=proc(term,expr)
local tmp;
local T1;

local update_T1:=proc()
T1:= hastype(op(1,tmp),identical(term)^anything) or hastype(op(1,tmp),identical(term));
if not T1 then
   T1:= hastype(op(2,tmp),identical(term)^anything) or hastype(op(2,tmp),identical(term));
fi;
end proc;

if type(expr,`*`) or not has(expr,term) then 
   return expr;
fi;

tmp := collect(expr,term);       
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
   update_T1();
   if T1 then
       return tmp;
   fi;
fi;

tmp :=factor(expr);
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
    update_T1();
    if T1 then
      return tmp;
    fi;
fi;

tmp := simplify(expr);
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
    update_T1();
    if T1 then              
      return tmp;
    fi;
fi;

return expr;
end proc:
############################

test_data:=[[x,x^2*Y+x],
[x,Y^2*x^3-x^3],
[x,x],
[x,x+2*x^2],
[x,x^4*diff(y(x),x)+x^7],
[x,x^4*diff(y(x),x)+x^7-sin(x)],
[y(x),y(x)^4*diff(y(x),x$2)^2*diff(y(x),x)+y(x)^2*diff(y(x),x)+y(x)],
[y(x),y(x)^4*diff(y(x),x$2)^2+y(x)^2*diff(y(x),x)+y(x)^9],
[x,x^4*y^2+x^2*y^2],
[y(x),y(x)^4*diff(y(x),x)^2+y(x)^2*diff(y(x),x)^2],
[diff(y(x),x),y(x)^4*diff(y(x),x)^2+y(x)^2*diff(y(x),x)^2],
[diff(y(x),x),y(x)*diff(y(x),x$2)^2*diff(y(x),x)*sin(x)+diff(y(x),x)^3],
[y(x),diff(y(x),x)-(1+x^(1/2))/(1+y(x)^(1/2))],
[y(x),diff(y(x),x) -(x-1)*y(x)^5/x^2/(-y(x)+2*y(x)^3)],
[y(x),3*y(x)+diff(y(x),x) - 2*x/exp(3*x)],
[x,3*x^2*y^3+7*x/y],
[y,A-(1+x)/(1+y^(1/2))]
]:
RESULT:=Matrix(nops(test_data),6);
for N,item in test_data do
    term:=item[1];
    expr:=item[2];
    RESULT[N,1]:=term; RESULT[N,2]:=expr;
    try
        result:=acer_V1_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,3]:=expr;#bypass, not correct output
        else
           RESULT[N,3]:=result;#accept
        fi;  
    catch:
        RESULT[N,3]:=expr;#reject
    end try;      

    try
        result:=acer_V2_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,4]:=expr;#bypass, not correct output
        else
           RESULT[N,4]:=result;#accept
        fi;  
    catch:
        RESULT[N,4]:=expr;#reject
    end try;      

    try
        result:=dharr_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,5]:=expr;#bypass, not correct output
        else
           RESULT[N,5]:=result;#accept
        fi;  
    catch:
        RESULT[N,5]:=expr;#reject
    end try;      


    try
        result:=me_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,6]:=expr;#bypass, not correct output
        else
           RESULT[N,6]:=result;#accept
        fi;  
    catch:
        RESULT[N,6]:=expr;#reject
    end try;      

od:

RESULT

how_to_do_special_factor.mw

Mapleprime will not let let insert content for some reason. Here is the output as screen shot but it is hard to read. But it is in the above worksheet.

help under object it says  (in Maple 2021)

The above has not been true for almost a year. Since in Maple 2021 one can do o:-m() 

person_class :=module()
  option object;
  export m:=proc(_self,$)
      print("you called me");
  end proc;
end module;

o:=Object(person_class);
o:-m()

            person_class := Object<<1758956556512>>
                  o := Object<<1758955674784>>
                        "you called me"

I hope this gets updated in Version 2022,  with examples also. The notation o:-method() is hidden in help and could not even find it, but it is meantioned in some pdf file which I lost track of at this moment. 

On another help page titled Overview of Object Methods it briefly mentions alternative call but the link that is supposed to explain it does not work. (clicking on it, produces nothing. Stays on same page). I guess no one tried this link before shipping Maple. 

Is this link somewhere to access directly in the help page?

I have not used Array much before. I made an array that has 3 elements, starting index is 0 and last index is 2.

I want each element in the array to be an empty list, so I can later add to it.  (since I do not know in advanced what size of list I need in each slot of the Array).

Array(0..2,[seq([],i=0..2)])

And this works in the code I am using. But the strange thing, each time I try to save the worksheet, I get Warning about saving Large calculation.

What large caclulation? The array is empty?

Even though the code is working, and I can add to each entry in the array lists OK and been using it OK, I think may be I am not doing something right.

How to correctly creat an Array from 0..N  and initialized each entry to empty list?

Maple 2021.2

When doing

item:=x;
res:=remove(has,item,x);

Maple returns, as expected

But when item is not a single symbol, say sin(x) or diff(y(x),x), then it no longer returns ()

item:=diff(y(x),x);
res:=remove(has,item,diff(y(x),x));

It does not return () but it now returns the input itself, as if it was not removed.

Why is that, and how to make it return () also on composite expression?  I tried flatten and inplace option. Otherwise, I will have to do a special test before. 

The strange thing is that it works on 

item:=2*diff(y(x),x);
res:=remove(has,item,diff(y(x),x));

Now it returns as expected. So now it did remove diff(y(x),x). But it does not remove it when it is on its own. I assume this is by design. But it is not intuitive to the user. One would expect it to work same way on removing `x` or `sin(x)` or `diff(y(x),x)`

First 42 43 44 45 46 47 48 Last Page 44 of 164