Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 355 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

@tomleslie Both sqrt(a) and a^b are uniquely defined and positive for any a > 0b::real. The "cannot determine" issue isn't due to ambiguity; it's due to Maple avoiding floating-point evaluation of symbolic constant expressions unless the user forces it to with is or by some other means.

@bmartin Given that the OP wishes to access the posted procedure from a library, the with command (used at the top level) wouldn't be appropriate, and it doesn't work correctly if used within the procedure (as explained at ?with).

@nryq I put my code for the plot of #2 under my earlier Answer.

@nryq To plot #2, the sphere-capped cone, you need to know that the sphere's center is [0, 0, 1/2] and its radius is 1/2. This Answer doesn't cover the steps (completeing the square) to do that. It's just simple algebra that I find easier to do in my head than with Maple.

Cone:= z=sqrt(x^2+y^2):
Sphere:= z=x^2+y^2+z^2:
simplify(
    changecoords([Cone, Sphere], [x,y,z], cylindrical, [rho, phi, z]),
    symbolic
);
                    [                2    2]
                    [z = rho, z = rho  + z ]
plots:-display(
    plot3d~(
        [[z, phi, z], [sqrt(z-z^2), phi, z]],
        z=~ [0..1/2, 1/2..1], phi= -Pi..Pi, coords= cylindrical,
        scaling= constrained
    )
);

MaplePrimes isn't letting me copy-and-paste plots anymore! You'll need to run the above to see the plot. It looks like a squat ice cream cone.

@dharr The significant difference, which is obscured by your use of 2D Input, is that you've used t__1 instead of the OP's t[1].

@acer Thanks for finding the error. It's now fixed in the Answer above.

@Jennzy26 You've asked many Questions over the past few days, and you've received several Answers with Maple code. But I haven't seen you try to write any. Can you try to write some, even if it's completely wrong? Then I'd be willing to help you correct it.

And, before you can code a solution, you need to understand the math. So, do you understand that my hint implies solving the extremely simple equations {f '(p) = tan(Pi/3), f '(q) = tan(-Pi/3)} where f(x) = 1-x^2, and then the points are P = (p, f(p)), Q = (q, f(q))?

@nm I understand the problem, but I have no workaround at this point. From my experiments so far, it seems that in the declaration

option object(parentclass);

the name parentclass must be global and already defined as an object module. There are still many things in Maple that need global names (such as procedures named `<some command>/...`).

Nonetheless, if you're willing to use a global name for the parent, it seems like inheritance, overriding, and polymorphism work as described in my Answer above.

Using Maple's object-oriented facility, you can create objects that will display (or print) in the ways that we've already discussed in this thread but can still be treated as ordinary Maple mathematical expressions. You can redefine what any of the arithmetic operators (such as +^) do when used with these objects. You can define what happens when the object is applied as a function to an argument or argument sequence. You can define what happens when the object is given an index or index sequence (such as the [i,j] in A[i,j]).

@Sradharam The presence of fractional powers of lambda makes the coefficient extraction a little bit tricky. I suggest replacing lambda with 1/L^2 from the start and then substituting L= 1/sqrt(lambda) after the coefficients are extracted, like this:

restart:
ODE:= ... your original

#new f, using L instead of lambda:
f:= x-> f__0(x) + L*f__w*f__1(x) + L^2*f__2(x):
 
Coeffs:= proc(
    e::{`=`, thistype}(algebraic), x::{thistype, list, set}(name)
)
local 
    t, 
    C:= coeffs(
        collect(`if`(e::`=`, (lhs-rhs)(e), e), x, 'distributed'), 
        x, t
    )
; 
    table([t]=~[C])
end proc
:
C:= table(subs(L= 1/sqrt(lambda), op(2, Coeffs(ODE, [L, f__w])))):

#List all appearing lambda^a*f__w^b combos ("1" is terms with no
#lambda, no f__w):
[indices](C, nolist);
[                            2                   3              
[     1        f__w      f__w       1        f__w         1     
[1, ------, -----------, ------, -------, -----------, -------, 
[   lambda        (3/2)  lambda        2        (3/2)        3  
[           lambda               lambda   lambda       lambda   

                                 2 ]
     f__w         f__w       f__w  ]
  -----------, -----------, -------]
        (5/2)        (1/2)        2]
  lambda       lambda       lambda ]

#Extract a coefficient:
C[1/lambda];
         /  3         \ /  2         \ /  2         \
         | d          | | d          | | d          |
    36 K |---- f__0(x)| |---- f__0(x)| |---- f__2(x)|
         |   3        | |   2        | |   2        |
         \ dx         / \ dx         / \ dx         /

                                           2
              /  3         \ /  2         \ 
              | d          | | d          | 
       + 18 K |---- f__2(x)| |---- f__0(x)| 
              |   3        | |   2        | 
              \ dx         / \ dx         / 

           /  3         \             /  3         \        
           | d          |             | d          |        
       + 2 |---- f__0(x)| f__2(x) + 2 |---- f__2(x)| f__0(x)
           |   3        |             |   3        |        
           \ dx         /             \ dx         /        

                                           /  3         \
           / d         \ / d         \     | d          |
       - 2 |--- f__0(x)| |--- f__2(x)| + 3 |---- f__2(x)|
           \ dx        / \ dx        /     |   3        |
                                           \ dx         /

#Extract another:
C[f__w/sqrt(lambda)];
         /  3         \ /  2         \ /  2         \
         | d          | | d          | | d          |
    36 K |---- f__0(x)| |---- f__0(x)| |---- f__1(x)|
         |   3        | |   2        | |   2        |
         \ dx         / \ dx         / \ dx         /

                                           2
              /  3         \ /  2         \ 
              | d          | | d          | 
       + 18 K |---- f__1(x)| |---- f__0(x)| 
              |   3        | |   2        | 
              \ dx         / \ dx         / 

           /  3         \             /  3         \        
           | d          |             | d          |        
       + 2 |---- f__0(x)| f__1(x) + 2 |---- f__1(x)| f__0(x)
           |   3        |             |   3        |        
           \ dx         /             \ dx         /        

                                           /  3         \
           / d         \ / d         \     | d          |
       - 2 |--- f__0(x)| |--- f__1(x)| + 3 |---- f__1(x)|
           \ dx        / \ dx        /     |   3        |
                                           \ dx         /
#etc.

 

@janhardo The last line in my code box is an example that runs all three procedures on the same input, producing the same output. Sorry for not posting the output, but MaplePrimes makes that difficult for Vector/Matrix output, which I often prefer because it's columnar. 

@Rouben Rostamian Certainly that output is okay for many purposes, and this Reply is not meant as criticism. Rather, I want to point out a surprising tiny detail that most people who read typeset mathematics are likely not consciously aware of but which will become subconsciously bothersome if it's changed: The space between operands in implied multiplication is larger than the space between the operator and the left parenthesis of the arguments in a function application. Simply compare the prettyprinted output of f(x) and f*``(x).

@janhardo Maple's large-integer arithmetic is done by GMP (it's just a coincidence that that is spelled similar to GIMPS). GMP is a 3rd-party open-source library which is highly optimized for different processors. It's likely that it makes significant use of your processor's cache memory (memory on the processor chip itself), which is much faster than your regular "internal" memory plugged into the motherboard. The bottleneck operation for the Lucas-Lehmer test (LLT) is the s:= s^2 (or its workaround s:= `*`(s,s)), where s is essentially an array of approximately ceil(p/64) 64-bit "words" (the conversion of s to base 2^64). I think that it's fairly easy to keep this array cached, or at least partially cached if the cache is small. For the largest known Mersenne prime, the array would be about 1.4 million words, which is not extremely large compared to other numeric arrays that are routinely handled by Maple.

@ArashMhasani The method that I showed has a brutal, unforgiving syntax where the only feedback that you'll get from the system is a simple echoing of your input if you make the slightest syntax error[*1]. So, Rouben's method is definitely the way to go when it works. However, that method will not work with arguments because the application of an operator to arguments takes precedence over exponentiation. Thus A^b(c) is interpreted as having b(c) in the exponent, whereas the system will refuse to display (A^b)(c) without parentheses around A^b.

The trick to get around this and many other printing dilemmas is to construct a symbol (a form of name) which Maple's mathematical/computational "kernel" (aka "engine") will treat as just a symbol but which displays as a more complicated mathematical object. That's where MathML comes in. 

[*1] I mean if you make a syntax error between back quotes `...`. That part is not analyzed by the kernel. 

@vv Yes, I enjoyed writing it. Here it is:

CyclSum:= (f, x::name, n::posint)->
    local j,k; add(f(seq(x[1+irem(j+k-2, n)], j= 1..n)), k= 1..n)
:   
CyclSum(`*`@(()-> args^~(p,q,r)), x, 3);
       p     q     r       p     q     r       p     q     r
   x[1]  x[2]  x[3]  + x[2]  x[3]  x[1]  + x[3]  x[1]  x[2]
First 109 110 111 112 113 114 115 Last Page 111 of 709