Joe Riel

9660 Reputation

23 Badges

20 years, 9 days

MaplePrimes Activity


These are replies submitted by Joe Riel

An example would be helpful.

@epostma Those were further refinements, as was the use of subsop, which didn't matter.  My initial version of mod2 (not shown) was what you had. 'Caching' f(t) made a significant difference, moving the subs outside less so.  Swapping the order of i and v (in the seqs) makes a theoretical difference [practically  unmeasurable] when n is 1 [a typical case].

In the unlikely case that anyone cares, following are some of the versions I tried while writing up the results.  To test these I do

 $ maple -q Ds.mpl
CodeTools:-Usage(Ds({cat(x,1 .. 10000)},3,0))
     mod1: memory used=14.19MiB, alloc change=14.00MiB, cpu time=112.00ms, real time=132.00ms
     mod2: memory used=15.49MiB, alloc change=15.25MiB, cpu time=84.00ms, real time=93.00ms
     mod3: memory used=13.81MiB, alloc change=13.37MiB, cpu time=68.00ms, real time=72.00ms
     mod4: memory used=13.81MiB, alloc change=13.37MiB, cpu time=76.00ms, real time=73.00ms
     mod5: memory used=13.81MiB, alloc change=13.37MiB, cpu time=76.00ms, real time=77.00ms
     mod6: memory used=9.35MiB, alloc change=9.12MiB, cpu time=144.00ms, real time=403.00ms
    mod6b: memory used=13.35MiB, alloc change=13.12MiB, cpu time=152.00ms, real time=435.00ms
     mod7: memory used=12.89MiB, alloc change=12.62MiB, cpu time=64.00ms, real time=63.00ms
    mod7b: memory used=12.90MiB, alloc change=12.62MiB, cpu time=76.00ms, real time=73.00ms
     mod9: memory used=15.64MiB, alloc change=14.25MiB, cpu time=172.00ms, real time=444.00ms

-------- start of Ds.mpl--------
$define CU CodeTools:-Usage(Ds({cat(x,1..10\000)},3,0))
$define TEST(S) printf("%9s: ",S): CU
printf("%A\n",'CU'):

restart;
Ds := proc(V::set,n::posint,t)
local i,v;
    {seq(seq((D@@i)(v)(t), i=1..n), v in V)};
end proc:

#TEST("original"):

restart;
InertApply := f -> 'f'(_rest):

Ds := proc(V::set,n::posint,t)
local i,v;
    {seq(InertApply('D'(v),t), v in V)
     , seq(seq(InertApply(InertApply('`@@`'('D',i),v),t), v in V), i=2..n)
    }:
end proc:
TEST("mod1"):

restart;
Ds := proc(V::set,n::posint,t)
local i,v,f,ft;
    ft := f(t);
    {seq(subs(f='D'(v), ft), v in V)
     , seq(seq(subs(f=f(v), f='`@@`'('D',i), ft), v in V), i=2..n)
    }:
end proc:
TEST("mod2"):

restart;
Ds := proc(V::set,n::posint,t)
local i,v,f,ft;
    ft := f(t);
    {seq(subs(f='D'(v), ft), v in V)
     , seq(subs(f='`@@`'('D',i), [seq(subs(f=f(v), ft), v in V)])[], i=2..n)
    }:
end proc:
TEST("mod3"):

restart;
Ds := proc(V::set,n::posint,t)
local i,v,f,ft;
    ft := f(t);
    {seq(subs(f='D'(v), ft), v in V)
     , seq(subs(f='`@@`'('D',i), [seq(subsop(0=f(v), ft), v in V)])[], i=2..n)
    }:
end proc:
TEST("mod4"):

restart;
Ds := proc(V::set,n::posint,t)
local i,j,v,w,wt,Dnwt;
    wt := w(t);
    Dnwt := subs(w=v(w),v='`@@`'('D',j), wt);
    {seq(subs(w='D'(v), wt), v in V)
     , seq(subs(j=i, [seq(subs(w=v, Dnwt), v in V)])[], i=2..n)
    }:
end proc:
TEST("mod5"):

restart;
Ds := proc(V::set,n::posint,t)
local i;
    `union`((x->'D(x)(t)')~(V)
            , seq( ((x,i)->'`@@`(D,i)(x)(t)')~(V,i)
                   , i = 2..n)
           );
end proc:
TEST("mod6"):


restart;
Ds := proc(V::set,n::posint,t)
local i,Dx,Dxi;
    Dx  := proc(x) 'D(x)(t)' end proc:
    Dxi := proc(x,i) '`@@`(D,i)(x)(t)' end proc:

    { Dx~(V)[]
      , seq( Dxi~(V,i)[], i = 2..n )
    };
end proc:
TEST("mod6b"):


restart;

Dxt  := proc(x,t) 'D(x)(t)' end proc:
Dixt := proc(i,x,t) '`@@`(D,i)(x)(t)' end proc:

Ds := proc(V::set,n::posint,t)
local i,v;
    { seq(Dxt(v,t), v in V)
      , seq(seq(Dixt(i,v,t), v in V), i=2..n)
    };
end proc:
TEST("mod7"):

restart;

Ds := proc(V::set,n::posint,t)
local i,v,Dx,Dxi;
    Dx  := (x) -> 'D(x)(t)';
    Dxi := (x,i) -> '`@@`(D,i)(x)(t)';
    { seq(Dx(v), v in V)
      , seq(seq(Dxi(v,i), v in V), i=2..n)
    };
end proc:
TEST("mod7b"):

restart;

Ds := proc(V::set,n::posint,t)
local d1,di,i;
    d1 := x -> 'D(x)(t)';
    di := x -> (''`@@`(D,i)(x)(t)''$i=2..n);
    {d1~(V)[], di~(V)[]};
end proc:
TEST("mod9"):

done


@mrashdan The usual way to do that is to substitute numerical values for the parameters, then call ?dsolve, passing it the numeric option. A procedure that can be used for evaluation and plotting is returned.  Alas, that does not work with this problem, dsolve/numeric does not handle boundary problems with more than two locations.  Fortunately, dsolve returns a usable symbolic solution. Just substitute the parameter values into it and plot.  For example

sol := dsolve(deqs union bcs);
params := {K=1, m=1, b=1, rho=1, h=1, GR=1, c1=1, c2=1, c3=1, c4=1}: # set appropriately
nsol := eval(sol, params):
plot(eval(N(y), nsol), y=-1..1);

@mrashdan The usual way to do that is to substitute numerical values for the parameters, then call ?dsolve, passing it the numeric option. A procedure that can be used for evaluation and plotting is returned.  Alas, that does not work with this problem, dsolve/numeric does not handle boundary problems with more than two locations.  Fortunately, dsolve returns a usable symbolic solution. Just substitute the parameter values into it and plot.  For example

sol := dsolve(deqs union bcs);
params := {K=1, m=1, b=1, rho=1, h=1, GR=1, c1=1, c2=1, c3=1, c4=1}: # set appropriately
nsol := eval(sol, params):
plot(eval(N(y), nsol), y=-1..1);

@epostma Any improvement will be interesting.  The point of this is to learn/demonstrate technique.  As a yardstick, here is a comparison of the original with two alternatives.

CodeTools:-Usage(Ds({cat(x,1 .. 100)},2,0))
 original: memory used=2.22MiB, alloc change=1.75MiB, cpu time=56.00ms, real time=78.00ms
     mod1: memory used=49.57KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us
     mod2: memory used=56.72KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns

To measure time I used more symbols and derivatives

CodeTools:-Usage(Ds({cat(x,1 .. 10000)},3,0))
     mod1: memory used=14.19MiB, alloc change=14.00MiB, cpu time=112.00ms, real time=120.00ms
     mod2: memory used=15.49MiB, alloc change=15.25MiB, cpu time=92.00ms, real time=90.00ms



@romildo It is available as a git repository.

The absolute value block is not needed because the result is squared.  Removing it saves an event.

Never mind, my brain was disengaged (that tends to cause events 8-).  That's a norm block ....

The absolute value block is not needed because the result is squared.  Removing it saves an event.

Never mind, my brain was disengaged (that tends to cause events 8-).  That's a norm block ....

Simpler might be to apply the assumptions to the global q:

(**) restart;
(**) with(Statistics):                                    
(**) assume(0<q, q<1);                                    
(**) X1 := RandomVariable(Geometric(q)):                  
(**) M:=Mean(X1);
                                                                  1 - q~
                                                             M := ------
                                                                    q~

(**) solve(M=mu,{q});
Warning, solve may be ignoring assumptions on the input variables.
                                                                      1
                                                            {q~ = ------}
                                                                  1 + mu

Simpler might be to apply the assumptions to the global q:

(**) restart;
(**) with(Statistics):                                    
(**) assume(0<q, q<1);                                    
(**) X1 := RandomVariable(Geometric(q)):                  
(**) M:=Mean(X1);
                                                                  1 - q~
                                                             M := ------
                                                                    q~

(**) solve(M=mu,{q});
Warning, solve may be ignoring assumptions on the input variables.
                                                                      1
                                                            {q~ = ------}
                                                                  1 + mu

@balteo What version of Maple are you using?  Ctrl+L works for me using the Standard GUI in Linux (Maple 14).

@balteo What version of Maple are you using?  Ctrl+L works for me using the Standard GUI in Linux (Maple 14).

@Alejandro Jakubi Thanks for following up on this.  I'll incorporate a test. Am modifying the code using some of Acer's suggestions.

@Alejandro Jakubi That fails, I believe, to test what may be the issue.  That is, if an existing file has a long filename, does referring to it using the short filename work?  The simplest thing to do is to check the actual name of the temporary file created by Compile.  Is it a long or short filename? If it is a long name, then can you copy it with FileTools:-Copy using the short name?

@Alejandro Jakubi Yes, but that doesn't test the 8.3 format, that is, when Windows uses shortened names (substituting ~ for a string of adjacent characters) when the path components exceed eight characters. I don't have a Windows box to test this, but it appears that shortened names were embedded into the LIB path, for example, the "DOCUME~1" component.

First 85 86 87 88 89 90 91 Last Page 87 of 195