detect sqrt in expression?



On Wed, Nov 16, 2011 at 19:03, Edwin Woollett <woollett at charter.net> wrote:

> On Nov. 16, 2011, Stavros Macrakis wrote:
> ---------------
>
>  Why are you using the internal function ?isinop -- it is in general a bad
>> idea to use internal Maxima functions unless you are familiar with the
>> Lisp
>> code yourself.
>>
>> As for listofops, it depends how exactly you ended up defining that....
>>
> -------------------------
> Dieter suggested the use of  ?isinop earlier in another context.
>

As I say, I think it is a bad idea unless you actually know the internals
pretty well.


> The current def of listofops is your code:
>
> listofops(expr) := block([inflag:true], if mapatom(expr) then {} else
>        adjoin(op(expr),xreduce(union,**maplist(listofops,expr))))$
>

Note that this uses inflag:true.

Yes, so this has op(sqrt(x)) => "^"


> ------------------
> On Nov. 16, Dieter Kaiser wrote:
> ---------------------
>
>  An alternativ is the Maxima function dispform, see the Maxima manual.
>> This functions transforms an expression into the external representation
>> which contains the SQRT function:
>>
> ------------------------
> Sometimes the dispform method does not work.
> ---------------------
> (%i12) ?isinop(dispform(a*sqrt(a)),**sqrt);
>

a*sqrt(a) simplifies to a^(3/2) -- see my earlier discussion about what
exactly you mean by "including the operator 'sqrt' ".  So perhaps you want
to write code recognizing a^(3/2) as "including a sqrt".  How about
sqrt(sqrt(a)) = a^(1/4)?  Do you want that to be considered as "including
the operator sqrt?  Surely you don't want sqrt(a)*sqrt(a) (i.e. a) to be
considered as "including the operator sqrt"?

As for dispform, please review the documentation.  If you want dispform to
work recursively, you must use dispform(... , all).

              -s