Skip to main content

Generic Cylindrical Algebraic Decomposition

Project description

Generic Cylindrical Algebraic Decomposition

Given a list of polynomials in $x_1,…,x_n$, GCAD separates $ℝ^n$ into cells of constant sign of all polynomials, each given as

$$\bigwedge_{1≤i≤n} l_i(x_1,…,x_{i-1}) < x_i < h_i(x_1,…,x_{i-1}),$$

where the boundaries $l_i$ and $h_i$ are either ±∞, or real roots of polynomials.

Conventionally, the input polynomials are given as inequalities, and only the cells that satisfy them are returned.

How to use

To decompose $2-x^2-y^2-z^2>0 ∧ 1-x^2-(y-1)^2-z^2>0 ∧ 1-z^2>0$ into cells:

import sympy as sp
import gcad

x, y, z = sp.symbols("x y z")
p1 = 2 - x**2 - y**2 - z**2
p2 = 1 - x**2 - (y-1)**2 - z**2
p3 = 1 - z**2
cells = gcad.merge(gcad.GCAD([p1 > 0, p2 > 0, p3 > 0], [x, y, z]))
for i, cell in enumerate(cells):
    print(f"Cell {i}:")
    for axis in cell:
        print(f"  {axis.cell_lo} < {axis.var} < {axis.cell_hi}")
print()
for i, cell in enumerate(cells):
    print(f"Cell {i} example point:")
    for axis in cell:
        print(f"  {axis.var} = {axis.point}")

The expected output is:

Cell 0:
  Root[#+1, 0] < x < Root[#-1, 0]
  Root[#^2-2*#+x^2, 0] < y < Root[#-1, 0]
  Root[#^2+x^2+y^2-2*y, 0] < z < Root[#^2+x^2+y^2-2*y, 1]
Cell 1:
  Root[#+1, 0] < x < Root[#-1, 0]
  Root[#-1, 0] < y < Root[#^2+x^2-2, 1]
  Root[#^2+x^2+y^2-2, 0] < z < Root[#^2+x^2+y^2-2, 1]

Cell 0 example point:
  x = -7/8
  y = 2/3
  z = 0
Cell 1 example point:
  x = -7/8
  y = 17/16
  z = 0

How to install

The latest release is available from PyPI.org/project/gcad, and can be installed via pip with

pip install gcad

If you prefer to experiment with the source code, then clone it, make sure you have a C++ compiler toolchain (GCC or Clang), install the dependencies listed in pyproject.toml, and build with make. Run tests with make test.

Note that the build system will build FLINT, MPFR, and GMP automatically (via hepware).

If the desired compiler is located in a non-standard location, you can set CC, CFLAGS, CXX, CXXFLAGS, and LDFLAGS environment variables before attempting installation to convey this information to the build system.

References

This implementation is based on the work of A. Strzeboński (S00). The root finding used here is based on the works of A. Akritas, A. Strzeboński, and others (ASV08, AAS08, ASV06, AS05). The variable ordering heuristics are from DSS04, dRE22, and PdRAEC23. The handling of rationals and polynomials is done by FLINT, MPFR, and GMP.

License

This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

API

Functions

GCAD (relations: Expr | list[Expr], varlist: list[Symbol]) → list[list[AxisBound]]

Generic Cylindrical Algebraic Decomposition (Algorithm 3.1 of S00). Take one or multiple multivariate polynomial inequalities, and decompose the region their conjunction defines into a set of cells. (The list of boundaries from the original algorithm is not computed here).

GPROJ (positives: list[Poly], varlist: list[Symbol]) → list[list[Poly]]

Generic projection (Algorithm 3.4 of S00). Return the list of $pr_i$, as polynomials with integer coefficients.

RSFC (positives: list[Poly], pr: list[list[Poly]], varlist: list[Symbol]) → list[list]

Recursive Solution Formula Construction (Algorithm 3.5 of S00).

greedy_mods_order (relations: Expr | list[Expr], var_groups: list[list[Symbol]]) → list[Symbol]

Variable order that greedily minimizes the "multiplication of degree sum" metric, as advocated in dRE22.

greedy_sotd_order (relations: Expr | list[Expr], var_groups: list[list[Symbol]]) → list[Symbol]

Variable order that greedily minimizes the "sum of total degrees" metric, as advocated in DSS04.

greedy_t1_order (relations: Expr | list[Expr], var_groups: list[list[Symbol]]) → list[Symbol]

Variable order that greedily minimizes the "t1" metric, as advocated in PdRAEC23.

merge (cells: list[list[AxisBound]]) → list[list[AxisBound]]

Merge adjacent cells (Remark 3.7 of S00) using an aggressive merging strategy, merging cells even if the inequalities may not hold at the boundaries between the cells.

relations_to_positives (relations: Expr | list[Expr], varlist: list[Symbol]) → list[Poly]

Turn one or more $a>b$ or $a<b$ relations into a list of positive expressions (i.e. turn $a>b$ into $a-b$, and $a<b$ into $b-a$).

Classes

AxisBound. Cell boundaries along one axis.

  • var: Symbol. Variable name corresponding to this axis.
  • point: Rational. A sample var value inside the cell.
  • cell_lo: PolyRoot | None. Lower bounding value. None means negative infinity.
  • cell_hi: PolyRoot | None. Higher bounding value. None means positive infinity.

PolyRoot. Real root of a polynomial.

  • poly: Poly. Polynomial defining the root.
  • var_idx: int. Index of the variable in which to find the roots.
  • idx: int. Index of the real root, if roots were ordered by value.
  • value_lo: Rational. Lower bound on the root's value at the sample point.
  • value_hi: Rational. Upper bound on the root's value at the sample point.

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

gcad-0.2.tar.gz (47.7 kB view details)

Uploaded Source

Built Distributions

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

gcad-0.2-cp310-abi3-musllinux_1_2_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

gcad-0.2-cp310-abi3-musllinux_1_2_aarch64.whl (6.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gcad-0.2-cp310-abi3-manylinux_2_28_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

gcad-0.2-cp310-abi3-manylinux_2_28_aarch64.whl (5.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

gcad-0.2-cp310-abi3-macosx_14_0_arm64.whl (4.9 MB view details)

Uploaded CPython 3.10+macOS 14.0+ ARM64

File details

Details for the file gcad-0.2.tar.gz.

File metadata

  • Download URL: gcad-0.2.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2.tar.gz
Algorithm Hash digest
SHA256 aa84dd528703d76b5e66895a841d4e0f271ef2e8ba12c64e4b825662e0f03b7d
MD5 cf29b90d4d5e42b5801a5ca16f4daa86
BLAKE2b-256 8c05aad676c2153ed2fb3a96b565b6e60a9d200df32ba86d4888e56eca667504

See more details on using hashes here.

File details

Details for the file gcad-0.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: gcad-0.2-cp310-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0df3c5403c26e6cddeeb836758243e6edab5e95ce914bb705c5d2ff5b3e5211b
MD5 89461d9f2aaf33225e72967cc75a6f5c
BLAKE2b-256 54658e1ea02f61af457bb3641775c5460e11cbf191e5b39171b67e476611dc2b

See more details on using hashes here.

File details

Details for the file gcad-0.2-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: gcad-0.2-cp310-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 17710fe317fb2e97e5059f6b9d8a44473d49413f6a5344782deb40f5fa755e03
MD5 19764ff81dd4592ec4506cc502827b9b
BLAKE2b-256 4a41cd69b16090bd7ad55de5b5b0af86590791be10843d22c869bf5f7f3f62ab

See more details on using hashes here.

File details

Details for the file gcad-0.2-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: gcad-0.2-cp310-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 5.9 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 32485289b18877d74d329cb9b17fc7c51ef7ba6dc06aab37490a7d80f6cc02fa
MD5 e8c482223faaab9f5ddfa5c3d41d71ec
BLAKE2b-256 e56e5400f1911baa52f4d4852fb3f28bde8bb856a89d515af7a261c5d82dd3d2

See more details on using hashes here.

File details

Details for the file gcad-0.2-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: gcad-0.2-cp310-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 5.9 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4ee87b0a3e9ba9663f376a187b87f0e91d87de2cde5264942fe5c69c8f0956f6
MD5 5437dcef16bad6784c05d4bf67838301
BLAKE2b-256 991aa56102118071f4d35509f67f500dd7a8513c42834faf8542cf71200693e5

See more details on using hashes here.

File details

Details for the file gcad-0.2-cp310-abi3-macosx_14_0_arm64.whl.

File metadata

  • Download URL: gcad-0.2-cp310-abi3-macosx_14_0_arm64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.10+, macOS 14.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gcad-0.2-cp310-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 28bbb332106f6d94ffba4c070ae06f18b7ef7d7d9ff3164062bdc54781ea5edd
MD5 ca2ce9752505ef9f958e81a7343aed58
BLAKE2b-256 8a48149c09940f272ea01ec1e2319abfaa3ce244a6b8d871a29c1d7701decdd7

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