Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple way to request a factorization over the Gaussians

I work in the Gaussian integers and use factor on them with success. However, occasionally the imaginary part can vanish, but I still want a factorization in the Gaussian integers.

As an example, the program for(j=-3, 3, print(j,": ",factor(17+j*I))) writes:

-3: [-I, 1; 1 + I, 1; 10 + 7*I, 1]
-2: [-I, 1; 2 + 17*I, 1]
-1: [-1, 1; 1 + I, 1; 1 + 2*I, 1; 2 + 5*I, 1]
0: Mat([17, 1])
1: [-I, 1; 1 + I, 1; 2 + I, 1; 5 + 2*I, 1]
2: Mat([17 + 2*I, 1])
3: [-I, 1; 1 + I, 1; 7 + 10*I, 1]

I would like the middle line in the output to be different:

-3: [-I, 1; 1 + I, 1; 10 + 7*I, 1]
-2: [-I, 1; 2 + 17*I, 1]
-1: [-1, 1; 1 + I, 1; 1 + 2*I, 1; 2 + 5*I, 1]
0: [-I, 1; 4 + I, 1; 1 + 4*I, 1]
1: [-I, 1; 1 + I, 1; 2 + I, 1; 5 + 2*I, 1]
2: Mat([17 + 2*I, 1])
3: [-I, 1; 1 + I, 1; 7 + 10*I, 1]

Is there some setting to do that? Or will I have to write my own "wrapper" that treats this case specially?

like image 502
Jeppe Stig Nielsen Avatar asked Dec 13 '25 14:12

Jeppe Stig Nielsen


1 Answers

Function factor(x, {D}) receives an optional parameter D indicating the factorisation domain. So just specify the target domain in call factor(x, I):

> for(j=-3, 3, print(j,": ",factor(17+j*I, I)))
-3: [-I, 1; 1 + I, 1; 10 + 7*I, 1]
-2: [-I, 1; 2 + 17*I, 1]
-1: [-1, 1; 1 + I, 1; 1 + 2*I, 1; 2 + 5*I, 1]
0: [-I, 1; 4 + I, 1; 1 + 4*I, 1]
1: [-I, 1; 1 + I, 1; 2 + I, 1; 5 + 2*I, 1]
2: Mat([17 + 2*I, 1])
3: [-I, 1; 1 + I, 1; 7 + 10*I, 1]
like image 165
Piotr Semenov Avatar answered Dec 16 '25 19:12

Piotr Semenov