Carl Love

Carl Love

28095 Reputation

25 Badges

13 years, 100 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

I'm assuming that the author did not supply the source code with the package, or you wouldn't be asking.

Not all of the following steps are necessarily needed. Let's say you want procedure P1 in package P:

interface(verboseproc= 2);
kernelopts(opaquemodules= false);
lprint(eval(P:-P1));

Now select and copy the output. Paste it to an input prompt, a Code Edit Region, or your own text editor. Your first editting step should be to add the line breaks and indenting.

Here are four things that you can do to get more information. I have listed them in order by how structured the information is, with the most structured first.

1. Set

infolevel[all]:= 5;

That will cause programs to print out additional information of the programmers' choosing. You can use higher or lower numbers for more or less information. Most programs don't use levels higher than 5.

2. Print the code of procedures with showstat:

showstat(int);
showstat(sin);
showstat(cos);

3. Trace the execution of particular procedures with trace:

trace(int);
trace(sin);

4. Trace the execution of everything with printlevel:

printlevel:= 10000:

You can use higher or lower numbers for more or less information.

 

 

For RSA to work, d and e must be multiplicative inverses mod ((p-1)*(q-1)). That is, we must have

e = 1/d mod ((p-1)*(q-1)).

That does not hold for your d and e.

(N,R):= selectremove(has, [a], I);

After executing the above, N will contain the nonreals and R will contain the reals.

The commands codegen:-cost, exprofile, excallgraph, and CodeTools:-Profiling:- may be useful to you.

Since you have provided increments for each variable, each variable takes on only a finite number of values. Hence there are only a finite number of possible evaluations for the profit expressions. Maple can process these quickly. Using the values of the "constants" that you provided, I was able to verify that ProfitB is greater than ProfitC at every evaluation. That is done like this:

restart:
c:= 1/10:  w:= 1/2:  p:= 1:
ProfitB:= (Pb*(p-w)/(1-Pb)-c)*Hb+w*(Pb*(1-Pa)*Hb+Pa*Pb*Hb)+wu*Pa*(1-Pb)*Ha;
ProfitC:= (Pa*(wu-w+Pb*(p-wu))/(1-Pa)-c)*(Ha+Hb)+w*(Pa*(1-Pb)*Ha+Pb*(1-Pa)*Hb+Pa*Pb*(Ha+Hb));

greater:= simplify(ProfitB - ProfitC);

for PB from 0 to 1/4 by 1/40 do
     for PA from 0 to 1/4 by 1/40 while PA < PB do
          for HB from 0 to 50 by 5 do
               for HA from 0 to HB by 5 while HA < HB do
                    for WU from 1/2 to 1 by 1/10 do
                         if eval(greater, [Pb,Pa,Hb,Ha,wu]=~ [PB,PA,HB,HA,WU]) <= 0 then
                              print(PB,PA,HB,HA,WU)
                         end if
                    end do
               end do
          end do
     end do
end do;  

Since there is no output printed, that verifies the result. If you want to supply ranges and increments for the "constants", a similar verification could be coded.

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

 

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