nm

8552 Reputation

19 Badges

12 years, 347 days

MaplePrimes Activity


These are questions asked by nm

given 

r1:=   -1 <= x and x <= 0;
r2:=   0 <= x and x <= 1;

We see that the above can be simplified to one inequality

-1<= x and x<=1

The closest I found to do this is

r1:=-1 <= x and x <= 0;
r2:=0 <= x and x <= 1;
solve(r1 or r2,x);

which gives RealRange(-1, 1) but I'd like to get the form  -1<= x and x<=1 similar to:

I tried convert to piecewise and simplify and few other things. Is there a trick in Maple to simplify/combine/join inequalites like the above? i.e. convert RealRange(-1, 1) to -1<=x and x<=1 

everything is on the real line.

Maple 2023.2

I have this overloaded function foo(). 

restart;

foo:= overload(  
        [
        proc(A::integer,$)option overload;
            print("first one, _passed = ", _passed," _npassed = ",_npassed);             
        end proc,

        proc(A::integer,B::integer,$)option overload;
            print("second one  _passed = ", _passed," _npassed = ",_npassed);
        end proc
       ]);

Which works OK. so I can now do 

foo(1)
foo(1,2)

But I wanted to indicate that the proc returns say ::integer , and this where I am stuck, I do not know where to add this ::integer

With non-overloaded proc's, this is the syntax

foo:=proc(A::integer,$)::integer;
     ......
end proc;

but I can't do this with the overloaded function. If I type

foo:= overload(  
        [
        proc(A::integer,$)option overload;
            print("first one, _passed = ", _passed," _npassed = ",_npassed);             
        end proc,

        proc(A::integer,B::integer,$)option overload;
            print("second one  _passed = ", _passed," _npassed = ",_npassed);
        end proc
       ])::integer;

Maple simply does not like it. typing foo(1) now it just echos the definition back.

And these give syntax errors

foo:= overload(  
        [
        proc(A::integer,$)::integer option overload;
            print("first one, _passed = ", _passed," _npassed = ",_npassed);    
        end proc,

        proc(A::integer,B::integer,$)::integer option overload;
            print("second one  _passed = ", _passed," _npassed = ",_npassed);
        end proc
       ]);

Tried many other variations and looked at help but see nothing to far.

Can one add ::type to indicate type proc returns with overloaded proc?

Maple 2023.2.1

I wanted to debug some code from worksheet A.  So added DEBUG(); command in the code where I want to start the GUI debugger from, and then run the command from the worksheet. All is working OK. the debugger GUI comes up and I can step in. 

Now I wanted to debug some other code from worksheet B. But without closing the currect debugger which is open and running.

It turned out this is not possible.  When running debugger from worksheet B, it uses the same debugger GUI that was up and running. I think it closed that session automtically also.

So basically using same Maple process, one can't open two debgging sessions at same time? Is there a way around this.

I run each worksheet using its own math engine. So each is separated from each other.

But this is first time I wanted to debug two things at same time, i.e. side by side, thinking I will be able to open two GUI debuggers at same time.

I know ofcourse I can open two separate Maple processes and then I will be able to do this. I think I am allowed to have two Maple's open at same time. Will try that next.

But it will be better if one is able to open two debuggers from same Maple at same time. I do not see why this should not be possible.

Any suggestions if there is a workaround? May be some hidden setting that allows this?

Maple 2023.2.1 on windows 10

I thought I was improving my code by adding ::type to all the _self in my OOP code. As this is one main advantage in programming in Maple, which is being able to attach types to all name and variables. Make code more robust.

But it turned out Maple is not very happy now and gives that drearded error

    Error, static procedure ... refers to non-static local or export ... in surrounding scope

Only place I found that adding ::type_name is to _self is allowed, is on the constructor signature.

But in no other method of the object module. local or export method, it does not matter. 

My question is, why is that?

So I went and removed all those _self::type_name and made it just _self to make Maple happy.

I also noticed this happes regardless of having kernelopts('assertlevel'=2): there or not.  Attached  is the worksheet.

Just tryting to understand the logic, that is all. 

This is using Maple 2023.2.1

interface(version)

`Standard Worksheet Interface, Maple 2023.2, Windows 10, November 24 2023 Build ID 1762575`

restart;

24100

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

3

A:=module()

  export module person()
   option object;
   local m_name::string;
   local m_age::integer;
   export ModuleCopy::static:=proc(_self::A:-person,proto::A:-person,name::string,age::integer,$)
          _self:-m_age := age;
          _self:-m_name:=name;
          NULL;
   end proc;
   export name::static:=proc(_self,$) m_name; end proc;
   export age::static:=proc(_self,$) m_age; end proc;
 end module;

export  module young_person()
   option object;
   local m_person::A:-person;
   export ModuleCopy::static:=proc(_self::A:-young_person,proto::A:-young_person,p::A:-person,$)
          _self:-m_person := p;     
          _self:-process_it();    
   end proc;
   local process_it::static:=proc(_self,$)
         print(m_person:-name());
         print(m_person:-age());
   end proc;

   #to fix the problem, check _self::A... to just _self,  then no error!
   export process_it_from_outside::static:=proc(_self::A:-young_person,$)
         print(m_person:-name());
         print(m_person:-age());
   end proc;

end module;

end module;

_m2782933017664

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

module person () local m_name::string, m_age::integer; option object; end module

p:=Object(A:-young_person,o);

 

Error, static procedure `young_person:-process_it_from_outside` refers to non-static local or export `young_person:-m_person::A:-person` in surrounding scope

 


Download why_adding_type_on_self_gives_error.mw

WHen using _self in object, help says

"As of Maple 2021, if the method has a formal parameter named _self, references
to its object's local or exported variables may be written without prefixing them.
That is, _self:-variable may be written as just variable. Maple will
add the self:- prefix internally when the method is simplified."

And the above is true for all static methods inside an object module, except for ModuleCopy which is also static.

It seems ModuleCopy is special. But why?  I am thinking it is because at time this is called, the object itself does not yet exist, but for all other methods, the object by then is fully constructed. But wanted to be sure.

Here is an example

restart;

person := module()
option object;
local  m_name::string;
local  m_age::integer;
export ModuleCopy :: static := proc(_self :: person
                                   , proto :: person, name::string, age::integer,$
                                )
         m_age := age;
         m_name := name;
    end proc;

export name::static:= proc(_self, $);
    RETURN(m_name); #no need to write _self:-m_name;
    end proc;

export age::static:= proc(_self, $);
    RETURN(m_age); #no need to write _self:-m_age;
    end proc;

export set_name::static:= proc(_self, name, $);
    m_name := name;   #no need to write _self:-m_name := name
    NULL;
    end proc;

export process::static:=proc(_self,$)
   print("name is ",m_name," age is ",m_age);
end proc;

end module:

And now


o:=Object(person,"me",10);

Error, static procedure `ModuleCopy` refers to non-static local or export `m_age::integer` in surrounding scope

Changing ModuleCopy to

export ModuleCopy :: static := proc(_self :: person
                                   , proto :: person, name::string, age::integer,$
                                )
         _self:-m_age := age;
         _self:-m_name := name;
    end proc;

Now there is no error. But notice that in all other static methods, I can write  m_name directly without using _self:-m_name;

I looked at help page for ModuleCopy but see no mention of this.

Why ModuleCopy is different?

Maple 2023.2 on windows 10

5 6 7 8 9 10 11 Last Page 7 of 164