I have a set of 3 Polynomial equations, (Basically representing a particular case of Apollonio's problem: given 3 circles of known positions and radius, find a a fourth one tangent to the other 3).
I have successfully used sympy to create the system and solve the equations for , say, x_4, y_4,r_4.
I obtain a solution quickly If I solve for a particular case, replacing the data of the 3 circles (9 parameters) with exact values, eg sympy.Rational(aNumber).
I tried instead to obtain a general solution expressed in terms of named parameters representing the 3 circle coordinates and radius, but sympy does not seem able to find a solution, even after one hour.
I have read that using symbols is slow, but I am not using direct numbers, I am using sp.Rational()
for all the coordinates.
From what I understand the Rational are not transormed to float. Also in my circles
there are no 0-coordinates that could lead to termi simplification and the general or specific equation do not seem different.
Could anybody explain?
import sympy as sp
#complete running example
x ,y ,x_1,y_1,r_1,x_2,y_2,r_2,x_3,y_3,r_3,x_4,y_4,r_4 = sp.symbols('x y x_1 y_1 r_1 x_2 y_2 r_2 x_3 y_3 r_3 x_4 y_4 r_4')
class Cerchio:
def __init__(self, x, y, r):
self.x = x
self.y = y
self.r = r
class Soluzione:
def crea_eq(self, x_i, y_i, r_i):
expr = (x - x_i) ** 2 + (y - y_i) ** 2 - r_i ** 2
posx = x_i + r_i * ((x_4 - x_i) / (r_4 + r_i))
posy = y_i + r_i * ((y_4 - y_i) / (r_4 + r_i))
val = expr.subs(x, posx).subs(y, posy)
return val
def __init__(self):
self.finale1 = self.crea_eq(x_1, y_1, r_1)
self.finale2 = self.crea_eq(x_2, y_2, r_2)
self.finale3 = self.crea_eq(x_3, y_3, r_3)
def find(self, c1, c2, c3, symbolic) -> object:
if symbolic: # seems to run forever
sol = sp.solve((self.finale1, self.finale2, self.finale3), (x_4, y_4, r_4), set=True)
else: # fast
qua1 = sp.Eq(self.replace(self.finale1, c1, c2, c3), 0)
qua2 = sp.Eq(self.replace(self.finale2, c1, c2, c3), 0)
qua3 = sp.Eq(self.replace(self.finale3, c1, c2, c3), 0)
sol = sp.solve((qua1,qua2,qua3),(x_4,y_4,r_4),set=True)
print(sol, '\nend of equation solution')
def replace(self, esp, c1, c2, c3):
return esp.subs(r_1, c1.r).subs(r_2, c2.r).subs(r_3, c3.r) \
.subs(x_1, c1.x).subs(y_1, c1.y).subs(x_2, c2.x) \
.subs(y_2, c2.y).subs(x_3, c3.x).subs(y_3, c3.y)
soluzione = Soluzione()
c4 = soluzione.find(Cerchio(sp.Rational(2), sp.Rational(2), sp.Rational(2)),
Cerchio(sp.Rational(5), sp.Rational(5), sp.Rational(2)),
Cerchio(sp.Rational(12), sp.sqrt(3), sp.Rational(2)), symbolic = False)
c4 = soluzione.find(Cerchio(sp.Rational(2), sp.Rational(2), sp.Rational(2)),
Cerchio(sp.Rational(5), sp.Rational(5), sp.Rational(2)),
Cerchio(sp.Rational(12), sp.sqrt(3), sp.Rational(2)), symbolic = True)
The general solution that you seek is going to be too complicated to really be useful. After transforming your equations to a system of polynomials solve will try to solve these equations:
In [42]: polys = [Poly(r_1**2*x_4**2 - 2*r_1**2*x_1*x_4 + r_1**2*y_4**2 - 2*r_1**2*y_1*y_4 - r_1**2*r
...: _4**2 - 2*r_1**3*r_4 - r_1**4 + r_1**2*x_1**2 + r_1**2*y_1**2, x_4, y_4, r_4, domain='ZZ[r_1
...: ,x_1,y_1]'), Poly(r_2**2*x_4**2 - 2*r_2**2*x_2*x_4 + r_2**2*y_4**2 - 2*r_2**2*y_2*y_4 - r_2*
...: *2*r_4**2 - 2*r_2**3*r_4 - r_2**4 + r_2**2*x_2**2 + r_2**2*y_2**2, x_4, y_4, r_4, domain='ZZ
...: [r_2,x_2,y_2]'), Poly(r_3**2*x_4**2 - 2*r_3**2*x_3*x_4 + r_3**2*y_4**2 - 2*r_3**2*y_3*y_4 -
...: r_3**2*r_4**2 - 2*r_3**3*r_4 - r_3**4 + r_3**2*x_3**2 + r_3**2*y_3**2, x_4, y_4, r_4, domain
...: ='ZZ[r_3,x_3,y_3]')]
In [43]: eqs = [p.as_expr() for p in polys]
In [44]: eqs[0]
Out[44]:
4 3 2 2 2 2 2 2 2 2 2 2 2 2
- r₁ - 2⋅r₁ ⋅r₄ - r₁ ⋅r₄ + r₁ ⋅x₁ - 2⋅r₁ ⋅x₁⋅x₄ + r₁ ⋅x₄ + r₁ ⋅y₁ - 2⋅r₁ ⋅y₁⋅y₄ + r₁ ⋅y₄
In [45]: eqs[1]
Out[45]:
4 3 2 2 2 2 2 2 2 2 2 2 2 2
- r₂ - 2⋅r₂ ⋅r₄ - r₂ ⋅r₄ + r₂ ⋅x₂ - 2⋅r₂ ⋅x₂⋅x₄ + r₂ ⋅x₄ + r₂ ⋅y₂ - 2⋅r₂ ⋅y₂⋅y₄ + r₂ ⋅y₄
In [46]: eqs[2]
Out[46]:
4 3 2 2 2 2 2 2 2 2 2 2 2 2
- r₃ - 2⋅r₃ ⋅r₄ - r₃ ⋅r₄ + r₃ ⋅x₃ - 2⋅r₃ ⋅x₃⋅x₄ + r₃ ⋅x₄ + r₃ ⋅y₃ - 2⋅r₃ ⋅y₃⋅y₄ + r₃ ⋅y₄
In [47]: syms = [x_4, y_4, r_4]
It might look like those are simple equations but that does not mean that their solutions are simple. Here is a method that can give you the solutions by computing a Groebner basis:
In [50]: gb = groebner(eqs, syms)
In [51]: gb[0]
Out[51]:
2 2 2 2 2 2
r₁ ⋅y₂ - r₁ ⋅y₃ - r₂ ⋅y₁ + r₂ ⋅y₃ + r₃ ⋅y₁ - r₃ ⋅y₂ + r₄⋅(2⋅r₁⋅y₂ - 2⋅r₁⋅y₃ - 2⋅r₂⋅y₁ + 2⋅r₂⋅y₃ + 2
2 2 2 2 2 2
⋅r₃⋅y₁ - 2⋅r₃⋅y₂) - x₁ ⋅y₂ + x₁ ⋅y₃ + x₂ ⋅y₁ - x₂ ⋅y₃ - x₃ ⋅y₁ + x₃ ⋅y₂ + x₄⋅(2⋅x₁⋅y₂ - 2⋅x₁⋅y₃ - 2
2 2 2 2 2 2
⋅x₂⋅y₁ + 2⋅x₂⋅y₃ + 2⋅x₃⋅y₁ - 2⋅x₃⋅y₂) - y₁ ⋅y₂ + y₁ ⋅y₃ + y₁⋅y₂ - y₁⋅y₃ - y₂ ⋅y₃ + y₂⋅y₃
In [52]: gb[1]
Out[52]:
2 2 2 2 2 2
- r₁ ⋅x₂ + r₁ ⋅x₃ + r₂ ⋅x₁ - r₂ ⋅x₃ - r₃ ⋅x₁ + r₃ ⋅x₂ + r₄⋅(-2⋅r₁⋅x₂ + 2⋅r₁⋅x₃ + 2⋅r₂⋅x₁ - 2⋅r₂⋅x₃
2 2 2 2 2 2 2 2
- 2⋅r₃⋅x₁ + 2⋅r₃⋅x₂) + x₁ ⋅x₂ - x₁ ⋅x₃ - x₁⋅x₂ + x₁⋅x₃ - x₁⋅y₂ + x₁⋅y₃ + x₂ ⋅x₃ - x₂⋅x₃ + x₂⋅y
2 2 2 2
₁ - x₂⋅y₃ - x₃⋅y₁ + x₃⋅y₂ + y₄⋅(2⋅x₁⋅y₂ - 2⋅x₁⋅y₃ - 2⋅x₂⋅y₁ + 2⋅x₂⋅y₃ + 2⋅x₃⋅y₁ - 2⋅x₃⋅y₂)
In [53]: gb[2]
Out[53]:
4 2 4 4 2 4 2 4 4 2 2 2 2 2
r₁ ⋅x₂ - 2⋅r₁ ⋅x₂⋅x₃ + r₁ ⋅x₃ + r₁ ⋅y₂ - 2⋅r₁ ⋅y₂⋅y₃ + r₁ ⋅y₃ - 2⋅r₁ ⋅r₂ ⋅x₁⋅x₂ + 2⋅r₁ ⋅r₂ ⋅x₁⋅
2 2 2 2 2 2 2 2 2 2 2 2
x₃ + 2⋅r₁ ⋅r₂ ⋅x₂⋅x₃ - 2⋅r₁ ⋅r₂ ⋅x₃ - 2⋅r₁ ⋅r₂ ⋅y₁⋅y₂ + 2⋅r₁ ⋅r₂ ⋅y₁⋅y₃ + 2⋅r₁ ⋅r₂ ⋅y₂⋅y₃ - 2⋅r₁ ⋅
2 2 2 2 2 2 2 2 2 2 2 2 2
r₂ ⋅y₃ + 2⋅r₁ ⋅r₃ ⋅x₁⋅x₂ - 2⋅r₁ ⋅r₃ ⋅x₁⋅x₃ - 2⋅r₁ ⋅r₃ ⋅x₂ + 2⋅r₁ ⋅r₃ ⋅x₂⋅x₃ + 2⋅r₁ ⋅r₃ ⋅y₁⋅y₂ - 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
⋅r₁ ⋅r₃ ⋅y₁⋅y₃ - 2⋅r₁ ⋅r₃ ⋅y₂ + 2⋅r₁ ⋅r₃ ⋅y₂⋅y₃ - 2⋅r₁ ⋅x₁ ⋅x₂ + 4⋅r₁ ⋅x₁ ⋅x₂⋅x₃ - 2⋅r₁ ⋅x₁ ⋅x₃
2 2 2 2 2 2 2 2 2 3 2 2 2
- 2⋅r₁ ⋅x₁ ⋅y₂ + 4⋅r₁ ⋅x₁ ⋅y₂⋅y₃ - 2⋅r₁ ⋅x₁ ⋅y₃ + 2⋅r₁ ⋅x₁⋅x₂ - 2⋅r₁ ⋅x₁⋅x₂ ⋅x₃ - 2⋅r₁ ⋅x₁⋅x₂⋅x₃
2 2 2 2 2 2 2 3 2 2 2
+ 2⋅r₁ ⋅x₁⋅x₂⋅y₂ - 4⋅r₁ ⋅x₁⋅x₂⋅y₂⋅y₃ + 2⋅r₁ ⋅x₁⋅x₂⋅y₃ + 2⋅r₁ ⋅x₁⋅x₃ + 2⋅r₁ ⋅x₁⋅x₃⋅y₂ - 4⋅r₁ ⋅
2 2 2 3 2 2 2 2 2 2 2 2
x₁⋅x₃⋅y₂⋅y₃ + 2⋅r₁ ⋅x₁⋅x₃⋅y₃ - 2⋅r₁ ⋅x₂ ⋅x₃ + 4⋅r₁ ⋅x₂ ⋅x₃ - 2⋅r₁ ⋅x₂ ⋅y₁ + 2⋅r₁ ⋅x₂ ⋅y₁⋅y₂ + 2⋅
2 2 2 2 2 3 2 2 2 2
r₁ ⋅x₂ ⋅y₁⋅y₃ - 2⋅r₁ ⋅x₂ ⋅y₂⋅y₃ - 2⋅r₁ ⋅x₂⋅x₃ + 4⋅r₁ ⋅x₂⋅x₃⋅y₁ - 4⋅r₁ ⋅x₂⋅x₃⋅y₁⋅y₂ - 4⋅r₁ ⋅x₂⋅x₃⋅
2 2 2 2 2 2 2 2 2 2
y₁⋅y₃ - 2⋅r₁ ⋅x₂⋅x₃⋅y₂ + 8⋅r₁ ⋅x₂⋅x₃⋅y₂⋅y₃ - 2⋅r₁ ⋅x₂⋅x₃⋅y₃ - 2⋅r₁ ⋅x₃ ⋅y₁ + 2⋅r₁ ⋅x₃ ⋅y₁⋅y₂ + 2
2 2 2 2 2 2 2 2 2 2 2 2 2 3
⋅r₁ ⋅x₃ ⋅y₁⋅y₃ - 2⋅r₁ ⋅x₃ ⋅y₂⋅y₃ - 2⋅r₁ ⋅y₁ ⋅y₂ + 4⋅r₁ ⋅y₁ ⋅y₂⋅y₃ - 2⋅r₁ ⋅y₁ ⋅y₃ + 2⋅r₁ ⋅y₁⋅y₂ -
2 2 2 2 2 3 2 3 2 2 2 2 3
2⋅r₁ ⋅y₁⋅y₂ ⋅y₃ - 2⋅r₁ ⋅y₁⋅y₂⋅y₃ + 2⋅r₁ ⋅y₁⋅y₃ - 2⋅r₁ ⋅y₂ ⋅y₃ + 4⋅r₁ ⋅y₂ ⋅y₃ - 2⋅r₁ ⋅y₂⋅y₃ + r
4 2 4 4 2 4 2 4 4 2 2 2 2 2 2
₂ ⋅x₁ - 2⋅r₂ ⋅x₁⋅x₃ + r₂ ⋅x₃ + r₂ ⋅y₁ - 2⋅r₂ ⋅y₁⋅y₃ + r₂ ⋅y₃ - 2⋅r₂ ⋅r₃ ⋅x₁ + 2⋅r₂ ⋅r₃ ⋅x₁⋅x₂
2 2 2 2 2 2 2 2 2 2 2 2 2
+ 2⋅r₂ ⋅r₃ ⋅x₁⋅x₃ - 2⋅r₂ ⋅r₃ ⋅x₂⋅x₃ - 2⋅r₂ ⋅r₃ ⋅y₁ + 2⋅r₂ ⋅r₃ ⋅y₁⋅y₂ + 2⋅r₂ ⋅r₃ ⋅y₁⋅y₃ - 2⋅r₂ ⋅r₃
2 3 2 3 2 2 2 2 2 2 2 2 2 2
⋅y₂⋅y₃ + 2⋅r₂ ⋅x₁ ⋅x₂ - 2⋅r₂ ⋅x₁ ⋅x₃ - 2⋅r₂ ⋅x₁ ⋅x₂ - 2⋅r₂ ⋅x₁ ⋅x₂⋅x₃ + 4⋅r₂ ⋅x₁ ⋅x₃ + 2⋅r₂ ⋅x₁ ⋅
2 2 2 2 2 2 2 2 2 2 2
y₁⋅y₂ - 2⋅r₂ ⋅x₁ ⋅y₁⋅y₃ - 2⋅r₂ ⋅x₁ ⋅y₂ + 2⋅r₂ ⋅x₁ ⋅y₂⋅y₃ + 4⋅r₂ ⋅x₁⋅x₂ ⋅x₃ - 2⋅r₂ ⋅x₁⋅x₂⋅x₃ + 2⋅r
2 2 2 2 2 2 3 2 2 2
₂ ⋅x₁⋅x₂⋅y₁ - 4⋅r₂ ⋅x₁⋅x₂⋅y₁⋅y₃ + 2⋅r₂ ⋅x₁⋅x₂⋅y₃ - 2⋅r₂ ⋅x₁⋅x₃ - 2⋅r₂ ⋅x₁⋅x₃⋅y₁ - 4⋅r₂ ⋅x₁⋅x₃⋅y
2 2 2 2 2 2 2 2 2
₁⋅y₂ + 8⋅r₂ ⋅x₁⋅x₃⋅y₁⋅y₃ + 4⋅r₂ ⋅x₁⋅x₃⋅y₂ - 4⋅r₂ ⋅x₁⋅x₃⋅y₂⋅y₃ - 2⋅r₂ ⋅x₁⋅x₃⋅y₃ - 2⋅r₂ ⋅x₂ ⋅x₃ -
2 2 2 2 2 2 2 2 2 3 2 2 2
2⋅r₂ ⋅x₂ ⋅y₁ + 4⋅r₂ ⋅x₂ ⋅y₁⋅y₃ - 2⋅r₂ ⋅x₂ ⋅y₃ + 2⋅r₂ ⋅x₂⋅x₃ + 2⋅r₂ ⋅x₂⋅x₃⋅y₁ - 4⋅r₂ ⋅x₂⋅x₃⋅y₁⋅y
2 2 2 2 2 2 2 2 2 2 2 2
₃ + 2⋅r₂ ⋅x₂⋅x₃⋅y₃ + 2⋅r₂ ⋅x₃ ⋅y₁⋅y₂ - 2⋅r₂ ⋅x₃ ⋅y₁⋅y₃ - 2⋅r₂ ⋅x₃ ⋅y₂ + 2⋅r₂ ⋅x₃ ⋅y₂⋅y₃ + 2⋅r₂ ⋅y
3 2 3 2 2 2 2 2 2 2 2 2 2 2
₁ ⋅y₂ - 2⋅r₂ ⋅y₁ ⋅y₃ - 2⋅r₂ ⋅y₁ ⋅y₂ - 2⋅r₂ ⋅y₁ ⋅y₂⋅y₃ + 4⋅r₂ ⋅y₁ ⋅y₃ + 4⋅r₂ ⋅y₁⋅y₂ ⋅y₃ - 2⋅r₂ ⋅y₁
2 2 3 2 2 2 2 3 4 2 4 4 2 4 2
⋅y₂⋅y₃ - 2⋅r₂ ⋅y₁⋅y₃ - 2⋅r₂ ⋅y₂ ⋅y₃ + 2⋅r₂ ⋅y₂⋅y₃ + r₃ ⋅x₁ - 2⋅r₃ ⋅x₁⋅x₂ + r₃ ⋅x₂ + r₃ ⋅y₁ -
4 4 2 2 3 2 3 2 2 2 2 2 2 2
2⋅r₃ ⋅y₁⋅y₂ + r₃ ⋅y₂ - 2⋅r₃ ⋅x₁ ⋅x₂ + 2⋅r₃ ⋅x₁ ⋅x₃ + 4⋅r₃ ⋅x₁ ⋅x₂ - 2⋅r₃ ⋅x₁ ⋅x₂⋅x₃ - 2⋅r₃ ⋅x₁ ⋅
2 2 2 2 2 2 2 2 2 2 2 3 2
x₃ - 2⋅r₃ ⋅x₁ ⋅y₁⋅y₂ + 2⋅r₃ ⋅x₁ ⋅y₁⋅y₃ + 2⋅r₃ ⋅x₁ ⋅y₂⋅y₃ - 2⋅r₃ ⋅x₁ ⋅y₃ - 2⋅r₃ ⋅x₁⋅x₂ - 2⋅r₃ ⋅x₁
2 2 2 2 2 2 2 2
⋅x₂ ⋅x₃ + 4⋅r₃ ⋅x₁⋅x₂⋅x₃ - 2⋅r₃ ⋅x₁⋅x₂⋅y₁ + 8⋅r₃ ⋅x₁⋅x₂⋅y₁⋅y₂ - 4⋅r₃ ⋅x₁⋅x₂⋅y₁⋅y₃ - 2⋅r₃ ⋅x₁⋅x₂⋅y
2 2 2 2 2 2 2 2 2
₂ - 4⋅r₃ ⋅x₁⋅x₂⋅y₂⋅y₃ + 4⋅r₃ ⋅x₁⋅x₂⋅y₃ + 2⋅r₃ ⋅x₁⋅x₃⋅y₁ - 4⋅r₃ ⋅x₁⋅x₃⋅y₁⋅y₂ + 2⋅r₃ ⋅x₁⋅x₃⋅y₂ +
2 3 2 2 2 2 2 2 2 2 2 2 2 2
2⋅r₃ ⋅x₂ ⋅x₃ - 2⋅r₃ ⋅x₂ ⋅x₃ - 2⋅r₃ ⋅x₂ ⋅y₁⋅y₂ + 2⋅r₃ ⋅x₂ ⋅y₁⋅y₃ + 2⋅r₃ ⋅x₂ ⋅y₂⋅y₃ - 2⋅r₃ ⋅x₂ ⋅y₃
2 2 2 2 2 2 2 2 2 2 2
+ 2⋅r₃ ⋅x₂⋅x₃⋅y₁ - 4⋅r₃ ⋅x₂⋅x₃⋅y₁⋅y₂ + 2⋅r₃ ⋅x₂⋅x₃⋅y₂ - 2⋅r₃ ⋅x₃ ⋅y₁ + 4⋅r₃ ⋅x₃ ⋅y₁⋅y₂ - 2⋅r₃ ⋅x
2 2 2 3 2 3 2 2 2 2 2 2 2 2 2
₃ ⋅y₂ - 2⋅r₃ ⋅y₁ ⋅y₂ + 2⋅r₃ ⋅y₁ ⋅y₃ + 4⋅r₃ ⋅y₁ ⋅y₂ - 2⋅r₃ ⋅y₁ ⋅y₂⋅y₃ - 2⋅r₃ ⋅y₁ ⋅y₃ - 2⋅r₃ ⋅y₁⋅y
3 2 2 2 2 2 3 2 2 2 2 ⎛ 2 2 2
₂ - 2⋅r₃ ⋅y₁⋅y₂ ⋅y₃ + 4⋅r₃ ⋅y₁⋅y₂⋅y₃ + 2⋅r₃ ⋅y₂ ⋅y₃ - 2⋅r₃ ⋅y₂ ⋅y₃ + r₄ ⋅⎝4⋅r₁ ⋅x₂ - 8⋅r₁ ⋅x₂⋅x
2 2 2 2 2 2 2
₃ + 4⋅r₁ ⋅x₃ + 4⋅r₁ ⋅y₂ - 8⋅r₁ ⋅y₂⋅y₃ + 4⋅r₁ ⋅y₃ - 8⋅r₁⋅r₂⋅x₁⋅x₂ + 8⋅r₁⋅r₂⋅x₁⋅x₃ + 8⋅r₁⋅r₂⋅x₂⋅x₃
2 2
- 8⋅r₁⋅r₂⋅x₃ - 8⋅r₁⋅r₂⋅y₁⋅y₂ + 8⋅r₁⋅r₂⋅y₁⋅y₃ + 8⋅r₁⋅r₂⋅y₂⋅y₃ - 8⋅r₁⋅r₂⋅y₃ + 8⋅r₁⋅r₃⋅x₁⋅x₂ - 8⋅r₁
2 2
⋅r₃⋅x₁⋅x₃ - 8⋅r₁⋅r₃⋅x₂ + 8⋅r₁⋅r₃⋅x₂⋅x₃ + 8⋅r₁⋅r₃⋅y₁⋅y₂ - 8⋅r₁⋅r₃⋅y₁⋅y₃ - 8⋅r₁⋅r₃⋅y₂ + 8⋅r₁⋅r₃⋅y₂⋅
2 2 2 2 2 2 2 2 2 2 2
y₃ + 4⋅r₂ ⋅x₁ - 8⋅r₂ ⋅x₁⋅x₃ + 4⋅r₂ ⋅x₃ + 4⋅r₂ ⋅y₁ - 8⋅r₂ ⋅y₁⋅y₃ + 4⋅r₂ ⋅y₃ - 8⋅r₂⋅r₃⋅x₁ + 8⋅r₂
2
⋅r₃⋅x₁⋅x₂ + 8⋅r₂⋅r₃⋅x₁⋅x₃ - 8⋅r₂⋅r₃⋅x₂⋅x₃ - 8⋅r₂⋅r₃⋅y₁ + 8⋅r₂⋅r₃⋅y₁⋅y₂ + 8⋅r₂⋅r₃⋅y₁⋅y₃ - 8⋅r₂⋅r₃⋅y
2 2 2 2 2 2 2 2 2 2 2 2
₂⋅y₃ + 4⋅r₃ ⋅x₁ - 8⋅r₃ ⋅x₁⋅x₂ + 4⋅r₃ ⋅x₂ + 4⋅r₃ ⋅y₁ - 8⋅r₃ ⋅y₁⋅y₂ + 4⋅r₃ ⋅y₂ - 4⋅x₁ ⋅y₂ + 8⋅x₁
2 2 2 2
⋅y₂⋅y₃ - 4⋅x₁ ⋅y₃ + 8⋅x₁⋅x₂⋅y₁⋅y₂ - 8⋅x₁⋅x₂⋅y₁⋅y₃ - 8⋅x₁⋅x₂⋅y₂⋅y₃ + 8⋅x₁⋅x₂⋅y₃ - 8⋅x₁⋅x₃⋅y₁⋅y₂ +
2 2 2 2 2 2 2
8⋅x₁⋅x₃⋅y₁⋅y₃ + 8⋅x₁⋅x₃⋅y₂ - 8⋅x₁⋅x₃⋅y₂⋅y₃ - 4⋅x₂ ⋅y₁ + 8⋅x₂ ⋅y₁⋅y₃ - 4⋅x₂ ⋅y₃ + 8⋅x₂⋅x₃⋅y₁ -
2 2 2 2 2⎞ ⎛ 3
8⋅x₂⋅x₃⋅y₁⋅y₂ - 8⋅x₂⋅x₃⋅y₁⋅y₃ + 8⋅x₂⋅x₃⋅y₂⋅y₃ - 4⋅x₃ ⋅y₁ + 8⋅x₃ ⋅y₁⋅y₂ - 4⋅x₃ ⋅y₂ ⎠ + r₄⋅⎝4⋅r₁ ⋅x₂
2 3 3 2 3 2 3 3 2 2 2
- 8⋅r₁ ⋅x₂⋅x₃ + 4⋅r₁ ⋅x₃ + 4⋅r₁ ⋅y₂ - 8⋅r₁ ⋅y₂⋅y₃ + 4⋅r₁ ⋅y₃ - 4⋅r₁ ⋅r₂⋅x₁⋅x₂ + 4⋅r₁ ⋅r₂⋅x₁⋅x₃
2 2 2 2 2 2 2 2
+ 4⋅r₁ ⋅r₂⋅x₂⋅x₃ - 4⋅r₁ ⋅r₂⋅x₃ - 4⋅r₁ ⋅r₂⋅y₁⋅y₂ + 4⋅r₁ ⋅r₂⋅y₁⋅y₃ + 4⋅r₁ ⋅r₂⋅y₂⋅y₃ - 4⋅r₁ ⋅r₂⋅y₃
2 2 2 2 2 2 2
+ 4⋅r₁ ⋅r₃⋅x₁⋅x₂ - 4⋅r₁ ⋅r₃⋅x₁⋅x₃ - 4⋅r₁ ⋅r₃⋅x₂ + 4⋅r₁ ⋅r₃⋅x₂⋅x₃ + 4⋅r₁ ⋅r₃⋅y₁⋅y₂ - 4⋅r₁ ⋅r₃⋅y₁⋅y₃
2 2 2 2 2 2 2 2
- 4⋅r₁ ⋅r₃⋅y₂ + 4⋅r₁ ⋅r₃⋅y₂⋅y₃ - 4⋅r₁⋅r₂ ⋅x₁⋅x₂ + 4⋅r₁⋅r₂ ⋅x₁⋅x₃ + 4⋅r₁⋅r₂ ⋅x₂⋅x₃ - 4⋅r₁⋅r₂ ⋅x₃
2 2 2 2 2 2 2
- 4⋅r₁⋅r₂ ⋅y₁⋅y₂ + 4⋅r₁⋅r₂ ⋅y₁⋅y₃ + 4⋅r₁⋅r₂ ⋅y₂⋅y₃ - 4⋅r₁⋅r₂ ⋅y₃ + 4⋅r₁⋅r₃ ⋅x₁⋅x₂ - 4⋅r₁⋅r₃ ⋅x₁⋅x₃
2 2 2 2 2 2 2 2
- 4⋅r₁⋅r₃ ⋅x₂ + 4⋅r₁⋅r₃ ⋅x₂⋅x₃ + 4⋅r₁⋅r₃ ⋅y₁⋅y₂ - 4⋅r₁⋅r₃ ⋅y₁⋅y₃ - 4⋅r₁⋅r₃ ⋅y₂ + 4⋅r₁⋅r₃ ⋅y₂⋅y₃
2 2 2 2 2 2 2 2 2 2
- 4⋅r₁⋅x₁ ⋅x₂ + 8⋅r₁⋅x₁ ⋅x₂⋅x₃ - 4⋅r₁⋅x₁ ⋅x₃ - 4⋅r₁⋅x₁ ⋅y₂ + 8⋅r₁⋅x₁ ⋅y₂⋅y₃ - 4⋅r₁⋅x₁ ⋅y₃ + 4⋅r
3 2 2 2 2
₁⋅x₁⋅x₂ - 4⋅r₁⋅x₁⋅x₂ ⋅x₃ - 4⋅r₁⋅x₁⋅x₂⋅x₃ + 4⋅r₁⋅x₁⋅x₂⋅y₂ - 8⋅r₁⋅x₁⋅x₂⋅y₂⋅y₃ + 4⋅r₁⋅x₁⋅x₂⋅y₃ + 4
3 2 2 3 2 2
⋅r₁⋅x₁⋅x₃ + 4⋅r₁⋅x₁⋅x₃⋅y₂ - 8⋅r₁⋅x₁⋅x₃⋅y₂⋅y₃ + 4⋅r₁⋅x₁⋅x₃⋅y₃ - 4⋅r₁⋅x₂ ⋅x₃ + 8⋅r₁⋅x₂ ⋅x₃ - 4⋅r₁
2 2 2 2 2 3 2
⋅x₂ ⋅y₁ + 4⋅r₁⋅x₂ ⋅y₁⋅y₂ + 4⋅r₁⋅x₂ ⋅y₁⋅y₃ - 4⋅r₁⋅x₂ ⋅y₂⋅y₃ - 4⋅r₁⋅x₂⋅x₃ + 8⋅r₁⋅x₂⋅x₃⋅y₁ - 8⋅r₁⋅x
2 2 2 2
₂⋅x₃⋅y₁⋅y₂ - 8⋅r₁⋅x₂⋅x₃⋅y₁⋅y₃ - 4⋅r₁⋅x₂⋅x₃⋅y₂ + 16⋅r₁⋅x₂⋅x₃⋅y₂⋅y₃ - 4⋅r₁⋅x₂⋅x₃⋅y₃ - 4⋅r₁⋅x₃ ⋅y₁
2 2 2 2 2 2 2 2
+ 4⋅r₁⋅x₃ ⋅y₁⋅y₂ + 4⋅r₁⋅x₃ ⋅y₁⋅y₃ - 4⋅r₁⋅x₃ ⋅y₂⋅y₃ - 4⋅r₁⋅y₁ ⋅y₂ + 8⋅r₁⋅y₁ ⋅y₂⋅y₃ - 4⋅r₁⋅y₁ ⋅y₃ +
3 2 2 3 3 2 2
4⋅r₁⋅y₁⋅y₂ - 4⋅r₁⋅y₁⋅y₂ ⋅y₃ - 4⋅r₁⋅y₁⋅y₂⋅y₃ + 4⋅r₁⋅y₁⋅y₃ - 4⋅r₁⋅y₂ ⋅y₃ + 8⋅r₁⋅y₂ ⋅y₃ - 4⋅r₁⋅y₂
3 3 2 3 3 2 3 2 3 3 2 2 2
⋅y₃ + 4⋅r₂ ⋅x₁ - 8⋅r₂ ⋅x₁⋅x₃ + 4⋅r₂ ⋅x₃ + 4⋅r₂ ⋅y₁ - 8⋅r₂ ⋅y₁⋅y₃ + 4⋅r₂ ⋅y₃ - 4⋅r₂ ⋅r₃⋅x₁ + 4
2 2 2 2 2 2 2
⋅r₂ ⋅r₃⋅x₁⋅x₂ + 4⋅r₂ ⋅r₃⋅x₁⋅x₃ - 4⋅r₂ ⋅r₃⋅x₂⋅x₃ - 4⋅r₂ ⋅r₃⋅y₁ + 4⋅r₂ ⋅r₃⋅y₁⋅y₂ + 4⋅r₂ ⋅r₃⋅y₁⋅y₃ -
2 2 2 2 2 2 2 2
4⋅r₂ ⋅r₃⋅y₂⋅y₃ - 4⋅r₂⋅r₃ ⋅x₁ + 4⋅r₂⋅r₃ ⋅x₁⋅x₂ + 4⋅r₂⋅r₃ ⋅x₁⋅x₃ - 4⋅r₂⋅r₃ ⋅x₂⋅x₃ - 4⋅r₂⋅r₃ ⋅y₁ + 4
2 2 2 3 3 2 2
⋅r₂⋅r₃ ⋅y₁⋅y₂ + 4⋅r₂⋅r₃ ⋅y₁⋅y₃ - 4⋅r₂⋅r₃ ⋅y₂⋅y₃ + 4⋅r₂⋅x₁ ⋅x₂ - 4⋅r₂⋅x₁ ⋅x₃ - 4⋅r₂⋅x₁ ⋅x₂ - 4⋅r₂⋅x
2 2 2 2 2 2 2 2
₁ ⋅x₂⋅x₃ + 8⋅r₂⋅x₁ ⋅x₃ + 4⋅r₂⋅x₁ ⋅y₁⋅y₂ - 4⋅r₂⋅x₁ ⋅y₁⋅y₃ - 4⋅r₂⋅x₁ ⋅y₂ + 4⋅r₂⋅x₁ ⋅y₂⋅y₃ + 8⋅r₂⋅x₁
2 2 2 2 3
⋅x₂ ⋅x₃ - 4⋅r₂⋅x₁⋅x₂⋅x₃ + 4⋅r₂⋅x₁⋅x₂⋅y₁ - 8⋅r₂⋅x₁⋅x₂⋅y₁⋅y₃ + 4⋅r₂⋅x₁⋅x₂⋅y₃ - 4⋅r₂⋅x₁⋅x₃ - 4⋅r₂⋅
2 2
x₁⋅x₃⋅y₁ - 8⋅r₂⋅x₁⋅x₃⋅y₁⋅y₂ + 16⋅r₂⋅x₁⋅x₃⋅y₁⋅y₃ + 8⋅r₂⋅x₁⋅x₃⋅y₂ - 8⋅r₂⋅x₁⋅x₃⋅y₂⋅y₃ - 4⋅r₂⋅x₁⋅x₃⋅y
2 2 2 2 2 2 2 2 3 2
₃ - 4⋅r₂⋅x₂ ⋅x₃ - 4⋅r₂⋅x₂ ⋅y₁ + 8⋅r₂⋅x₂ ⋅y₁⋅y₃ - 4⋅r₂⋅x₂ ⋅y₃ + 4⋅r₂⋅x₂⋅x₃ + 4⋅r₂⋅x₂⋅x₃⋅y₁ - 8
2 2 2 2 2 2
⋅r₂⋅x₂⋅x₃⋅y₁⋅y₃ + 4⋅r₂⋅x₂⋅x₃⋅y₃ + 4⋅r₂⋅x₃ ⋅y₁⋅y₂ - 4⋅r₂⋅x₃ ⋅y₁⋅y₃ - 4⋅r₂⋅x₃ ⋅y₂ + 4⋅r₂⋅x₃ ⋅y₂⋅y₃
3 3 2 2 2 2 2 2
+ 4⋅r₂⋅y₁ ⋅y₂ - 4⋅r₂⋅y₁ ⋅y₃ - 4⋅r₂⋅y₁ ⋅y₂ - 4⋅r₂⋅y₁ ⋅y₂⋅y₃ + 8⋅r₂⋅y₁ ⋅y₃ + 8⋅r₂⋅y₁⋅y₂ ⋅y₃ - 4⋅r₂⋅
2 3 2 2 3 3 2 3 3 2 3
y₁⋅y₂⋅y₃ - 4⋅r₂⋅y₁⋅y₃ - 4⋅r₂⋅y₂ ⋅y₃ + 4⋅r₂⋅y₂⋅y₃ + 4⋅r₃ ⋅x₁ - 8⋅r₃ ⋅x₁⋅x₂ + 4⋅r₃ ⋅x₂ + 4⋅r₃ ⋅
2 3 3 2 3 3 2 2 2
y₁ - 8⋅r₃ ⋅y₁⋅y₂ + 4⋅r₃ ⋅y₂ - 4⋅r₃⋅x₁ ⋅x₂ + 4⋅r₃⋅x₁ ⋅x₃ + 8⋅r₃⋅x₁ ⋅x₂ - 4⋅r₃⋅x₁ ⋅x₂⋅x₃ - 4⋅r₃⋅x₁
2 2 2 2 2 2 2 3 2
⋅x₃ - 4⋅r₃⋅x₁ ⋅y₁⋅y₂ + 4⋅r₃⋅x₁ ⋅y₁⋅y₃ + 4⋅r₃⋅x₁ ⋅y₂⋅y₃ - 4⋅r₃⋅x₁ ⋅y₃ - 4⋅r₃⋅x₁⋅x₂ - 4⋅r₃⋅x₁⋅x₂
2 2 2
⋅x₃ + 8⋅r₃⋅x₁⋅x₂⋅x₃ - 4⋅r₃⋅x₁⋅x₂⋅y₁ + 16⋅r₃⋅x₁⋅x₂⋅y₁⋅y₂ - 8⋅r₃⋅x₁⋅x₂⋅y₁⋅y₃ - 4⋅r₃⋅x₁⋅x₂⋅y₂ - 8⋅r
2 2 2 3
₃⋅x₁⋅x₂⋅y₂⋅y₃ + 8⋅r₃⋅x₁⋅x₂⋅y₃ + 4⋅r₃⋅x₁⋅x₃⋅y₁ - 8⋅r₃⋅x₁⋅x₃⋅y₁⋅y₂ + 4⋅r₃⋅x₁⋅x₃⋅y₂ + 4⋅r₃⋅x₂ ⋅x₃ -
2 2 2 2 2 2 2 2
4⋅r₃⋅x₂ ⋅x₃ - 4⋅r₃⋅x₂ ⋅y₁⋅y₂ + 4⋅r₃⋅x₂ ⋅y₁⋅y₃ + 4⋅r₃⋅x₂ ⋅y₂⋅y₃ - 4⋅r₃⋅x₂ ⋅y₃ + 4⋅r₃⋅x₂⋅x₃⋅y₁ -
2 2 2 2 2 2 3
8⋅r₃⋅x₂⋅x₃⋅y₁⋅y₂ + 4⋅r₃⋅x₂⋅x₃⋅y₂ - 4⋅r₃⋅x₃ ⋅y₁ + 8⋅r₃⋅x₃ ⋅y₁⋅y₂ - 4⋅r₃⋅x₃ ⋅y₂ - 4⋅r₃⋅y₁ ⋅y₂ + 4⋅
3 2 2 2 2 2 3 2
r₃⋅y₁ ⋅y₃ + 8⋅r₃⋅y₁ ⋅y₂ - 4⋅r₃⋅y₁ ⋅y₂⋅y₃ - 4⋅r₃⋅y₁ ⋅y₃ - 4⋅r₃⋅y₁⋅y₂ - 4⋅r₃⋅y₁⋅y₂ ⋅y₃ + 8⋅r₃⋅y₁⋅y
2 3 2 2⎞ 4 2 4 4 2 4 2 4 4
₂⋅y₃ + 4⋅r₃⋅y₂ ⋅y₃ - 4⋅r₃⋅y₂ ⋅y₃ ⎠ + x₁ ⋅x₂ - 2⋅x₁ ⋅x₂⋅x₃ + x₁ ⋅x₃ + x₁ ⋅y₂ - 2⋅x₁ ⋅y₂⋅y₃ + x₁
2 3 3 3 2 3 2 3 2 3 3 2
⋅y₃ - 2⋅x₁ ⋅x₂ + 2⋅x₁ ⋅x₂ ⋅x₃ + 2⋅x₁ ⋅x₂⋅x₃ - 2⋅x₁ ⋅x₂⋅y₂ + 4⋅x₁ ⋅x₂⋅y₂⋅y₃ - 2⋅x₁ ⋅x₂⋅y₃ - 2⋅x
3 3 3 2 3 3 2 2 4 2 3 2 2 2
₁ ⋅x₃ - 2⋅x₁ ⋅x₃⋅y₂ + 4⋅x₁ ⋅x₃⋅y₂⋅y₃ - 2⋅x₁ ⋅x₃⋅y₃ + x₁ ⋅x₂ + 2⋅x₁ ⋅x₂ ⋅x₃ - 6⋅x₁ ⋅x₂ ⋅x₃ + 2⋅
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
x₁ ⋅x₂ ⋅y₁ - 2⋅x₁ ⋅x₂ ⋅y₁⋅y₂ - 2⋅x₁ ⋅x₂ ⋅y₁⋅y₃ + 2⋅x₁ ⋅x₂ ⋅y₂ - 2⋅x₁ ⋅x₂ ⋅y₂⋅y₃ + 2⋅x₁ ⋅x₂ ⋅y₃ +
2 3 2 2 2 2 2 2 2
2⋅x₁ ⋅x₂⋅x₃ - 4⋅x₁ ⋅x₂⋅x₃⋅y₁ + 4⋅x₁ ⋅x₂⋅x₃⋅y₁⋅y₂ + 4⋅x₁ ⋅x₂⋅x₃⋅y₁⋅y₃ + 2⋅x₁ ⋅x₂⋅x₃⋅y₂ - 8⋅x₁ ⋅x
2 2 2 4 2 2 2 2 2 2 2 2
₂⋅x₃⋅y₂⋅y₃ + 2⋅x₁ ⋅x₂⋅x₃⋅y₃ + x₁ ⋅x₃ + 2⋅x₁ ⋅x₃ ⋅y₁ - 2⋅x₁ ⋅x₃ ⋅y₁⋅y₂ - 2⋅x₁ ⋅x₃ ⋅y₁⋅y₃ + 2⋅x₁ ⋅
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
x₃ ⋅y₂ - 2⋅x₁ ⋅x₃ ⋅y₂⋅y₃ + 2⋅x₁ ⋅x₃ ⋅y₃ + 2⋅x₁ ⋅y₁ ⋅y₂ - 4⋅x₁ ⋅y₁ ⋅y₂⋅y₃ + 2⋅x₁ ⋅y₁ ⋅y₃ - 2⋅x₁
3 2 2 2 2 2 3 2 4 2 3 2 2 2
⋅y₁⋅y₂ + 2⋅x₁ ⋅y₁⋅y₂ ⋅y₃ + 2⋅x₁ ⋅y₁⋅y₂⋅y₃ - 2⋅x₁ ⋅y₁⋅y₃ + x₁ ⋅y₂ - 2⋅x₁ ⋅y₂ ⋅y₃ + 2⋅x₁ ⋅y₂ ⋅y₃
2 3 2 4 4 3 2 3 2 3 3
- 2⋅x₁ ⋅y₂⋅y₃ + x₁ ⋅y₃ - 2⋅x₁⋅x₂ ⋅x₃ + 2⋅x₁⋅x₂ ⋅x₃ - 2⋅x₁⋅x₂ ⋅y₁ + 4⋅x₁⋅x₂ ⋅y₁⋅y₃ - 2⋅x₁⋅x₂ ⋅y
2 2 3 2 2 2 2 2 2
₃ + 2⋅x₁⋅x₂ ⋅x₃ + 2⋅x₁⋅x₂ ⋅x₃⋅y₁ + 4⋅x₁⋅x₂ ⋅x₃⋅y₁⋅y₂ - 8⋅x₁⋅x₂ ⋅x₃⋅y₁⋅y₃ - 4⋅x₁⋅x₂ ⋅x₃⋅y₂ + 4⋅x
2 2 2 4 2 2 2 2
₁⋅x₂ ⋅x₃⋅y₂⋅y₃ + 2⋅x₁⋅x₂ ⋅x₃⋅y₃ - 2⋅x₁⋅x₂⋅x₃ + 2⋅x₁⋅x₂⋅x₃ ⋅y₁ - 8⋅x₁⋅x₂⋅x₃ ⋅y₁⋅y₂ + 4⋅x₁⋅x₂⋅x₃ ⋅
2 2 2 2 2 2 2 2
y₁⋅y₃ + 2⋅x₁⋅x₂⋅x₃ ⋅y₂ + 4⋅x₁⋅x₂⋅x₃ ⋅y₂⋅y₃ - 4⋅x₁⋅x₂⋅x₃ ⋅y₃ - 2⋅x₁⋅x₂⋅y₁ ⋅y₂ + 4⋅x₁⋅x₂⋅y₁ ⋅y₂⋅y₃
2 2 2 2 3 2 2
- 2⋅x₁⋅x₂⋅y₁ ⋅y₃ + 4⋅x₁⋅x₂⋅y₁⋅y₂ ⋅y₃ - 8⋅x₁⋅x₂⋅y₁⋅y₂⋅y₃ + 4⋅x₁⋅x₂⋅y₁⋅y₃ - 2⋅x₁⋅x₂⋅y₂ ⋅y₃ + 4⋅x
3 4 3 2 3 3 2 2 2
₁⋅x₂⋅y₂⋅y₃ - 2⋅x₁⋅x₂⋅y₃ - 2⋅x₁⋅x₃ ⋅y₁ + 4⋅x₁⋅x₃ ⋅y₁⋅y₂ - 2⋅x₁⋅x₃ ⋅y₂ - 2⋅x₁⋅x₃⋅y₁ ⋅y₂ + 4⋅x₁⋅x
2 2 2 3 2 2
₃⋅y₁ ⋅y₂⋅y₃ - 2⋅x₁⋅x₃⋅y₁ ⋅y₃ + 4⋅x₁⋅x₃⋅y₁⋅y₂ - 8⋅x₁⋅x₃⋅y₁⋅y₂ ⋅y₃ + 4⋅x₁⋅x₃⋅y₁⋅y₂⋅y₃ - 2⋅x₁⋅x₃⋅y₂
4 3 2 2 4 2 4 2 4 4 2 3 3
+ 4⋅x₁⋅x₃⋅y₂ ⋅y₃ - 2⋅x₁⋅x₃⋅y₂ ⋅y₃ + x₂ ⋅x₃ + x₂ ⋅y₁ - 2⋅x₂ ⋅y₁⋅y₃ + x₂ ⋅y₃ - 2⋅x₂ ⋅x₃ - 2⋅x₂
3 2 3 3 2 2 4 2 2 2 2 2 2 2
⋅x₃⋅y₁ + 4⋅x₂ ⋅x₃⋅y₁⋅y₃ - 2⋅x₂ ⋅x₃⋅y₃ + x₂ ⋅x₃ + 2⋅x₂ ⋅x₃ ⋅y₁ - 2⋅x₂ ⋅x₃ ⋅y₁⋅y₂ - 2⋅x₂ ⋅x₃ ⋅y₁
2 2 2 2 2 2 2 2 2 4 2 3 2 3
⋅y₃ + 2⋅x₂ ⋅x₃ ⋅y₂ - 2⋅x₂ ⋅x₃ ⋅y₂⋅y₃ + 2⋅x₂ ⋅x₃ ⋅y₃ + x₂ ⋅y₁ - 2⋅x₂ ⋅y₁ ⋅y₂ - 2⋅x₂ ⋅y₁ ⋅y₃ + 2⋅x
2 2 2 2 2 2 2 2 2 2 2 2 2 3
₂ ⋅y₁ ⋅y₂ + 2⋅x₂ ⋅y₁ ⋅y₂⋅y₃ + 2⋅x₂ ⋅y₁ ⋅y₃ - 4⋅x₂ ⋅y₁⋅y₂ ⋅y₃ + 2⋅x₂ ⋅y₁⋅y₂⋅y₃ - 2⋅x₂ ⋅y₁⋅y₃ + 2
2 2 2 2 3 2 4 3 2 3 3 2 4
⋅x₂ ⋅y₂ ⋅y₃ - 2⋅x₂ ⋅y₂⋅y₃ + x₂ ⋅y₃ - 2⋅x₂⋅x₃ ⋅y₁ + 4⋅x₂⋅x₃ ⋅y₁⋅y₂ - 2⋅x₂⋅x₃ ⋅y₂ - 2⋅x₂⋅x₃⋅y₁
3 3 2 2 2 2 2
+ 4⋅x₂⋅x₃⋅y₁ ⋅y₂ + 4⋅x₂⋅x₃⋅y₁ ⋅y₃ - 2⋅x₂⋅x₃⋅y₁ ⋅y₂ - 8⋅x₂⋅x₃⋅y₁ ⋅y₂⋅y₃ - 2⋅x₂⋅x₃⋅y₁ ⋅y₃ + 4⋅x₂⋅x₃
2 2 2 2 4 2 4 4 2 2 4
⋅y₁⋅y₂ ⋅y₃ + 4⋅x₂⋅x₃⋅y₁⋅y₂⋅y₃ - 2⋅x₂⋅x₃⋅y₂ ⋅y₃ + x₃ ⋅y₁ - 2⋅x₃ ⋅y₁⋅y₂ + x₃ ⋅y₂ + x₃ ⋅y₁ - 2⋅x₃
2 3 2 3 2 2 2 2 2 2 2 2 2 3 2
⋅y₁ ⋅y₂ - 2⋅x₃ ⋅y₁ ⋅y₃ + 2⋅x₃ ⋅y₁ ⋅y₂ + 2⋅x₃ ⋅y₁ ⋅y₂⋅y₃ + 2⋅x₃ ⋅y₁ ⋅y₃ - 2⋅x₃ ⋅y₁⋅y₂ + 2⋅x₃ ⋅y₁
2 2 2 2 4 2 3 2 2 2 4 2 4 4
⋅y₂ ⋅y₃ - 4⋅x₃ ⋅y₁⋅y₂⋅y₃ + x₃ ⋅y₂ - 2⋅x₃ ⋅y₂ ⋅y₃ + 2⋅x₃ ⋅y₂ ⋅y₃ + y₁ ⋅y₂ - 2⋅y₁ ⋅y₂⋅y₃ + y₁ ⋅y₃
2 3 3 3 2 3 2 3 3 2 4 2 3 2 2 2
- 2⋅y₁ ⋅y₂ + 2⋅y₁ ⋅y₂ ⋅y₃ + 2⋅y₁ ⋅y₂⋅y₃ - 2⋅y₁ ⋅y₃ + y₁ ⋅y₂ + 2⋅y₁ ⋅y₂ ⋅y₃ - 6⋅y₁ ⋅y₂ ⋅y₃ +
2 3 2 4 4 3 2 2 3 4 4 2 3
2⋅y₁ ⋅y₂⋅y₃ + y₁ ⋅y₃ - 2⋅y₁⋅y₂ ⋅y₃ + 2⋅y₁⋅y₂ ⋅y₃ + 2⋅y₁⋅y₂ ⋅y₃ - 2⋅y₁⋅y₂⋅y₃ + y₂ ⋅y₃ - 2⋅y₂ ⋅
3 2 4
y₃ + y₂ ⋅y₃
Now the first two equations give x_4 and y_4 linearly in terms of r_4. The third equation is a quartic polynomial for r_4. There is a quartic formula so you can have the general solution if you want but the quartic formula is very complicated and this polynomial has complicated coefficients so the expression for the solutions will be extremely complicated. If you want to see it then you can do:
In [55]: sols = roots(gb[2], r_4, multiple=True)
In [56]: sols[0]
Out[56]:
...
Here I won't show the output because it exceeds StackOverflow's limit on the number of characters that can be included in an answer but that output would show the expression for r_4 in the first of the 4 solutions. To see the solution for x_4 you would do:
In [59]: solve(gb[0], x_4)[0].subs(r_4, sols[0])
This is now an extremely complicated solution having an operation count of 10175:
In [59]: solve(gb[0], x_4)[0].subs(r_4, sols[0]).count_ops()
Out[59]: 10175
The bottom line here is that sometimes a general symbolic solution is too complicated to be useful.
Related
The whole thing about this polynomial time is confusing to me for example: I want to write a program in a polynomial time algorithm that will just pick only 4 integers that sum to 0 from a set.
For instance: Let assume I have the following set of integers {8, 20, 3, -2, 3, 7, 16, -9}. How can I pick only 4 distinct integers that sum to 0 from a set in polynomial time without having needed to check through every possible length other than 4? Note in the program I don’t need to search through any other possible length than 4. My expected solution is {8, 3, -2, -9} = 0. knowing fully well that i only need 4 integers from the set {8, 20, 3, -2, 3, 7, 16, -9}.
Edit: Will I found a polynomial time solution of {8, 3, -2, -9} even if I increase only the length of the original set from 8 to 100 integers while I will still have to pick my 4 elements that sum to 0 but from the set of 100 integers will it still be polynomial fast with respect to the size of the input (i.e the number of bits used to store the input)?
The following algorithm runs in O(N^3 * logN).
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>
using quadruple = std::tuple<int, int, int, int>;
std::vector<quadruple> find(std::vector<int> vec) {
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
std::vector<quadruple> ret;
for (auto i = 0u; i + 3 < vec.size(); ++i) {
for (auto j = i + 1; j + 2 < vec.size(); ++j) {
for (auto k = j + 1; k + 1 < vec.size(); ++k) {
auto target = 0 - vec[i] - vec[j] - vec[k];
auto it = std::lower_bound(vec.begin() + k + 1,
vec.end(),
target);
if (it != vec.end() && *it == target) {
ret.push_back(std::make_tuple(
vec[i], vec[j], vec[k], target));
}
}
}
}
return ret;
}
int main() {
std::vector<int> input = {8, 20, 3, -2, 3, 7, 16, -9};
auto output = find(input);
for (auto& quad : output) {
std::cout << std::get<0>(quad) << ' '
<< std::get<1>(quad) << ' '
<< std::get<2>(quad) << ' '
<< std::get<3>(quad) << std::endl;
}
}
Try all quadruples without repetitions. This takes at most (N^4-6N³+11N²-6N)/24 attempts each made in constant time.
8 + 20 + 3 - 2 = 29
8 + 20 + 3 + 3 = 34
8 + 20 + 3 + 7 = 38
8 + 20 + 3 + 16 = 47
8 + 20 + 3 - 9 = 22
8 + 20 - 2 + 3 = 29
8 + 20 - 2 + 7 = 33
8 + 20 - 2 + 16 = 42
8 + 20 - 2 - 9 = 17
8 + 20 + 3 + 7 = 38
8 + 20 + 3 + 16 = 47
8 + 20 + 3 - 9 = 22
8 + 20 + 7 + 16 = 51
8 + 20 + 7 - 9 = 26
8 + 20 + 16 - 9 = 35
8 + 3 - 2 + 3 = 12
8 + 3 - 2 + 7 = 16
8 + 3 - 2 + 16 = 25
8 + 3 - 2 - 9 = 0 <==
8 + 3 + 3 + 7 = 21
8 + 3 + 3 + 16 = 30
8 + 3 + 3 - 9 = 5
8 + 3 + 7 + 16 = 34
8 + 3 + 7 - 9 = 9
8 + 3 + 16 - 9 = 18
8 - 2 + 3 + 7 = 16
8 - 2 + 3 + 16 = 25
8 - 2 + 3 - 9 = 0 <==
8 - 2 + 7 + 16 = 29
8 - 2 + 7 - 9 = 4
8 - 2 + 16 - 9 = 13
8 + 3 + 7 + 16 = 34
8 + 3 + 7 - 9 = 9
8 + 3 + 16 - 9 = 18
8 + 7 + 16 - 9 = 22
20 + 3 - 2 + 3 = 24
20 + 3 - 2 + 7 = 28
20 + 3 - 2 + 16 = 37
20 + 3 - 2 - 9 = 12
20 + 3 + 3 + 7 = 33
20 + 3 + 3 + 16 = 42
20 + 3 + 3 - 9 = 17
20 + 3 + 7 + 16 = 46
20 + 3 + 7 - 9 = 21
20 + 3 + 16 - 9 = 30
20 - 2 + 3 + 7 = 28
20 - 2 + 3 + 16 = 37
20 - 2 + 3 - 9 = 12
20 - 2 + 7 + 16 = 41
20 - 2 + 7 - 9 = 16
20 - 2 + 16 - 9 = 25
20 + 3 + 7 + 16 = 46
20 + 3 + 7 - 9 = 21
20 + 3 + 16 - 9 = 30
20 + 7 + 16 - 9 = 34
3 - 2 + 3 + 7 = 11
3 - 2 + 3 + 16 = 20
3 - 2 + 3 - 9 = -5
3 - 2 + 7 + 16 = 24
3 - 2 + 7 - 9 = -1
3 - 2 + 16 - 9 = 8
3 + 3 + 7 + 16 = 29
3 + 3 + 7 - 9 = 4
3 + 3 + 16 - 9 = 13
3 + 7 + 16 - 9 = 17
- 2 + 3 + 7 + 16 = 24
- 2 + 3 + 7 - 9 = -1
- 2 + 3 + 16 - 9 = 8
- 2 + 7 + 16 - 9 = 12
3 + 7 + 16 - 9 = 17
Update:
At the request of the OP, stopped when a solution is found.
8 + 20 + 3 - 2 = 29
8 + 20 + 3 + 3 = 34
8 + 20 + 3 + 7 = 38
8 + 20 + 3 + 16 = 47
8 + 20 + 3 - 9 = 22
8 + 20 - 2 + 3 = 29
8 + 20 - 2 + 7 = 33
8 + 20 - 2 + 16 = 42
8 + 20 - 2 - 9 = 17
8 + 20 + 3 + 7 = 38
8 + 20 + 3 + 16 = 47
8 + 20 + 3 - 9 = 22
8 + 20 + 7 + 16 = 51
8 + 20 + 7 - 9 = 26
8 + 20 + 16 - 9 = 35
8 + 3 - 2 + 3 = 12
8 + 3 - 2 + 7 = 16
8 + 3 - 2 + 16 = 25
8 + 3 - 2 - 9 = 0 <==
This was a Google question i didn't figure out was right or wrong but a 2nd opinion never hurt. but the question is "given an n length bit-string solve for the number of times "111" appeared in all possible combinations."
now i know to find total combinations is 2^n what took me trouble was figuring out the number of occurrences i did find a pattern in occurrences but who knows for sure what happens when n becomes vast.
My logical solution was
#Level (n length) # combos # strings with "111" in it
_________________ ________ _____________________________
0 0 0
1("1" or "0") 2 0
2("11","01" etc. 4 0
3 8 1("111")
4 16 3
5 32 8
6 64 20
------------------------------------Everything before this is confirmed
7 128 49
8 256 119
9 512 288
10 1000 696
etc.. i can post how i came up with the magical fairy dust but yeah
I can help you with a solution:
Call the function to calculate number of string with n bit contains 111 is f(n)
If the first bit of the string is 0, we have f(n) += f(n - 1)//0 + (n - 1 bits)
If the first bit of the string is 1, we have f(n) += f(n - 2) + f(n - 3) + 2^(n - 3)
More explanation for case first bit is 1
If the first bit is 1, we have three cases:
10 + (n - 2 bits) = f(n - 2)
110 + (n - 3 bits) = f(n - 3)
111 + (n - 3 bits) = 2^(n - 3) as we can take all combinations.
So in total f(n) = f(n - 1) + f(n - 2) + f(n - 3) + 2^(n - 3).
Apply to our example:
n = 4 -> f(4) = f(3) + f(2) + f(1) + 2^1 = 1 + 0 + 0 + 2 = 3;
n = 5 -> f(5) = f(4) + f(3) + f(2) + 2^2 = 3 + 1 + 0 + 4 = 8;
n = 6 -> f(6) = f(5) + f(4) + f(3) + 2^3 = 8 + 3 + 1 + 8 = 20;
n = 7 -> f(7) = f(6) + f(5) + f(4) + 2^4 = 20 + 8 + 3 + 16 = 47;
n = 8 -> f(8) = f(7) + f(6) + f(5) + 2^5 = 47 + 20 + 8 + 32 = 107;
n = 9 -> f(9) = f(8) + f(7) + f(6) + 2^6 = 107 + 47 + 20 + 64 = 238;
I am multiplying constant to an expression which can be seen from below. But the final expression is getting reduced. I just want it to be multiplied.
(x^2 (-((1. (2 - 1/x)^3 x^5)/(
Sqrt[1 - x^2] (0. + 1. x^2)^1.5)) + ((2 - 1/x)^3 x^5)/((1 - x^2)^(
3/2) (0. + 1. x^2)^0.5) + (3 (2 - 1/x)^2 x^2)/(
Sqrt[1 - x^2] (0. + 1. x^2)^0.5) + (4 (2 - 1/x)^3 x^3)/(
Sqrt[1 - x^2] (0. + 1. x^2)^0.5)))/(3 (2 - 1/x)^2) * (4)
Kindly help. Thanks in advance.
It simplifies ok.
expr = (x^2 (-((1. (2 - 1/x)^3 x^5)/
(Sqrt[1 - x^2] (0. + 1. x^2)^1.5)) +
((2 - 1/x)^3 x^5)/
((1 - x^2)^(3/2) (0. + 1. x^2)^0.5) +
(3 (2 - 1/x)^2 x^2)/
(Sqrt[1 - x^2] (0. + 1. x^2)^0.5) +
(4 (2 - 1/x)^3 x^3)/
(Sqrt[1 - x^2] (0. + 1. x^2)^0.5)))/
(3 (2 - 1/x)^2)*(4);
Simplify[expr] // InputForm
(-2.6666666666666665*x^4*(-1.5*x^6*(x^2)^0.5 + 1.x^7(x^2)^0.5 + 1.5*x*(x^2)^1.5 -
4.5*(x^2)^2.5 + x^5*(-0.25*(x^2)^0.5 - 3.(x^2)^1.5) +
x^4(1.375*(x^2)^0.5 + 3.(x^2)^1.5) + x^3(-0.75*(x^2)^0.5 + 3.25*(x^2)^1.5)))/
((0.5 - 1.x)^2(x^2)^2.Sqrt[1 - x^2](-1. + x^2))
I'm not quite certain how to go about interpreting this.
I'm solving a fairly large system of differential equations, DSolve sometimes spits out a list of replacement rules that include terms that have a #1 . I know that #1 is a placeholder for an argument, but I just have no clue where it comes from.
If I have a system of equations similar to
eqs = {
x1'[t] = a1*x1[t] + b1*y1[t]
x2'[t] = a2*x2[t] + b2*y2[t]
...
y1'[t] = c1*y1[t] + d1*x1[t]
y2'[t] = c2*y2[t] + d2*x2[t]}
DSolve[eqs,vars,t] spits out something like
x1 -> e^(-ta1)
x2 -> e^(-t)RootSum[a1a2+a3b4#1 + a3a1b2#1]
...
Obviously a little more complicated but you get the point.
Nothing in the documentation hints as to why this is occurring, And it only happens under certain permuations of parameters (e.g. when I play around with parameters in the original system it either works or doesn't)
This RootSum may be generated by Integrate, which is used by DSolve internally, like so:
In[511]:= Integrate[1/(1 + x + x^2 + x^3 + x^4), x]
Out[511]= RootSum[1 + #1 + #1^2 + #1^3 + #1^4 &,
Log[x - #1]/(1 + 2 #1 + 3 #1^2 + 4 #1^3) &]
It represents a symbolic expression that is the Sum[ Log[x-t]/(1+2*t+3 t^2+4 t^3), {t, {"roots of 1+t+t^2+t^3+t^4"}] (caution, invalid syntax intentional). You can recover the expected normal form using Normal:
In[512]:= Normal[%]
Out[512]=
Log[(-1)^(1/5) + x]/(1 - 2 (-1)^(1/5) + 3 (-1)^(2/5) - 4 (-1)^(3/5)) +
Log[-(-1)^(2/5) + x]/(
1 - 4 (-1)^(1/5) + 2 (-1)^(2/5) + 3 (-1)^(4/5)) +
Log[(-1)^(3/5) + x]/(
1 - 3 (-1)^(1/5) - 2 (-1)^(3/5) + 4 (-1)^(4/5)) +
Log[-(-1)^(4/5) + x]/(1 + 4 (-1)^(2/5) - 3 (-1)^(3/5) + 2 (-1)^(4/5))
Or using the Sum directly:
In[513]:= Sum[
Log[x - t]/(1 + 2*t + 3 t^2 + 4 t^3), {t,
t /. {ToRules[Roots[1 + t + t^2 + t^3 + t^4 == 0, t]]}}]
Out[513]=
Log[(-1)^(1/5) + x]/(1 - 2 (-1)^(1/5) + 3 (-1)^(2/5) - 4 (-1)^(3/5)) +
Log[-(-1)^(2/5) + x]/(
1 - 4 (-1)^(1/5) + 2 (-1)^(2/5) + 3 (-1)^(4/5)) +
Log[(-1)^(3/5) + x]/(
1 - 3 (-1)^(1/5) - 2 (-1)^(3/5) + 4 (-1)^(4/5)) +
Log[-(-1)^(4/5) + x]/(1 + 4 (-1)^(2/5) - 3 (-1)^(3/5) + 2 (-1)^(4/5))
In[514]:= % - %% // FullSimplify
Out[514]= 0
What is a mathematical way of of saying 1 - 1 = 12 for a month calculation? Adding is easy, 12 + 1 % 12 = 1, but subtraction introduces 0, stuffing things up.
My actual requirement is x = x + d, where x must always be between 1 and 12 before and after the summing, and d any unsigned integer.
Assuming x and y are both in the range 1-12:
((x - y + 11) % 12) + 1
To break this down:
// Range = [0, 22]
x - y + 11
// Range = [0, 11]
(x - y + 11) % 12
// Range = [1, 12]
((x - y + 11) % 12) + 1
I'd work internally with a 0 based month (0-11), summing one for external consumption only (output, another calling method expecting 1-12, etc.), that way you can wrap around backwards just as easily as wrapping around forward.
>>> for i in range(15):
... print '%d + 1 => %d' % (i, (i+1)%12)
...
0 + 1 => 1
1 + 1 => 2
2 + 1 => 3
3 + 1 => 4
4 + 1 => 5
5 + 1 => 6
6 + 1 => 7
7 + 1 => 8
8 + 1 => 9
9 + 1 => 10
10 + 1 => 11
11 + 1 => 0
12 + 1 => 1
13 + 1 => 2
14 + 1 => 3
>>> for i in range(15):
... print '%d - 1 => %d' % (i, (i-1)%12)
...
0 - 1 => 11
1 - 1 => 0
2 - 1 => 1
3 - 1 => 2
4 - 1 => 3
5 - 1 => 4
6 - 1 => 5
7 - 1 => 6
8 - 1 => 7
9 - 1 => 8
10 - 1 => 9
11 - 1 => 10
12 - 1 => 11
13 - 1 => 0
14 - 1 => 1
You have to be careful with addition, too, since (11 + 1) % 12 = 0. Try this:
x % 12 + 1
This comes from using a normalisation function:
norm(x) = ((x - 1) % 12) + 1
Substituting,
norm(x + 1) = (((x + 1) - 1) % 12 + 1
norm(x + 1) = (x) % 12 + 1
The % (modulus) operator produces an answer in the range 0..(N-1) for x % N. Given that your inputs are in the range 1..N (for N = 12), the general adding code for adding a positive number y months to current month x should be:
(x + y - 1) % 12 + 1
When y is 1, this reduces to
x % 12 + 1
Subtracting is basically the same. However, there are complications with the answers produced by different implementations of the modulus operator when either (or both) of the operands is negative. If the number to be subtracted is known to be in in the range 1..N, then you can use the fact that subtracting y modulo N is the same as adding (N - y) modulo N. If y is unconstrained (but positive), then use:
(x + (12 - (y % 12) - 1) % 12 + 1
This double-modulo operation is a common part of the solution to problems like this when the range of the values is not under control.