nm

3646 Reputation

17 Badges

7 years, 362 days

MaplePrimes Activity


These are questions asked by nm

This was generated when running some code on Maple 2020.1.

Just wondering if this might indicate some problem internally, or is this something that can happen.

restart;
ZZ:=Int(-(a*_a^2+(_a^4*a^2-4*_a*b*y(x))^(1/2))/(a*_a^3+_a*(_a^4*a^2-4*_a*b*y(x))^(1/2)+6*y(x)),_a = _b .. x)+Intat(-2/(a*x^3+x*(a^2*x^4-4*_f*b*x)^(1/2)+6*_f)-Int(2/(_a^4*a^2-4*_a*_f*b)^(1/2)*b*_a/(a*_a^3+_a*(_a^4*a^2-4*_a*_f*b)^(1/2)+6*_f)+(a*_a^2+(_a^4*a^2-4*_a*_f*b)^(1/2))/(a*_a^3+_a*(_a^4*a^2-4*_a*_f*b)^(1/2)+6*_f)^2*(-2*_a^2/(_a^4*a^2-4*_a*_f*b)^(1/2)*b+6),_a = _b .. x),_f = y(x))+_C1 = 0;

timelimit(30,value(ZZ))

Error, (in discont/zero) too many levels of recursion

The problem is that I am not able to trap the error. This does not work

try
ZZ:=Int(-(a*_a^2+(_a^4*a^2-4*_a*b*y(x))^(1/2))/(a*_a^3+_a*(_a^4*a^2-4*_a*b*y(x))^(1/2)+6*y(x)),_a = _b .. x)+Intat(-2/(a*x^3+x*(a^2*x^4-4*_f*b*x)^(1/2)+6*_f)-Int(2/(_a^4*a^2-4*_a*_f*b)^(1/2)*b*_a/(a*_a^3+_a*(_a^4*a^2-4*_a*_f*b)^(1/2)+6*_f)+(a*_a^2+(_a^4*a^2-4*_a*_f*b)^(1/2))/(a*_a^3+_a*(_a^4*a^2-4*_a*_f*b)^(1/2)+6*_f)^2*(-2*_a^2/(_a^4*a^2-4*_a*_f*b)^(1/2)*b+6),_a = _b .. x),_f = y(x))+_C1 = 0;
timelimit(30,value(ZZ));
catch:
  print("ignore");
end try;

Error, (in discont/zero) too many levels of recursion

Why can't one catch this error inside try/catch? It means the whole program can not  continue.

Maple 2020.1

This works

restart;
patmatch(3*g(x),A::nonunit(algebraic)*B::function,'la');
la

[A = 3, B = g(x)]

But this fails

restart;
patmatch(3*g(x),conditional(A::nonunit(algebraic)*B::function, true ),'la');

Error, (in PatternMatching:-AlgStruct:-Match) improper op or subscript selector
 

I am not able to see why. In the above I used true for the condition, just to keep things simple. Any boolean valued expression will work.  

changing the above to

restart;
patmatch(3*g(x),conditional(A::anything*B::function, true ),'la');

it works. No error. [A = 3, B = g(x)]

What did I do wrong in the above syntax which generated the error?

Maple 2020.1

 

let me just explains the big picture first, then give small example.

When using standard modules, I had one module, and number of smaller modules, all private to the main module. This worked well.

Each sub module, can only be accessed from the top module, which is seen by user. The sub modules can't be called by user directly.

Now I changed the main module to become an object (since I want to make more instances of it).

I want to still use the code in those submodules I had, but want to keep them private to the object class, so they can be seen only from inside the object class methods. So they are part of the object class now. But remain as modules. I do not want to copy all those methods in these submodules and put them in the object class directly.

But I can't get the syntax right to do this. I do not want to modify the code inside the sub-modules, but only how to integrate them into the object.

Notice that I can call those external modules fine from the object, but I simply want to make them private to the object class, so they can't be called from outside. 

The question is how to do this? 

Here is a very small example. (in practice, I have these submodules in .mpl files, but here I put them all in the example).

restart;	
module car_class()
      option object;
      local name::string :="UNKNOWN";

      export set_name::static:=proc(o::car_class,_name::string)
        o:-name := _name;
        o:-big_car:-set_name(o,_name);#this call does not work
      end proc;

      #this is module, that I want to be private to this class only
      #eventually, I'd like this module be in separate mpl file also.
      local big_car::static :=module()  #module does not take arguments!

            #this below should be private only to the this module
            #and not seen by the enclosing object.
            local big_car_name::string:="UNKNOWN";  

            #this export to allow parent object to call it
            export set_name::static:=proc(o::car_class,_name::string)
                   o:-big_car:-big_car_name:=_name;
            end proc;

      end module;

end module:

o:=Object(car_class);
o:-set_name(o,"GM");

Error, (in set_name) module `car_class` does not export `big_car`

I found after playing more with it, that this works

I just replaced o:-big_car:-big_car_name:=_name;  with big_car:-big_car_name:=_name; had to remove ::static from definition of proc inside the private module.

restart;	
module car_class()
      option object;
      local name::string :="UNKNOWN";

      export set_name::static:=proc(o::car_class,_name::string)
        o:-name := _name;
        o:-big_car:-set_name(o,_name);
      end proc;

      local big_car::static  :=module() 
          local big_car_name::string:="UNKNOWN";  

          export set_name:=proc(o::car_class,_name::string)
              big_car_name:=_name;
          end proc;

     end module;
end module:

Now it works. However, maple help says "In Maple, method names should be declared as static. "

 

If one refers to a name in Maple, I thought it will look at the global context to find it. So when one does latex(....) then this is assumed to be the system latex command. No need to do :-latex()

But if there is local variable in Object class called latex, why then is object:-latex gets confused with global Maple command latex()?  Here is an example

module ode_class()
      option object;
      local latex::strring :="";

      export init::static:=proc(o::ode_class)
        o:-latex:= latex(1/2,output=string);
      end proc;
end module:

my_ode:=Object(ode_class): 

Error, static procedure `ode_class:-init` refers to non-static local or export `ode_class:-latex::strring` in surrounding scope
 

ofcourse easy to fix, I just replace the RHS latex(1/2,output=string);  with :-latex(1/2,output=string); 

But my question why is object:-latex := latex(...)  makes Maple think the latex in the RHS is the variable name in the class, when it does not have the  object:- prefix?  Is this expected  behaviour in Maple? 

But now I am starting to worry that each maple command/function/name used inside the Object needs  :- added to it, just in case of a current or future name conflict with local object variables names.

 

 

in my object, I have few private variables. To make sure the object is correctly initialized between each use, I'd like to initialize these private variables each time at the start of the call each time the object is called to process something.

Some of these variables represent equations, or symbols or functions. Some of these are set by the user of the object, but some are not. And I do not want to leave those that are not set, using old values from last call.

The problem  I can't use {} nor NULL to initialized these private variables, since I am telling Maple they are of type `=` or `symbol` or `function`.

To give a small example, I use a proc here to illustrate, since it the same idea, but less code.

restart;
kernelopts('assertlevel'=2):
foo:=proc(input_ode::`=`)
   local ode::`=`:={};  #i'd like to give this some initial value. But what?
   ode:=input_ode;
end proc;

now foo(diff(y(x),x)=5) gives

Error, (in foo) assertion failed in assignment, expected `=`, got {}
Same type of error happens if I use NULL.

Is there a special value or tag one can use to initialize/reset any variable, regardless of its type? I thought at first that NULL will work, but it is not.

The idea is that I'd like all my object private variable to always have known state when the same object is called each time. ie. to clean it up before the next time is made.

The above is just an example. Ofcourse I could just do this

restart;
kernelopts('assertlevel'=2):
foo:=proc(input_ode::`=`)
   local ode::`=`; #leave it un-initialized since it will be overwritten next
   ode:=input_ode;
end proc;

And now no error. 

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