nm

11538 Reputation

20 Badges

13 years, 113 days

MaplePrimes Activity


These are questions asked by nm

I am finding many problems using overload in OOP.

But for starter, here is a basic one that does not use Object. Will make separate question for other issues once I figure this basic one out.

I have overload with two procs.

First proc takes 2 arguments of type string, and the second proc one argument also of type string.

When calling the overloaded proc with one argument or two arguments, it always calls the first one which takes 2 arguments.

It never calls the second, even though the call is using one argument only. It always matchs the first proc.

It seems Maple just checks if the first argument match and stops.

I also made sure to use $ for end of arguments flag.

Now when changing the order and putting as the first proc the one that take one argument and the second proc which takes two arguments, now it works. Maple calls the correct proc based on the number of arguments.

How could this be possible? Is order of procs in overload important?? How does one then figure the correct order. It should be based on match of signature of proc, not the order. i.e. match made based on number and type of arguments. 

Is there a way to make the first one work as is without having to worry about order? Or Am I making mistake somewhere?

restart;

interface(version);

`Standard Worksheet Interface, Maple 2025.1, Linux, June 12 2025 Build ID 1932578`

restart;

set_name :=overload(
        [     
            proc(first_name::string,last_name::string,$) option overload;
                print("in proc which takes two arguments");
            end,
       
            proc(the_name::string,$) option overload;
                 print("in proc which takes one argument");
            end          
        ]
    ):

set_name("me"); #why this call the first proc and not the second?

"in proc which takes two arguments"

set_name("me","joe");

"in proc which takes two arguments"

restart;

#change order of procs in list
set_name :=overload(
        [            
            proc(the_name::string,$) option overload;
                 print("in proc which takes one argument");
            end,      

            proc(first_name::string,last_name::string,$) option overload;
                print("in proc which takes two arguments");
            end       
        ]
    ):

set_name("me");

"in proc which takes one argument"

set_name("me","joe");

"in proc which takes two arguments"

 

 

Download why_order_makes_differenence_in_overload_nov_1_2025.mw

Solving an ode, dsolve says it used exact method and gives two solutions as result (correct result).

But when asking dsolve to solve same ode but now specifying that it uses exact method (i.e. same one it used itself before), now it gives one solution only, not two as before.

Why is that? Should not both commands give same result? i.e. two solutions?

interface(version);

`Standard Worksheet Interface, Maple 2025.1, Linux, June 12 2025 Build ID 1932578`

SupportTools:-Version()

`The Customer Support Updates version in the MapleCloud is 29 and is the same as the version installed in this computer, created June 23, 2025, 10:25 hours Eastern Time.`

Physics:-Version()

`The "Physics Updates" version in the MapleCloud is 1881 and is the same as the version installed in this computer, created 2025, October 7, 16:4 hours Pacific Time.`

restart;

ode:=3*y(x)^3*x^2+y(x)^4+(3*x^3*y(x)^2+y(x)^4+4*x*y(x)^3)*diff(y(x),x) = 0;
DEtools:-odeadvisor(ode);
infolevel[dsolve]:=5:

3*y(x)^3*x^2+y(x)^4+(3*x^3*y(x)^2+y(x)^4+4*x*y(x)^3)*(diff(y(x), x)) = 0

[_exact, _rational]

sol:=dsolve(ode); #gives two solutions

Classification methods on request

Methods to be used are: [exact]

----------------------------

* Tackling ODE using method: exact

--- Trying classification methods ---

trying exact

<- exact successful

y(x) = 0, x*y(x)^4+x^3*y(x)^3+(1/5)*y(x)^5+c__1 = 0

maple_sol:=dsolve(ode,[exact]);  #why y=0 solution do not show here??

Classification methods on request

Methods to be used are: [exact]

----------------------------

* Tackling ODE using method: exact

--- Trying classification methods ---

trying exact

<- exact successful

x*y(x)^4+x^3*y(x)^3+(1/5)*y(x)^5+c__1 = 0

sol:=dsolve(ode); #gives two solutions again

Classification methods on request

Methods to be used are: [exact]

----------------------------

* Tackling ODE using method: exact

--- Trying classification methods ---

trying exact

<- exact successful

y(x) = 0, x*y(x)^4+x^3*y(x)^3+(1/5)*y(x)^5+c__1 = 0

 

 

Download why_different_solutions_maple_2025_1_oct_22_2025.mw

When solution was obtained using earlier call to solve with _EnvAllSolutions := true: set, then odetest givens internal error.

When _EnvAllSolutions := false: then no error.

Why? And is there a workaround so I can use _EnvAllSolutions := true: but have odetest still work?

interface(version);

`Standard Worksheet Interface, Maple 2025.1, Linux, June 12 2025 Build ID 1932578`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1881 and is the same as the version installed in this computer, created 2025, October 7, 16:4 hours Pacific Time.`

SupportTools:-Version();

`The Customer Support Updates version in the MapleCloud is 29 and is the same as the version installed in this computer, created June 23, 2025, 10:25 hours Eastern Time.`

 

Example fail when using _EnvAllSolutions := true:

 

restart;

kernelopts('assertlevel'=2):

ode:=diff(y(x),x) = ln(1+y(x)^2);
IC:=y(0)=0;
x0:=0;
sol:=y(x) = -sqrt(-1 + exp(RootOf(-Intat(-1/(2*tau*sqrt(-1 + exp(tau))*exp(-tau)), tau = _Z) + x + _C2)));

eq:=0=eval(rhs(sol),x=x0);
_EnvAllSolutions := true:
_EnvExplicit := true:
sol_C:=_C2=solve(eq,_C2);
sol:=eval(sol,sol_C);
odetest(%,[ode,IC])

diff(y(x), x) = ln(1+y(x)^2)

y(0) = 0

0

y(x) = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+x+_C2)))^(1/2)

0 = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+_C2)))^(1/2)

_C2 = Intat(-(1/2)*exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = (2*I)*Pi*_Z1)

y(x) = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+x+Intat(-(1/2)*exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = (2*I)*Pi*_Z1))))^(1/2)

Error, (in series/csgn) assertion failed

 

Example Works  when using _EnvAllSolutions := false:

 

restart;

kernelopts('assertlevel'=2):

ode:=diff(y(x),x) = ln(1+y(x)^2);
IC:=y(0)=0;
x0:=0;
sol:=y(x) = -sqrt(-1 + exp(RootOf(-Intat(-1/(2*tau*sqrt(-1 + exp(tau))*exp(-tau)), tau = _Z) + x + _C2)));

eq:=0=eval(rhs(sol),x=x0);
_EnvAllSolutions := false:
_EnvExplicit := true:
sol_C:=_C2=solve(eq,_C2);
sol:=eval(sol,sol_C);
odetest(%,[ode,IC])

diff(y(x), x) = ln(1+y(x)^2)

y(0) = 0

0

y(x) = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+x+_C2)))^(1/2)

0 = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+_C2)))^(1/2)

_C2 = Intat(-(1/2)*exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = 0)

y(x) = -(-1+exp(RootOf(-Intat(-(1/2)/(tau*(-1+exp(tau))^(1/2)*exp(-tau)), tau = _Z)+x+Intat(-(1/2)*exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = 0))))^(1/2)

[RootOf(Intat(exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = _Z)+2*x-Intat(exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = 0))-ln(exp(RootOf(Intat(exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = _Z)+2*x-Intat(exp(tau)/(tau*(-1+exp(tau))^(1/2)), tau = 0)))), 0]

 

 

 

 

Download odetest_fail_when_using_envAllsol_maple_2025_1_oct_21_2025.mw

The nice addition added to Maple 2022 in this  post made it clear that c__1 and _C1 are the same under the cover.

But then why in Maple 2025.1 it does not give this?

I found this when I was trying to find constants of integrations in solution of an ode, and used 

                 indets(sol,And(symbol, suffixed(_C, nonnegint))); 

Which did not find the constants of integration, since I happened to have typed the solution using c__1 and not _C1, but I thought they are the same.

Did something change or I still dont understand well the difference between c__1 and _C1 ?

Worksheet below.

interface(version);

`Standard Worksheet Interface, Maple 2025.1, Linux, June 12 2025 Build ID 1932578`

SupportTools:-Version();

`The Customer Support Updates version in the MapleCloud is 29 and is the same as the version installed in this computer, created June 23, 2025, 10:25 hours Eastern Time.`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1881 and is the same as the version installed in this computer, created 2025, October 7, 16:4 hours Pacific Time.`

restart;

sol:= y(x)=-cos(x)/2+sin(x)/2+c__1*exp(-x);
indets(sol,And(symbol, suffixed(_C, nonnegint)));

y(x) = -(1/2)*cos(x)+(1/2)*sin(x)+c__1*exp(-x)

{}

sol:= y(x)=-cos(x)/2+sin(x)/2+c__1*exp(-x);
indets(sol,And(symbol, suffixed(c__, nonnegint)));

y(x) = -(1/2)*cos(x)+(1/2)*sin(x)+c__1*exp(-x)

{c__1}

sol:= y(x)=-cos(x)/2+sin(x)/2+_C1*exp(-x);
indets(sol,And(symbol, suffixed(c__, nonnegint)));

y(x) = -(1/2)*cos(x)+(1/2)*sin(x)+_C1*exp(-x)

{}

sol:= y(x)=-cos(x)/2+sin(x)/2+_C1*exp(-x);
indets(sol,And(symbol, suffixed(_C, nonnegint)));

y(x) = -(1/2)*cos(x)+(1/2)*sin(x)+_C1*exp(-x)

{_C1}

c__1 - _C1

c__1-_C1

addressof(c__1);

36893628553737883996

addressof(_C1);

36893628553623934140

Download why_c1_and_C1_not_same_oct_19_2025.mw

Update

Found out why. This only works if one calls dsolve() first.  Here is an example

sol:=dsolve(diff(y(x),x)=x)

y(x) = (1/2)*x^2+c__1

c__1 - _C1;

0

indets(sol,And(symbol, suffixed(_C, nonnegint)));

{c__1}

restart;

my_sol:=y(x)=(x^2)/2+c__1;

y(x) = (1/2)*x^2+c__1

c__1 - _C1;

c__1-_C1

indets(my_sol,And(symbol, suffixed(_C, nonnegint)));

{}

 

 

Download why_c1_and_C1_not_same_oct_19_2025_V1.mw

But this is really confusing. c__1 before calling dsolve is not the same as c__1 after calling dsolve.

It will be better if Maple is changed such that these work the same all the time without having to call dsolve() first.

Maple help does not have an example I could find showing the right way to call method, which is meant to be called only from the constructor the object, before the object is fully build.

Help page does not have such example.

This worksheet shows 3 possible ways to do this. All seem to work fine. I am sure one can come up with more variations.

The question is, which one of these calls is the "right" way?

The method called from the constructor in this example is called process_age().

If someone knows an official Maple documentation showing one example of calling  a proc from constructor that will also help.

Version 1

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=process_age(age);
   end proc;

   local process_age:=proc(age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint, process_age; option object; end module

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint, process_age; option object; end module

100

 

 

Version 2

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=process_age(age);
   end proc;

   local process_age::static:=proc(age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint; option object; end module

 

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint; option object; end module

100

 

 

Version 3

 

restart;

module person()
   option object;

   local _name::string;
   local _age::posint;

   export ModuleCopy::static := proc( _self, proto::person,
        name::string,age::posint,$)
        _name:=name;
        _age:=_self:-process_age(age);
   end proc;

   local process_age::static:=proc(_self,age::posint,$)::posint;
         age+1;
   end proc;

   export get_age::static:=proc(_self,$)::posint;
          _age;
   end proc;
end module;

module person () local _name::string, _age::posint; option object; end module

 

 

o:=Object(person,"me",99);
o:-get_age()

module person () local _name::string, _age::posint; option object; end module

100

 

 

Download correct_way_to_call_method_from_constructor_oct_17_2025.mw

1 2 3 4 5 6 7 Last Page 1 of 203