-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaussian_representations.sf
43 lines (35 loc) · 2.16 KB
/
gaussian_representations.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/ruby
# Author: Trizen
# Date: 05 May 2022
# https://github.com/trizen
# Represent a given integer as a product of two Gaussian integers.
# For example: 5 = (2 + i)(2 − i) and 13 = (3 + 2i)(3 − 2i).
func gaussian_divisors(n) {
var D = []
n.sum_of_squares.map_2d {|a,b|
[[1,-1], [-1, -1], [-1, 1], [1,1]].map_2d {|i,j| ([i*a, j*b], [j*b, i*a]) }...
}.each_2d {|a,b|
D << Gauss(a,b)
}
D.sort.uniq
}
for n in (1..20) {
var g = gaussian_divisors(n) || next
say ("#{n} = ", g.map {|d|
var u = Gauss(n,0)/d
"(%s + %si)*(%s + %si)" % (d.a, d.b, u.a, u.b)
}.join(' = '))
}
__END__
1 = (-1 + 0i)*(-1 + 0i) = (0 + -1i)*(0 + 1i) = (0 + 1i)*(0 + -1i) = (1 + 0i)*(1 + 0i)
2 = (-1 + -1i)*(-1 + 1i) = (-1 + 1i)*(-1 + -1i) = (1 + -1i)*(1 + 1i) = (1 + 1i)*(1 + -1i)
4 = (-2 + 0i)*(-2 + 0i) = (0 + -2i)*(0 + 2i) = (0 + 2i)*(0 + -2i) = (2 + 0i)*(2 + 0i)
5 = (-2 + -1i)*(-2 + 1i) = (-2 + 1i)*(-2 + -1i) = (-1 + -2i)*(-1 + 2i) = (-1 + 2i)*(-1 + -2i) = (1 + -2i)*(1 + 2i) = (1 + 2i)*(1 + -2i) = (2 + -1i)*(2 + 1i) = (2 + 1i)*(2 + -1i)
8 = (-2 + -2i)*(-2 + 2i) = (-2 + 2i)*(-2 + -2i) = (2 + -2i)*(2 + 2i) = (2 + 2i)*(2 + -2i)
9 = (-3 + 0i)*(-3 + 0i) = (0 + -3i)*(0 + 3i) = (0 + 3i)*(0 + -3i) = (3 + 0i)*(3 + 0i)
10 = (-3 + -1i)*(-3 + 1i) = (-3 + 1i)*(-3 + -1i) = (-1 + -3i)*(-1 + 3i) = (-1 + 3i)*(-1 + -3i) = (1 + -3i)*(1 + 3i) = (1 + 3i)*(1 + -3i) = (3 + -1i)*(3 + 1i) = (3 + 1i)*(3 + -1i)
13 = (-3 + -2i)*(-3 + 2i) = (-3 + 2i)*(-3 + -2i) = (-2 + -3i)*(-2 + 3i) = (-2 + 3i)*(-2 + -3i) = (2 + -3i)*(2 + 3i) = (2 + 3i)*(2 + -3i) = (3 + -2i)*(3 + 2i) = (3 + 2i)*(3 + -2i)
16 = (-4 + 0i)*(-4 + 0i) = (0 + -4i)*(0 + 4i) = (0 + 4i)*(0 + -4i) = (4 + 0i)*(4 + 0i)
17 = (-4 + -1i)*(-4 + 1i) = (-4 + 1i)*(-4 + -1i) = (-1 + -4i)*(-1 + 4i) = (-1 + 4i)*(-1 + -4i) = (1 + -4i)*(1 + 4i) = (1 + 4i)*(1 + -4i) = (4 + -1i)*(4 + 1i) = (4 + 1i)*(4 + -1i)
18 = (-3 + -3i)*(-3 + 3i) = (-3 + 3i)*(-3 + -3i) = (3 + -3i)*(3 + 3i) = (3 + 3i)*(3 + -3i)
20 = (-4 + -2i)*(-4 + 2i) = (-4 + 2i)*(-4 + -2i) = (-2 + -4i)*(-2 + 4i) = (-2 + 4i)*(-2 + -4i) = (2 + -4i)*(2 + 4i) = (2 + 4i)*(2 + -4i) = (4 + -2i)*(4 + 2i) = (4 + 2i)*(4 + -2i)