6
$\begingroup$

I would like to solve this equation:

x1y1 + x2y2 + x3y3 + x4y4 = 0

and I would like to count the number of distict solutions. Here $x_1,\dots,x_4$ and $y_1,\dots,y_4$ can be only $\pm1$. How can I do? Thank you in advance. I tried this:

Reduce[x1*y1 + x2*y2 + x3*y3 + x4*y4 == 0, {x1, x2, x3, x4, y1, y2, y3, y4}, Integers] 

But of course it returns every possible integer solution to this kind of diophantine equation.

$\endgroup$
3
  • 2
    $\begingroup$ You could always brute-force the thing: signs = Tuples[{1, -1}, 4]; 2 * Length[Flatten[Table[If[signs[[j]] . signs[[k]] == 0, {j, k}, Nothing], {j, Length[signs]}, {k, j}], 1]], but I'm sure there's a more clever approach. $\endgroup$ Commented Jul 24, 2022 at 15:24
  • 2
    $\begingroup$ The condition $x = \pm 1$ is equivalent to the equation $x^2 = 1$, maybe you can use that? $\endgroup$
    – user293787
    Commented Jul 24, 2022 at 16:00
  • 4
    $\begingroup$ With[{u={x1,x2,x3,x4},v={y1,y2,y3,y4}},Solve[{u.v==0,u^2==1,v^2==1},Join[u,v]]] $\endgroup$
    – chyanog
    Commented Jul 24, 2022 at 16:09

2 Answers 2

8
$\begingroup$

Could just add the appropriate constraints. I set this up programmatically to save wear and tear on my four typing fingers.

xvars = Array[x, 4];
yvars = Array[y, 4];
allvars = Join[xvars, yvars];
eqn = xvars . yvars == 0;
constraints = Map[#^2 - 1 == 0 &, allvars];
allsolns = Reduce[Join[{eqn}, constraints], allvars];
Length[allsolns]
allsolns[[1 ;; 5]]

(* Out[361]= 96

Out[362]= (x[1] == -1 && x[2] == -1 && x[3] == -1 && x[4] == -1 && 
   y[1] == -1 && y[2] == -1 && y[3] == 1 && 
   y[4] == 1) || (x[1] == -1 && x[2] == -1 && x[3] == -1 && 
   x[4] == -1 && y[1] == -1 && y[2] == 1 && y[3] == -1 && 
   y[4] == 1) || (x[1] == -1 && x[2] == -1 && x[3] == -1 && 
   x[4] == -1 && y[1] == -1 && y[2] == 1 && y[3] == 1 && 
   y[4] == -1) || (x[1] == -1 && x[2] == -1 && x[3] == -1 && 
   x[4] == -1 && y[1] == 1 && y[2] == -1 && y[3] == -1 && 
   y[4] == 1) || (x[1] == -1 && x[2] == -1 && x[3] == -1 && 
   x[4] == -1 && y[1] == 1 && y[2] == -1 && y[3] == 1 && y[4] == -1) *)
$\endgroup$
0
7
$\begingroup$

If you just want the count:

Count[Tuples[{-1, 1}, 8], v_ /; v[[1 ;; 4]] . v[[5 ;; 8]] == 0]
(*    96    *)

or with a more explicit criterion:

Count[Tuples[{-1, 1}, 8],
      {x1_, x2_, x3_, x4_, y1_, y2_, y3_, y4_} /; x1*y1 + x2*y2 + x3*y3 + x4*y4 == 0]
(*    96    *)

If you want the actual solutions in the form $\{x_1,x_2,x_3,x_4,y_1,y_2,y_3,y_4\}$:

Select[Tuples[{-1, 1}, 8], #[[1 ;; 4]] . #[[5 ;; 8]] == 0 &]
(*    {{-1, -1, -1, -1, -1, -1, 1, 1}, {-1, -1, -1, -1, -1, 1, -1, 1},
      ...
       {1, 1, 1, 1, 1, -1, 1, -1}, {1, 1, 1, 1, 1, 1, -1, -1}}    *)
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.