Triples
Triples is an automatic inequality proving software developed by ForeverHaibara, based on the Python SymPy library. It focuses on generating readable proofs of inequalities through sum of squares (SOS). The program offers both a graphical user interface and a code interface to facilitate the exploration of Olympiad-level algebraic inequalities.
Homepage: https://github.com/ForeverHaibara/Triple-SOS
To install, use:
pip install triples
Code Usage
from triples import sum_of_squares
import sympy as sp
a, b, c, x, y, z = sp.symbols("a b c x y z")
Sum of Squares
Given a sympy polynomial, the sum_of_squares solver will return a Solution-class object if it succeeds. It returns None if it fails (but it does not mean the polynomial is not a sum of squares or positive semidefinite).
Example 1 $a,b,c\in\mathbb{R}$, prove: $\left(a^2+b^2+c^2\right)^2\geq 3\left(a^3b+b^3c+c^3a\right)$.
>>> sol = sum_of_squares((a**2 + b**2 + c**2)**2 - 3*(a**3*b + b**3*c + c**3*a))
>>> sol.solution # this should be a sympy expression
(Σ(a**2 - a*b - a*c - b**2 + 2*b*c)**2)/2
>>> sol.solution.doit() # this expands the cyclic sums
(-a**2 + 2*a*b - a*c - b*c + c**2)**2/2 + (a**2 - a*b - a*c - b**2 + 2*b*c)**2/2 + (-a*b + 2*a*c + b**2 - b*c - c**2)**2/2
If there are inequality or equality constraints, send them as a list of sympy expressions to ineq_constraints and eq_constraints.
Example 2 $a,b,c\in\mathbb{R}_+$, prove: $a(a-b)(a-c)+b(b-c)(b-a)+c(c-a)(c-b)\geq 0$.
>>> sol = sum_of_squares(a*(a-b)*(a-c) + b*(b-c)*(b-a) + c*(c-a)*(c-b), ineq_constraints = [a,b,c])
>>> sol.solution
((Σ(a - b)**2*(a + b - c)**2)/2 + Σa*b*(a - b)**2)/(Σa)
If you want to track the inequality and equality constraints, you can send in a dict containing the alias of the constraints.
Example 3 $a,b,c\in\mathbb{R}_+$ and $abc=1$, prove: $\sum \frac{a^2}{2+a}\geq 1$.
>>> sol = sum_of_squares(((a+2)*(b+2)*(c+2)*(a**2/(2+a)+b**2/(2+b)+c**2/(2+c)-1)).cancel(), ineq_constraints=[a,b,c], eq_constraints={a*b*c-1:x})
>>> sol.solution
x*(Σ(2*a + 13))/6 + Σa*(b - c)**2 + (Σa*b*(c - 1)**2)/6 + 5*(Σ(a - 1)**2)/6 + 7*(Σ(a - b)**2)/12
>>> sol.solution.doit()
a*b*(c - 1)**2/3 + a*c*(b - 1)**2/3 + a*(-b + c)**2 + a*(b - c)**2 + b*c*(a - 1)**2/3 + b*(-a + c)**2 + b*(a - c)**2 + c*(-a + b)**2 + c*(a - b)**2 + x*(4*a + 4*b + 4*c + 78)/6 + 7*(-a + b)**2/12 + 7*(-a + c)**2/12 + 5*(a - 1)**2/3 + 7*(a - b)**2/12 + 7*(a - c)**2/12 + 7*(-b + c)**2/12 + 5*(b - 1)**2/3 + 7*(b - c)**2/12 + 5*(c - 1)**2/3
>>> F = sp.Function("F")
>>> sol = sum_of_squares(((a+2)*(b+2)*(c+2)*(a**2/(2+a)+b**2/(2+b)+c**2/(2+c)-1)).cancel(), {a: F(a), b: F(b), c: F(c)}, {a*b*c-1:x})
>>> sol.solution
x*(Σ(2*F(a) + 13))/6 + Σ(a - b)**2*F(c) + (Σ(a - 1)**2*F(b)*F(c))/6 + 5*(Σ(a - 1)**2)/6 + 7*(Σ(a - b)**2)/12
Warnings
- The
triplespackage uses dynamic patches to fix some known bugs in the SymPy library for older versions of SymPy, and may slightly affect the behaviour of SymPy. This includes a fix forradsimpat https://github.com/sympy/sympy/pull/26720 and settingCRootOf.is_algebraic = Trueat https://github.com/sympy/sympy/pull/26806.
Metadata
Release files for triples 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| triples-0.2.0.tar.gz | 653.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| triples-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.4 MB
Release files / triples-0.2.0.tar.gz
| Download URL | triples-0.2.0.tar.gz |
|---|---|
| Size | 653.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0b55927480d83b48103d210c7428afa55d3782b0dbd4a94affc858c1db7afc1
|
|
BLAKE2b-256 checksum How to use checksums |
aebbf2fd3f9d3ccf10ddd01dc303d96364ffdd6b1d649a99605136db405f92a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / triples-0.2.0-py3-none-any.whl
| Download URL | triples-0.2.0-py3-none-any.whl |
|---|---|
| Size | 730.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
552fc11028479d24f9bced9f51f6e79ab175d809f2542fd5205720b7b68c24d4
|
|
BLAKE2b-256 checksum How to use checksums |
ebeca2c531bd7e3b4815f3570ad822a250b75d2e3ff1fe6ada99b1c16b6c673a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|