[sub-project] Perfect cuboid

Fehler und Wünsche zum Projekt yoyo@home
Bugs and wishes for the project yoyo@home

Re: [sub-project] Perfect cuboid

Unread postby x3mEn » 31.03.2011 12:36

Robert Gerbicz wrote:
x3mEn wrote:For a more realictic view, we can ask even the next:
How many odd numbers less than 2^64 has only 4k+1 primes in its decomposition to divisors, if the largest divisor is less than 2^32 (2^40 or any other number, that we will set as a goal)

Why not simulate it? For 100000 random numbers gives 595 such numbers. So we can expect approx. 595/100000*2^64~10^17 numbers to test. It's a pretty huge. Only for one number on average you should check thousands of triangle pairs.

I'll recheck your result later.

Some notes to your estimate.
First, we no need to check g = prime 4k+1, because in this case g² has only 2 decompositions to a sum of squares. So we can skip these diagonals.
Second, primes p=4k+1, 2^64/25 < p < 2^64/5 produce diagonals with only 2 divisors: p and (5 or 13 or 17)
The square of these diagonals g^2 has only 4 decompositions to a sum of squares, at the same time one of them is trivial: g² = 0² + g²
Thus a huge amount of primes p=4k+1, 2^64/25 < p < 2^64/5 produce diagonal with only 1 triangle of pairs.
The chance that this 1 triangle of pairs will produce a perfect cuboid is miserable.
And all efforts will be spend not on diagonals checking, but simply to the bust of primes.

FYI. g = 5*p, where p = x²+y² produce the next 4 decompositions:
g² = 0² + (5p)²
g² = (y² - x²)² + (2xy)²
g² = (6xy - 4y² + 4x²)² + (8xy + 3y² - 3x²)²
g² = (8xy - 3y² + 3x²)² + (6xy + 4y² - 4x²)²
Maybe someone can prove that the last three are not a perfect cuboid pairs?

First decomposition we'll skip. Other three first must be ordered in way g² = k² + l², where k < l.
After that, these three must be ordered by k acsending.
Top 2 pairs make
g² = a² + f²
g² = b² + e²
The last equation contains c and d in unknown order (maybe c < d, maybe c > d).
Thus our the only task is to check, that, for example
a² + b² = d²
we can do this check in a different ways.
a, b, d are 64-bit integers, thus we can't calculate a sum of squares directly.
First, we can check, for example that
byte(byte(a)²) + byte(byte(b)²) = byte(byte(d)²)
byte returns the last 8 bit of number.
Thus if equation is correct for 64 bits, it will be correct for the last 8 bits too.
This routine is very fast and very effective.

If check is passed, after that I apply more strong condition
integer(integer(a)²) + integer(integer(b)²) = integer(integer(d)²)
integer returns the last 32 bits.

And only after passing and this check, I apply the check, which use sqrt:
a = sqrt(d - b) sqrt(d + b)
The argument of sqrt is a number <2^65.
sqrt is real class numbers function.
Especially to point that the result must be 64 bit I use in Delphi the next trick:
a = sqrt(d - b + 0.0) sqrt(d + b + 0.0)
Thus 64 bit extended multiplied by another 64 bit extended. The result is 64 bit extended too.
Thus it's very important to sqrt correctly figured at least 48 characters and multiplication of extended must have 64 bit precision.
It's one of the weak sides of my program.
Because I don't exactly know what is an actual precision of these functions from the math library, what Delphi uses.
They say that sqrt(extended) returns extended, but how accurate this extended is calculated, I don't know.
The same about an accurancy of multiply operation.
If someone could advise something better, I'll make it.

There are some other trivial checks before the sqrt is used but I don't want to spend your time to these details.
Posts: 39
Joined: 20.03.2011 22:23

Re: [sub-project] Perfect cuboid

Unread postby Robert Gerbicz » 31.03.2011 15:47

x3mEn wrote:Some notes to your estimate.
First, we no need to check g = prime 4k+1, because in this case g² has only 2 decompositions to a sum of squares. So we can skip these diagonals.

You are funny, when I make an estimation then in the next reply: no, you don't need to check some numbers and lower my original estimation by 0.0001 percentage. This leads to nowhere.
In fact my code skipped that numbers where g has got a prime divisor p>2^32 , as you requested. So the suggested speedup is to skip the 4k+1 primes<2^32.

When I code the first two things that is in my mind: is it a good program, is it solve the problem? What is the running time for the average case/best case? Ram?
Robert Gerbicz
Posts: 56
Joined: 08.06.2010 19:06

Re: [sub-project] Perfect cuboid

Unread postby x3mEn » 01.04.2011 18:46

I have rechecked the estimation.

First, High(Int64)=2^63-1 in Delphi
There are ~2^61 numbers 4k+1 between 1 and 2^63-1
I've got 100000 random numbers 4k+1 between 1 and 2^63-1

Unfortunately, [table] BB-codes or monospace font choise are absent on this forum (or engine, I don't know),
so I'll try to show the result here as is:
2^N| 4K+1 | ?_4K+1 | Primes | Max_Div|

how to read this table:
1st column - the power N of 2, defines the bounds for group: 2^N .. 2^(N+1)-1
All other columns figure the amount of numbers in the next categories:
1) quantity of all 4k+1 numbers
2) quantity of 4k+1 numbers, which are a product of 4k+1 prime dividers only
3) quantity of primes on the 2nd group
4) quantity of numbers of the 2nd group in distribution on their biggest divider

Thus, if I havn't made a mistake,
1) quantity of primes is signifacant (8% of all 4k+1 numbers, or 30% of all 4k+1 that has only 4k+1 dividers)
2) my estimation of quantity of all diagonals between 1 and 2^63-1 is 16658/100000*2^61 ~ 3.8*10^17
The lion part of them are produced with a participation of very big dividers, which are unreachable anyway.
For example, 96.7% of all these diagonals are produced with a participation of primes bigger than 2^35.
90.82% - bigger than 2^39
3) my estimation of quantity of all diagonals between 1 and 2^63-1 with the largest divider less than 2^32 is 201/100000*2^61 ~ 4.6*10^15

Source code attached.
(1.23 KiB) Downloaded 67 times
Posts: 39
Joined: 20.03.2011 22:23

Re: [sub-project] Perfect cuboid

Unread postby x3mEn » 08.04.2011 13:59

Robert Gerbicz, do you agree with my estimate? Or what your silence means?
I can assume that you have made certain conclusions for yourself and this topic is no longer interesting for you, but then you may say about it, agree?
My estimation is 100 times less then your. I think it's important, who, me or you, have made a mistake, isn't it?
Posts: 39
Joined: 20.03.2011 22:23

Re: [sub-project] Perfect cuboid

Unread postby Death » 02.12.2011 15:47

Is there any progress? :roll:
Posts: 11
Joined: 14.04.2010 08:32

Re: [sub-project] Perfect cuboid

Unread postby Randall » 26.03.2012 22:16

Since I am the person who has searched for all cuboids with the smallest edge <= 22 billion+ and growing now, I would like to offer some input to this discussion.

Just searching the space diagonal is going to miss all the body cuboids.

My search finds all 3 types of cuboids, so that nothing is missed.

I know that we're trying to find the perfect cuboid, but it isn't that simple. You need a very fast square root op on the computer. Right now the cuda devices that I am working on cannot even handle 128 bit code yet.

Posts: 1
Joined: 26.03.2012 22:13

Re: [sub-project] Perfect cuboid

Unread postby fwjmath » 06.04.2012 23:46


I am very interested by your work and how it progresses. Would you mind to share your method and your code? If it is embarrassingly parallel, or at least somehow parallel, maybe the community here can still make a subproject out of it that might greatly push the search forward.

And another rather irrelevant question, how fast should that square root be and for what range of numbers?

Posts: 54
Joined: 19.10.2010 15:26

Re: [sub-project] Perfect cuboid

Unread postby x3mEn » 16.09.2012 19:18

Actually from the time of my last trial to push up my idea there were some changes in approach.
In general it is: factorization + decomposition of any 4k+1 number instead of composing a number as a product of 4k+1 primes
It leads to the next improvements:
1) we can sequentially run up to high values
2) we can do batch processing for mass number exclusion and factorization

In details:

1) we take some range of numbers (this is our Work Unit). For example:
and generate a pool of 4k+1 numbers from the range

2) we organize loop for i from 3 up to sqrt(Fin) step 2
for every number i from loop we calculate first odd value j that i*j >= Ini
while i*j <= Fin we do loop for j step 2 and
- exclude numbers if not(i is 4k+1 form & j is 4l+1 form) (Sieve of Eratosthenes)
- else we memorize i and change the value of number N to N/i (if i<=sqrt(N))
After full loop for i we get that some numbers in the range will be
- or excluded
- or factorized by primes 4k+1 form
The 2nd group is our candidates.

3) We gather all factors we meet during factorization of this group and begin their decomposition into the sum of 2 squares
After this step batch processing is completed.

4) For every factorized number from the range we build all its different decompositions into the sum of 2 squares

5) We check all triples of pairs for:
- perfect cuboids
- almost perfect cuboids of 2 types:
-- where the space diagonal and two of the three face diagonals are integers
-- where the space diagonal and two of the three edges are integers
Posts: 39
Joined: 20.03.2011 22:23


Return to Fehler, Wünsche / Bugs, Wishes

Who is online

Users browsing this forum: No registered users and 3 guests