vv

13837 Reputation

20 Badges

9 years, 319 days

MaplePrimes Activity


These are answers submitted by vv

BIN:=module()
export ModuleApply, Fac, Fac1;
local pmax:=trunc(2^((kernelopts(wordsize)-1)/2));

Fac:=proc(n,m,p)
  local r:=1,k;
  for k from n to m do r := irem(r*k,p) od
end:

Fac1:=proc(n::integer,m::integer,p::integer)::integer;
  option autocompile;
  local r::integer:=1, k::integer;
  for k from n to m do r := irem(r*k,p) od
end:

ModuleApply := proc(N::nonnegint, K::nonnegint, p::prime)  # combined with Carl's
local r:=1, n:=N, k:=min(K, N-K), Bin, fac:=`if`(p<pmax,Fac1,Fac);

Bin:=proc(N,K)  # 0 <=K < p, 0 <= N
local k:=min(K,N-K);
if k<0 then return 0 fi;
fac(N-k+1,N,p)/fac(1,k,p) mod p
end;

if k<0 then return 0 fi;
while k > 0 and r > 0 do 
   r:= irem(r*Bin(irem(n,p,'n'), irem(k,p,'k')), p) 
od;
r
end:

end module:

p:=nextprime(8*10^7): n:=p*2-1:  k:=floor(p/2):
CodeTools:-Usage(BIN(n,k,p));

memory used=2.97MiB, alloc change=0 bytes, cpu time=1.89s, real time=1.88s, gc time=0ns
                            80000022

p:=nextprime(9*10^8): n:=p*2-1:  k:=floor(p/2):
CodeTools:-Usage(BIN(n,k,p));

memory used=2.11KiB, alloc change=0 bytes, cpu time=20.78s, real time=20.78s, gc time=0ns
                           900000010

NOTE. The compiler works for p < 3.037*10^9. For p greater than that, BIN uses the non-compiled Fac but then k should be smaller (or at least the reductions via Lucas' theorem) to have reasonable execution time. The magnitude of N is not important.
 

The following simple procedure is much faster for p>N.
Note that it requires K<p but can be adapted for this case too.

 

restart;

Fac:=proc(n,m,p)
local r:=1,k;
for k from n to m do r := irem(r*k,p) od
end:

Bin:=proc(N::posint,K::satisfies(n -> (n::nonnegint and n<p)),p::prime)
local k:=min(K,N-K);
`if`(k<0, 0, Fac(N-k+1,N,p)/Fac(1,k,p) mod p)
end:

 

`mod/Binomial`:= proc(N::nonnegint, K::nonnegint, p::prime)
description "Computes binomial(N,K) mod p, p::prime, by Lucas's theorem";
option
   author= "Carl Love <carl.j.love@gmail.com> 30-Oct-2018",
   reference= "https://en.wikipedia.org/wiki/Lucas%27s_theorem"
;
local r:= 1, n:= N, k:= min(K, N-K);
   while k > 0 and r > 0 do
      r:= r*irem(binomial(irem(n,p,'n'), irem(k,p,'k')), p)
   od;
   r mod p
end proc:

 

aa:=800000;bb:=500000;
pp:=nextprime(aa);

800000

 

500000

 

800011

(1)

CodeTools:-Usage(Bin(aa, bb,pp));

memory used=13.75MiB, alloc change=-2.00MiB, cpu time=484.00ms, real time=489.00ms, gc time=218.40ms

 

494383

(2)

CodeTools:-Usage(Binomial(aa, bb) mod pp);

memory used=35.43GiB, alloc change=91.49MiB, cpu time=81.78s, real time=74.28s, gc time=45.05s

 

494383

(3)

 

macro(ff=2*a*b-3*a-2*b-c):
f:=(a,b,c)-> `if`(ff<=30 and ff>=15,ff,0):
A:=Array(0..10,1..5,0..1,f, storage=sparse):
indices(A,pairs); # or simply inspect the Array using the matrix browser

(10, 3, 1) = 23, (7, 4, 1) = 26, (5, 4, 0) = 17, (4, 5, 1) = 17, (9, 3, 0) = 21, (8, 3, 1) = 17, (4, 5, 0) = 18, (6, 4, 0) = 22, (5, 4, 1) = 16, (8, 3, 0) = 18, (10, 3, 0) = 24, (5, 5, 0) = 25, (7, 4, 0) = 27, (5, 5, 1) = 24, (9, 3, 1) = 20, (7, 3, 0) = 15, (6, 4, 1) = 21

Vector needs a procedure (with 1 argument) as initializer.
fenq  is such a procedure but  fsenq(2.1, j)   (actually you mean fseqn) is not; it's an expression.
So, use

psf := Vector(5, j->fseqn(2.1, j));

or maybe the more "sophisticated"

psf := Vector(5, curry(fseqn, 2.1));

 

 

The roots of integer numbers are not automatically simplified. Not even 4^(1/2). It is by design.
Unfortunately it is hard to find in the help pages "automatic simplification",  even if the Programming Guide contains information about this important aspect.

plots:-animate(plot3d,
[[y, x, (1/3)*Pi], x = 0 .. 2*Pi*a, y = 0 .. 5*a, coords = spherical, scaling = constrained,axes=none], a = 0 .. 1);

using spherical coordinates.

d1:=3: d2:=3: d3:=5:    x0:=0: y0:=0: z0:=0:
eq:=[x^2+y^2+z^2-d1^2, (x-3)^2+y^2+z^2-d2^2, x^2+y^2+(z-4)^2-d3^2]:
sph:=[x=x0+r*sin(v)*cos(u), y=y0+r*sin(v)*sin(u), z=z0+r*cos(v)]:
Eq:=simplify(eval(eq,sph)):
R:=min(seq(max(solve(e,r)),e=Eq)) assuming real:
plot3d(rhs~(eval(sph,r=R)), u=0..2*Pi, v=0..Pi, color=green);

int( R^3*sin(v)/3, u=0..2*Pi, v=0..Pi, numeric, epsilon=1e-5); #volume
                          23.55847110
# The integral can be computed symbolically but the result is ugly.

Edit: the code is now a bit more general.

Note first that you are using incorrectly the 2D input. You have a space after assume which is interpreted as multiplication; so all the assume stuff is ignored (actually it is anyway useless in your case).

Maple is not smart enough to obtain such bounds. It does not know Grönwall's inequality (see wiki).

Edit. You should also avoid gamma which is a Maple constant (unless this is what you want).

 

 

 

Maple does automatic simplifications which cannot be prevented.

 

(a^2)^3;

a^6

(1)

'(a^2)^3';

a^6

(2)

You neeed unevaluation to obtain (partially) what you want.

'(a^2)'^3;  # this is not enough

a^6

(3)

(a^2) ^ ''3'';

(a^2)^'3'

(4)

''(a^2)'' ^ 3;

'a^2'^3

(5)

###################

The only method is to use as input inert operators: the inert form of the operator u  is  %u

ex:=(a %^ 2) %^ 3;
op(0,ex); op(ex);

`%^`(`%^`(a, 2), 3)

 

`%^`

 

`%^`(a, 2), 3

(6)

ex:=a %/ b;
op(0,ex); op(ex);

`%/`(a, b)

 

`%/`

 

a, b

(7)

ex:=a %- b;
op(0,ex); op(ex);

`%-`(a, b)

 

`%-`

 

a, b

(8)

 

 

It is better to use P[n](t)  instead of P(n,t).

Using your equations it is of course possible to express P[m]  but it will depend of P[0] (and its derivatives)  because P[0] is arbitrary (C^m differentiable).

 

restart;

eqn:=D(P[n]) = -(lambda+mu)*P[n]+lambda*P[n-1]+mu*P[n+1]; # n>0

D(P[n]) = -(lambda+mu)*P[n]+lambda*P[n-1]+mu*P[n+1]

(1)

eq0:=D(P[0]) = -lambda*P[0]+mu*P[1];

D(P[0]) = -lambda*P[0]+mu*P[1]

(2)

En:=rhs(isolate(eqn,P[n+1]));
E0:=rhs(isolate(eq0,P[1]));

-(-D(P[n])-(lambda+mu)*P[n]+lambda*P[n-1])/mu

 

-(-D(P[0])-lambda*P[0])/mu

(3)

m:=4;
D(mu):=0: D(lambda):=0:

4

(4)

P[1]:=E0:
for n to m-1 do  P[n+1]:=En od:

''P''[m]=simplify(P[m]);

'P'[4] = ((4*lambda^3+3*lambda^2*mu+2*lambda*mu^2+mu^3)*D(P[0])+(6*lambda^2+6*lambda*mu+3*mu^2)*(D@@2)(P[0])+(3*mu+4*lambda)*(D@@3)(P[0])+lambda^4*P[0]+(D@@4)(P[0]))/mu^4

(5)

The series F diverges for any x if n>3.

F:=sum(GAMMA((1/2)*n+1/2)*GAMMA((1/2)*n-1+i)*GAMMA(i+1)^(-i)*((-n+1-2*i)*GAMMA((1/2)*n+1/2)/((x^2-1)*GAMMA((1/2)*n+1/2+i)*(n-1)))^(-i)/(GAMMA((1/2)*n+1/2+i)*GAMMA((1/2)*n-1)), i = 1 .. infinity):
a:=op(1,F):
r:=eval(a,i=i+1)/a:
r1:=simplify(r)/(1-x^2) assuming i::posint:
limit(r1, i=infinity) assuming n>3;

      infinity

For n=3, F = (1-x)/(1+x), 0 <= x < 1.
 

 

A:=proc(n::posint)
  local t:=A(n-1);
  <t,1+~0*t;0*t,t>
end:
A(1):=<<c__0>>:

seq(A(n),n=1..4);

Matrix(1, 1, {(1, 1) = c__0}), Matrix(2, 2, {(1, 1) = c__0, (1, 2) = 1, (2, 1) = 0, (2, 2) = c__0}), Matrix(4, 4, {(1, 1) = c__0, (1, 2) = 1, (1, 3) = 1, (1, 4) = 1, (2, 1) = 0, (2, 2) = c__0, (2, 3) = 1, (2, 4) = 1, (3, 1) = 0, (3, 2) = 0, (3, 3) = c__0, (3, 4) = 1, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = c__0}), Matrix(8, 8, {(1, 1) = c__0, (1, 2) = 1, (1, 3) = 1, (1, 4) = 1, (1, 5) = 1, (1, 6) = 1, (1, 7) = 1, (1, 8) = 1, (2, 1) = 0, (2, 2) = c__0, (2, 3) = 1, (2, 4) = 1, (2, 5) = 1, (2, 6) = 1, (2, 7) = 1, (2, 8) = 1, (3, 1) = 0, (3, 2) = 0, (3, 3) = c__0, (3, 4) = 1, (3, 5) = 1, (3, 6) = 1, (3, 7) = 1, (3, 8) = 1, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = c__0, (4, 5) = 1, (4, 6) = 1, (4, 7) = 1, (4, 8) = 1, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = c__0, (5, 6) = 1, (5, 7) = 1, (5, 8) = 1, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = c__0, (6, 7) = 1, (6, 8) = 1, (7, 1) = 0, (7, 2) = 0, (7, 3) = 0, (7, 4) = 0, (7, 5) = 0, (7, 6) = 0, (7, 7) = c__0, (7, 8) = 1, (8, 1) = 0, (8, 2) = 0, (8, 3) = 0, (8, 4) = 0, (8, 5) = 0, (8, 6) = 0, (8, 7) = 0, (8, 8) = c__0})

(1)

If (more interesting) 1 denotes the unit matrix then replace 1+~0*t with 1+0*t

Your procedure newprocedure does not return both matices H and psi; it returns H only.
So, change
return H:
psi:

to
return H, psi:
(actually return is superfluous).

You should also remove interface(rtablesize...) for several reasons, e.g. it is in a loop, you have Dimensions instead of Dimension.

Why don't you save in a text file? E.g.
save newprocedure, "file.mpl";

 

eq:=Y = (-2*k^3+6*k^2+sqrt(k^8-12*k^7+64*k^6-198*k^5+448*k^4-636*k^3+369*k^2)-7*k-15)/((k^3-3*k^2+5*k-15)*(1+k)):
isolate(eq, indets(eq,sqrt)[])^2:
factor((rhs-lhs)(%)):
select(has,%, Y):
collect(%,Y,factor) = 0;

The equivalence holds if you don't care the branch of the sqrt.

Your code does not work. Try this:

Pairs:=proc(p::prime)
local b, a:=2, t:=0, R:=table():
while (a<p) do
  b := 1/a mod p;
  if isprime(b) and not member([b,a],R)  then t:=t+1; R[t]:=[a,b] fi;
  a:=nextprime(a);
od:
entries(R,nolist)
end:

Pairs(101);
             [7, 29], [37, 71], [43, 47], [53, 61]

 

First 62 63 64 65 66 67 68 Last Page 64 of 120