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], max_cells: int | None) → list[list]
Recursive Solution Formula Construction (Algorithm 3.5 of S00).
find_instance (relations: Expr | list[Expr], varlist: list[Symbol]) → list[Rational] | None
Find a rational point that lies inside a region defined by the conjunction of the given polynomial relations (using GCAD), and return its coordinates, or None, if no such point exists.
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.
Nonemeans negative infinity. - cell_hi: PolyRoot | None. Higher bounding value.
Nonemeans 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.
Metadata
Release files for gcad 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gcad-0.3.tar.gz | 49.4 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| gcad-0.3-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| gcad-0.3-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| gcad-0.3-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| gcad-0.3-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| gcad-0.3-cp310-abi3-macosx_14_0_arm64.whl | CPython 3.10 | abi3 | macOS 14.0+ ARM64 | Details |
Total release size: 28.8 MB
Release files / gcad-0.3.tar.gz
| Download URL | gcad-0.3.tar.gz |
|---|---|
| Size | 49.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
464b491cb07c688417c2120d5c79599506f8d0479e0e7c4ee6955b3ded433eea
|
|
BLAKE2b-256 checksum How to use checksums |
35207671038094b374db264bcc8439f38a0b5899a5da94f9e0febe36248e8872
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / gcad-0.3-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | gcad-0.3-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1d1c5ae4ba087b491fdeee5f8d9898b79492a5b9a33deff49101271b62e9235b
|
|
BLAKE2b-256 checksum How to use checksums |
150c45ec8976aa51167b1ac57aa7c5a523f343be9764a8301a86ca6aef5b8502
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / gcad-0.3-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | gcad-0.3-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ae0b44464eaf408946a6b188d246637831503dfc761a0d072718d3b7ffd36706
|
|
BLAKE2b-256 checksum How to use checksums |
e81e4d56ba2608b72f405a3147db5beb3d14668b6a4b5f19650ed15ace8a31c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / gcad-0.3-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | gcad-0.3-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d61e84426ac795cd81561542e3f2b1f2b10c7d6c83a3be6d5657ab9fa32dbe6e
|
|
BLAKE2b-256 checksum How to use checksums |
40726a0d234e6520f57b3138c3964c0118dcc187aea10592e6a1874d7bce4332
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / gcad-0.3-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | gcad-0.3-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
a87c41226229007fe67dda74cd59ff1b702e74e5075cb72f1bbb705e3eea8b68
|
|
BLAKE2b-256 checksum How to use checksums |
0706f396020ac384cba148a032c9e43f90ed6bb2dfb9140d6e4e239684ae8ec3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / gcad-0.3-cp310-abi3-macosx_14_0_arm64.whl
| Download URL | gcad-0.3-cp310-abi3-macosx_14_0_arm64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.10 abi3 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1139c3ceccb927e114f88b321e6ebcdea28a15ed54c3b8541d76ea9e5885c11a
|
|
BLAKE2b-256 checksum How to use checksums |
408f031068f1d6b61e03090ff2e81105f2de8d58404c25633c59778f32ef39d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|