acer

32303 Reputation

29 Badges

19 years, 307 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

restart;

with(Statistics):

r := sqrt(RandomVariable(Uniform(0,1))):

x := cos(RandomVariable(Uniform(0, 2*Pi))):

PDF(r, t) assuming t>0, t<1;

2*t

PDF(x, t) assuming t>-1, t<1;

1/(Pi*(-t^2+1)^(1/2))

PDF(x*r, t) assuming t>-1, t<0;

2*(-t^2+1)^(1/2)/Pi

PDF(x*r, t) assuming t>0, t<1;

2*(-t^2+1)^(1/2)/Pi

PDF(x*r, t) assuming t<-1;

0

PDF(x*r, t) assuming t>1;

0

Download rv_pdf_prod_ex.mw

The above four choices of assumptions handle all real t, for PDF(x*r, t). It's straightforward to combine the pieces into a piecewise.

I mentioned in your previous Question thread that I wonder whether it really is necessary to change all your module exports/locals, etc, just to get it to work in Grid.

When I want to avoid typing out the long-form names of module members I take one of the following two approaches. Neither of these ever involves utilizing use, which I dislike and find problematic.

1) Utilize uses instead, per procedure. Yes, I might have lots of procedures, but I only need to write the uses line once at each beginning, and I still find it far easier than using a long form each time I want to call a member.

restart;

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  local some_very_long_name:= module() #NOTICE, now local
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;

  local B:= module()
     export foo:=proc()
         uses toX=some_very_long_name:-toX;

         toX(1);
     end proc;
  end module;

end module:

A:-main_entry()

2

Download mod_uses.mw

2) Utilize a $define directive (only once per file), in a source text file that I read. The code to use would look like,

    read "nm_mod.mpl";  # or omit this altogether if I had stored it in a .mla archive
    A:-main_entry();

and the test file contains, say,

$define TOX some_very_long_name:-toX

A := module()

  export main_entry:=proc()
     B:-foo();
  end proc;

  local some_very_long_name:= module() #NOTICE, now local
        export toX:=proc(n::integer)::integer;
              n+1;
        end proc;
  end module;

  local B:= module()
     export foo:=proc()
         TOX(1);
     end proc;
  end module;

end module:

$undef TOX

You only need to call rand(...) once, and then you can utilize its returned procedure many times. (There are other ways, but if you're intent on using rand...)

Also, your approach to compute the cumulative sum repeatedly adds all the way from the start, for each i=1..N, which is relatively inefficient. It repeats each previous step's work, and so has a higher than necessary order of computational complexity.

restart;
randomize():
R := rand(1..6):
N := 10^2:
y := [ seq(R(), i = 1..N) ]:
Y :=  map(yy->ifelse(yy<=3,-1,1), y):
C := Statistics:-CumulativeSum(Y):
plot([$N],C);

There are more efficient ways to accomplish this. But this should get you started.

You can compare timings for just the cumulative sum computation. (I haven't made lots of other possible speedups; just focusing on that difference.)

restart;
randomize():
R := rand(1..6):
N := 10^4:
y := [ seq(R(), i = 1..N) ]:
Y :=  map(yy->ifelse(yy<=3,-1,1), y):

CodeTools:-Usage([ seq(add(Y[ .. i]), i = 1..N) ]):
memory used=1.23GiB, alloc change=45.16MiB, cpu time=4.64s, real time=4.64s, gc time=278.23ms

CodeTools:-Usage(Statistics:-CumulativeSum(Y)):
memory used=246.43KiB, alloc change=0 bytes, cpu time=1000.00us, real time=1000.00us, gc time=0ns

LinearAlgebra:-Norm(Vector[column](%)-Vector[column](%%));
                               0.

The performance gaps widens as N increases.

If you are supposed to write your own routine for computing the cumulative sum then please let us know. At the ith step you just need to add the previous step's (i-1)th sum to the ith y entry.

Your code calls eval like this,

   eval(M, [:-alpha=alpha, :-gamma = gamma, :-mu = mu, :-lambda=lambda, :-B[1]=B__1, :-B[2]=B__2],:-beta[0]=beta__0)

but the closing right bracket is in the wrong place, ie. before beta[0]=beta__0. So you're invalidly calling eval with three arguments. That's what the error message tells you, too. It should be,

   eval(M, [:-alpha=alpha, :-gamma = gamma, :-mu = mu, :-lambda=lambda, :-B[1]=B__1, :-B[2]=B__2,:-beta[0]=beta__0])

Also, you're code tries to substitute for global :-gamma, which you've declared local at the top-level.

Also, some parts of your expression might take either very large/very small values, when done computed at hardware precision. You can force use of "software" floats instead of hardware double-precision. And you might also want to experiment with how much (if any) increased working precision might benefit the accuracy.

You might also need to adjust your hard-coded view, in the plot3d call in procedure G.

plot1_ac.mw

ps. One of the useful ideas behind having such a G procedure is that you can just call it with numeric arguments and get a single plot. That's easier to debug and figure out than is a whole Explore call. Focus on getting a/any good result from G. Then, when that works (at all!) try Explore.

Please check for mistakes. I may have misunderstood, and I wrote it quickly.

The basic idea is that if you can get at the allowed functions (of the Xi names) then you could freeze those function calls. The resulting (frozen) placeholder names might then be added to the set of Xi names and done altogether with the methodology for handling your first bullet point cases.

If you have some particular allowed "functions" in mind then you could adjust the typefunc
specification below, changing from name to something else (eg. identical(...), or other...)

restart;

 

H := proc(expr, S) local K,SS,temp;
  K := typefunc(identical(S[]),name);
  SS := freeze~(indets(expr, K)) union S;
  temp := subsindets(expr, K, freeze);
  ormap(s->type(expr, linear(s)), SS)
   and
  andmap(s->type(temp, And(polynom(anything,s),
                           satisfies(t->degree(t,s)<2))), SS);
end proc:

 

H( a*f(X1, X2)*g(X4) + b*X3*g(X4) + c*X1 + d*X1*X2,
   {X1,X2,X3,X4} );

true

H( a*b + c,
   {X1,X2,X3,X4} );

false

H( a*f(X1, X2)*g(X4)^2 + b*X3*g(X4) + c*X1 + d*X1*X2,
   {X1,X2,X3,X4} );

false

H( a*f(X1, X2)*g(X4) + b*X3^4*g(X4) + c*X1 + d*X1*X2,
   {X1,X2,X3,X4} );

false

H( a*f(X1, X2)*g(X4) + b*X3*g(X4) + c^2*X1 + d*X1*X2*X3*X4,
   {X1,X2,X3,X4} );

true

H( a*b*X3 + c^2*X1 + d*X1*X2*X3*X4,
   {X1,X2,X3,X4} );

true

H( a*b*X3^4 + c^2*X1 + d*X1*X2*X3*X4,
   {X1,X2,X3,X4} );

false

H( a*b + c^2*X1,
   {X1,X2,X3,X4} );

true

Download typefunc_ex.mw

restart;

kernelopts(version);

`Maple 2024.2, X86 64 LINUX, Oct 29 2024, Build ID 1872373`

A := module()
  local DEBUG_MSG::truefalse:=false;
  export work_proc:=proc(n::integer)
     print("My flag is ",DEBUG_MSG);
  end proc;
end module:

kernelopts(opaquemodules=false):

Grid:-Set(0,A:-work_proc,'A:-DEBUG_MSG');
Grid:-Run(0,A:-work_proc,[ 0 ]);
Grid:-Wait();

"My flag is ", false

A:-DEBUG_MSG := true:

Grid:-Set(0,A:-work_proc,'A:-DEBUG_MSG');
Grid:-Run(0,A:-work_proc,[ 0 ]);
Grid:-Wait();

"My flag is ", true


Download grid_set_module_local.mw

Yes, it is a bug.  If x is real then at least one of the pair is satisfied.

A developer might classify it as a "weakness".

I couldn't get it with a single is call and unrestricted real x (or equivalent) and the point is that ideally that would be possible.

restart;

S := cos(x) + sqrt(1-sin(x)^2) = 0, cos(x) - sqrt(1-sin(x)^2) = 0;

cos(x)+(1-sin(x)^2)^(1/2) = 0, cos(x)-(1-sin(x)^2)^(1/2) = 0

I wasn't able to merge these assumptions into a single `is` call (say, using
`Or`, including adding x::real, etc).

is(Or(S)) assuming cos(x)<=0;
is(Or(S)) assuming cos(x)>=0;

true

true

I also couldn't "merge" this pair (even with the abs converted to signum or piecewise).

is(Or(C + abs(C) = 0, C - abs(C) = 0)) assuming C>=0;
is(Or(C + abs(C) = 0, C - abs(C) = 0)) assuming C<=0;

true

true

Download is_trig_01.mw

You might guess that I have a hunch that an underlying problem is with combining such pairs, rather than just internal problems with trig handling...

A helping prod, that happens to work:

is(x*y*z = 0) assuming Or(x=0,z=0);

             true

I suppose that `solve` could be leveraged to get that Or() construction programmatically. Multiple results from solve can be taken as Or, and individual results within that can be taken as And (or just themselves if a singleton sequence).

I like nm's Answer.

In your Document, the expression assigned to Ghat contains a name-quoted minus symbol instead of just the infix minus.

That makes it a name, not the expected arithmetic operator. And the spaces around that name make the whole thing get interpreted (2D Input) as implicit multiplication.

It parses your form as,
   2*sqrt(2)*GAMMA(5/2)*`-`*(7*sqrt(2))/6*GAMMA(7/2)/(r^(5/2)*r^(7/2))

If I replace it with just the usual infix minus sign then it goes as expected.

restart

g := exp(-r*cosh(x))*x^(2*n); G := Int(g, x = 0 .. infinity)

Int(exp(-r*cosh(x))*x^(2*n), x = 0 .. infinity)

f0 := arccosh(1+y); df0 := diff(f0, y)

1/(y^(1/2)*(2+y)^(1/2))

f := f0^(2*n)*df0

arccosh(1+y)^(2*n)/(y^(1/2)*(2+y)^(1/2))

n := 2; series(f, y)

2*2^(1/2)*y^(3/2)-(7/6)*2^(1/2)*y^(5/2)+(47/80)*2^(1/2)*y^(7/2)-(17281/60480)*2^(1/2)*y^(9/2)+O(y^(11/2))

r := 6; evalf(G)

0.8560816424e-4

Ghat := exp(-r)*(2*sqrt(2)*GAMMA(5/2)/r^(5/2)-(7*sqrt(2)*(1/6))*GAMMA(7/2)/r^(7/2))

(109/20736)*exp(-6)*2^(1/2)*Pi^(1/2)*6^(1/2)

Ghat1 := evalf(Ghat)

0.8000187796e-4

NULL

Download asyapprox_ac.mw

Here I've used Maple 2022.2, since that's the version in which your attachment was last saved.

It can be simplified with just,

   simplify(B1,exp)

however below also I give a few minor variants on the final form (and checks on all results).

restart;

kernelopts(version);

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

interface(showassumed=0):

assume(x::real);assume(t::real);assume(lambda1::complex);assume(b::real);

alias(psi1 = psi1(x,t), psi2 = psi2(x,t), phi1 = phi1(x,t), phi2 = phi2(x,t), beta = beta(t), alpha =alpha(t));

psi1, psi2, phi1, phi2, beta, alpha

rel := {psi1 = exp((-I*lambda1)*x - (1/(4*I*lambda1))*int((alpha + b*beta),t)), psi2 = exp((I*lambda1)*x + (1/(4*I*lambda1))*int((alpha + b*beta),t)), phi1= exp((-I*conjugate(lambda1))*x - (1/(4*I*conjugate(lambda1)))*int((alpha + b*beta),t)), phi2 = exp((I*conjugate(lambda1))*x + (1/(4*I*conjugate(lambda1)))*int((alpha + b*beta),t))}

{phi1 = exp(-I*conjugate(lambda1)*x+((1/4)*I)*(int(b*beta+alpha, t))/conjugate(lambda1)), phi2 = exp(I*conjugate(lambda1)*x-((1/4)*I)*(int(b*beta+alpha, t))/conjugate(lambda1)), psi1 = exp(-I*lambda1*x+((1/4)*I)*(int(b*beta+alpha, t))/lambda1), psi2 = exp(I*lambda1*x-((1/4)*I)*(int(b*beta+alpha, t))/lambda1)}

Bnum := psi2*phi1*conjugate(lambda1) + psi1*lambda1*phi2;

psi2*phi1*conjugate(lambda1)+psi1*lambda1*phi2

Bnumexp := subs(rel,Bnum):

Den := -phi1*psi2 - phi2*psi1;

-phi1*psi2-phi2*psi1

expDen := subs(rel, Den)

-exp(-I*conjugate(lambda1)*x+((1/4)*I)*(int(b*beta+alpha, t))/conjugate(lambda1))*exp(I*lambda1*x-((1/4)*I)*(int(b*beta+alpha, t))/lambda1)-exp(I*conjugate(lambda1)*x-((1/4)*I)*(int(b*beta+alpha, t))/conjugate(lambda1))*exp(-I*lambda1*x+((1/4)*I)*(int(b*beta+alpha, t))/lambda1)

sr := Bnumexp/expDen: ratiosr := simplify(diff(sr,t), complex):

B := b - (4*I/beta)*ratiosr

b+2*exp(((1/4)*I)*(4*lambda1^2*x-(int(b*beta+alpha, t)))/lambda1)*exp(((1/4)*I)*(4*conjugate(lambda1)^2*x-(int(b*beta+alpha, t)))/conjugate(lambda1))*(lambda1-conjugate(lambda1))^2*exp(-((1/4)*I)*(4*lambda1^2*x-(int(b*beta+alpha, t)))/lambda1)*(b*beta+alpha)*exp(-((1/4)*I)*(4*conjugate(lambda1)^2*x-(int(b*beta+alpha, t)))/conjugate(lambda1))/(beta*(exp(-((1/4)*I)*(4*conjugate(lambda1)^2*x-(int(b*beta+alpha, t)))/conjugate(lambda1))*exp(((1/4)*I)*(4*lambda1^2*x-(int(b*beta+alpha, t)))/lambda1)+exp(((1/4)*I)*(4*conjugate(lambda1)^2*x-(int(b*beta+alpha, t)))/conjugate(lambda1))*exp(-((1/4)*I)*(4*lambda1^2*x-(int(b*beta+alpha, t)))/lambda1))^2*lambda1*conjugate(lambda1))

p := {alpha = t^2, beta = exp(-t)}

{alpha = t^2, beta = exp(-t)}

B1 := eval(B, p);

b+2*exp(((1/4)*I)*(4*lambda1^2*x-(1/3)*t^3+b*exp(-t))/lambda1)*exp(((1/4)*I)*(4*conjugate(lambda1)^2*x-(1/3)*t^3+b*exp(-t))/conjugate(lambda1))*(lambda1-conjugate(lambda1))^2*exp(-((1/4)*I)*(4*lambda1^2*x-(1/3)*t^3+b*exp(-t))/lambda1)*(b*exp(-t)+t^2)*exp(-((1/4)*I)*(4*conjugate(lambda1)^2*x-(1/3)*t^3+b*exp(-t))/conjugate(lambda1))/(exp(-t)*(exp(-((1/4)*I)*(4*conjugate(lambda1)^2*x-(1/3)*t^3+b*exp(-t))/conjugate(lambda1))*exp(((1/4)*I)*(4*lambda1^2*x-(1/3)*t^3+b*exp(-t))/lambda1)+exp(((1/4)*I)*(4*conjugate(lambda1)^2*x-(1/3)*t^3+b*exp(-t))/conjugate(lambda1))*exp(-((1/4)*I)*(4*lambda1^2*x-(1/3)*t^3+b*exp(-t))/lambda1))^2*lambda1*conjugate(lambda1))

ans1 := simplify(B1,exp);
simplify(ans1-B1);

b+(1/2)*(b*exp(-t)+t^2)*(lambda1-conjugate(lambda1))^2*exp(t)/(conjugate(lambda1)*lambda1*cos((1/12)*(lambda1-conjugate(lambda1))*(-12*lambda1*x*conjugate(lambda1)-t^3+3*b*exp(-t))/(lambda1*conjugate(lambda1)))^2)

0

subsindets(ans1,`*`,u->combine(u,trig)):
ans2 := subsindets(%,trig,u->simplify(u));
simplify(ans2-B1);

b+(b*exp(-t)+t^2)*(lambda1-conjugate(lambda1))^2*exp(t)/(conjugate(lambda1)*lambda1*(cos((1/6)*(lambda1-conjugate(lambda1))*(-12*x*abs(lambda1)^2-t^3+3*b*exp(-t))/abs(lambda1)^2)+1))

0

subsindets(ans1,`*`,simplify);
simplify(simplify(%-B1));

b-2*Im(lambda1)^2*(t^2*exp(t)+b)/(cosh((1/6)*Im(lambda1)*(12*x*abs(lambda1)^2+t^3-3*b*exp(-t))/abs(lambda1)^2)^2*abs(lambda1)^2)

0

subsindets(ans2,`*`,simplify);
simplify(simplify(%-B1));

b-4*Im(lambda1)^2*(t^2*exp(t)+b)/((cosh((-(1/3)*t^3-4*x*abs(lambda1)^2+b*exp(-t))*Im(lambda1)/abs(lambda1)^2)+1)*abs(lambda1)^2)

0

NULL

Download simplify_3_ac.mw

Are you trying to say that previously unopened .mw files on your machine have changed, as saved files?

Or are you trying to say that when you now Open any .mw file (Document) that was previously untouched (as a file on your OS) that the GUI opens it wrongly, and alters the input lines as displayed.

If the latter, then are you also saying the uninstalling/reinstalling doesn't help? Are you sure that when uninstalling your personal GUI Preferences file is removed? It would usually be somewhere like this on MS-Windows:
    C:\Users\%USERNAME%\AppData\Roaming\Maple\2023\Maple.ini
If that's still present (on uninstallinging) then you might consider removing it prior to reinstallation.

(It seems weird, if a wholly clean install were now to show different behaviour when opening files that haven't been changed since before the problem started.)

Here are some fixes that allow the problematic sections 17.6, 17.9, and 17.10 to run in a newer version such as Maple 2018 or Maple 2024.

ch17_acc_2018.mw


The problems come in the following varieties:
i) Failure of plots:-spacecurve with operator-form calling sequence. Remedy is simple: since the operators return unevaluated when passed a name, replace the operator names (in the first argument triple) with those same names applied to `t`, and use t=range instead of just range. Or just use plots:-odeplot (which is usually better, btw), in its usual way. (I will submit a bug report; it broke in Maple 2016.)
ii) Use of bare name y alongside aliases to indexed names y[i] in section 17.9.
iii) Dubious recursive definition in loop in section 17.9,
    for i from 0 to e_order do   
        eta[i] := t -> eta[i](t)
    end do:

The whole alias/macro/defn business of that section is obfuscated.
iii) Repeated (chained) aliases in section 17.6, which is hokey.
iv) Access to casesplit results by location in the returned sequence, in section 17.10, which was fragile programming. Changed it to access by property of nontriviality does better, including in Maple 2024 whose casesplit result differs in form/nature from that of Maple 2018.
v) I also added a few normal/simplification/sort calls, to get some of the (mathematically) ok results to look&feel even more like in the "target" .mws file's output.

There is an example about this on the Help page for assuming. (It's the example about a procedure f).

The essence is that the usual assuming facility does not place assumptions on variables inside the procedure body, up front (which is how it works).

That page documents the following as an alternative, which leverages a revised mechanism that does what you are after:

restart

Physics:-Setup(assumingusesAssume = true)

[assumingusesAssume = true]

`&omega;__b` := proc (alpha) options operator, arrow; `&omega;__0`*sqrt(1+alpha+sqrt(alpha+alpha^2)) end proc

proc (alpha) options operator, arrow; omega__0*sqrt(1+alpha+sqrt(alpha+alpha^2)) end proc

`assuming`([limit(`&omega;__b`(alpha), alpha = infinity)], [`&omega;__0`::positive]) = infinityNULL

`assuming`([limit(`&omega;__b`(alpha), alpha = infinity)], [`&omega;__0` > 0]) = infinityNULL

NULL

Download assuming_ac.mw

Another way to handle your example is to first assign your procedure call to an expression, in which case the usual assuming mechanism "sees" the relevant variable name.

restart

`&omega;__b` := proc (alpha) options operator, arrow; `&omega;__0`*sqrt(1+alpha+sqrt(alpha+alpha^2)) end proc

proc (alpha) options operator, arrow; omega__0*sqrt(1+alpha+sqrt(alpha+alpha^2)) end proc

expr := `&omega;__b`(alpha)

omega__0*(1+alpha+(alpha^2+alpha)^(1/2))^(1/2)

`assuming`([limit(expr, alpha = infinity)], [`&omega;__0`::positive]) = infinityNULL

`assuming`([limit(expr, alpha = infinity)], [`&omega;__0` > 0]) = infinityNULL

NULL

Download assuming_acc.mw

Notice the difference, according to whether we assume m__1 is greater than or less than 0, or just real.

expr := sqrt(-(-m__1-m__2+sqrt(m__2*(m__1+m__2)))*`&omega;__0`^2/m__1)

(-(-m__1-m__2+(m__2*(m__1+m__2))^(1/2))*omega__0^2/m__1)^(1/2)

`assuming`([simplify(simplify(expr, {m__2/m__1 = alpha}))], [m__1 > 0])

(-omega__0^2*((alpha*(alpha+1))^(1/2)-alpha-1))^(1/2)

`assuming`([simplify(simplify(expr, {m__2/m__1 = alpha}))], [m__1 < 0])

(omega__0^2*((alpha*(alpha+1))^(1/2)+alpha+1))^(1/2)

`assuming`([simplify(simplify(expr, {m__2/m__1 = alpha}))], [m__1::real])

(-omega__0^2*(signum(m__1)*(alpha*(alpha+1))^(1/2)-alpha-1))^(1/2)

NULL

Download simplify_side_radical.mw

Here are a couple of ways to get such an effect.

restart

kernelopts(version)

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

v := `<,>`(`<|>`(a), `<|>`(b))

Matrix(%id = 36893628100656344948)


Here I use . (a period) instead of  *

expr := cos(t*theta+phi).v

cos(t*theta+phi).Matrix(%id = 36893628100656344948)

I can turn it into the usual multiplication, programmatically.

eval(expr, `.` = `*`)

Matrix(%id = 36893628100656329420)

Since some commands can "simplify" the above expr
and distribute the multiplication across the Vector, this
might not be the best approach for you (if you intend on
doing symbolic computations with your expr as defined.
(So see next nethod, below.)

simplify(expr)

Matrix(%id = 36893628100656327724)


Here I use `%*` instead of   * , ie. the inert operator.

In 2D Input this cannot be used with infix syntax in Maple 2022.
So I use it in prefix form.

expr := `%*`(cos(t*theta+phi), v)

`%*`(cos(t*theta+phi), Matrix(%id = 36893628100656344948))

I can turn it into the usual multiplication, it two ways.

value(expr)

Matrix(%id = 36893628100656308940)

eval(expr, `%*` = `*`)

Matrix(%id = 36893628100656306164)

I can also display expr as if it had a usual
multiplication symbol, ie. not a lighter gray asterisk.

InertForm:-Display(expr, inert = false)

0, "%1 is not a command in the %2 package", _Hold, Typesetting

In 1D plaintext input I can enter it in infix form.

expr := cos(t*theta + phi) %* v;

`%*`(cos(t*theta+phi), Vector(2, {(1) = a, (2) = b}))

NULL

Download expr_inert_mult.mw

First 7 8 9 10 11 12 13 Last Page 9 of 336