Skip to main content

Automatic sum-of-squares proofs for algebraic inequalities

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

triples-0.1.0.tar.gz (609.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

triples-0.1.0-py3-none-any.whl (677.5 kB view details)

Uploaded Python 3

File details

Details for the file triples-0.1.0.tar.gz.

File metadata

  • Download URL: triples-0.1.0.tar.gz
  • Upload date:
  • Size: 609.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for triples-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f5fca03432a091943433a761290b82cdec3b25bdcdb3bbfeb1229f0b28e24633
MD5 310959ff0ee0bb8352b8972596f00d4b
BLAKE2b-256 9521d56bce82c101daa91afbcb3c52393f5b36b7b071508e24714d05bbf6c93a

See more details on using hashes here.

File details

Details for the file triples-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: triples-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 677.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for triples-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6f819deb6f082a4adc438dd642e803da0e9b4e63498f5f287daea8304613b10
MD5 df485ac7b0aacbb6577cbb6c273f015f
BLAKE2b-256 e404bcb80804a611348a70ad2ab0f0f868c96b901e6d7b396a0322917f24ae44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page