nm

11378 Reputation

20 Badges

13 years, 43 days

MaplePrimes Activity


These are questions asked by nm

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

On my PC I can't see the plus and minus sign in the quotient expression when using Student:-Basics:-LongDivision.

Is this a know display issue and is there to correct it?

Windows 10, Maple 2021.2

interface(version);

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

restart;

A:=4*x^4;
B:=3*x^2-60*x+36;
Student:-Basics:-LongDivision(A,B,x); #NOTICE, no + sign shows in quotient

A := 4*x^4

B := 3*x^2-60*x+36

"[[(`%+`(3 x^2,-60 x,36)),[[,(4 x^2)/3,(80 x)/3,1552/3,],[),4 x^4,,,,],[,(4 x^4-80 x^3+48 x^2)/(),],[,,80 x^3-48 x^2,,],[,,(80 x^3-1600 x^2+960 x)/(),,],[,,,1552 x^2-960 x,,,],[,,,(1552 x^2-31040 x+18624)/(),,,],[,,,,30080 x-18624,,,,]]]]"

rem(A,B,x);
quo(A,B,x); #signs shows up here OK

30080*x-18624

(4/3)*x^2+(80/3)*x+1552/3

 

Download no_signs.mw

First 74 75 76 77 78 79 80 Last Page 76 of 200