-
Notifications
You must be signed in to change notification settings - Fork 0
/
special_factorization_identity.sf
48 lines (38 loc) · 1.09 KB
/
special_factorization_identity.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
44
45
46
47
48
#!/usr/bin/ruby
# Daniel "Trizen" Suteu
# Date: 09 August 2019
# https://github.com/trizen
# A new special factorization identity for:
#
# a(n) = (2^f(n) - f(n) + 1) * 2^f(n) + 1
#
# where: f(n) = 4*n*(n+1).
# The sequence a(n) can be factorized as:
#
# a(n) = (x - y - z + 1)(x + y + z + 1)
#
# where: x = 2^f(n)
# y = 2^(f(n)/2)
# z = n * 2^(f(n)/2 + 1)
func f(n) { 4 * n * (n+1) }
func a(n) {
(2**f(n) - f(n) + 1) * 2**f(n) + 1
}
func factors_of_a(n) {
var x = 2**f(n)
var y = 2**(f(n)/2)
var z = n*(2**(f(n)/2 + 1))
[(x - y - z + 1), (x + y + z + 1)]
}
for n in (1..5) {
var u = a(n)
var t = factors_of_a(n)
say "#{u} = #{t.join(' * ')}"
assert_eq(u, t.prod)
}
__END__
63745 = 209 * 305
281474590834689 = 16756737 * 16797697
79228162514251108269638549505 = 281474859270145 * 281475094151169
1461501637330902918203589327576533463951130755073 = 1208925819604733570056193 * 1208925819624524779356161
1766847064778384329583297500742918357649352398470630082568566027931615233 = 1329227995784915860221670509605027841 * 1329227995784915885585943610955661313