sursumCorda

1174 Reputation

13 Badges

2 years, 76 days

MaplePrimes Activity


These are replies submitted by sursumCorda

@C_R Thanks. I believe that the default simplifier is set up to avoid some of sophisticated but time‐consuming transformations that may make remarkable simplifications. (So I hope there will be a smarter approach to automatically simplify the second one in Maple.) 

@vv Thanks. I think there're (at least) 2 points: 

  1. In practice, simply typing <…, …; …, …> is apparently more convenient than typing Matrix([[..., ...], [..., ...]])), and 
  2. it appears that in this way one can access a new container (a Matrix) without constructing another temporary data structure (a list (of list)). 

@vv Thanks. The trouble is that neither special evaluation nor Construction Shortcuts mentions that `<,>` (as well as `<|>`) has special evaluation rules. Anyway, is there a direct way to force the arguments to be completely evaluated immediately (rather than being evaluated under the control of the procedure)?

@nm A simpler result of int(sin(x)^(1/3),x) seems to be `&*`(3/4,(cos(x)/'sqrt'(cos(x)**2)),hypergeom([1/2,2/3],[5/3],sin(x)**2),sin(x)**(4/3))+_C, yet Maple cannot verify it: 

RealDomain:-simplify(diff(3/4*cos(x)/sqrt(cos(x)^2)*hypergeom([1/2, 2/3], [5/3], sin(x)^2)*sin(x)^(4/3), x) - sin(x)^(1/3));
 = 
1        (1/3) /                  /[3  5]  [8]        2\       2
-- sin(x)      |3 cos(x) hypergeom|[-, -], [-], sin(x) | sin(x) 
10             \                  \[2  3]  [3]         /        

                        /[1  2]  [5]        2\
   + 10 cos(x) hypergeom|[-, -], [-], sin(x) |
                        \[2  3]  [3]         /

                      \               
   - 10 signum(cos(x))| signum(cos(x))
                      /               


plot(%, x = -Pi .. Pi);

plot(RealDomain:-simplify(-sin(x)^(1/3) + diff(3/4/(cos(x)/sqrt(cos(x)^2))*hypergeom([1/2, 2/3], [5/3], sin(x)^2)*sin(x)^(4/3), x)),x=-Pi/1..Pi/1)

@Thomas Richard Thanks. After some experimentation, I find that after the normalization, one can directly use simplify rather than evalccombine:  

combine(evalc(normal(convert(sineExpr(4), exp), expanded)), trig);
   sin(a[4] + a[3] + a[2] + a[1] - b[1] - b[3] - b[2] - b[4])

simplify(normal(convert(sineExpr(4), exp), expanded), exp);
   sin(a[4] + a[3] + a[2] + a[1] - b[1] - b[3] - b[2] - b[4])

combine(evalc(normal(convert(sineExpr(5), exp), expanded)), trig);
sin(a[5] + a[4] + a[3] + a[2] + a[1] - b[2] - b[5] - b[4] - b[1] - b[3])


simplify(normal(convert(sineExpr(5), exp), expanded), exp);
sin(a[5] + a[4] + a[3] + a[2] + a[1] - b[2] - b[5] - b[4] - b[1] - b[3])


Anyway, your approach is still illuminating! 

@Christian Wolinski Actually, all of these functions are purely syntactical; none of them attempts to recognize hidden zero values 

m__1 := <allvalues(RootOf(_Z*(4*_Z^2 - 3)*((4*_Z + 1)^2 - 5) + 2))> -
    :-cos ~ (2*Pi/11*<2, 1, 3, 4, 5>):
ArrayTools:-IsZero(m__1);
 = 
                             false

andmap(is, m__1, 0);
 = 
                              FAIL

rtable_is_zero(m__1);
 = 
                             false

andmap(testeq, m__1);
 = 
                              FAIL

linalg:-iszero(m__1);
 = 
                             false

even if no nonzero item exists: 

radnormal~(convert~(m__1, RootOf)); # Each element is zero. 
                              [0]
                              [ ]
                              [0]
                              [ ]
                              [0]
                              [ ]
                              [0]
                              [ ]
                              [0]

I think this is partly because that kind of function is somewhat mathematically irrelevant to both linear algebra and matrix theory.

By the way, for a rtable, the most efficient command seems to be the undocumented rtable_is_zero

m__0 := Array((1 .. 1e2) $ 4): # not sparse 
CodeTools:-Usage(ArrayTools:-IsZero(m__0));
 = 
memory used=1.49KiB, alloc change=0 bytes, cpu time=25.00s, real time=25.07s, gc time=0ns

                              true

CodeTools:-Usage(andmap(`=`, m__0, 0));
 = 
memory used=6.71GiB, alloc change=0 bytes, cpu time=5.82m, real time=76.52s, gc time=5.27m

                              true

CodeTools:-Usage(rtable_is_zero(m__0));
 = 
memory used=1.14KiB, alloc change=0 bytes, cpu time=703.00ms, real time=704.00ms, gc time=0ns

                              true

CodeTools:-Usage(linalg:-iszero(m__0));
Error, (in linalg:-iszero) argument must be a matrix or a vector 

 (The elasped time appears to be the "real time" instead of the "cpu time".) 

Sorry, what is the exact meaning of the term "twin"? (For example, what is the relationship between 1 and [4, 5]? I cannot find any relationship between 2 and [9, 12].) 

@acer Thanks. These are really good ideas. But oddly enough, your second replacement rule for m = 4 works in the version released ten years ago! And the execution time in Maple 18 is far less than that in the latest version (although your first approach is still more efficient). 
 

restart;

interface(version)

Warning, inserted missing semicolon at end of statement

 

`Standard Worksheet Interface, Maple 18.02, Windows 8, October 20 2014 Build ID 991181`

(1)

sineExpr:=(m::posint)-> #_local t,j;
                        add(mul(`if`(j<>t,
                                     ':-sin'(a[j]-b[t])/':-sin'(b[j]-b[t]),
                                     ':-sin'(a[t]-b[t])),j=1..m),t=1..m):

P2_real:=proc(n) local i,e,r,T;
        e:=sineExpr(n):
        r:=add(b[i],i=1..n)=T;
        eval(combine(simplify(expand(RealDomain:-simplify(e,{r},'parse'("mindeg"))))),(rhs=lhs)(r));
end proc:

seq(CodeTools:-Usage(print(P2_real(i))), i=1..4);

sin(a[1]-b[1])

memory used=1.96MiB, alloc change=8.10MiB, cpu time=62.00ms, real time=62.00ms

sin(a[2]+a[1]-b[1]-b[2])

memory used=8.31MiB, alloc change=4.06MiB, cpu time=63.00ms, real time=63.00ms

sin(a[1]+a[2]-b[1]-b[2]-b[3]+a[3])

memory used=49.63MiB, alloc change=49.10MiB, cpu time=500.00ms, real time=515.00ms

sin(a[3]-b[1]-b[2]-b[3]-b[4]+a[4]+a[1]+a[2])

memory used=4.29GiB, alloc change=1.31GiB, cpu time=55.67s, real time=55.50s

(2)


 

Download sinId_acce.mw

 Regretfully, the same result of P2_real(4) cannot be reproduced in recent versions (e.g., Maple 2024); this indisputably implies a terrible performance regression. (Actually, some scholars recently stated that “for certain trigonometric computations, Maple is less effective”, which is likely due to such a performance regression.) 

@Scot Gould According to DLMF, at least those hypergeometric functions in my initial example doesn't need the valuable to be limited to non-negative. As for the assumptions, I think this could be due to the following reasons: Though the result given by Mma contains the natural logarithm and the cosine integral, and the two are not defined for non-positive real values, the difference between them (namely, ln(x)-Ci(x)) has no singularities or discontinuities in (-∞, 0], which might be more usable (especially in physics and engineering). 

It turns out to be zero but only at origin x=0

I think that this is because a real solution is missing (without any warning message): 

ode:=diff(y(x),x)=3*x*(y(x)-1)^(1/3):
ic:=y(3)=-7:
y(x)=1-(x^2-5)^(3/2); # the lost solution 
                    y(x)=1-RealDomain:-`^`(x^2-5,3/2)

odetest(`%`,[map(convert,ode,surd),ic],y(x)) assuming x^2>=5;
                             [0, 0]

@dharr Thanks! Quite strangely, 

convert(hypergeom([1, 1, 3/2], [5/2, 5/2, 3, 3], +z), 'StandardFunctions'):

works, but

convert(hypergeom([1, 1, 3/2], [5/2, 5/2, 3, 3], -z), 'StandardFunctions'):

does not work. I believe Maple forgot something here. 

Besides, I try to use the same idea to simplify (or expand) the Gauss hypergeometric function 

hypergeom([1/4, 1/2], [5/4], z**4);

 unfortunately, even the more powerful `convert/StandardFunctions` does not work this time: 

simplify(hypergeom([1/4, 1/2], [5/4], z**4), hypergeom);
 = 
              simplify(hypergeom([1/4, 1/2], [5/4], z^4), hypergeom) 

convert(hypergeom([1/4, 1/2], [5/4], z**4), 'StandardFunctions');
 = 
                   convert(hypergeom([1/4, 1/2], [5/4], z^4), 'StandardFunctions')

convert(hypergeom([1/4, 1/2], [5/4], z**4), 'Elliptic_related');
 = 
             convert(hypergeom([1/4, 1/2], [5/4], z^4), 'Elliptic_related')

convert(hypergeom([1/4, 1/2], [5/4], z**4), EllipticF);
 = 
                   convert(hypergeom([1/4, 1/2], [5/4], z^4), EllipticF)

Yet plot(InverseJacobiSN(z, I)/z - hypergeom([1/4, 1/2], [5/4], z**4), z = -Pi/3 .. Pi/3, 'legend' = hypergeom([1/4, 1/2], [5/4], z**4) - EllipticF(z, I)/z, 'color'=ColorTools:-Color([0.368417, 0.506779, 0.709798]), 'discont'=true, 'adaptive'=8, 'gridlines'=true) suggests that piecewise(z<>0,hypergeom([1/4, 1/2], [5/4], z**4) = EllipticF(z, I)/z)
Is there a workaround to transform z*hypergeom([1/4, 1/2], [5/4], z**4) into EllipticF(z, I)

@Thomas Richard Many thanks. I had only noticed the `simplify/hypergeom` before and did not realize there was also a `convert/StandardFunctions`. (There exists a typo in the initial instance. Sorry for this ... I made the correction just now.) 

I think there are two additional questions:
The documentation says that the expand command also expands most mathematical functions, but those "most mathematical functions" do not include the generalized hypergeometric functions. If I understood correctly, convert(hypergeom(…), 'StandardFunctions') is semantically equivalent to expand(hypergeom(…)), but why is only the former form valid? 
And can hypergeom([1, 1, 3/2], [5/2, 5/2, 3, 3], -(x/2)**2) (the first one in the aboce list) be transformed by Maple (as this time even `convert/StandardFunctions` does not work)? 

   local f:=proc(a,b)
      RETURN(MmaTranslator:-Mma:-LeafCount(a)<MmaTranslator:-Mma:-LeafCount(b))
   end proc;

However, Mathematica by default does not use LeafCount to rank the complexity

In[1]:= FullSimplify[4*Log[10]] (* by default *) 

Out[1]= 4 Log[10]

In[2]:= FullSimplify[4 Log[10], ComplexityFunction \[Rule] ByteCount]

Out[2]= Log[10000]

In[3]:= FullSimplify[4*Log[10], ComplexityFunction \[Rule] LeafCount]

Out[3]= Log[10000]

Compare: 

full_simplify(4*ln(10));
 = 
                            4 ln(10)

So, in the sense that MmaTranslator:-Mma:-LeafCount is used to assess the complexity, your full_simplify does not fully simplify 4*ln(10) to the desired ln(10000). (And it seems that there is much more that needs to be implemented to follow Mma's FullSimplify.) 

@nm The first distribution that supported Python 3 is Maple 2018. Although this is practicable, I believe that that it is more advisable not to install another Python; otherwise Maple will have to become a bloat-ware in the future (as there will be increasingly fashionable external evaluate frameworks other than Python (such as Julia and Go))! 

2 3 4 5 6 7 8 Last Page 4 of 22