Carl Love

Carl Love

28095 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

Here are a pair of procedures for it. The procedure Sumof2Squares computes the first square (the 259 in your example) then loops with procedure FermatDescent to lower the coefficient (the 34 in your case). By using trace, we can observe the iterations.

Notice that I use mods(..., m) rather than the more-usual (... mod m). This guarantees that the residue will be between -m/2 and m/2. This is needed to guarantee that the coefficient is reduced at each iteration and thus ends at 1.
 

restart:

Sumof2Squares:= proc(p::And(prime, satisfies(p-> irem(p,4)=1)))
local x, y:= 1;
   x:= mods(Roots(x^2+y^2), p)[2,1];
   while x^2+y^2 > p do
      (x,y):= FermatDescent(x,y,p)
   end do;
   (x,y)
end proc:

FermatDescent:= proc(x::posint, y::posint, p::posint)
local
   m:= (x^2+y^2)/p,
   a:= mods(x,m),  
   b:= mods(y,m)
;
   (abs((a*x+b*y)/m), abs((a*y-b*x)/m))
end proc:
   

trace(FermatDescent):

Sumof2Squares(1973);

{--> enter FermatDescent, args = 259, 1, 1973

 

34

 

-13

 

1

 

99, 8

 

<-- exit FermatDescent (now in Sumof2Squares) = 99, 8}
{--> enter FermatDescent, args = 99, 8, 1973

 

5

 

-1

 

-2

 

23, 38

 

<-- exit FermatDescent (now in Sumof2Squares) = 23, 38}

 

23, 38

(1)

do
   p:= 4*rand()+1;
   if isprime(p) then break fi
od:

p;

426028214629

(2)

Sumof2Squares(p);

{--> enter FermatDescent, args = 171429182709, 1, 426028214629

 

68981263858

 

33466654993

 

1

 

83169849211, 2

 

<-- exit FermatDescent (now in Sumof2Squares) = 83169849211, 2}
{--> enter FermatDescent, args = 83169849211, 2, 426028214629

 

16236539225

 

1987153086

 

2

 

10178968574, 10

 

<-- exit FermatDescent (now in Sumof2Squares) = 10178968574, 10}
{--> enter FermatDescent, args = 10178968574, 10, 426028214629

 

243203144

 

-35563474

 

10

 

1488465479, 420

 

<-- exit FermatDescent (now in Sumof2Squares) = 1488465479, 420}
{--> enter FermatDescent, args = 1488465479, 420, 426028214629

 

5200429

 

1142785

 

420

 

327087635, 120120

 

<-- exit FermatDescent (now in Sumof2Squares) = 327087635, 120120}
{--> enter FermatDescent, args = 327087635, 120120, 426028214629

 

251125

 

122885

 

120120

 

160113859, 156396240

 

<-- exit FermatDescent (now in Sumof2Squares) = 160113859, 156396240}
{--> enter FermatDescent, args = 160113859, 156396240, 426028214629

 

117589

 

-42359

 

2870

 

53860529, 60246410

 

<-- exit FermatDescent (now in Sumof2Squares) = 53860529, 60246410}
{--> enter FermatDescent, args = 53860529, 60246410, 426028214629

 

15329

 

-5577

 

3440

 

6075577, 34005770

 

<-- exit FermatDescent (now in Sumof2Squares) = 6075577, 34005770}
{--> enter FermatDescent, args = 6075577, 34005770, 426028214629

 

2801

 

208

 

-1171

 

13765454, 5065227

 

<-- exit FermatDescent (now in Sumof2Squares) = 13765454, 5065227}
{--> enter FermatDescent, args = 13765454, 5065227, 426028214629

 

505

 

164

 

77

 

5242687, 453946

 

<-- exit FermatDescent (now in Sumof2Squares) = 5242687, 453946}
{--> enter FermatDescent, args = 5242687, 453946, 426028214629

 

65

 

-18

 

-14

 

1549594, 1003486

 

<-- exit FermatDescent (now in Sumof2Squares) = 1549594, 1003486}
{--> enter FermatDescent, args = 1549594, 1003486, 426028214629

 

8

 

2

 

-2

 

136527, 638270

 

<-- exit FermatDescent (now in Sumof2Squares) = 136527, 638270}

 

136527, 638270

(3)

%[1]^2 + %[2]^2 = p;

426028214629 = 426028214629

(4)

 


 

Download FermatDescent.mw

There are several algorithms for this sum-of-two-squares problem. Fermat Descent is not the fastest, but it's not horribly slow either.

convert(exp(x^2), compose, FormalPowerSeries, GAMMA);

The issue is operator precedence, as VV pointed out. As usual, the precedence can be overridden by using parentheses:

(3 = 0) mod 3;

When doing pure integer arithmetic, it's better to use irem rather than mod:

irem(3,3);
irem(0,3);

A simple linear transformation (x-> 2*x-1) of 0..1 makes it -1..1.

RM:= Matrix((10$2), 2*rand(0..1) - 1);

Here I've performed arithmetic directly on the procedure rand(0..1), which produces a new procedure. This is different than

RM:= Matrix((10$2), ()-> 2*rand(1) - 1);

although both produce a matrix of uniformly distributed -1s and 1s.

It's not hosted by Maplesoft, but I highly recommend the question & answer site math.stackexchange.com

Some general mathematical discussions are welcome here on MaplePrimes. If your questions haven't been answered, it's because no one knows what to say, not because we think that your questions are irrelevant to this site. So, no offense is intended by a failure to answer. If material is truly irrelevant, it gets deleted or its irrelevance is quickly commented on.

In Maple 12, you can sort numeric (i.e., decimal) values by magnitude by

sort([Y], (x,y)-> abs(x) < abs(y));

In recent versions of Maple, this can be done more efficiently by

sort([Y], key= abs);

Like this

Pts:= [[0, 438.912], [0.0295, 402.336], [0.125, 365.76], [0.2009, 341.376]]:
plot(
   [Pts$2], style= [point, line], symbol= diamond, symbolsize= 12, 
   color= blue, gridlines, view= [0..0.25, 0..500]
);

 

Using printlevel is a crude tool for debugging only. It's impossible to get it to display only the information that you want. Thus it is never intended for the display the output of a finished procedure.

If you have a procedure that generates plots which are not the official return value of the procedure, but you want to see them anyway, the use print in the procedure, as in

print(plots[display]( ...your exact same display command here...));

The point-data matrices can be extracted from a plot like this:

P:= implicitplot(...your exact same command...);
(M1,M2):= map2(op, -1, [plottools:-getdata(P)])[];

Now M1 and M2 will both be two-column matrices, the first for disf and the second for dispbeamf.

How about

convert(simplify(eval(diff(f(x),x)*cos(f(x)), x= RootOf(f(x),x))), D);

 

Use eliminate instead of solve. The second set returned is the conditions (which must be understood to be equated to 0).

You're asking for a 3D plot, yet nowhere in your command do you specify which functions are to be represented on each of the three axes.

If you want all decimal numbers to be displayed with 3 digits after the decimal point (or decimal comma, if that's what your culture uses), give the command

interface(displayprecision= 3);

This can also be set from the Tools -> Options menu.

Factoring polynomials over the rationals is a completely solved problem, whose solution has been completely implemented in Maple for a great many years, at least 17. If you mean to express the given polynomial as a sum of some small number (but greater than one) of factored polynomials, that's a different problem that's not called "factoring" strictly speaking.

If you have an example of a rational-coefficient polynomial that Maple can't completely factor, please report that as a bug, or post it here.

You can see a plaintext form of your most-recent output by the command lprint(%).

First 182 183 184 185 186 187 188 Last Page 184 of 395