John May

Dr. John May

2616 Reputation

18 Badges

17 years, 294 days
Maplesoft
Pasadena, California, United States

Social Networks and Content at Maplesoft.com

I have been a part of the Mathematical Software Group at Maplesoft since 2007. I have a Ph.D in Mathematics from North Carolina State University as well as Masters and Bachelors degrees from the University of Oregon. I have been working on research in computational mathematics since 1997. I currently work on symbolic solvers and visualization as well as other subsystems of Maple.

MaplePrimes Activity


These are replies submitted by John May

As I understand it, subs will do a traversal of the full expression as a tree while eval is more careful to traverse the expression as a DAG.  With Maple 12:

foo:=expand((sin(v)+cos(u)+cos(w)+2*sin(w)+cos(v)+1)^20):
bar := add((foo+i)^2, i=1..200):
time(subs({u=0, v=0, w=0}, bar));
                                    30.717

memory used=893.6MB, alloc=809.4MB, time=51.10

And in a new session:

foo:=expand((sin(v)+cos(u)+cos(w)+2*sin(w)+cos(v)+1)^20):
bar := add((foo+i)^2, i=1..200):
time(eval(bar,{u=0, v=0, w=0}));
                                    22.685

memory used=588.2MB, alloc=573.5MB, time=41.66

John

As I understand it, subs will do a traversal of the full expression as a tree while eval is more careful to traverse the expression as a DAG.  With Maple 12:

foo:=expand((sin(v)+cos(u)+cos(w)+2*sin(w)+cos(v)+1)^20):
bar := add((foo+i)^2, i=1..200):
time(subs({u=0, v=0, w=0}, bar));
                                    30.717

memory used=893.6MB, alloc=809.4MB, time=51.10

And in a new session:

foo:=expand((sin(v)+cos(u)+cos(w)+2*sin(w)+cos(v)+1)^20):
bar := add((foo+i)^2, i=1..200):
time(eval(bar,{u=0, v=0, w=0}));
                                    22.685

memory used=588.2MB, alloc=573.5MB, time=41.66

John

This tripped me up not too long ago, so I feel like I should point out that the subs and eval calls Mariner gives are not exactly equivalent,   the eval will do similtaneous substitution while the subs call does sequential substitution:

subs( x=y, y=x, [x,y] );
                                    [x, x]

eval([x,y], {x=y, y=x});
                                    [y, x]


The following are equivalent:

# Simultaneous
subs( [x=y, y=x], [x,y] );
                                    [y, x]

eval([x,y], {x=y, y=x});
                                    [y, x]

and

# Sequential
subs( x=y, y=x, [x,y] );
                                    [x, x]

eval(eval([x,y], x=y), y=x);
                                    [x, x]

Also, on complicated expressions, the calls to eval will generally be faster.

John

This tripped me up not too long ago, so I feel like I should point out that the subs and eval calls Mariner gives are not exactly equivalent,   the eval will do similtaneous substitution while the subs call does sequential substitution:

subs( x=y, y=x, [x,y] );
                                    [x, x]

eval([x,y], {x=y, y=x});
                                    [y, x]


The following are equivalent:

# Simultaneous
subs( [x=y, y=x], [x,y] );
                                    [y, x]

eval([x,y], {x=y, y=x});
                                    [y, x]

and

# Sequential
subs( x=y, y=x, [x,y] );
                                    [x, x]

eval(eval([x,y], x=y), y=x);
                                    [x, x]

Also, on complicated expressions, the calls to eval will generally be faster.

John

Sorry, I spoke too soon.

f(x,a,b) assuming a::integer, b::integer;

does indeed return a result invalid for b>1. Using the other seems to give the expected value:

g := f(x,a,b) assuming a::positive, b::positive;

                        a
                       x  hypergeom([a, -b + 1], [1 + a], x)
                  g := -------------------------------------
                                         a
 (expand@simplify)(eval(g, [a=2, b=3]) ); 
                                2        3        4
                           1/2 x  - 2/3 x  + 1/4 x

Clearly something wierd is happening in both cases, however.

John

Sorry, I spoke too soon.

f(x,a,b) assuming a::integer, b::integer;

does indeed return a result invalid for b>1. Using the other seems to give the expected value:

g := f(x,a,b) assuming a::positive, b::positive;

                        a
                       x  hypergeom([a, -b + 1], [1 + a], x)
                  g := -------------------------------------
                                         a
 (expand@simplify)(eval(g, [a=2, b=3]) ); 
                                2        3        4
                           1/2 x  - 2/3 x  + 1/4 x

Clearly something wierd is happening in both cases, however.

John

value( Int( t^(a-1) * (1-t)^(b-1), t=0..x ) );

is exactly equivalent to calling

int( t^(a-1) * (1-t)^(b-1), t=0..x );

The point of setting

f := (x,a,b) -> Int( t^(a-1) * (1-t)^(b-1), t=0..x );
                                    x
                                   /
                                  |    (a - 1)        (b - 1)
               f := (x, a, b) ->  |   t        (1 - t)        dt
                                  |
                                 /
                                   0

would be work around the problem in int to avoid computing the integral with symbolic parameters a and b and instead to only compute after values were assigned:

v1:=value( f(2,3,2/5) ); v2:=evalf( f(2,3,.4) );

In Maple 12:

                                                 2/5
                                  125   365 (-1)
                            v1 := --- - -----------
                                  84        84

                      v2 := 0.1453428221 - 4.132567005 I

If you are only interested in floating point values this is probably faster (v2 is computed very differently than v1).

John

value( Int( t^(a-1) * (1-t)^(b-1), t=0..x ) );

is exactly equivalent to calling

int( t^(a-1) * (1-t)^(b-1), t=0..x );

The point of setting

f := (x,a,b) -> Int( t^(a-1) * (1-t)^(b-1), t=0..x );
                                    x
                                   /
                                  |    (a - 1)        (b - 1)
               f := (x, a, b) ->  |   t        (1 - t)        dt
                                  |
                                 /
                                   0

would be work around the problem in int to avoid computing the integral with symbolic parameters a and b and instead to only compute after values were assigned:

v1:=value( f(2,3,2/5) ); v2:=evalf( f(2,3,.4) );

In Maple 12:

                                                 2/5
                                  125   365 (-1)
                            v1 := --- - -----------
                                  84        84

                      v2 := 0.1453428221 - 4.132567005 I

If you are only interested in floating point values this is probably faster (v2 is computed very differently than v1).

John

Bizarrely, however, both:

f(x,a,b) assuming a>2, b>2;

and

f(x,a,b) assuming a::integer, b::integer;

both work more or less as expected.

John

Bizarrely, however, both:

f(x,a,b) assuming a>2, b>2;

and

f(x,a,b) assuming a::integer, b::integer;

both work more or less as expected.

John

It looks like in Maple 10,  the integral

int( t^(a-1) * (1-t)^(b-1), t=0..x );

returned unevaluated, so you could get back to that original behavior with

f := (x,a,b) -> Int( t^(a-1) * (1-t)^(b-1), t=0..x );

And using value(f(x,a,b)); for specific values.

John

It looks like in Maple 10,  the integral

int( t^(a-1) * (1-t)^(b-1), t=0..x );

returned unevaluated, so you could get back to that original behavior with

f := (x,a,b) -> Int( t^(a-1) * (1-t)^(b-1), t=0..x );

And using value(f(x,a,b)); for specific values.

John

You probably want to do:

Tsol :=fsolve(f,T);
y1 := eval( (p1s*x1*gamma1)/p , T=Tsol );

John

You probably want to do:

Tsol :=fsolve(f,T);
y1 := eval( (p1s*x1*gamma1)/p , T=Tsol );

John

 In Drupal it is possible to allow other choices on the "Input format" selector based on the user role.  I think in Mapleprimes, all users are the same type after they have 2? points. 

It should be possible to assign some users (possibly based on points 50+, 100+ ?) to a "trusted user role" that is allowed to post full HTML in blog posts. At least, I think the reason for allowing only "filtered HTML" is for security.

John

First 13 14 15 16 17 18 19 Page 15 of 19