nm

8552 Reputation

19 Badges

12 years, 348 days

MaplePrimes Activity


These are replies submitted by nm

@ecterrab 

I was trying to understand your code. So I started with simpler example.

expr:=x*sin(x)+5/(3*sin(2*x));

now, I wanted to change  anything*sin(anything)   with say Z.   I found it works on the numerator, but not the denominator. Like this

expr:=x*sin(x)+5/(3*sin(2*x));
`type/F` := u -> u::`&*`(anything $ 2) and andmap(membertype, [sin(anything), anything], [op(u)]):
subsindets(expr, F, e->Z);

How do would one tell it to look for the subexpression both in numerator and denominator? 

Thanks.

 

@ecterrab 

I can't get your method to work. I must be doing something wrong, but do not see it. I copied your code as is and just used the expression I wanted. But it remains the same. No changes are made. This tells me the pattern is not being detected?

restart;

expr:=(-x + sqrt(9*x^2*exp(2*c) + 8)*exp(-c)+99)/(4*x)+ (a*sqrt(z)-99+sin(c*sqrt(r+4)+20))/3+10+1/(c+exp(-x)*sqrt(exp(x)))+sqrt(h);
`type/F` := u -> u::`&*`(anything $ 3) and andmap(membertype, [exp(anything), anything, radical], [op(u)]):
subsindets(expr, F, e->simplify( sqrt(e^2)));

Also this not changing it

subsindets(expr, F, e->Z);

What do I need to change to use your code correctly?

Maple 2021.1

@ecterrab 

Thanks, I Will try your method.

I asked separete question, as it was new functionality I was asking about. I did not want to cluter this question by asking things like "and how would you now solve this, if I wanted to do this instead..." type of thing.

This is actually the recommended way in other forms. If someone asks question, and gets an answer, then if they want to add additional functionality to the one allready asked and answered, the policy is to make a separate question

It is not fair for the person who allready answered the question to keep modifying their answer or adding new answer to the new functionality asked.

In addition what I asked about is completely new pattern.  So I do not understand why the question was deleted. It is also not right and I find it rude to delete a question like this before even letting one at least know there is an issue. It means al the work that was done making the question is now lost and one has to recreate it again.

The correct policy should be, is to first let the person know, so if they need to move the question somewhere else, then they can copy/paste it first.  Or better, have a way for the system to copy the question to another thread.

Something is wrong in this forum to allow this deletion of questions to happen all the time like this. 

Thanks again for your reply. Attached PDF is my deleted question.

p.pdf

 

@Carl Love 

great. Thanks now it works.

@Carl Love 

humm.. I could swear when I looked at the output before, your code gave the result I wanted. but now I see it does it? It must be I did not look very carefully. 

it gives

It did not include the term that was multiplying the sqrt() as I expected. The result I am looking for it

The whole reason I asked this question is that I wanted to replace    anything*sqrt(anything) and not just sqrt(anything).

Did it work on your version as in the above?  I am using Maple 2021.1

 

restart:
expr:= 
    (-x + sqrt(9*x^2*exp(2*c) + 8)*exp(-c)+99)/(4*x)
    + (a*sqrt(z)-99+sin(c*sqrt(r+4)+20))/3 
    + 10
    + 1/(c+exp(-x)*sqrt(exp(x)))
    + sqrt(h)
;
sq:= anything^{-1/2, 1/2}:
subsindets(
    expr, 
    {sq, And(`*`, satisfies(e-> membertype(sq, {op}(e))))},
    LargeExpressions:-Veil[Z]
);

 

@Carl Love 

Thanks. Is there a reason to use LargeExpressions:-Veil[Z]   (which I never saw before) vs. just the normal ee->Z for the transformer? As in

sq:= anything^{-1/2, 1/2}:
subsindets(
    expr, 
    {sq, And(`*`, satisfies(e-> membertype(sq, {op}(e))))},
    ee->Z
);

They both gives same correct result. 

btw, this is an example, where sometimes I think pattern match is simpler actually. For example, in Mathematica, I would just use the pattern I want to replace, and let the system figure how to find it. Like this

It seems to me pattern matching is a more universal method. But I could not do the same in Maple using patmatch. But I do like Maple's type system. I am just not good at it still.

 

@Carl Love 

But your version will remove a/b and a^b, etc... as well

f := a*b+a*c+a+b+c+a/b;
select(t-> has(t,a) and not has(t,b), [op](_x+f));

    [a*c, a]

I assume op wanted a/b this kept there when they said

  extract all items that contain "a" in an expression except "ab"

Could you at least type the input in Maple notation?

I assume you know how to type an ODE in Maple, since you are using Maple to solve ODE's.

This eliminate one typing these in Maple and making a mistake reading your handwriting.

 

I can now reproduce this error in Maple 2021

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
expr:=exp(x)*sin(y)-3*x^2+(exp(x)*cos(y)+1/3/y^(2/3))*Z = 0;
solve(expr,y);
#same problem using  PDEtools:-Solve(expr,y);

 

Error, (in SolveTools:-CancelInverses) assertion failed, simplify should not leak _Z variables out from RootOfs

The problem is that it is not possible to even catch this exception in a try/catch block, so the whole program/script stops.

Any suggestion for a workaround? if I can catch the exception, it will OK for now until Maple fixes this.,

Removing the assert works also, but I need to keep the assert on.

@Carl Love 

I found the problem. I am still not able to make a MWE due to hard to reproduce all the call flow which leads to it in a small example, but I found how to change the ode_type module to make things now work, such that I can define local variable as   o::ode_type and also keep the assert on.

Before the ode_type module, which is an object had this definition, in file ode_type.mpl

local ode_type:=module()
    option object;
    export ode; 
    #other fields
    local ModuleLoad::static:= ()->
           TypeTools:-AddType(':-ode_type', ode_type);
    ModuleLoad()      

end module:

The last part of the code above is one I took from your other answer.   The above module was sitting inside my main root module, like this

A:=module()
$include  "ode_type.mpl"     #types 
#other modules
end module;

And now when I use my other functions inside A module, which uses the type ode_type and pass the Object as we talked about before, into a local variable defined as  o::ode_type I was getting the exception

Error, (in A:-dsolve) assertion failed in assignment to ode_obj, expected ode_type, got _m1657072644000 

I changed ode_type module now to the following

local ode_type:=module()
    option object;
    export ode; 
    local ModuleLoad:=proc() #it also work if I add  ::static, no difference.
           TypeTools:-AddType(':-ode_type', t->type(t,'object'));
    end proc;        
end module:

And now suddenly the exception went away. 

I am able to keep local defintion using o::ode_type and keep the kernelopts('assertlevel'=2): on and no errors and everything is working fine.

I do not know exactly why Maple was not happy with the first version. But the above does what I want for now. This might be considered a work around, and I think there is still a bug inside Maple why it does not like the first version. 

I think the problem is name scoping/name binding.  Why? Because I can use the first version above of ode_type module, if I evaluate it in the worksheet at global level, before invoking my function inside the A module. (And remove the module ode_type from inside A module since now not needed any more).

Like this

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

ode_type:=module() 
   option object; 
   export ode; 
   local ModuleLoad::static:= ()-> TypeTools:-AddType(':-ode_type', ode_type); 
   ModuleLoad() 
end module: 

read "A.mpl"; 

A:-my_proc();

The above now works, no exception raised.   Because ode_type was set in global name space before loading the A module. But ofcourse the above is not a good workaround, as I want to keep all modules inside my main A module. 

Maple 2021

@Carl Love 

You are right, I need to make an actual assignment first to make the MWE I posted work. I was trying to make the simplest example for the problem in my large code to try to find why it fails there.

This means the MWE I posted does not represent the actual problem I have in my main code. Because there I am making an assignment, else nothing would work. I run 1,000 problems tests, and all is working fine, but I had to change local ODE::ode_type;  to local ODE; to avoid the error Maple gives me. 

Error, (in my_module_name:-dsolve) assertion failed in assignment to ode_obj, expected ode_type, got _m1657072644000 

Again, everything works fine when I remove the ::ode_type from the local variable. If the Object was not allocated, nothing would have worked.  

This means I need to work harder to make new MWE which illustrates this problem. Something else is wrong, due to some modules inside others, it makes it hard to reproduce by making a simple MWE. But will try to do that later.

Right now, everything is working fine, once I remove the ::ode_type from the local variable definition and keep the assert there also.

 

 

 

@Carl Love 

As I mentioned in my edit (I seem to have updated it while you are writing?) that if I remove the local from the module definiton, the crash goes away, but the assignment error remain. My question remains the same, why?

The other proc called is returning back an object of ode_type, and the receiving variable on the caller side is defined as a local variable of type ode_type

But Maple thinks the retunring object is not of type ode_type 

And that is the question. You say you get the error message that you should get. but why?  things work for other types, like integer, string, etc.. but why not for ode_type as defined above?

 

@Joe Riel 

I do get lots of superficial warning messages printed on the screen, which I never could figure how to get rid of. I wonder then if these are the cause of the slow down?

Even if I do     read "A.mpl":   vs  read "A.mpl"; these same warning messages still display on the worksheet screen. 

There are thousands of them. They are all harmless due to how I build the Latex strings inside. They have been there for years. 

It takes about 8 minutes now to finish reading the mpl file.   My computer has very fast intel CPU with 64 GB Ram.

read "A.mpl":
Warning, incomplete string; use " to end the string
Warning, incomplete string; use " to end the string
Warning, incomplete string; use " to end the string
....
after 8 minutes and hundreds of screen pages scrolling, it finishes
....

Would you know a way to turn these off to see if this is why it is slow? I use a worksheet to read the file.

btw, same timing for building .mla file also, since to build .mla, I have to first read the .mpl file to memory.

 

Could you write the ODE using Maple 1D standard math language and not using the Maple 2D langauge? I can't fully understand what you wrote there.  Is this 4th order ode?

Also better to use "insert code snippet" option here to enter the plain text code.

And what is the sinh and cosh method?  My school teacher never mentioned such a method.  Do you have a link to such  a method?   Did you try the dsolve() command on it?

@Carl Love 

Thanks. I understand what you did. You basically created a global typename to use for the local type there.  And now I can make the Object which defines the type as local. This is all fine.

Except, I do not like that Maple forces one to make type names global. if I have many modules and submodules, and may be define other types somewhere else, it would have been better to have typename fully qualified by where it is defined. Similar to names of procs inside modules.

This helps when reading the code instead of having to search the many files to find where this type came from.  Here is what I mean

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

A:=module()

   #define local type to use in child modules
   local module person_type()
       option object;
       export name::string, age::string; 
       local ModuleLoad::static:= ()->
           TypeTools:-AddType(':-person_type', person_type);
       ModuleLoad()
    end module;

   #child module
   export module_A1:=module()
        export boo:=proc()
          local X::':-person_type':=Object(person_type);          

          #something like this below would have been better, but Maple will not allow it
          #local Y::'A:-person_type':=Object(A:-person_type); 
          return 1;
       end proc;
    end module:
   
end module:

 

i.e when adding type using TypeTools:-AddType the type name is global. I'd like to do something like ::A:-B:-type_name which tells me that the type is defined in module B which is inside module A when I look at the code. Now I have to write ::':-type_name' and I lose the information given by a fully qualified name. 

This is the same reason I prefer to write fully qualified names of functions inside packages, instead of using with(package) and just use the name of the function inside the package.

But  your solution allows me to make the module which represent the type now local, which is good.

 

First 17 18 19 20 21 22 23 Last Page 19 of 71