nm

11353 Reputation

20 Badges

13 years, 15 days

MaplePrimes Activity


These are questions asked by nm

I have my code in mla. Using try/catch, I am able to capture an error that happend deep in some call chain. But it is hard to know the exact location where this error happened.

I use StringTools:-FormatMessage( lastexception[2..-1] inside the catch clause to print the exception. But this only prints the message. It does not tell me exactly which line/function/module this happened.

Is there a way to display these information?  Using debugger and stoperror all did not help at all. It does not stop at the line where the error happened. not sure why. I tried it many times. may be I am not using it correctly?

Is it possible to display may be the trace of the calls inside the catch of the try? To know the actual statement that generated the error? Now each time I get an exception, I have to step into the debugger line by line until  I get to the place where the error was which is time consuming. Here is a MWE

 

restart;
A:=module()  
  local B:=module()
     export foo:=proc(n)
         1/n;
     end proc;
  end module;

  export main:=proc()
    try
       B:-foo(0);
    catch:
      print("error happened", StringTools:-FormatMessage( lastexception[2..-1] ));
    end try;
  end proc;

end module;

And now

    A:-main()

                "error happened", "numeric exception: division by zero"

I'd like to get more information than the above as I said. Line number/proc name/module name or stacktrace showing the calls made up to where the exception started (similar to output from where command in debugger).

The above was done in worksheet. My actual code in inside .mla build from lots of .mpl files.

Maple 2021.2 on windows

Here is short description of the problem with code MWE below.

Short version of the question

I want to change

parent:=module()
  local foo:=proc()
     NULL;
  end proc;

  local child:=module()    
     export boo:=proc()
        foo(); #call works as is
     end proc;
  end module;

end module;

To

parent:=module()
  local foo:=proc()
     NULL;
  end proc;

  local child:=module()    
     export boo:=proc()

         #now call no longer works. Maple wants foo exported
         #I want to add parent:- to the call to remind me where foo((
         #lives but do not want to make foo() in parent exported

         parent:-foo();

     end proc;
  end module;
end module;

Longer version of the question

I have a parent module with one child local module inside it. In the child module, there is a proc which wants to call parent's local proc named foo().

As is, the child module can just call the parent's local proc foo() by typing foo() without the need to do parent:-foo() this is because child module has access to parent local proc's and maple knows which foo() by searching the scope from bottom up.

The problem comes when I added a proc also called foo() (by mistake) in the child module without noticing there is one with same name in the parent's.

Now the call foo() will end up calling the child's module foo() and not the parent's foo() becuase that is the "closest" one with this name in the scope. All of this makes sense so far.

The problem comes when the child module wants to really call the parent's foo().

One solution is to change the call to parent:-foo() to explicitly says which foo() to call.

This however now fail, since the parent foo() is local ! And Maple when it sees call to parent:-foo() it now insist it be exported proc (even though the call is being made from inside, i.e. from the child).

I do not want to make the parent's foo() exported just so the child can call it.  I want to keep parent's foo() local, as it is meant to be used only inside the parent and by its children.

You might ask, why not then change the name of the child's foo() to some other name so it does not clash with the parent's local proc name. Yes, I can do this. But for large modules in different files with many procs(), there is a always a chance  a local proc can be added by mistake with happend to be the same name as one in the parent and having to manually keep checking names does not look like the right solution.

My question is: How can a child module call parent's local proc() explicitly, but without making the parent proc exported?  Is there is different syntax to use?

Here is a MWE

 

restart;
parent:=module()

  export main:=proc()
     child:-boo();
  end proc;

  local foo:=proc()
     print("in parent:-foo() proc");
  end proc;

  local child:=module()     
     export boo:=proc()
        print("in child:-boo() proc");
        foo(); #this works. It called parent's local foo()
     end proc;
  end module;

end module;

Now doing parent:-main() works as expected. Notice parent's foo is local to parent module.

Now I changed the child module and did this

parent:=module()

  export main:=proc()
     child:-boo();
  end proc;

  local foo:=proc()
     print("in parent:-foo() proc");
  end proc;

  local child:=module()
     local foo:=proc() #added this using same name by mistake
        print("in child:-boo()");
     end proc;

     export boo:=proc()
        print("in child:-boo() proc");
        foo(); #now this calls the child's foo() ofcourse. But it was meant to call the parents's
     end proc;
  end module;

end module;

The fix is to change the call from the child to becomes    parent:-foo() but now Maple will give an error saying parent does not export foo().

Since the child have access to parent's local proc's, is there a different way to tell Maple I want to call parent's foo() and not my own foo() without making parent's foo() exported? 

For example , in Python one call call parent's method expliclity using super().foo() 

Maple 2021.2

I have code which in module which does this

           DEtools:-kovacicsols(ode,func)

Where ode is some ode and func is y(x).  When I step in the debugger, I get exception at this. It says

       DBG> DEtools:-kovacicsols(ode,func)
       Error, `DEtools` does not evaluate to a module

Same exact code works OK from worksheet as expected.   SO for some reason, inside this module it does not see DEtools and I have no idea why.

Then I tried with :-  before DEtools, but this did not help. it gives

DBG> :-DEtools:-kovacicsols(ode,func)
Error, `table([(dperiodic_sols)=proc () `DEtools/init`() <> 0; `ODEtools/intfactor`(_passed); end etc...
` does not evaluate to a module

In a worksheet, it all works OK

ode:=diff(diff(y(x),x),x) = (-3/16/x^2-2/9/(x-1)^2+3/16/x/(x-1))*y(x);
func:=y(x);
DEtools:-kovacicsols(ode,func)

Gives the solution with no error.

Any suggestion what could be the cause and what to try next? I never seen anything like this. I am running this code using 

interface(warnlevel=4);
kernelopts('assertlevel'=2):

I am able to make a MWE. It seems this always happens in the debugger.  But if  I let it run, it works somehow. Only when I try to step into it, it gives error. Here is MWE

interface(warnlevel=4);
kernelopts('assertlevel'=2):
foo:=proc(ode,func)
   local result;
    DEBUG();   
    result:=DEtools:-kovacicsols(ode,func);
    return result;
  end proc;

And now

ode:=diff(diff(y(x),x),x) = (-3/16/x^2-2/9/(x-1)^2+3/16/x/(x-1))*y(x);
func:=y(x);
foo(ode,y(x))

Now in the debugger if I do DEtools:-kovacicsols(ode,func) or if I stepin the call, I get the error. But I hit the continue botton, I do not get the error and it gives solution. 

Why this happens?

Maple 2021.2 on windows 10

Why int gives this error? Is this a known problem?

Update

fyi, This is reported to Maplesoft.

Here is updated worksheet. The int() command does not generate the error the second time it used, but generates the error the very first time used. Hopefully will be fixed in 2022 Maple.
 

interface(version);

`Standard Worksheet Interface, Maple 2021.2, Windows 10, November 23 2021 Build ID 1576349`

restart;

Example 1

 

expr:=(7*x - 3 + sqrt(x^2 + (x^3*(x - 1)^2)^(1/3) - x) + sqrt(-2*((-x^2 + x + (x^3*(x - 1)^2)^(1/3)/2)*sqrt(x^2 + (x^3*(x - 1)^2)^(1/3) - x) + x^2*(x - 1))/sqrt(x^2 + (x^3*(x - 1)^2)^(1/3) - x)))/(12*x*(x - 1));

(1/12)*(7*x-3+(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2)+(-2*((-x^2+x+(1/2)*(x^3*(x-1)^2)^(1/3))*(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2)+x^2*(x-1))/(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2))^(1/2))/(x*(x-1))

int(expr,x)

Error, (in IntegrationTools:-Indefinite:-AlgebraicFunction) invalid argument for sign, lcoeff or tcoeff

int(expr,x)

int((1/12)*(7*x-3+(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2)+(-2*((-x^2+x+(1/2)*(x^3*(x-1)^2)^(1/3))*(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2)+x^2*(x-1))/(x^2+(x^3*(x-1)^2)^(1/3)-x)^(1/2))^(1/2))/(x*(x-1)), x)


 

Download int_problem_feb_13_2022.mw

I need to use convert of complex exponentials to trig, but only to convert exp(I*x) to cos/sin using Euler formula.

The problem is that, since this is done in code without looking at what is inside the exp(), Maple will also convert non complex exponentials as exp(x) to hyperpolic trig which I do not want.  An example will make this clear

For an example, given exp(3*I*x - x)  and applying convert/trig to this it gives 

             (cosh(x) - sinh(x))*(cos(3*x) + sin(3*x)*I)                       --(1)

But I only want to conver the exp(3*I*x) part of the of the above to obtain

          exp(-x) *  (cos(3*x) + sin(3*x)*I)                          ---(2)

I can break  exp(3*I*x - x) first using expand command and obtain  exp(-x) exp(3*I*x) and then parse this and filter out the complex exponentials (may be using select with has I) and then use convert on those terms only leaving the non-complex exponentials alone. But this gets messy for more complex exponentials.

Is there an easy way to tell Maple  to convert expression of the form exp(I*f(x) + g(x)) to trig but only to sin/cos, hence leaving the exp( g(x) ) as a factor? I looked at help but see nothing there so far.

Maple 2021.2

First 73 74 75 76 77 78 79 Last Page 75 of 199