Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 359 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

If you plot(v3, y= -1..1), you will see that v3 approaches two different limiting values as y approaches 0 from the left or right. So, Maple's answer of undefined is correct. But, I suppose that you are interested in the limit as y approaches 0 from the right. If you ask Maple directly for this limit, it will return unevaluated. You can also ask for a numeric evaluation of the limit like this:

Digits:= 4:
evalf(Limit(v3, y= 0, right));

That will take a few minutes to compute. The answer I got was 0.9996. You can get a faster result by using Digits:= 3:

Further advice: Change all occurences of int in your worksheet to Int. This will prevent Maple from repeatedly wasting time trying to evaluate integrals that it can't do anyway.

Yes, in Maple any expression whatsoever can be made into an assignable name by enclosing it in single back quotes ` `. However, names created thus won't necessarily display the same way as their mathematical counterparts. If you want it to display the same way, the Answer by Edgardo shows how to do that. However, the names created by that method may be too long to be of practical value.

In the example that you gave with subs, the command whose syntax you're emulating is applyrule, not subs.

applyrule(sin(c::anything)= c, sin(x)+f);

So, applying this to your integrals yields

ex:= Int(x*f(x), x= 0..1) + Int(x, x= 0.. 1/3) + 3*Int(x*f(x), x= 0..2/3):
applyrule(Int(c::anything, d::anything)= c, ex);

Since the value of n is necessarily integer, you won't hit 1 exactly, but you can use a loop to find the nearest integer.

a:= 0.2:  b:= 0.09:  c:= 0.57:  p:= 0.3:  q:= 0.7:
A_n:= ((1+c*p)*a/q+(2+c*p)*b)*product((1+c*q^k)*p, k= 1..n-1)+
     sum((a+b+k*b*q)*product((1+c*q^j)*p, j= k..n-1), k= 2..n):
for N from 2 while eval(A_n, n= N) < 1 do end do;
N;

     7

eval(A_n, n=6);

     0.9567704620

eval(A_n, n= 7);

     1.037279427

Please post your code as plaintext, not as images. That way I won't have to retype your code.

Note that I used sum rather than add above.

 

The line that begins with subimage:=  needs to end with a semicolon (or a colon).

I see that you've chosen to ignore our advice that you switch to 1D input.

Do this:

y:= 2*x^2+7:
plot(eval(y, x= sqrt(x1)), x1= -5..5);

I don't know enough about events to answer whether you're doing it wrong. But you can do what you want by trapping the error in a try ... catch block (see ?try). Something like this:

try
     TOVr(very_big_r)
catch "cannot evaluate the solution further right":
     return TOVr('last')
end try;
error "No dsolve error, use a bigger r";

If you provide your actual code in plaintext or 1D input form, I'll code it for you.

It doesn't come prepackaged, but here's a one-liner procedure to do it. I generalized it so that the base doesn't have to be 10, but defaults to 10.

logspace:= proc(a,b,n,{base:= 10})  evalf(base^~<seq(a..b, (b-a)/(n-1))>)  end proc;

I can see three approaches to deciding whether the stated integer factorization is "feasible":

  1. By happenstance, ifactor(P) may return the full prime factorization in a reasonable amount of time. This will happen when there's at most one large prime factor.
  2. We use the easy option to ifactor. Then ifactor will return the prime factors that it can get in a short amount of time and leave the rest unfactored.
  3. Use the timelimit command with ifactor. Then you can decide the maximum amount of time to spend on each factorization. The problem with this approach is that the result will be a full prime factorization or nothing. Unlike the easy option, it will not return the factors that have already been found when the time is up.

My guess is that a procedure combining approaches 1 and 2 is most promising. I have coded that below.

Are you sure about the requirement that kp2 be 56 bits? That seems much too strict, and I think that it would take hours to find a kp2 of exactly 56 bits. Are you sure that it's not 56 bits or more? Below, I coded it so that kp2 is between 56 and 500 bits. 

Please give the procedure WuSun below a few minutes to finish. I will also code something combining approaches 1, 2, and 3 and post it as a followup.


# Wu/Sun Schema A RSA key-generation algorithm

#Step 1:

e:= 1+2*rand(2^566..2^567-1)();

638477039545866035527860419740482646570391916634928775736040584757086812229395112512513825510987293920066911133709134097913777979837572903596538728204373509530589747233207

(1)

R160:= rand(2^159..2^160-1):

WuSun:= proc(e::posint)
local kp1, x, P, p, dp, kp2, k, f;
     do
          #Step 2,5:
          kp1:= R160();
          while igcd(kp1,e) <> 1 do kp1:= R160() end do;

          #Step 3,6:
          x:= 1/e mod kp1;
          P:= (e*x-1)/kp1 + e;
          # We need P even.
          if irem(P,2) <> 0 then next end if;
          dp:= x+kp1;

          #Step 4,7:

          (* To understand the following block of code, you need to know
          the format that Maple uses as return values from ifactor(...)
          and from ifactor(..., easy). See ?ifactor. Note that we have
          to allow for the possibility that ifactor(..., easy) returns
          the full factorization. *)

          #In the case of partial factorization, extract the integer part.
          #If the factorization is complete, kp2 is just P.
          kp2:= lcoeff(expand(ifactor(P, easy)));
          if ilog2(kp2) > 56 then
               #Find a divisor of kp2 that exceeds 56 bits but is as
               #close to 56 as we can get.
               f:= {op(ifactor(kp2))}; #Use set form to sort the primes.
               #The next line takes all 2-factors except the first. We
               #need to reserve one 2 for p0.
               kp2:= expand(f[1])/2;
               for k from 2 while ilog2(kp2) < 56 do
                    kp2:= kp2*expand(f[k])
               end do;
               if ilog2(kp2) > 500 then next end if;
               p:= P/kp2+1;
               if isprime(p) then return (P,p,dp) end if
          end if
     end do
end proc:  

(P,p,dp):= WuSun(e);

738128369139531838496569556654872585925136555974030282183676186481539482269159258484159200907676482767878497234800377628089047432478417813368297172188311270732197373724736, 1918544712641923648670613788298823623760588329878670906610782998053997421196324793470688529185105921916883691012591844385509740821387976086985634331483163, 1568309843248958963093916698552291336065205971015

(2)

(Q,q,dq):= WuSun(e);

925236977107069560793616487316895377905249519434128416407262042755975946109512434956689807066041362698019505939233456189374304749765695310092084174550242779443341104382760, 612995618251549166027274494149527964947780585363585516998336792270311149073629737679340444932441188179739250519735880544604490268227318342176809333407319, 1616555250820037357480406825254465394169750917223

(3)

 


Download WuSun.mw

 

Everytime that you invoke e() or kp1(), you get different random numbers. So, the e() and kp1() that you checked the gcd of are not the same e() and kp1() that you're trying to compute the modular inverse for. You need to do something like this:

E:= e();
KP1:= kp1();
while igcd(E,KP1) <> 1 do  KP1:= kp1()  end do;

Your way of choosing long random numbers is much more convoluted than it needs to be: rand will take a range as the argument. So, to get a 568-bit random number, do

e:= rand(2^567..2^568-1)();

(However, note that your algorithm requires e to be odd, so make that

e:= 1 + 2*rand(2^566..2^567-1)();

)

Finally, since you are new to Maple, please don't get used to using 2D input. That's the devil's path. Start using 1D input now.

Do yourself a huge favor and use exclusively 1D input for programming. There are numerous "invisible" bugs that can occur in 2D input that even us experts have trouble finding.

To give you a start, I've retyped most of your code as 1D input and attached a worksheet below.

For an image, height is the first dimension and width is the second dimension. You had those reversed, and I corrected it. Your code won't work as is if k > 1---you get an Array out of bounds error. I included a try ... catch block so that you can investigate this error. I think that you need to subtract more than 2 from each index when k > 1.


restart:

with(ImageTools):

with(FileTools):

################
# Input section
#

     filelocation:= "C:/Users/Carl/Desktop/I Become My Resting Place.jpg";
     k:= 1;
#############

"C:/Users/Carl/Desktop/I Become My Resting Place.jpg"

 

1

(1)

zimage:= Read(filelocation):

View(zimage);

zwidth:= Width(zimage):

kernel_length:= 2*k+1:

kernel_data:= Matrix(1..kernel_length, 1..kernel_length, 1).~(1/kernel_length^2):

new2zpic:= zimage: # Warning: this does not create a copy of zimage.

dummy:= 0:

for i from k+1 to Height(zimage,upper) - k do
     for j from k+1 to Width(zimage,upper) - k do
          for m from 1 to kernel_length do
               for n from 1 to kernel_length do
                    try
                         dummy := dummy + kernel_data[m,n]*new2zpic[i+m-2,j+n-2]
                    catch:
                         print(i+m-k, j+n-k);
                         error
                    end try
               end do
          end do;

          new2zpic[i,j]:= dummy;  dummy:= 0

     end do
end do;

 

View(new2zpic);

 


Download Ex_II_1.0_1d_input.mw

First, it's clear that the desired limit is the same as the limit as (x,y) -> (0,0) of

f:= sin(x*y)/(exp(x^2+y^2)-1);

We consider the limits along different radial paths approaching the origin. Use paths of the form y = m*x:

eval(f, y= m*x);

Now take the limit as x -> 0, which necessarily makes y -> 0.

limit(%, x= 0);

We see that the limit depends on m, that it is not path independent. Hence, the multidimensional limit does not exist.

You need to solve a system of five equations, not three: one for each partial derivative of the Lagrangian and one for each constraint.

Here's a trick for minimizing and maximizing distance functions: The extrema are obtained at the same points as the extrema of the square of the distance, which is easier to work with. In this problem, you'll still get the answers is you don't use this trick.

restart:
Con1:= x^2+y^2+2*z+x:
Con2:= z^2+y^2-1:
Obj:= x^2+y^2+z^2:
F:= Obj - L1*Con1 - L2*Con2:
G:= VectorCalculus:-Gradient(F, [x,y,z]):
Sols:= {solve({convert(G,list)[], Con1, Con2}, {x,y,z,L1,L2}, explicit)};

seq(evalf(eval(Obj, s)), s= Sols);

You can discard the complex solutions. So, the minimum distance is 1, obtained at four points, and the maximum distance is sqrt(5), obtained at one point.

 

RiemannSum is a command in a package, so, you need to refer to it with the package name prefix:

Student:-Calculus1:-RiemannSum(T(10), method= midpoint);

But what is your point in doing this? To numerically evaluate an integral? This is not the way to do it! Instead, use

evalf(T(10));

Your expression S1-S2 simplifies to x^2*Sum(..., k= n+1..infinity). We take this expression, replace infinity with 10000, replace Sum by add, and make it a procedure.

S1:= t-> abs(x^2*add(t^(k*alpha+1)/GAMMA(k*alpha+2), k= n+1..10000));

logplot(S1, 0..1);

First 271 272 273 274 275 276 277 Last Page 273 of 395