detect sqrt in expression?



On Nov. 19, Raymond Toy wrote:
---------------------------
>If multival really means multi-valued function, then aren't all of the
>following wrong?  Shouldn't they return true because they are multivalued?

My description of this function  must include that it is only
to be used in the context of nint, that is numerical integration,
in which the integrand is stuff which evaluates to numbers
except for the (real!) variable of integration (here, x), and the limits
of integration are either minf, inf, or things which evaluate
to numbers.

Constructing a function which could be used generally with
Maxima to detect a multiple valued function in the widest
possible context was not my goal.

I am just concerned with avoiding integrate for a numerical
definite integral when there is a possibility of a wrong
answer.

>> (%i5) multival(x*sqrt(x^2),x);
>>
>> (%o5) false

this case would never be tested inside nint because it
would already be simplified before multival ever looked at it.

(%i2) x*sqrt(x^2);

(%o2) x*abs(x)

will be a single valued real number if x is real (which it is in nint),
and
(%i4) multival(x*abs(x),x);

(%o4) false

>> (%i6) multival(a^x,x);
>>
>> (%o6) false

It was misleading to use an undefined symbol a
in my tests, since such cannot legally appear in the
integrand for the case of getting a number from
a definite integral. Instead I should have used real or imaginary
numbers, or %e or %pi.

>> (%i7) multival(a^(%i*x),x);
>>
>> (%o7) false
>>

the case a^(%i*x) includes cases where a is a number
  or %pi or %e, in the latter case exp(%i*x) is an
  entire function
  3^(%i*x) = exp(log(3^(%i*x))) = exp(%i*x*log(3)) is
  also an entire function

If a = %i, then multival should return true.

My first version returned wrong results for both
 %i^x and x^x.

This second version has cures.
-------------------------------------------------
Maxima 5.25.1 http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (a.k.a. GCL)

(%i1) load(hasmultv);

(%o1) "c:/work2/hasmultv.mac"
(%i2) multival(%i^x,x);

(%o2) true
(%i3) multival((3*%i)^x,x);

(%o3) true
(%i4) multival((3+%i)^x,x);

(%o4) true
(%i5) multival(3^x,x);

(%o5) false
(%i6) multival(3^(%i*x),x);

(%o6) false
(%i7) multival(%i^(x^2),x);

(%o7) true
(%i8) multival(x^(3+1/2),x);

(%o8) true
(%i9) multival(x^%i,x);

(%o9) true
(%i10) multival(x^x,x);

(%o10) true
(%i11) multival(sqrt(x),x);

(%o11) true
(%i12) multival(x*sqrt(x),x);

(%o12) true
(%i13) multival(x*sqrt(x^2),x);

(%o13) false

(%i14) multival(5^(2/3),x);

(%o14) false
(%i15) multival(%pi^(2/3),x);

(%o15) false
(%i16) multival(x^(2/3),x);

(%o16) true
(%i17) multival(x^(%i*x),x);

(%o17) true
(%i18) multival(x^(%i*sin(x)),x);

(%o18) true
(%i19) multival(log(x),x);

(%o19) true
(%i20) multival(sqrt(x)*log(x),x);

(%o20) true
(%i21) multival(acos(x),x);

(%o21) true
(%i22) multival(x^acos(x),x);

(%o22) true

=============================
with the code

any_of(list) := member(true,list)$

 /* multival(e,x) returns true if a potentially multiple valued
     function of x is detected in expression e */


multival(ex,var) := block([inflag:true,listconstvars:true],
      if debug then print("  multival, ex = ",ex),

      if mapatom(ex) then false

      else if member(op(ex), '[log, acos,acosh,acot,acoth,acsc,acsch,
                            asec,asech,asin,asinh,atan,atan2,atanh] ) and
                      member(var,listofvars(ex)) then true

      else if op(ex) = "^" and mvp(ex,var) then true

      else any_of(maplist(lambda ([u],multival(u,var)),ex)))$





  /* version 2 mvp(e,v)
        mvp(e,v) returns true if  e = f^g has either the
         form %i^g(x), f(%i)^g(x),  f(x)^g with g # integer */

   mvp (e,v) := block([inflag:true],

       if debug then print("  mvp,  e = ",e),

       if mapatom(e) then false

       else if length(e) = 1 then false

       else if part(e,1) = -1 and
                  member(v,listofvars(part(e,2))) then true

       else if lfreeof ([v,%i], part (e,1)) then false

       else if integerp(part(e,2)) then false

       else if member(v,listofvars(part(e,1))) and
                    not integerp(part(e,2)) then true

       else if member(%i,listofvars(part(e,1))) and
                  member(v,listofvars(part(e,2))) then true

       else any_of(maplist(lambda ([u],mvp(u,v)),e)))$


  debug:false$
 -----------------------------------------

Ted