Diagonals checkingSearch for edges and face diagonals, satisfying the system

a² + b² = d²

a² + c² = e²

b² + c² = f²

a² + f² = g²

With the system it follows that

g² = a² + f²

g² = b² + e²

g² = c² + d²

We'd obtained all possible decompositions of the square of a space diagonal g² to sums of two squares.

The problem is to find three pairs (a, f), (b, e), (c, d), satisfying the conditions of the system.

First, note that

a < b < c

d < e < f

a < b < d < e < f

How are related to each other c and d - is not known.

Maybe c < d, maybe d < c

Secondly, knowing the 2 pairs (a, f), (b, e), then the pair (c, d) should not look for,

c² = e² - a²

c² = f² - b²

So edge c can be deducted on one of formulas like this:

? = sqrt(f² - b²) = sqrt(f - b) * sqrt(f + b)

Well diagonal d can either be deducted from the formula

d = sqrt(g - c) * sqrt (g + c),

or you can simply search for a pair between g decompositions,

just c² + d² = g².

Please note, if you know c, you have to search and pair (c, d) and pair (d, c)

If all decompositions of g² are stored in some table TASK,

so we can search target a, b, c, d, e, f from the query:

WITH t(A, B, F, E, FBextC, C) AS

(SELECT

a.X AS A

,b.X AS B

,a.Y AS F

,b.Y AS E

,CAST(SQRT( F-B ) AS DECIMAL(25,4)) * CAST(SQRT( F+B ) AS DECIMAL(25,4)) AS FBextC

,CAST(FBextC AS BIGINT) AS C

FROM TASK a, TASK b

WHERE A > 0

AND A < B

AND B < F / SQRT(2)

AND E > A * SQRT(2)

AND ABS(FBextC-C) < 0.001

AND ((A MOD 2) + (B MOD 2) <> 2)

AND ((A MOD 2) + (B MOD 2) + (C MOD 2) = 1)

AND (((A MOD 5) = 0) OR ((B MOD 5) = 0) OR ((C MOD 5) = 0))

AND (((A MOD 7) = 0) OR ((B MOD 7) = 0) OR ((C MOD 7) = 0))

AND (((A MOD 9) = 0) OR ((B MOD 9) = 0) OR ((C MOD 9) = 0))

AND (((A MOD 11) = 0) OR ((B MOD 11) = 0) OR ((C MOD 11) = 0))

AND (((A MOD 16) = 0) OR ((B MOD 16) = 0) OR ((C MOD 16) = 0))

AND (((A MOD 19) = 0) OR ((B MOD 19) = 0) OR ((C MOD 19) = 0))

AND ((CASE WHEN ((A MOD 3) = 0) THEN 1 ELSE 0 END) + (CASE WHEN ((B MOD 3) = 0) THEN 1 ELSE 0 END) + (CASE WHEN ((C MOD 3) = 0) THEN 1 ELSE 0 END)) >= 2

AND ((CASE WHEN ((A MOD 4) = 0) THEN 1 ELSE 0 END) + (CASE WHEN ((B MOD 4) = 0) THEN 1 ELSE 0 END) + (CASE WHEN ((C MOD 4) = 0) THEN 1 ELSE 0 END)) >= 2

)

SELECT A, B, C, d.Y AS D, E, F

FROM t, TASK AS d

WHERE C = d.X

UNION ALL

SELECT A, B, C, d.X AS D, E, F

FROM t, TASK AS d

WHERE C = d.Y;

The query check the next conditions:

1. A > 0 for discarding a trivial decomposition g² = 0² + g²

2. A < B

3. as far as b < c ? b² + c² = f², thus b < f / sqrt(2)

4. as far as a < c ? a² + c² = e², thus e > a * sqrt(2)

5. a and b can't be odd simultaneously

6. 2 of the edges a, b, c must be even and 1 edge must be odd

7. 1 of the edges a, b, c must be divisible by 5

8. 1 of the edges a, b, c must be divisible by 7

9. 1 of the edges a, b, c must be divisible by 9

10. 1 of the edges a, b, c must be divisible by 11

11. 1 of the edges a, b, c must be divisible by 16

12. 1 of the edges a, b, c must be divisible by 19

13. at least two of of the edges a, b, c must be divisible by 3

14. at least two of of the edges a, b, c must be divisible by 4

All these conditions are described here:

en.wikipedia.org/wiki/Perfect_cuboid