On Wed, Nov 16, 2011 at 2:54 PM, Edwin Woollett <woollett at charter.net>wrote:
> I need a way to detect the op sqrt in an expression.
>
> So far, neither ?isinop or listofops seems to work:
> ------------------------------**---------------
> Maxima 5.25.1 http://maxima.sourceforge.net
> using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)
>
> (%i1) display2d:false$
>
> (%i2) ?isinop(a*bessel_j(0,x),**bessel_j);
>
> (%o2) bessel_j(0,x)
>
> (%i3) ?isinop(a*sqrt(x),sqrt);
>
> (%o3) false
>
If you want to know what's happening, try the following:
(%i2) sqrt(x);
(%o2) sqrt(x)
(%i3) :lisp $%o2
((MEXPT SIMP) $X ((RAT SIMP) 1 2))
Thus, sqrt is converted internally to, essentially, x^(1/2).
(%i3) ?isinop(a*sqrt(x),?mexpt);
(%o3) sqrt(x)
This doesn't check that the exponent is 1/2, though.
>
> (%i4) ?isinop(sqrt(x^2),sqrt);
>
> (%o4) false
>
This fails because sqrt(x^2) has already been simplified to abs(x) by the
time isinop sees it.
Ray