nm

11353 Reputation

20 Badges

13 years, 12 days

MaplePrimes Activity


These are replies submitted by nm

@vv 

wow. I never seen such a bug before in Maple.

ps. could someone please make a bug report on this to Maplesoft (SCR?) I do not know how to do this.

(I will change now all my code to use (lhs-rhs)(mysol) = 0 when using odetest.)

thanks.

@Carl Love 

You are right. When I removed the flat option, now both methods give the same output.  So all is OK now. 

 

@Carl Love 

I got a chance to do little  testing. I compared your method with Edgardo's. I found case where they give different output.    Here is the code

restart;
Carl:= expr-> 
    local rad:= anything^fraction;
    subsindets(expr, And(`*`, satisfies(e-> andmap(membertype,[rad, {specop(exp), specop(exp)^anything}],{op(e)}))),
        e-> local d:= ilcm(map2(op, [2,2], indets(e, rad))[]); G(e) #simplify((e^d)^(1/d))
   ):

Edgardo:=expr->subsindets[flat](expr, And(`*`, satisfies(u -> andmap(membertype, [Or(exp(anything), exp(anything)^(-1)), anything^fraction], [op(u)]))), G): 

I changed the operation to just `G` to make it more clear where it is applied and to compare. 

I used this example on the above two procedures to see if they give same result

expr:=exp(sqrt(exp(exp(z)*sqrt(h))))*1/(exp(z)*sqrt(h));
Carl(expr);
Edgardo(expr);

I think what happens is this: Edgardo's method treated the whole numerator exp(sqrt(exp(exp(z)*sqrt(h)))) as say and so the whole input becomes like   A*(exp(z)*sqrt(h))^(-1)  and this pattern matched, so it applied G once to the whole input and stopped.

Your method seems to start from inside out. It found the inner exp(z)*sqrt(h) hidden inside there, applied G to it, then looking outside, it also found the same pattern again and applied G again on the whole thing as shown above.

My cases will not hit such complicated possibilities anyway, but thought to point this out. I am not sure which one is considered the correct output as it might be a matter of interpretation.

Thanks for the help.

 

 

 

 

@ecterrab 

For that reason I mentioned "note that denominators are represented as negative powers". You seem to have not noticed the comment. It is at the beginning of my previous reply. It is the same reply where you missed the example.

I did not miss it. I knew the reason. I just did not know how in Maple to handle it in one call/type as you showed now. It is the same issue in Mathematica, but there I use the command Alternatives. I did not know how to do it in Maple, since I am not as familar with it.

This language is remarkably flexible and expressive,

It is  yes. But not everyone has 40 years experience programming in Maple as you do :)  also, Maple help pages lack many non trivial examples to help someone learn from. Even the Maple programming manual do not have any such detailed examples.Only this, on page 122 of the 2020  version

That is it. 

Thanks for the new version of the code that handles both numerator and denomanitaor at same time. I will test it in my main code later today. 

@Carl Love 

Thanks. I also could not get your method to work on subexpression which happened to be in the denominator

expr:=a*exp(z)*sqrt(h)+exp(z)*sqrt(h)+1/(3*exp(z)*sqrt(h));

It finds the first 2 and transforms them correctly, but not the third one. I did not know how to combine both into one type as I mentioned in the above reply I just made. 

 

@ecterrab 

No. I showed - in the reply you are replying to - how to match that pattern for "any number of operands, 2, 3, or other",

Sorry, I overlooked this new version you had there. I was concentrating on the earlier version you showed using 

u::`&*`(anything $ 2)

You are right, the new version works for any  number. But I could not make it work when the pattern is in the denominator. So I ended up having to run it two times. One for the numerator and one for the denominator. May be there is a better way, but this is what I could find so far. Here is an example

restart;
expr:=a*exp(z1)*sqrt(h1)+exp(z2)*sqrt(h2)+1/(exp(z3)*sqrt(h3));

Your code changes the first two term above, but not the third, because the pattern is in the denominator.  (different type, in Maple talk). So I changed it as follows, by doing 2 passes

restart;
expr:=a*exp(z1)*sqrt(h1)+exp(z2)*sqrt(h2)+1/(exp(z3)*sqrt(h3));
expr:=subsindets[flat](expr, And(`*`, satisfies(u -> andmap(membertype, [exp(anything),  anything^(fraction)],[op(numer(u))]))), e->G(e));
expr:=subsindets[flat](expr, And(`*`, satisfies(u -> andmap(membertype, [exp(anything),  anything^(fraction)],[op(denom(u))]))), e->1/G(denom(e)));

The first pass changes the subexpression in numerator, second passes for the denominator.

I did not know how to make a type that combines both together.  But the above works OK for me now. 

Someone should write a Maple book on just these operations and methods and techniques, as Maple help have very little examples to learn from and no Maple books  I know about even talk about such topics.

 

 

@ecterrab 

"Then your original question asks about "a product of three operands only, where one is an exponential one is a a radical, the third one is anything". That is what  exp(anything)*anything*sqrt(anything) isThe "three operands in a product" are matched with `&*`(anything$3), but in your expression, I do not see any product of three operands, so Maple gives up before going into the contents of any product."

 

I know, but the above is meant to be a "pattern" to match    exp(x)*sqrt(y) or a*exp(x)*sqrt(y).   because I thought  anything can match an implicit 1.

This is the pattern I showed in Mathematica, where one can tell it to that a pattern can be zero or more length (i.e. present or not), like this

expr=Exp[x]*Sqrt[y]
expr/. Exp[any1_]*any2_.*Sqrt[any3_]->Z

The above also works on expression 

expr=Exp[x]*a*Sqrt[y]

Because the dot after any2_. The dot says this pattern can be there or not.

So you are saying basically, in Maple, I need to create two types: one for exp(anything)*sqrt(anything) and one for exp(anything)*anything*sqrt(anyting) to account for both possibilities. I tried to do that, but I could not make it work by telling subsindents to use either type. But I can do it by trying to match first type, then trying to match the second type, like this

restart;
expr:=exp(x)*a*sqrt(y)+exp(z)*sqrt(h);
`type/F1` := u -> u::`&*`(anything $ 2) and andmap(membertype, [exp(anything), radical], [op(u)]):
`type/F2` := u -> u::`&*`(anything $ 3) and andmap(membertype, [exp(anything), anything, radical], [op(u)]):
expr:=subsindets(expr, F1, e->Z);
expr:=subsindets(expr, F2, e->Z);

I can do that. It just means I have to do it separately for each possible type I want to transform, instead of just using one call as with a pattern matching.

This is not a big problem, I will work on this more. I wish there was a tutorial or more examples in help that teachs how to do these things. I learn better by examples.

 

@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.

 

First 37 38 39 40 41 42 43 Last Page 39 of 91