5x5 Bimagic Square
Formulations
Special Cases Introduction Associated 5x5 Bimagic Square Formulation Associated 5x5 Bimagic Square Computer Procedure Local Block 5x5 Bimagic Square Formulation Local Block 5x5 Bimagic Square Computer Procedure The General Case Introduction The Magic Difference Formulation Magic Difference Translation Invariance Magic Difference of Squares Translation Zero Magic Difference Formulation Zero Magic Difference Computer Procedure Zero Magic Difference of Squares Formulation Zero Magic Difference of Squares Computer Procedure Special Cases Introduction Finding a bimagic square can be simplified if it is constrained to have a certain type of complementary structure. This is described in Bimagic Square General Theorems. Associated 5x5 Bimagic Square Formulation A B C D E F G H I J K L 0 -L -K -J -I -H -G -F -E -D -C -B -A The magic sum is 0. Because of the structure, the four lines going through the center must sum to 0. This leaves the four lines, A+B+C+D+E = 0, F+G+H+I+J = 0, A+F+K-J-E = 0, B+G+L-I-D = 0. The other four lines form duplicate equations. Solving for B,D,F,J, we get the general formula for an associated 5x5 magic square. (1) B = [-(A+C+E) - (G+L-I)]/2 (2) D = [-(A+C+E) + (G+L-I)]/2 (3) F = [-(G+H+I) - (A+K-E)]/2 (4) J = [-(G+H+I) + (A+K-E)]/2 Any choice of A,C,E,G,H,I,K,L will work. We just have to watch out for duplicate terms and fractions. To be bimagic, we must have 2(E2+I2) = 2(A2+G2), 2(K2+L2) = 2(A2+G2), 2(C2+H2) = 2(A2+G2), A2+B2+C2+D2+E2 = 2(A2+G2), F2+G2+H2+I2+J2 = 2(A2+G2), A2+F2+K2+J2+E2 = 2(A2+G2), B2+G2+L2+I2+D2 = 2(A2+G2). The other four lines form duplicate equations. Combine the first three equations and express B,D,F,J in terms of the others, (5) A2+G2 = E2+I2 = K2+L2 = C2+H2, (6) B2+D2 = A2+2G2-E2-C2, (7) F2+J2 = 2A2+G2-I2-H2, (8) F2+J2 = A2+2G2-E2-K2, (9) B2+D2 = 2A2+G2-I2-L2. Equate (7) and (8) and rearrange, (8a) G2-E2 = A2-I2+K2-H2. Equate (6) and (9) and rerrange, (9a) G2-E2 = A2-I2+C2-L2. From (5), C2-L2 = K2-H2, thus (8a) and (9a) are equivalent and one can be eliminated. From (5), I2-A2 = G2-E2, thus (6a) B2+D2 = G2+I2-C2, (7a) F2+J2 = A2+E2-H2, (8b) 2(G2-E2) = C2-L2. The full formulation is (1) B = [-(A+C+E) - (G+L-I)]/2, (2) D = [-(A+C+E) + (G+L-I)]/2, (3) F = [-(G+H+I) - (A+K-E)]/2, (4) J = [-(G+H+I) + (A+K-E)]/2, (5) A2+G2 = E2+I2 = K2+L2 = C2+H2, (6a) B2+D2 = G2+I2-C2, (7a) F2+J2 = A2+E2-H2, (8b) 2(G2-E2) = C2-L2. Additional Derivation [not used in the computer procedure] Compute B2+D2 from (1) and (2) and equate to (6a), (6b) [(A+C+E)2 + (G+L-I)2]/2 = G2+I2-C2. Compute F2+J2 from (3) and (4) and equate to (7a), (7b) [(G+H+I)2 + (A+K-E)2]/2 = A2+E2-H2. Multiply out (6b) and (7b), (6c) A2+3C2+E2-G2+L2-I2 + 2(AC+AE+CE) + 2(GL-GI-IL) = 0, (7c) G2+3H2+I2-A2+K2-E2 + 2(GH+GI+HI) + 2(AK-AE-EK) = 0. Use A2-I2 = E2-G2 and 2(G2-E2) = C2-L2 = K2-H2 and divide by 2, (6d) C2+L2 + (AC+AE+CE) + (GL-GI-IL) = 0, (7d) H2+K2 + (GH+GI+HI) + (AK-AE-EK) = 0. Factor and rearrange, (6e) (A+C)(E+C) = (G+L)(I-L), (7e) (A+K)(E-K) = (G+H)(I+H). Associated 5x5 Bimagic Square Computer Procedure Step (1) Find a number expressible as the sum of two squares in four distinct ways A2+G2 = E2+I2 = K2+L2 = C2+H2. Step (2) Verify that the expression satisfies 2(G2-E2) = C2-L2. Step (3) For each expression, precompute u := G2+I2-C2, v := A2+E2-H2. Step (4) Negate combinations of A,G,E,I,K,L,C,H. Step (5) For each combination, compute B := [(-A-C-E) + (I-G-L)]/2, D := [(-A-C-E) - (I-G-L)]/2, F := [(-G-H-I) + (E-K-A)]/2, J := [(-G-H-I) - (E-K-A)]/2. [No need to check for fractions; B,D,F,J will be integer.] Verify that positive or negative values of B,D,F,J don't duplicate each other or A,G,E,I,K,L,C,H. Step (6) Verify that B2+D2 = u, F2+J2 = v. Step (7) Arrange the 12 variables in a square, each appearing as both positive and negative values. A B C D E F G H I J K L 0 -L -K -J -I -H -G -F -E -D -C -B -A Step (8) Find z, the most negative term. Add (1-z) to all terms, producing an all-positive-distinct-integer 5x5 bimagic square having an associated structure. Implementation Notes The number of combinations that will pass both Steps (1) and (2) will be very small, so you can afford to be somewhat inefficient for the rest of the steps. Notes for Step (1). Make multiple passes of generating sums of two squares for a narrow range of sums. After each pass, sort the pairs and scan for matching sums, appending them to a list of 4-pair expressions. Produce only one combination of the same pairs; permutations will be done in Step 2. Use only positive numbers; negative combinations will be assigned in Step 4. Notes for Step (2). Permute the values of the 4-pair expression to satisfy the equation. There are 6 choices of the pairs to become the C,H and K,L pairs. Note that C2-L2 = K2-H2 and G2-E2 = I2-A2, reducing the number of inequivalent permutations. Notes for Step (4). Keep variable A positive, and select the 128 combinations of negations for the other 7 variables. Notes for Step (5). Here is the proof that no fractions will be encountered. Since 2(G2-E2) = C2-L2, C2-L2 must be even and C-L and C+L will be even. Since C2-L2 = K2-H2, K+H and K-H will be even. Since A2+G2 = E2+I2, A+G and A-G will have the same odd-even parity as E+I and E-I, thus their sum or difference will be even. Therefore, all the expressions in Step (5) will be even and B,D,F,J will be divisible by 2 without fractions. Local Block 5x5 Bimagic Square Formulation A B C D E -B -A -C -E -D F -F 0 -G G -I -H -J -L -K H I J K L The magic sum is 0. Because of the structure, the four lines going through the center must sum to 0. This leaves the four lines A+B+C+D+E = 0, H+I+J+K+L = 0, A-B+F-I+H = 0, E-D+G-K+L = 0. The other four lines form duplicate equations. Express B,D,I,K in terms of the others, (1) B+D = -(A+C+E), (2) I+K = -(H+J+L), (3) B+I = A+F+H, (4) D+K = E+G+L. Subtract (4) from (1), (1a) B-K = -(A+C+E)-(E+G+L). Subtract (1a) + (2) from (3), (2a) 2(A+L+E+H)+F+G+C+J = 0. Subtract (2a) from (1a), (1b) B-K = (J+L+H)+(A+F+H). Rearrange (3) and (4), (1b) B-K = (J+L+H)+(A+F+H) (2a) 2(A+L+E+H)+F+G+C+J = 0, (3a) I = A+F+H-B, (4a) D = E+G+L-K. To be bimagic, we must have 2(E2+H2) = 2(A2+L2), 2(F2+G2) = 2(A2+L2), 2(C2+J2) = 2(A2+L2), A2+B2+C2+D2+E2 = 2(A2+L2), H2+I2+J2+K2+L2 = 2(A2+L2), A2+B2+F2+I2+H2 = 2(A2+L2), E2+D2+G2+K2+L2 = 2(A2+L2). The other four lines form duplicate equations. Combine the first three equations and express the B,D,I,K in terms of the others, (5) A2+L2 = E2+H2 = F2+G2 = C2+J2, (6) B2+D2 = A2+2L2-E2-C2, (7) I2+K2 = 2A2+L2-H2-J2, (8) B2+I2 = A2+2L2-H2-F2, (9) D2+K2 = 2A2+L2-E2-G2. Subtract (9) from (6), (9a) B2-K2 = L2-A2+G2-C2. Subtract (7) from (8), (8a) B2-K2 = L2-A2+J2-F2. From (5), G2-C2 = J2-F2, thus (9a) and (7a) are equivalent and (9a) can be eliminated. From (5), L2-E2 = H2-A2, so (6) becomes (6a) B2+D2 = H2+L2-C2. From (5), A2-J2 = C2-L2 and A2-H2 = E2-L2, so (7) becomes (7a) I2+K2 = C2+E2-L2. Rearrange (6a) and (7a), (1b) B-K = (J+L+H)+(A+F+H), (2a) 2(A+L+E+H)+F+G+C+J = 0, (3a) I = A+F+H-B, (4a) D = E+G+L-K, (5) A2+L2 = E2+H2 = F2+G2 = C2+J2, (6b) D2 = H2+L2-C2-B2, (7b) I2 = C2+E2-L2-K2, (8a) B2-K2 = L2-A2+J2-F2. Use (1b) and (8a), and solve for B and K, u = B-K = (J+L+H)+(A+F+H), v = B2-K2 = (J2+L2)-(A2+F2), which yields K = (v-u2)/(2u), B = (v+u2)/(2u). Local Block 5x5 Bimagic Square Computer Procedure Find expressions of numbers as the sum of two squares in four distinct ways A2+L2 = E2+H2 = F2+G2 = C2+J2. For each permutation of an expression, form negation combinations of the variables that satisfy 2(A+L + E+H) + (F+G + C+J) = 0. For each negation combination, compute u := (L+J + A+F + 2H) and if u is not zero, compute v := (L2+J2) - (A2+F2), K := (v-u2)/(2u) B := (v+u2)/(2u) D := (E+G+L) - K, I := (A+F+H) - B and if D2 = (H2+L2) - (C2+B2), I2 = (C2+E2) - (L2+K2), then you have a solution. If there are fractions, multiply all variables by their common denominator [or just multiply by (2u)] to form an all-integer solution. Fill in this pattern with each variable and its negation. A B C D E -B -A -C -E -D F -F 0 -G G -I -H -J -L -K H I J K L Find z, the most negative number and then add (1-z) to all terms to form an all-positive-integer 5x5 bimagic square. The General Case Introduction A straight-forward method of searching for a 5x5 bimagic square is to enumerate 5-tuple multigrade equations. But there are too many of them to make this approach practical. It would be much better if the problem could be formulated in terms of 2-tuple and 3-tuple equations. Bimagic squares come in families. You can scale and translate a bimagic square to form another bimagic square in the same family. In enumerating all bimagic squares, it is sufficient to find one member from each family, because all the rest can be computed by scaling and translation. The best choice for the member would be the one that most simplifies the formulation. A translation can make an expression zero. The best expression to make zero is not a term or a sum, but a difference. The Magic Difference Formulation We convert the formulation for a 5x5 bimagic square from magic sums and magic sums of squares into magic differences and magic differences of squares. A B C D E F G H I J K L M N P Q R S T U V W X Y Z Here is the magic sum formulation, where s is the magic sum and r is the magic sum of squares. (S1) (A+G+M+T+Z) = s (R1) (A2+G2+M2+T2+Z2) = r (S2) (E+I+M+R+V) = s (R2) (E2+I2+M2+R2+V2) = r (S3) (A+B+C+D+E) = s (R3) (A2+B2+C2+D2+E2) = r (S4) (A+F+K+Q+V) = s (R4) (A2+F2+K2+Q2+V2) = r (S5) (V+W+X+Y+Z) = s (R5) (V2+W2+X2+Y2+Z2) = r (S6) (E+J+P+U+Z) = s (R6) (E2+J2+P2+U2+Z2) = r (S7) (F+G+H+I+J) = s (R7) (F2+G2+H2+I2+J2) = r (S8) (Q+R+S+T+U) = s (R8) (Q2+R2+S2+T2+U2) = r (S9) (B+G+L+R+W) = s (R9) (B2+G2+L2+R2+W2) = r (S10) (D+I+N+T+Y) = s (R10) (D2+I2+N2+T2+Y2) = r (S11) (K+L+M+N+P) = s (R11) (K2+L2+M2+N2+P2) = r (S12) (C+H+M+S+X) = s (R12) (C2+H2+M2+S2+X2) = r Define the magic difference as the magic sum minus the four corner and center terms: d = s - (A+E+V+Z+M). Define the magic difference of squares correspondingly as: e = r - (A2+E2+V2+Z2+M2). Get an equivalent definition. Add (S1) and (S2): (A+G+M+T+Z) + (E+I+M+R+V) = 2s. Subtract s + (A+E+V+Z+M) from both sides: (G+I+R+T+M) - s = s - (A+E+V+Z+M) or (G+I+R+T+M) - s = d. Repeating the above using the squares, (G2+I2+R2+T2+M2) - r = e. Transform the sum formulation into the difference formulation as follows. Subtract (A+E+V+Z+M) from both sides of (S1),(S2),(S3),(S4),(S5),(S6) and replace s - (A+E+V+Z+M) with d. Subtract both sides of (S7),(S8),(S9),(S10),(S11),(S12) from (G+I+R+T+M) and replace (G+I+R+T+M) - s with d. Subtract (A2+E2+V2+Z2+M2) from both sides of (R1),(R2),(R3),(R4),(R5),(R6) and replace r - (A2+E2+V2+Z2+M2) with e. Subtract both sides of (R7),(R8),(R9),(R10),(R11),(R12) from (G2+I2+R2+T2+M2) and replace (G2+I2+R2+T2+M2) - r with e. (D1) (G+T) - (E+V) = d (E1) (G2+T2) - (E2+V2) = e (D2) (I+R) - (A+Z) = d (E2) (I2+R2) - (A2+Z2) = e (D3) (B+C+D) - (M+V+Z) = d (E3) (B2+C2+D2) - (M2+V2+Z2) = e (D4) (F+K+Q) - (M+E+Z) = d (E4) (F2+K2+Q2) - (M2+E2+Z2) = e (D5) (W+X+Y) - (M+A+E) = d (E5) (W2+X2+Y2) - (M2+A2+E2) = e (D6) (J+P+U) - (M+A+V) = d (E6) (J2+P2+U2) - (M2+A2+V2) = e (D7) (M+R+T) - (F+H+J) = d (E7) (M2+R2+T2) - (F2+H2+J2) = e (D8) (M+G+I) - (Q+S+U) = d (E8) (M2+G2+I2) - (Q2+S2+U2) = e (D9) (M+I+T) - (B+L+W) = d (E9) (M2+I2+T2) - (B2+L2+W2) = e (D10) (M+G+R) - (D+N+Y) = d (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11) (G+I+R+T) - (K+L+N+P) = d (E11) (G2+I2+R2+T2) - (K2+L2+N2+P2) = e (D12) (G+I+R+T) - (C+H+S+X) = d (E12) (G2+I2+R2+T2) - (C2+H2+S2+X2) = e Subtract (D11) from (D12); subtract (E11) from (E12), (D12a) (K+L+N+P) = (C+H+S+X) (E12a) (K2+L2+N2+P2) = (C2+H2+S2+X2) Compute (D3)+(D5)+(D9)+(D10)-(D1)-(D2) and (E3)+(E5)+(E9)+(E10)-(E1)-(E2) to get (D3a) (C+X) - (L+N) = 2d (E3a) (C2+X2) - (L2+N2) = 2e Compute (D4)+(D6)+(D7)+(D8)-(D1)-(D2) and (E4)+(E6)+(E7)+(E8)-(E1)-(E2) to get (D4a) (K+P) - (H+S) = 2d (E4a) (K2+P2) - (H2+S2) = 2e Note that (D4a)-(D3a)=(D12a) and (E4a)-(E3a)=(E12a), thus (D12a) and (E12a) can be removed. This is the starting formulation in preparation for the next step, when either d=0 or e=0. (D1) (G+T) - (E+V) = d (E1) (G2+T2) - (E2+V2) = e (D2) (I+R) - (A+Z) = d (E2) (I2+R2) - (A2+Z2) = e (D3a) (C+X) - (L+N) = 2d (E3a) (C2+X2) - (L2+N2) = 2e (D4a) (K+P) - (H+S) = 2d (E4a) (K2+P2) - (H2+S2) = 2e (D5) (W+X+Y) - (M+A+E) = d (E5) (W2+X2+Y2) - (M2+A2+E2) = e (D6) (J+P+U) - (M+A+V) = d (E6) (J2+P2+U2) - (M2+A2+V2) = e (D7) (M+R+T) - (F+H+J) = d (E7) (M2+R2+T2) - (F2+H2+J2) = e (D8) (M+G+I) - (Q+S+U) = d (E8) (M2+G2+I2) - (Q2+S2+U2) = e (D9) (M+I+T) - (B+L+W) = d (E9) (M2+I2+T2) - (B2+L2+W2) = e (D10) (M+G+R) - (D+N+Y) = d (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11) (G+I+R+T) - (K+L+N+P) = d (E11) (G2+I2+R2+T2) - (K2+L2+N2+P2) = e Magic Difference Translation Invariance If we translate the bimagic square by adding t to every term, we get another bimagic square with changed values of the magic sum and magic sum of squares. However, the magic difference does not change. We use (D1) to illustrate. (G+t) + (T+t) - (E+t) - (V-t) = d + 2t - 2t = d. In each case, the same number of t values are added and subtracted, cancelling each other out. Magic Difference Of Squares Translation The magic difference of squares changes with translation as follows. We use (D1) to illustrate. (G+t)2 + (T+t)2 - (E+t)2 - (V-t)2 which expands to (G2+T2+E2+V2) + 2t[(G+T)-(E+V)] + 2t2 - 2t2 then reduces to e + 2td. So the result does not depend on the individual terms. Note that if d = 0, then e becomes translation invariant. However, if d is not zero, then e will be translated to 0 if e + 2td = 0, or t = -e/(2d). So in every 5x5 bimagic square family, there exists a member with d = 0 or else a translated member with e = 0. Furthermore, when d = 0, we can translate so that some term or expression becomes 0, making further simplifications. Zero Magic Difference Formulation There are two cases for the general 5x5 bimagic square. Either the magic difference d is 0 or it is not. This section assumes d is 0. We also assume that e is not 0, otherwise there must be duplications. This is because we would have (D1) (G+T) = (E+V), (E1) (G2+T2) = (E2+V2), in which case {G,T} must have the same values as {E,V}. When d is 0 and e is not 0, the 5x5 bimagic square has this formulation. (D1) (G+T) = (E+V) (E1) (G2+T2) - (E2+V2) = e (D2) (I+R) = (A+Z) (E2) (I2+R2) - (A2+Z2) = e (D3a) (C+X) = (L+N) (E3a) (C2+X2) - (L2+N2) = 2e (D4a) (K+P) = (H+S) (E4a) (K2+P2) - (H2+S2) = 2e (D5) (W+X+Y) = (M+A+E) (E5) (W2+X2+Y2) - (M2+A2+E2) = e (D6) (J+P+U) = (M+A+V) (E6) (J2+P2+U2) - (M2+A2+V2) = e (D7) (M+R+T) = (F+H+J) (E7) (M2+R2+T2) - (F2+H2+J2) = e (D8) (M+G+I) = (Q+S+U) (E8) (M2+G2+I2) - (Q2+S2+U2) = e (D9) (M+I+T) = (B+L+W) (E9) (M2+I2+T2) - (B2+L2+W2) = e (D10) (M+G+R) = (D+N+Y) (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11) (G+I+R+T) = (K+L+N+P) (E11) (G2+I2+R2+T2) - (K2+L2+N2+P2) = e. Since d is translation invariant, we can translate to another form with d = 0 to make further simplifications. Here is one idea for a translation. We translate so that (G+T) = 0. From (D1), this gives (E+V) = 0 and thus T = -G, V = -E, T2 = G2, V2 = E2. We now have a 5x5 bimagic square with this formulation that has eliminated one equation and two variables. (E1) 2(G2-E2) = e (D2) (I+R) = (A+Z) (E2) (I2+R2) - (A2+Z2) = e (D3a) (C+X) = (L+N) (E3a) (C2+X2) - (L2+N2) = 2e (D4a) (K+P) = (H+S) (E4a) (K2+P2) - (H2+S2) = 2e (D5) (W+X+Y) = (M+A+E) (E5) (W2+X2+Y2) - (M2+A2+E2) = e (D6) (J+P+U) = (M+A-E) (E6) (J2+P2+U2) - (M2+A2+E2) = e (D7) (M+R-G) = (F+H+J) (E7) (M2+G2+R2) - (F2+H2+J2) = e (D8) (M+G+I) = (Q+S+U) (E8) (M2+G2+I2) - (Q2+S2+U2) = e (D9) (M+I-G) = (B+L+W) (E9) (M2+G2+I2) - (B2+L2+W2) = e (D10) (M+G+R) = (D+N+Y) (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11) (I+R) = (K+L+N+P) (E11) (2G2+I2+R2) - (K2+L2+N2+P2) = e We use some common terms in the difference of squares section to eliminate e in three of the equations. Equate (E5),(E6) to make (E5a). Equate (E7),(E10) to make (E7a). Equate (E8),(E9) to make (E8a). (E1) 2(G2-E2) = e (D2) (I+R) = (A+Z) (E2) (I2+R2) - (A2+Z2) = e (D3a) (C+X) = (L+N) (E3a) (C2+X2) - (L2+N2) = 2e (D4a) (K+P) = (H+S) (E4a) (K2+P2) - (H2+S2) = 2e (D5) (W+X+Y) = (M+A+E) (E5a) (W2+X2+Y2) = (J2+P2+U2) (D6) (J+P+U) = (M+A-E) (E6) (J2+P2+U2) - (M2+A2+E2) = e (D7) (M+R-G) = (F+H+J) (E7a) (D2+N2+Y2) = (F2+H2+J2) (D8) (M+G+I) = (Q+S+U) (E8a) (B2+L2+W2) = (Q2+S2+U2) (D9) (M+I-G) = (B+L+W) (E9) (M2+G2+I2) - (B2+L2+W2) = e (D10) (M+G+R) = (D+N+Y) (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11) (I+R) = (K+L+N+P) (E11) (2G2+I2+R2) - (K2+L2+N2+P2) = e We modify some more equations in order to express variables in terms of others so they can be solved. Equate (D7)+(D8) with (D9)+(D10) to make (D7a). Compute (D9)+(D10) to make (D9a). Compute (D4a)+(D11) to make (D11a). (E1) 2(G2-E2) = e (D2) (I+R) = (A+Z) (E2) (I2+R2) - (A2+Z2) = e (D3a) (C+X) = (L+N) (E3a) (C2+X2) - (L2+N2) = 2e (D4a) (K+P) = (H+S) (E4a) (K2+P2) - (H2+S2) = 2e (D5) (W+X+Y) = (M+A+E) (E5a) (W2+X2+Y2) = (J2+P2+U2) (D6) (J+P+U) = (M+A-E) (E6) (J2+P2+U2) - (M2+A2+E2) = e (D7a) (B+L+W+D+N+Y) = (F+H+J+Q+S+U) (E7a) (D2+N2+Y2) = (F2+H2+J2) (D8) (M+G+I) = (Q+S+U) (E8a) (B2+L2+W2) = (Q2+S2+U2) (D9a) (2M+R+I) = (B+L+W+D+N+Y) (E9) (M2+G2+I2) - (B2+L2+W2) = e (D10) (M+G+R) = (D+N+Y) (E10) (M2+G2+R2) - (D2+N2+Y2) = e (D11a) (I+R) = (H+L+N+S) (E11) (2G2+I2+R2) - (K2+L2+N2+P2) = e We now solve for individual variables. Rearrange (D2), (D2a) Z = I+R-A. Rearrange (D3a), (D3b) C = L+N-X. Rearrange (D4a), (D4b) K = H+S-P. Add and subtract (D5) and (D6), (D5a) A = (W+X+Y)/2 + (J+P+U)/2 - M, (D6a) E = (W+X+Y)/2 - (J+P+U)/2. Subtract (D8) from (D10), (D10a) (R-I) = (D+N+Y)-(Q+S+U). Rearrange (D8), (D8a) G = (Q+S+U)-(M+I). Subtract (11a) from (9a), (D9b) M = [(B+W+D+Y) - (H+S)]/2. Add and subtract (D10a) and (D11a), (D10b) R = (H+L+2N+D+Y)/2-(Q+U)/2, (D11b) I = (H+L+2S+Q+U)/2-(D+Y)/2. Review. (D2a) Z = I+R-A, (D3b) C = L+N-X, (D4b) K = H+S-P, (D5a) A = (W+X+Y)/2 + (J+P+U)/2 - M, (D6a) E = (W+X+Y)/2 - (J+P+U)/2, (D7a) (B+L+W+D+N+Y) = (F+H+J+Q+S+U), (D8a) G = (Q+S+U)-(M+I), (D9b) M = [(B+W+D+Y) - (H+S)]/2, (D10b) R = (H+L+2N+D+Y)/2-(Q+U)/2, (D11b) I = (H+L+2S+Q+U)/2-(D+Y)/2. Zero Magic Difference Computer Procedure Find a := (W2+X2+Y2) = (J2+P2+U2) b := (D2+N2+Y2) = (F2+H2+J2) c := (B2+L2+W2) = (Q2+S2+U2) such that a negation combination exists that satisfies (B+L+W+D+N+Y) = (F+H+J+Q+S+U), then compute M := [(B+W+D+Y) - (H+S)]/2, A := (W+X+Y)/2 + (J+P+U)/2 - M, I := (H+L+2S+Q+U)/2-(D+Y)/2. G := (Q+S+U)-(M+I), C := L+N-X, K := H+S-P, E := (W+X+Y)/2 - (J+P+U)/2, R := (H+L+2N+D+Y)/2-(Q+U)/2, Z := I+R-A, e := 2(G2-E2), and if (I2+R2) - (A2+Z2) = e, (C2+X2) - (L2+N2) = 2e, (K2+P2) - (H2+S2) = 2e, a - (M2+A2+E2) = e, (M2+G2+I2) - c = e, (M2+G2+R2) - b = e, (2G2+I2+R2) - (K2+L2+N2+P2) = e, then you have a solution. Assemble into A B C D E F G H I J K L M N P Q R S -G U -E W X Y Z Find z, the most negative term and add (1-z) to all terms. Zero Magic Difference of Squares Formulation There are two cases for the general 5x5 bimagic square. Either the magic difference d is 0 or it is not. This section assumes d is not 0. When the magic difference d is not 0, we can translate by t = -e/(2d), then scale by 2d, making an integer solution such that the magic difference of squares e is 0. After translation the 5x5 bimagic square has this formulation. (D1) (G+T) - (E+V) = d (G2+T2) = (E2+V2) (D2) (I+R) - (A+Z) = d (I2+R2) = (A2+Z2) (D3a) (C+X) - (L+N) = 2d (C2+X2) = (L2+N2) (D4a) (K+P) - (H+S) = 2d (K2+P2) = (H2+S2) (D5) (W+X+Y) - (M+A+E) = d (W2+X2+Y2) = (M2+A2+E2) (D6) (J+P+U) - (M+A+V) = d (J2+P2+U2) = (M2+A2+V2) (D7) (M+R+T) - (F+H+J) = d (M2+R2+T2) = (F2+H2+J2) (D8) (M+G+I) - (Q+S+U) = d (M2+G2+I2) = (Q2+S2+U2) (D9) (M+I+T) - (B+L+W) = d (M2+I2+T2) = (B2+L2+W2) (D10) (M+G+R) - (D+N+Y) = d (M2+G2+R2) = (D2+N2+Y2) (D11) (G+I+R+T) - (K+L+N+P) = d (G2+I2+R2+T2) = (K2+L2+N2+P2) Zero Magic Difference of Squares Computer Procedure A B C D E F G H I J K L M N P Q R S T U V W X Y Z (M2+I2+G2) = (Q2+U2+S2) (M+I+G) - (Q+U+S) = (d1) (M2+I2+T2) = (B2+W2+L2) (M+I+T) - (B+W+L) = (d1) (M2+R2+G2) = (D2+Y2+N2) (M+R+G) - (D+Y+N) = (d1) (M2+R2+T2) = (F2+J2+H2) (M+R+T) - (F+J+H) = (d1) (M2+A2+E2) = (W2+Y2+X2) (M+A+E) - (W+Y+X) = -(d1) (M2+A2+V2) = (U2+J2+P2) (M+A+V) - (U+J+P) = -(d1) (M2+Z2+E2) = (Q2+F2+K2) (M+Z+E) - (Q+F+K) = -(d1) (M2+Z2+V2) = (B2+D2+C2) (M+Z+V) - (B+D+C) = -(d1) (G2+T2) = (E2+V2) (G+T) - (E+V) = (d1) (I2+R2) = (A2+Z2) (I+R) - (A+Z) = (d1) for each s-range form triples all distinct, non-negative combinations s,M,I,G where s = (M2+I2+G2) and within s-range M < I < G sort by s form pairs (M2+I2+G2) = (Q2+U2+S2), append to list next s-range get pairs from list form negations and permutations, but leave M non-negative d, M,I,G, Q,U,S where d = [(M+I+G)-(Q+U+S)] check all distinct only after negations assigned include M,I,G,-M,-I,-G,d, etc don't store records where d = 0 sort by abs(d), then M, then I for each abs(d),M group form pairs I,G,Q,U,S I,T,B,W,L, d matching I,d all others distinct from each other and M sort by G, then T form pairs I,G,Q,U,S, I,T,B,W,L R,G,D,Y,N, R,T,F,J,H, d matching G,T,d, all others distinct for each pair in list, verify matches and distincts I,G,Q,U,S I,T,B,W,L R,G,D,Y,N R,T,F,J,H d A,E,W,Y,X A,V,U,J,P Z,E,Q,F,K Z,V,B,D,C -d verify (G2+T2) = (E2+V2) (I2+R2) = (A2+Z2) (G+T) - (E+V) = d (I+R) - (A+Z) = d next abs(d),M group