6214 Reputation

17 Badges

7 years, 316 days

MaplePrimes Activity

These are replies submitted by mmcdara

@Carl Love 

After correction I get these results:

Two observations:

  1. The evaluation of the Horner factored polynomial is about twice faster than than the evaluation of the polynomial itself and uses about half the latter's.
    U := RandomVariable(Uniform(0, 1)):
    P := randpoly(U, dense, degree=500): H := convert(P, horner, U):
    p := unapply(P, U):
    h := unapply(H, U):
    SU := Sample(U, 10^4):
    SP := CodeTools:-Usage( p~(SU) ):
    SH := CodeTools:-Usage( h~(SU) ):
    memory used=226.30MiB, alloc change=76.01MiB, cpu time=2.35s, real time=2.35s, gc time=219.37ms
    memory used=152.99MiB, alloc change=32.00MiB, cpu time=1.34s, real time=1.31s, gc time=50.12ms
    So the difference is not that large than the one you display in you answer to @Aliocha
    My question is: Why?
  2. Can you explain me a direct sampling of the two polynomials:
    1. give almost the same performances?
      Sh := CodeTools:-Usage( Sample(H, 10^4) ):
      S  := CodeTools:-Usage( Sample(P, 10^4) ):
      memory used=0.69MiB, alloc change=0 bytes, cpu time=619.00ms, real time=619.00ms, gc time=0ns
      memory used=505.40KiB, alloc change=0 bytes, cpu time=681.00ms, real time=681.00ms, gc time=0ns
    2. are much faster than the evaluations of these polynomials on a  U sample (point 1 bove)?

Finally, as the data type emphasize or lessen the differences between Horner and non Horner:

# With Integers

SU := LinearAlgebra:-RandomVector(10^4, generator=-10^3..10^3):
SP := CodeTools:-Usage( p~(SU) ):
SH := CodeTools:-Usage( h~(SU) ):
memory used=4.53GiB, alloc change=64.00MiB, cpu time=8.58s, real time=6.30s, gc time=3.76s
memory used=2.79GiB, alloc change=0 bytes, cpu time=4.30s, real time=2.99s, gc time=2.10s

# With Rationals

S1 := LinearAlgebra:-RandomVector(10^3, generator=1..10^3):
S2 := LinearAlgebra:-RandomVector(10^3, generator=1..10^3):
S3 := 2 *~ LinearAlgebra:-RandomVector(10^3, generator=0..1) -~1:
SU := S3 *~ S1 /~ S2:

SP := CodeTools:-Usage( p~(SU) ):
SH := CodeTools:-Usage( h~(SU) ):
memory used=1.78GiB, alloc change=0 bytes, cpu time=13.81s, real time=13.24s, gc time=925.67ms
memory used=0.95GiB, alloc change=0 bytes, cpu time=1.38s, real time=1.09s, gc time=458.98ms

when is Horner factorization useful and when it's useless?

# With Irrationals

S1 := LinearAlgebra:-RandomVector(10^4, generator=1..10^3):
SU := sqrt~(S1):

SP := CodeTools:-Usage( p~(SU) ):
SH := CodeTools:-Usage( h~(SU) ):
memory used=3.88GiB, alloc change=32.00MiB, cpu time=17.81s, real time=11.56s, gc time=8.61s
memory used=1.76GiB, alloc change=32.00MiB, cpu time=12.25s, real time=8.82s, gc time=5.09s












  2684004425077425823763313576 401      - 4360993989574992282441\












Error, while processing result

@Carl Love 

I've just updated my last reply

@Carl Love 

I think I'm also among those whi have been fooled by these stumbling blocks.
Could you help me understand what makes your results that different than those I uploaded in my initial comment.

And what yours are different from these:

@Preben Alsholm 

 I would replace Pi and sqrt(2) by evalf(Pi) and sqrt(2.), respectfully...
Right, I had already noticed that (equation (4) in the file  I attached to my my comment).
I suspected the error was a "display" erro due to the lentgh of the factored expression.

Yhanks for the kernelopts tip.

Interesting question, even if 10 or 12 is two small a degree to hope seeing something.
Nevertheless, using a degree of 500 (in Maple 2015 convert(P(x), horner, x) generates an error if degree(P(x), x)=1000) shows several differences as described in this file

In summary, it doesn't seem (that is my own feeling and I will be happy to read the opinion of more skilled members here) that the Horner representation has any real practical interest beyond its educational aspect.


because it is the closest of a build-in function (I already found your second solution).
As you're using linalg, I guess there's no LinearAlgebra equivalence, is there?

@Carl Love 

Thanks, this is what I suspected.


I didn't know about the `&#`||k||`;` syntax.

Does this mean that  mo(...)mi(...) are only useful if you want to change the font or add modifiers like mathsize and mathcolor for instance (not to mention msup, mover, ... of course)?


Sorry, I delete my reply

@Axel Vogt 

Thanks Axel.
I had just seen that Combine gave more or less the desired result when I saw your reply.

Unfortunately It doesn't work as it is with Maple 2015 (simplify doesn't drop the numeric part of the integrands out of the integrals... but this can be fixed by doing some extra opertaions).

Thanks again

Updated file:


Agree, Advanced Search is pitiful

@C_R already answered your question, so just take this as a simple comment:

eq  := a*x^2 + b*x = v;

eq1 := lhs(eq) - rhs(eq);

eq2 := a*x^2 + b*x - v;

a*x^2+b*x = v






type~([eq, eq1, eq2], `=`)

[true, false, false]


map(e -> if type~(e, `=`) then 'lhs'(e) = lhs(e) else "not of type `=`" end if, [eq, eq1, eq2])

[lhs(a*x^2+b*x = v) = a*x^2+b*x, "not of type `=`", "not of type `=`"]


for e in [eq, eq1, eq2] do
    print('lhs'(e) = lhs(e))
  end try
end do:

lhs(a*x^2+b*x = v) = a*x^2+b*x


select(type, [eq, eq1, eq2], `=`)

[a*x^2+b*x = v]


selectremove(type, [eq, eq1, eq2], `=`)

[a*x^2+b*x = v], [a*x^2+b*x-v, a*x^2+b*x-v]





Another idea which avoid intrducing intermediate points in the definition of the red line rl:

bl   := plot([[1, 0], [6, 5]], color="#0072BD", thickness=3):
lr3D := transform((x, y) -> [x, y, -1/2])(lr):
rr3D := transform((x, y) -> [x, y, 1/2])(rr):

rl := plots:-spacecurve([x, x, tanh(100*(x-7/2))], x=1..6, color=red, thickness=3):

bl3D := transform((x, y) -> [x, y, 0])(bl):

  lr3D, rr3D, bl3D, 
  lightmodel=none, labels=[x, y, z], orientation=[-90, 0, 0]

For information: my first try was

plot([[1, 1], [6, 1]], color=red, thickness=3):
 lr3D, rr3D, bl3D,
 transform((x, y) ->[ x, y, tanh(100*(x-7/2)])(rl)

but for some unknown reason (in Maple 2015) the red line is not "broken and looks like the result of 

plot([[1, 1, -1], [6, 1, 1]], color=red, thickness=3):

For fun this can be generalized this way to make a weawing


I asked this question a few years ago (I wasn't aware to recover it) and, from memory, I was said the order was predefined my Maple (lines are always before rectangles circles, ...).

Here is a workaround where each line is transformed into a polygon, for instance:

h  := 0.1:
al := [[1, 0], [6, 5]]:
al := [al[], (al[[2, 1]] +~ [[0, h]$2])[]]:
pl := PLOT(POLYGONS(al, COLOR(RGB, ColorTools:-HexToRGB24("#0072BD")[]), STYLE(PATCHNOGRID))):

@Preben Alsholm 

Thanks for these last comments.

(123 is indeed quite large)

To illustrate my previous reply here is a very simple example concerning what I am working on.
The aim here is to prove the relation: variance(V) = mean(V^2) - (mean(V))^2.

4 5 6 7 8 9 10 Last Page 6 of 126