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

@The function 

For the spherical and hemispherical tanks, the tank's constant height and radius R (as opposed to the fluid's variable height h and top radius r(h)) are the same, H=R, so only is used.

I know from your other posts that you're pursuing a self-education in calculus (and perhaps other math subjects). Are you using Maple merely as an aid to learning calculus? Or are you trying to obtain a good knowledge of Maple as well? If it's just an aid, I wouldn't put too much effort into studying all of my code above, because the non-calculus parts are too deep. Specifically, the too-deep parts are

  1. handling tank types in an object-oriented way with Record,
  2. processing an array of tanks with single operations using elementwise operators (those containing the character ~),
  3. tabular formatting of the output using the Matrix/Vector constructors <...> and <...|...>,
  4. using MathML to format the tanks' names via nprintf(`#mn("%s")`, T:-name).

Anyway, any questions that you have about it are welcome.

@nm You wrote in another thread but referring to this thread:

  • I will test your code there [in this thread] now and see how it works. I am sure it will work well.

I'm not 100% confident that it (i.e., object-method overriding and polymorphism) works perfectly. That's why I was so eager to get a response regarding your testing. Please let me know if your testing reveals anything.

@nm Thank you for responding.

I wholeheartedly agree that Stackexchange has numerous features along these lines that MaplePrimes lacks.

Re email subscriptions: The box that Rouben mentioned used to be pre-checked, which is commonly called an "opt-out" option. I believe that Canada enacted a law or regulation requiring "opt-in" for email subscriptions, which is why that box is no longer pre-checked.

I'll put a response specifically related to the other thread in that thread.

I have no problem with people asking purely mathematical Questions here, i.e., Questions without obvious Maple content; so this Reply is not meant as a criticism of your posting etiquette. Anyway, it's obvious that Maple has the ability to manipulate the objects that you asked about.

Googling "circular polynomials" hasn't revealed to me anything relevant. Is there perhaps another name for these polynomials?

What, if any, Maple operations would you like to perform with these? 

Although I'm sure that you're capable of writing your own constructor, here's mine: 

CircPoly:= (x::name, n::And(posint, Not(1)), E::[algebraic,algebraic])->
    inner(zip(`^`~, (index~)~(x, [[$1..n], [$2..n, 1]]), E)[]) 
:
CircPoly(x, 3, [p, q]);

                p     q       p     q       p     q
            x[1]  x[2]  + x[2]  x[3]  + x[3]  x[1] 

It doesn't matter whether p and q are instantiated before or after the construction or at all.

@lcz When used in a procedure, _rest is a keyword for arguments, if any, that were passed in but weren't declared as parameters.

@mmcdara Although it apparently hasn't happened in this particular case (for a reason given below), the method that you show is almost as prone to catasthrophic roundoff as the original expression. Kitonum's method completely avoids the roundoff by reducing the number of floating-point computations to just one, the final division.

The reason that you avoided the problem is that the simplify caused an extreme reduction in degree, which seems like quite a nonstandard circumstance.

(degree@~[numer,denom])~([expr, simplify(expr)]);
                     
[[28, 36], [8, 16]]

I'm sorry to post here about an unrelated Question, but you've either missed or ignored my Reply to you on this other thread "provide way to override variable and method in base class by classes that extend base class?" If you won't write a meaningful response to my Answer there, then I won't take the time and effort to respond to any more of your Questions (which are usually good questions). I am very disappointed by the lack of responses from you and others.

@janhardo Are you proposing to use an SSD instead of your primary memory because it might be faster that way? I'd be surprised if that worked, but I suppose it's theoretically possible if the primary memory is significantly older technologically than the SSD. 

@Nimd_at In this code snippet

DirectSearch:-DataFit(
    ffit2(etaL, L0, t)
  , [eta_L=0.0001 .. 0.1, L0=1.5e10 .. 1.7e10]
  , X0, Y0, t
  , strategy=globalsearch
  , evaluationlimit=30000, initialpoint=[L0=1e10, eta_L=0.006]
);

you've used both etaL and eta_L. I don't see how both could be correct.

@The function You wrote:

  • For ever height down, the radius grows with 1/4 the height. The formula for the volume of a cone according to google is: V=Pi*(r^2)*h/3, and that gives the formula volume V=Pi*((x/4)^2)*x/3. Its as easy as that. Nothing more to explain there.

But the volume of the cone is irrelevant. The horizontal slice at height x and infinitesimal thickness dx should be considered a cylinder. Its volume does matter. That volume is Pi*(x/4)^2*dx. That volume is lifted a distance of (2-x) to get it out of the tank. So the work done just getting that slice out is rho*g*Pi*(x/4)^2*(2-x)*dx (where rho is the density and g is the acceleration due to gravity). Integrate that from 0 to 2.

Parts b and c should also be done as horizontal slices, which will also be cylinders. The only difference from part a is the height-radius relationship.

@janhardo The number of base-10 digits of M_n = 2^n-1 (regardless of whether that's prime) can be quickly computed with logarithms without needing to actually compute M_n, like this

MersenneDigits:= (n::posint)-> ceil(evalf[2+ilog10(n)](n*log10(2))):
MersenneDigits(82589933);

                           
24862048

Maple has no trouble computing M_n itself; however, I warn you not to display it onscreen!! Use a colon to suppress the output!

@lijr07 I think that this'll work in Maple 2019:

TypeTools:-RemoveType('Monomial'): #avoid silly warning
TypeTools:-AddType(
    'Monomial',
    proc(e)
    local Var:= 'Y'[integer $ 2], Pow:= {Var, Var^rational};
        e::Pow or 
        e::'specop'(
            {Pow, Not({constant, 'satisfies'(e-> hastype(e, Var))})},
            `*`
        )
    end proc
)
:

@janhardo 

The memory allocation required for my code is quite modest and is proportional to (the exponent), i.e., it's O(p). Specifically, it's (3/4)*p bytes for the data (4 p-bit integers and 1 2*p-bit integer) plus a constant amount for Maple to load the procedures.

However, you did discover (and I can document) an extremely severe memory-leak bug in Maple's handling of very-large-integer arithmetic. Specifically, this bug occurs if and only if the prime p > 524221. That's far above the range that I tested. I found a surprisingly simple workaround: Just replace s^2 with `*`(s, s) (I think that that may require 1D input to not get automatically converted back to s^2). Here's the updated code, and I've made a few other very minor changes.

(*---
Compute N mod (2^n-1) via bitwise operations. N must be < 4^n, which'll
always be true if this is used in a repeated-squaring operation such as
in IsMersennePrimeExponent.
-----*)
BitMod:= (N::posint, n::posint)->
local B:= Bits:-Split(N, n);
    `if`(nops(B) < 2, `if`(ilog2(N+1) = n, 0, N), thisproc(add(B), n))
:
(*---
Check whether (2^p-1) is prime by Lucas-Lehmer algorithm.
-----*)
IsMersennePrimeExponent:= proc(p::And(prime, Not(2)))
local s:= 4;
    to p-2 do s:= BitMod(`*`(s,s), p) - 2 od;
    evalb(s=0)
end proc:
IsMersennePrimeExponent(2):= true
:


The next prime after 524221 is 524331. I just tested with this exponent using a total memory allocation of 146.1 Mb and a time of 32 minutes. The time required for the algorithm is essentially proportional to p^2 when the more-efficient large-integer multiplication kicks in. Specifically, it's O(p^2*ln(p)*ln(ln(p))). I suspect that the value of that I just used is precisely where that more-efficient multiplication kicks in because that's the first prime value of p such that the GMP representation of 2^p-1 has more than 2^13 memory words. Extrapolating from that 32 minutes, I predict that your prime 1398269 would take 4 hours 12 minutes on my computer, an Intel Core I-7 @ 2.7 GHz. Extra processors have little effect on this (but can be used to process multiple primes simultaneously).

@lijr07 Thanks. I modified the Answer so that it now also handles inert exponents, as in x%^2.

@lijr07 What about sin(t+x)*x?

First 110 111 112 113 114 115 116 Last Page 112 of 709