Overview
A computer algebra system. Exact coefficients are riptide_precision Rationals; numeric values are BigFloats.
What's in it
| Area | API |
|---|---|
| Expressions | Immutable trees: Num (exact rational), Flt (BigFloat), Sym (with positive/real/integer/nonnegative assumptions), Const (pi, I, oo, zoo, nan, eulerGamma; E is exp(1)), Add, Mul, Pow, Fn, Derivative. Structural hashing: equal trees are == with equal hashes. Operators + - * /, .pow. |
| Automatic simplification | SymPy's canonical forms on construction: flatten, collect numeric coefficients, combine like terms and like powers, combine exp factors, 2*(x+y) -> 2*x + 2*y, radicals sqrt(12) -> 2*sqrt(3), sqrt(2)*sqrt(3) -> sqrt(6), I**2 -> -1, infinities, assumption-aware sqrt(r**2) -> r. |
| Functions | exp log sin cos tan cot sec csc asin acos atan acot sinh cosh tanh coth asinh acosh atanh Abs sign re im conjugate gamma polygamma erf erfc factorial binomial legendre assoc_legendre laguerre assoc_laguerre hermite Ynm, exact values at special points (multiples of \frac{\pi}{12}, half-integer gamma...), parity, shifts by multiples of \frac{\pi}{2}. function('f') for undefined functions, FunctionDef.custom for your own rules. |
| Algorithms | subs, diff (any order, chain rule, Derivative for undefined functions), expand (multinomial), freeSymbols, has, transform, assumptions (isPositive, isReal...). |
| Numeric | evalf(digits) to any precision in the complex plane (leaves symbols in place), toBigFloat, toDouble. |
| Polynomials | MPoly<T> sparse multivariate over zz (ZZ), qq (QQ), PrimeField(p) (GF(p)) with MonoOrder.lex/grlex/grevlex: arithmetic, multivariate division, exact quotient, derivative, evaluation. polyFromExpr, polyGens. Expression level: gcd, lcm, div, resultant (subresultant PRS), discriminant, sqfList/sqf (Yun), factorList/factor (Zassenhaus with Cantor–Zassenhaus over GF(p) and quadratic Hensel lifting; multivariate by content removal + Kronecker substitution). |
| Gröbner bases | groebner(polys, gens, order, method: buchberger/f4, modulus:) reduced bases; Buchberger with Gebauer–Möller criteria, F4 (symbolic preprocessing, sparse row reduction), FGLM conversion from grevlex for zero-dimensional ideals in other orders; inIdeal, eliminate, reduced, groebnerBasis on MPoly. |
| Simplification | together, cancel, apart (partial fractions over QQ), collect, trigsimp, powsimp, radsimp, simplify (tries the rewrites and keeps the fewest operations), countOps. |
| Calculus | integrate(f, x) / integrate(f, x, a, b): table of linear-argument forms, polynomials, rational functions (ratint: Horowitz–Ostrogradsky + partial fractions with log/atan, Rothstein–Trager for higher-degree factors), Gaussian → erf, \frac{1}{\mathrm{sqrt}}(quadratic) → asin/asinh/log, derivative-divides substitution, integration by parts, trigonometric polynomials via complex exponentials, heuristic Risch–Norman (rischNorman); unevaluated Integral otherwise. series(f, x, x0, n:) Taylor/Laurent/Puiseux with O (PSeries, seriesCoefficients). limit(f, x, x0, dir:) by asymptotic leading terms (Gruntz-lite). |
| Linear algebra | solveRational (Bareiss), bareissDet, linsolve (Gauss–Jordan over expressions), linearCoefficients. |
| Solving | solve(eq, x): polynomials factored over QQ, then radicals (linear, quadratic, Cardano, Ferrari) or CRootOf(p, k) (numeric via Aberth iteration, SymPy's root order); parametric quadratics; equations polynomial in one function of x (exp(2x) - 3exp(x) + 2), inverted through exp/log/trig/hyperbolic; denominators' zeros removed. solveSystem(eqs, vars): linear systems by Gauss–Jordan, polynomial systems by a lex Gröbner basis and back substitution. |
| Text | Expr.parse('x^2 + sin(y)/3') (also **, implicit products, pi E I oo), toString (SymPy str), toLatex (SymPy latex), srepr. |
Correctness
Against SymPy 1.14 fixtures: plain-text and LaTeX output for 41 expressions match character for character; 41 automatic-simplification cases match SymPy's canonical form structurally; 34 expansions (up to (x+y+z+1)**8, radicals, I) match exactly; 63 derivatives of random nested expressions agree (most exactly after expansion, the rest numerically to 30 digits); 40 evalf cases (elementary, gamma, polygamma, erf/erfc, complex arguments, exp(pi*sqrt(163)), cos(10**10)) agree with mpmath to 48+ digits. Property tests check the ring axioms on random polynomials.
Polynomials: 23 gcd/lcm pairs, 15 resultants, 6 discriminants, 35 factorisations (compared as multisets of irreducible factors with the content; cyclotomics, x**4 + 4, Swinnerton-Dyer x**4 - 10x**2 + 1, bi- and trivariate cases), square-free decompositions and divisions match SymPy exactly; reduced Gröbner bases match SymPy exactly with both Buchberger and F4 for 16 systems (Cyclic-4 in lex/grlex/grevlex and mod 32003, Cyclic-5 grevlex, Katsura-4 grevlex and lex, random systems). Katsura-4 lex takes 0.3 s here via FGLM (46 s in SymPy). Properties: \operatorname{factor}(\operatorname{expand}(f)) = f, the gcd divides both inputs.
Calculus: all 48 indefinite integrals are found, differentiate back to the integrand (numerically to 30 digits) and differ from SymPy's antiderivative by a constant; 15 definite integrals (to \pm oo included) equal SymPy's exactly; 23 series expansions (Laurent 1/sin x, Puiseux-free cases, gamma(1 + x) with zeta values, expansions about 1) match coefficient for coefficient; 22 limits match exactly. Property: \frac{d}{dx} \int f = f on random elementary integrands; Risch–Norman cases such as \int x \frac{e^{x}}{(x + 1)^{2}} = \frac{e^{x}}{x + 1}.
Solving: 27 single equations (degrees 1–6, casus irreducibilis cubics, quartics, quintics as CRootOf, exponential/logarithmic equations) give the same distinct roots as SymPy to 30 digits; 6 linear and polynomial systems give the same solution sets.
Showcase: the hydrogen atom in atomic units. Spherical harmonics for l \le 3 built from Rodrigues' formula agree with the built-in Ynm, are verified eigenfunctions of the angular Laplacian (eigenvalue -l(l + 1)) and orthonormal by exact \theta and \varphi integrals; radial functions R_{nl} for n \le 3 from Rodrigues' Laguerre polynomials solve the radial Schrödinger equation with E_{n} = -\frac{1}{2n^{2}} (and solving H R = E R for E returns it), are normalised by exact integrals to infinity, and LaTeX is produced for each.
Simplification: cancel matches SymPy's canonical p/q form character for character; apart agrees with SymPy on 18 rational functions; simplify returns forms equivalent to SymPy's and no more complex.
Limits
evalfevaluates twice at increasing guard precision; results are accurate but not proven bounds.zetais exact at even and non-positive integers only (no numeric value yet).- Multivariate factorisation uses Kronecker's substitution: exponential in the number of univariate factors of the image, so it is meant for small polynomials (it refuses images of degree > 4000 or with > 20 factors); Wang's EEZ is the next step. GCDs use the recursive primitive PRS (no modular/heuristic GCD yet).
- Integration is heuristic (no full Risch decision procedure): a non-elementary integrand and an elementary one the heuristics miss both come back as
Integral(f, x). Rational functions with irreducible denominator factors of degree >= 3 and irrational residues stay unevaluated (no RootSum). Definite integrals do not detect singularities inside the interval. - Limits handle polynomial/exponential/logarithmic growth and functions analytic at their argument's limit; oscillating limits at infinity (
sin(x)) raiseLimitError. solvereturns radicals in Cardano/Ferrari form (not denested; casus irreducibilis roots involve complex cube roots), and polynomial systems need a zero-dimensional ideal whose triangular back substitution stays at degree <= 4 per step.apartis univariate over QQ (no symbolic parameters, no algebraic extensions).simplifyis a heuristic like SymPy's; it does not tryfactor-heavy orexptrigsimpstrategies.- Printing order follows SymPy's lex order for polynomial-like sums; exotic sums may order differently from SymPy.
Also exported here
Functions and constants
Functions
bool isNumber(Expr e)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${isNumber(e('3/4'))}, ${isNumber(x)}, ${isNumber(e('pi'))}');
}true, false, false
Expr numAdd(Expr a, Expr b)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${numAdd(e('1/3'), e('1/6'))}');
}1/2
Expr numMul(Expr a, Expr b)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${numMul(e('2/3'), e('9/4'))}');
}3/2
List<Sym> symbols(String names, {bool positive = false, bool real = false, bool integer = false})Symbols from a space- or comma-separated list: symbols('x y z').
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final s = symbols('a b c', positive: true);
print('$s; √(a²) = ${sqrt(s[0].pow(2))} (a is positive)');
}[a, b, c]; √(a²) = a (a is positive)
Expr exp(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('exp(1) and exp(log(x)): ${exp(1)}, ${exp(log(x))}');
print('derivative in x: ${exp(log(x)).diff(x)}');
}exp(1) and exp(log(x)): E, x derivative in x: 1
Expr log(Object x, [Object? base])Natural logarithm, or log(x)/log(base) when base is given.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('log(e), log(8, 2): ${log(e('E'))}, ${log(8, 2)}');
}log(e), log(8, 2): 1, log(8)/log(2)
Expr sqrt(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('√8, √(x²): ${sqrt(8)}, ${sqrt(x.pow(2))}');
print('derivative in x: ${sqrt(x.pow(2)).diff(x)}');
}√8, √(x²): 2*sqrt(2), sqrt(x**2) derivative in x: x/sqrt(x**2)
Expr root(Object x, int n)The principal n-th root.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('∛27, ∜16: ${root(27, 3)}, ${root(16, 4)}');
}∛27, ∜16: 3, 2
Expr sin(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('sin(π/6), sin(−x): ${sin(e('pi/6'))}, ${sin(-x)}');
print('derivative in x: ${sin(-x).diff(x)}');
}sin(π/6), sin(−x): 1/2, -sin(x) derivative in x: -cos(x)
Expr cos(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('cos(π/3), cos(−x): ${cos(e('pi/3'))}, ${cos(-x)}');
print('derivative in x: ${cos(-x).diff(x)}');
}cos(π/3), cos(−x): 1/2, cos(x) derivative in x: -sin(x)
Expr tan(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('tan(π/4): ${tan(e('pi/4'))}, ${tan(x)}');
print('derivative in x: ${tan(x).diff(x)}');
}tan(π/4): 1, tan(x) derivative in x: tan(x)**2 + 1
Expr cot(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('cot(π/4): ${cot(e('pi/4'))}, ${cot(x)}');
print('derivative in x: ${cot(x).diff(x)}');
}cot(π/4): cot(pi/4), cot(x) derivative in x: -cot(x)**2 - 1
Expr sec(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('sec(0): ${sec(0)}, ${sec(x)}');
print('derivative in x: ${sec(x).diff(x)}');
}sec(0): 1, sec(x) derivative in x: tan(x)*sec(x)
Expr csc(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('csc(π/2): ${csc(e('pi/2'))}, ${csc(x)}');
print('derivative in x: ${csc(x).diff(x)}');
}csc(π/2): csc(pi/2), csc(x) derivative in x: -cot(x)*csc(x)
Expr asin(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('asin(1/2): ${asin(e('1/2'))}, ${asin(x)}');
print('derivative in x: ${asin(x).diff(x)}');
}asin(1/2): pi/6, asin(x) derivative in x: 1/sqrt(-x**2 + 1)
Expr acos(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('acos(1/2): ${acos(e('1/2'))}, ${acos(x)}');
print('derivative in x: ${acos(x).diff(x)}');
}acos(1/2): pi/3, acos(x) derivative in x: -1/sqrt(-x**2 + 1)
Expr atan(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('atan(1): ${atan(1)}, ${atan(x)}');
print('derivative in x: ${atan(x).diff(x)}');
}atan(1): pi/4, atan(x) derivative in x: 1/(x**2 + 1)
Expr sinh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('sinh(0): ${sinh(0)}, ${sinh(x)}');
print('derivative in x: ${sinh(x).diff(x)}');
}sinh(0): 0, sinh(x) derivative in x: cosh(x)
Expr cosh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('cosh(0): ${cosh(0)}, ${cosh(x)}');
print('derivative in x: ${cosh(x).diff(x)}');
}cosh(0): 1, cosh(x) derivative in x: sinh(x)
Expr tanh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('tanh(0): ${tanh(0)}, ${tanh(x)}');
print('derivative in x: ${tanh(x).diff(x)}');
}tanh(0): 0, tanh(x) derivative in x: -tanh(x)**2 + 1
Expr asinh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('asinh(0): ${asinh(0)}, ${asinh(x)}');
print('derivative in x: ${asinh(x).diff(x)}');
}asinh(0): 0, asinh(x) derivative in x: 1/sqrt(x**2 + 1)
Expr acosh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('acosh(1): ${acosh(1)}, ${acosh(x)}');
print('derivative in x: ${acosh(x).diff(x)}');
}acosh(1): 0, acosh(x) derivative in x: 1/(sqrt(x - 1)*sqrt(x + 1))
Expr atanh(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('atanh(0): ${atanh(0)}, ${atanh(x)}');
print('derivative in x: ${atanh(x).diff(x)}');
}atanh(0): 0, atanh(x) derivative in x: 1/(-x**2 + 1)
Expr absE(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('|−3|, |x|: ${absE(-3)}, ${absE(x)}');
print('derivative in x: ${absE(x).diff(x)}');
}|−3|, |x|: 3, Abs(x) derivative in x: sign(x)
Expr signE(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('sign(−5): ${signE(-5)}, ${signE(x)}');
print('derivative in x: ${signE(x).diff(x)}');
}sign(−5): -1, sign(x) derivative in x: 0
Expr re(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('re(3 + 4i): ${re(e('3 + 4*I'))}, ${re(x)}');
print('derivative in x: ${re(x).diff(x)}');
}re(3 + 4i): 3, re(x) derivative in x: Derivative(re(x), x)
Expr im(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('im(3 + 4i): ${im(e('3 + 4*I'))}, ${im(x)}');
print('derivative in x: ${im(x).diff(x)}');
}im(3 + 4i): 4, im(x) derivative in x: Derivative(im(x), x)
Expr conjugate(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('conj(3 + 4i): ${conjugate(e('3 + 4*I'))}, ${conjugate(x)}');
print('derivative in x: ${conjugate(x).diff(x)}');
}conj(3 + 4i): 3 - 4*I, conjugate(x) derivative in x: Derivative(conjugate(x), x)
Expr gamma(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('Γ(5), Γ(1/2): ${gamma(5)}, ${gamma(e('1/2'))}');
}Γ(5), Γ(1/2): 24, sqrt(pi)
Expr erf(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('erf(0): ${erf(0)}, ${erf(x)}');
print('derivative in x: ${erf(x).diff(x)}');
}erf(0): 0, erf(x) derivative in x: 2*exp(-x**2)/sqrt(pi)
Expr erfc(Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('erfc(0): ${erfc(0)}, ${erfc(x)}');
print('derivative in x: ${erfc(x).diff(x)}');
}erfc(0): 1, erfc(x) derivative in x: -2*exp(-x**2)/sqrt(pi)
Expr factorial(Object n)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('5!, 20!: ${factorial(5)}, ${factorial(20)}');
}5!, 20!: 120, 2432902008176640000
Expr binomial(Object n, Object k)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('C(10, 3) = ${binomial(10, 3)}, C(n, 2) expanded: ${binomial(Sym('n'), 2).expand()}');
}C(10, 3) = 120, C(n, 2) expanded: binomial(n, 2)
Expr legendre(Object n, Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final p = legendre(3, x).expand();
print('P₃(x) = $p');
}P₃(x) = 5*x**3/2 - 3*x/2
Expr assocLegendre(Object n, Object m, Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('P₂¹(x) = ${assocLegendre(2, 1, x)}');
}P₂¹(x) = -3*x*sqrt(-x**2 + 1)
Expr laguerre(Object n, Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final p = laguerre(3, x).expand();
print('L₃(x) = $p');
}L₃(x) = -x**3/6 + 3*x**2/2 - 3*x + 1
Expr assocLaguerre(Object n, Object a, Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('L₂^(1)(x) = ${assocLaguerre(2, 1, x).expand()}');
}L₂^(1)(x) = x**2/2 - 3*x + 3
Expr hermite(Object n, Object x)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final p = hermite(4, x).expand();
print('H₄(x) = $p');
}H₄(x) = 16*x**4 - 48*x**2 + 12
Expr ynm(Object n, Object m, Object theta, Object phi)The spherical harmonic Y_{n}^{m}(\theta, \varphi) (Condon–Shortley phase, SymPy's convention); explicit for integer n, m.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final t = Sym('theta'), p = Sym('phi');
print('Y₁⁰ = ${ynm(1, 0, t, p)}');
}Y₁⁰ = sqrt(3)*cos(theta)/(2*sqrt(pi))
FunctionDef function(String name)An uninterpreted function: final f = function('f'); f([x]).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = function('f');
final g = f([x.pow(2)]);
print('d/dx f(x²) = ${g.diff(x)}');
}d/dx f(x²) = Derivative(f(x**2), x)
BigInt integerRoot(BigInt n, int k)Floor of the k-th root of n \ge 0 (Newton's method on BigInt).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${integerRoot(BigInt.from(10).pow(30), 3)}');
}10000000000
(BigInt, int) perfectPower(BigInt n)(b, k) with n == b^k and k maximal (k = 1 when n is not a perfect power).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${perfectPower(BigInt.from(3).pow(20))}');
}(3, 20)
Map<BigInt, int> factorInteger(BigInt n, {int limit = 1 << 16})Prime factorisation of n \ge 1 by trial division up to limit; a remaining cofactor is reported as a perfect power of an unfactored base (which may be composite). Returns base -> multiplicity.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${factorInteger(BigInt.parse('600851475143'))}');
}{71: 1, 839: 1, 1471: 1, 6857: 1}BigInt factorialBig(int n)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('30! = ${factorialBig(30)}');
}30! = 265252859812191058636308480000000
BigInt binomialBig(int n, int k)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('C(100, 50) = ${binomialBig(100, 50)}');
}C(100, 50) = 100891344545564193334812497256
int compareExpr(Expr a, Expr b)The canonical total order on expressions used to sort Add and Mul arguments.
Numbers come first (by value), then constants, symbols (by name), derivatives, functions, powers, products and sums. A power is ordered by its base first and then its exponent, so x, x**2 and x**3 sit together.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${compareExpr(x, y)}, ${compareExpr(y, x)}, ${compareExpr(x, x)}');
}-1, 1, 0
List<Expr> printOrder(List<Expr> terms)Sorts the terms of a sum for display: lexicographic in the generators (symbols by name first), higher powers first, constants last, matching SymPy's default order='lex' printing for polynomial-like sums.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(printOrder([e('1'), x.pow(3), x, x.pow(2)]));
}[x**3, x**2, x, 1]
List<Expr> polyGens(Iterable<Expr> es)The generators of e (after expansion): symbols sorted by name, then other non-numeric atoms (sin(x)).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(polyGens([e('x^2*y + sin(z)'), e('y + 1')]));
}[x, y, sin(z)]
MPoly<Rational> polyFromExpr(Expr e, List<Expr> gens, {MonoOrder order = MonoOrder.lex})e as a polynomial over QQ in gens.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final p = polyFromExpr(e('x^2*y - 3*x + 1/2'), [x, y]);
print('$p, degree in x ${p.degree(0)}');
}x**2*y - 3*x + 1/2, degree in x 2
(BigInt, MPoly<BigInt>) clearDenominators(MPoly<Rational> f)Clears denominators: returns (d, F) with F = d \cdot f over ZZ, d > 0 the lcm of the denominators.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final (d, p) = clearDenominators(polyFromExpr(e('x/2 + y/3'), [x, y]));
print('$d · ($p)');
}6 · (3*x + 2*y)
MPoly<Rational> toQQ(MPoly<BigInt> f, PolyRing<Rational> ring)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final (d, p) = clearDenominators(polyFromExpr(e('x/2 + y/3'), [x, y]));
print(toQQ(p, polyFromExpr(e('x'), [x, y]).ring));
}3*x + 2*y
Expr gcd(Expr a, Expr b)Greatest common divisor. Integer polynomials keep their integer content (gcd(2x+2, 4x+4) = 2x + 2); otherwise the result is monic, as in SymPy.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
print('gcd(x² − y², x² + 2xy + y²) = ${gcd(Expr.parse('x^2 - y^2'), Expr.parse('x^2 + 2*x*y + y^2'))}');
}gcd(x² − y², x² + 2xy + y²) = x + y
Expr lcm(Expr a, Expr b)Least common multiple (same normalisation as gcd).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${lcm(e('x^2 - 1'), e('x^2 + 2*x + 1'))}');
}x**3 + x**2 - x - 1
(Expr, Expr) div(Expr a, Expr b, Sym x)Division with remainder in x over QQ (other symbols as further lex generators): a = q·b + r.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final (q, r) = div(e('x^3 + 2*x + 1'), e('x - 1'), x);
print('q = $q, r = $r');
}q = x**2 + x + 3, r = 4
Expr resultant(Expr a, Expr b, Sym x)The resultant of a and b with respect to x.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('Res(x² − 2, x² − y) = ${resultant(e('x^2 - 2'), e('x^2 - y'), x)}');
}Res(x² − 2, x² − y) = y**2 - 4*y + 4
Expr discriminant(Expr a, Sym x)The discriminant of a with respect to x.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('disc(ax² + bx + c) = ${discriminant(e('a*x^2 + b*x + c'), x)}');
}disc(ax² + bx + c) = -4*a*c + b**2
(Rational, List<(Expr, int)>) sqfList(Expr a, {List<Expr>? gens})Square-free decomposition a = c · Π g_k^k over QQ.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(sqfList(e('x^5 - 2*x^4 + x^3')));
}(1, [(x - 1, 2), (x, 3)])
Expr sqf(Expr a, {List<Expr>? gens})The square-free form as a product.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(sqf(e('(x - 1)^2*(x + 2)^3')));
}(x - 1)**2*(x + 2)**3
(Rational, List<(Expr, int)>) factorList(Expr a, {List<Expr>? gens})Factorisation over QQ into irreducibles over ZZ: a = c · Π h^k (h primitive with positive leading coefficient).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(factorList(e('2*x^4 - 2')));
}(2, [(x + 1, 1), (x - 1, 1), (x**2 + 1, 1)])
Expr factor(Expr a, {List<Expr>? gens})Factors a polynomial, or numerator and denominator of a rational function, over the rationals.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
print('x⁴ − 1 = ${factor(Expr.parse('x^4 - 1'))}');
print('x²y − y³ = ${factor(Expr.parse('x^2*y - y^3'))}');
print('x³ − 6x² + 11x − 6 = ${factor(Expr.parse('x^3 - 6*x^2 + 11*x - 6'))}');
}x⁴ − 1 = (x - 1)*(x + 1)*(x**2 + 1) x²y − y³ = y*(x + y)*(x - y) x³ − 6x² + 11x − 6 = (x - 3)*(x - 2)*(x - 1)
List<Expr> groebner(List<Expr> polys, List<Expr> gens, {MonoOrder order = MonoOrder.lex, GroebnerMethod method = GroebnerMethod.buchberger, int? modulus})The reduced Gröbner basis of polys in gens under order, as SymPy prints it: over QQ each element is the primitive integer multiple with positive leading coefficient; with modulus p the coefficients lie in GF(p) (symmetric representatives) and elements are monic.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final circle = Expr.parse('x^2 + y^2 - 25'), line = Expr.parse('x - 2*y + 5');
print('Gröbner basis (lex, x > y): ${groebner([circle, line], [x, y])}');
print('intersections: ${solveSystem([circle, line], [x, y])}');
}Gröbner basis (lex, x > y): [x - 2*y + 5, y**2 - 4*y]
intersections: [{y: 0, x: -5}, {y: 4, x: 3}]bool inIdeal(Expr f, List<Expr> polys, List<Expr> gens, {MonoOrder order = MonoOrder.grevlex})Whether f lies in the ideal generated by polys (via a Gröbner basis in gens).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${inIdeal(e('x^3 - y^3'), [e('x - y')], [x, y])}, ${inIdeal(e('x + y'), [e('x - y')], [x, y])}');
}true, false
List<Expr> eliminate(List<Expr> polys, List<Expr> vars, List<Expr> otherGens)Eliminates vars from the ideal: the lex Gröbner basis elements free of them (gens order: vars first).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
// Eliminate t from x = t², y = t³: the cusp y² = x³.
final t = Sym('t');
print(eliminate([e('x - t^2'), e('y - t^3')], [t], [x, y]));
}[x**3 - y**2]
(List<Expr>, Expr) reduced(Expr f, List<Expr> polys, List<Expr> gens, {MonoOrder order = MonoOrder.lex})Normal form of f modulo polys by multivariate division (quotients and remainder), over QQ.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(reduced(e('x^2*y + x*y^2 + y^2'), [e('x*y - 1'), e('y^2 - 1')], [x, y]));
}([x + y, 1], x + y + 1)
List<MPoly<T>> groebnerBasis<T>(List<MPoly<T>> fs, {GroebnerMethod method = GroebnerMethod.buchberger})The reduced Gröbner basis of the ideal generated by fs (coefficients in a field).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final r = polyFromExpr(e('x'), [x, y]).ring;
final g = groebnerBasis([polyFromExpr(e('x^2 + y^2 - 1'), [x, y]), polyFromExpr(e('x - y'), [x, y])]);
print(g.map((p) => p.toExpr()).toList());
}[x - y, y**2 - 1/2]
bool isZeroDimensional<T>(List<MPoly<T>> g)Whether the ideal with Gröbner basis g has finitely many solutions (every variable has a pure-power LM).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final g = groebnerBasis([polyFromExpr(e('x^2 + y^2 - 1'), [x, y]), polyFromExpr(e('x - y'), [x, y])]);
print('${isZeroDimensional(g)} (finitely many solutions)');
}true (finitely many solutions)
List<MPoly<T>> fglm<T>(List<MPoly<T>> g, PolyRing<T> target)FGLM (Faugère, Gianni, Lazard, Mora): converts the reduced Gröbner basis g of a zero-dimensional ideal to the reduced basis in the order of target, by linear algebra on normal forms.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final ring = PolyRing(const RationalField(), [x, y], order: MonoOrder.grevlex);
final g = groebnerBasis([polyFromExpr(e('x^2 + y^2 - 1'), [x, y], order: MonoOrder.grevlex), polyFromExpr(e('x - y'), [x, y], order: MonoOrder.grevlex)]);
print(fglm(g, ring.withOrder(MonoOrder.lex)).map((p) => p.toExpr()).toList());
}[x - y, y**2 - 1/2]
bool idealContains<T>(List<MPoly<T>> g, MPoly<T> f)Whether f lies in the ideal with Gröbner basis g.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final g = groebnerBasis([polyFromExpr(e('x - y'), [x, y])]);
print('${idealContains(g, polyFromExpr(e('x^2 - y^2'), [x, y]))}');
}true
Expr together(Expr e)Combines a sum of fractions over a common denominator (no expansion, no cancellation): 1/x + 1/y -> (x + y)/(x*y).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(together(e('1/x + 1/y')));
}(x + y)/(x*y)
Expr cancel(Expr e)Puts a rational function into canonical p/q form: expanded numerator and denominator with no common factor, integer coefficients in the denominator with positive leading coefficient, rational content in front.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(cancel(e('(x^2 - 1)/(x - 1)')));
}x + 1
Expr collect(Expr e, Expr x)Collects the terms of the expanded expression by powers of x: a*x + b*x + c -> x*(a + b) + c.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(collect(e('a*x + b*x + x^2*c + d*x^2'), x));
}x**2*(c + d) + x*(a + b)
Expr apart(Expr e, Sym x)Partial fraction decomposition of a rational function in x over the rationals.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(apart(e('1/(x^2 - 1)'), x));
}-1/(2*(x + 1)) + 1/(2*(x - 1))
int countOps(Expr e)A complexity measure: the number of nodes, with powers and functions weighted like SymPy's count_ops.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${countOps(e('x^2 + 2*x*y + y^2'))} vs ${countOps(e('(x + y)^2'))}');
}8 vs 3
Expr trigsimp(Expr e)Trigonometric and hyperbolic simplification: applies \sin^{2} + \cos^{2} = 1 (and \cosh^{2} - \sinh^{2} = 1) by substituting for the squares in both directions and keeping the shortest result; also rewrites tan/cot/sec/csc via sin and cos when that is shorter.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(trigsimp(e('sin(x)^2 + cos(x)^2')));
print(trigsimp(e('2*sin(x)*cos(x)')));
}1 sin(2*x)
Expr powsimp(Expr e)Combines powers: same base (automatic) and same exponent for non-negative bases (sqrt(2)*sqrt(x) -> sqrt(2*x) when x >= 0), and exp products (automatic).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(powsimp(e('x^a*x^b')));
}x**(a + b)
Expr radsimp(Expr e)Rationalises denominators with square roots: 1/(a + b*sqrt(c)) -> (a - b*sqrt(c))/(a^2 - b^2*c).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(radsimp(e('1/(1 + sqrt(2))')));
}sqrt(2) - 1
Expr simplify(Expr e)SymPy-style heuristic simplification: tries cancel, factor-free rational normal forms, trigsimp, powsimp, radsimp and expansion, and returns the candidate with the fewest operations.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
print('sin²x + cos²x = ${simplify(Expr.parse('sin(x)^2 + cos(x)^2'))}');
print('cancel (x² − 1)/(x − 1) = ${cancel(Expr.parse('(x^2 - 1)/(x - 1)'))}');
print('apart 1/(x(x + 1)) = ${apart(Expr.parse('1/(x*(x + 1))'), Sym('x'))}');
}sin²x + cos²x = 1 cancel (x² − 1)/(x − 1) = x + 1 apart 1/(x(x + 1)) = -1/(x + 1) + 1/x
Expr integrate(Expr f, Sym x, [Object? a, Object? b])\int f dx, or \int_{a}^{b} f dx when a and b are given.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
Expr e(String s) => Expr.parse(s);
print('∫ x·exp(x) dx = ${integrate(e('x*exp(x)'), x)}');
print('∫ 1/(x² − 1) dx = ${integrate(e('1/(x^2 - 1)'), x)}');
print('∫₀¹ x³ + x dx = ${integrate(e('x^3 + x'), x, 0, 1)}');
print('∫₀^π sin(x) dx = ${integrate(e('sin(x)'), x, 0, e('pi'))}');
print('∫₀¹ 4/(1 + x²) dx = ${integrate(e('4/(1 + x^2)'), x, 0, 1)}');
}∫ x·exp(x) dx = x*exp(x) - exp(x) ∫ 1/(x² − 1) dx = log(x - 1)/2 - log(x + 1)/2 ∫₀¹ x³ + x dx = 3/4 ∫₀^π sin(x) dx = 2 ∫₀¹ 4/(1 + x²) dx = pi
Expr ratint(Expr n, Expr d, Sym x)\int \frac{n}{d} dx for polynomials over QQ in x.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(ratint(e('1'), e('x^2 + 1'), x));
}atan(x)
Expr? rischNorman(Expr f, Sym x)A heuristic Risch–Norman ansatz (in the spirit of SymPy's heurisch): the integrand's transcendental monomials (exp, log, tan, sin, cos, sqrt-free) become symbols, the candidate is a polynomial of bounded total degree in them divided by the integrand's denominator, plus log terms of the denominator's factors; matching the derivative gives a linear system for the rational coefficients. Returns null if the ansatz fails.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(rischNorman(e('x*exp(x)'), x));
}x*exp(x) - exp(x)
Expr limit(Expr e, Sym x, Object x0, {String dir = '+'})The limit of e as x -> x0; dir is '+' (from above, default), '-' or '+-' (both sides must agree).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
print('lim x→0 sin(x)/x = ${limit(Expr.parse('sin(x)/x'), x, 0)}');
print('lim x→0 (1 − cos x)/x² = ${limit(Expr.parse('(1 - cos(x))/x^2'), x, 0)}');
print('lim x→∞ (1 + 1/x)^x = ${limit(Expr.parse('(1 + 1/x)^x'), x, Expr.parse('oo'))}');
}lim x→0 sin(x)/x = 1 lim x→0 (1 − cos x)/x² = 1/2 lim x→∞ (1 + 1/x)^x = E
PSeries seriesAt0(Expr e, Sym x, int n)Expands e at x = 0 to absolute order n (terms below x^{n} are exact).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(seriesAt0(e('exp(x)'), x, 6).toExpr(x));
}1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
Expr series(Expr e, Sym x, {Expr? x0, int n = 6, bool withOrder = true})Series expansion of e in x about x0 (default 0) up to but excluding (x - x0)^n, with an O term. x0 = oo expands in \frac{1}{x}.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
print('exp(x) = ${series(Expr.parse('exp(x)'), x, n: 5)}');
print('sin(x) = ${series(Expr.parse('sin(x)'), x, n: 8)}');
print('1/(1 − x) = ${series(Expr.parse('1/(1 - x)'), x, n: 5)}');
}exp(x) = 1 + x + x**2/2 + x**3/6 + x**4/24 + O(x**5) sin(x) = x - x**3/6 + x**5/120 - x**7/5040 + O(x**8) 1/(1 − x) = 1 + x + x**2 + x**3 + x**4 + O(x**5)
Map<Rational, Expr> seriesCoefficients(Expr e, Sym x, int n)The coefficients of the expansion at 0 (exponent -> coefficient) up to order n.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(seriesCoefficients(e('1/(1 - x)'), x, 5));
}{0: 1, 1: 1, 2: 1, 3: 1, 4: 1}List<Rational>? solveRational(List<List<Rational>> a, List<Rational> b)Solves A x = b over QQ by Bareiss' fraction-free elimination on the integer-scaled augmented matrix. Returns one solution (free variables set to 0) or null if inconsistent.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(solveRational([[Rational.fromInt(2), Rational.fromInt(1)], [Rational.fromInt(1), Rational.fromInt(3)]], [Rational.fromInt(3), Rational.fromInt(5)]));
}[4/5, 7/5]
BigInt bareissDet(List<List<BigInt>> a)Determinant of an integer matrix by Bareiss' algorithm.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(bareissDet([[2, -1, 0], [-1, 2, -1], [0, -1, 2]].map((r) => r.map(BigInt.from).toList()).toList()));
}4
(List<Expr>, Expr)? linearCoefficients(Expr e, List<Sym> vars)Splits a linear expression in vars into coefficients and the constant term (null if not linear).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(linearCoefficients(e('3*x - 2*y + 7'), [x, y]));
}([3, -2], 7)
Map<Sym, Expr>? linsolve(List<Expr> eqs, List<Sym> vars)Solves a linear system of equations (expressions equal to zero) for vars by Gauss–Jordan elimination with cancel-normalised pivots (coefficients may contain parameters). Returns null if inconsistent; free variables stay symbolic (they appear in the other values).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(linsolve([e('x + y - 3'), e('x - y - 1')], [x, y]));
}{x: 2, y: 1}List<Expr> solve(Expr eq, Sym x)The distinct solutions of eq = 0 for x (SymPy's solve for a single equation).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
print('x² − 5x + 6 = 0: ${solve(Expr.parse('x^2 - 5*x + 6'), x)}');
print('x² − 2 = 0: ${solve(Expr.parse('x^2 - 2'), x)}');
print('x² + 1 = 0: ${solve(Expr.parse('x^2 + 1'), x)}');
}x² − 5x + 6 = 0: [2, 3] x² − 2 = 0: [-sqrt(2), sqrt(2)] x² + 1 = 0: [-I, I]
List<Expr> rootsOfIrreducible(Expr q, Sym x)The roots of an irreducible polynomial over QQ: radicals up to degree 4 (degree 3 and 4 by Cardano and Ferrari), CRootOf otherwise.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(rootsOfIrreducible(e('x^2 - x - 1'), x));
}[-sqrt(5)/2 + 1/2, sqrt(5)/2 + 1/2]
List<Map<Sym, Expr>> solveSystem(List<Expr> eqs, List<Sym> vars)Solves a system of equations (expressions = 0) for vars: linear systems by Gauss–Jordan, polynomial systems by a lex Gröbner basis and back substitution. Returns the list of solutions.
Constants and variables
final Expr pifinal Expr Ifinal Expr oofinal Expr zoofinal Expr nanfinal Expr eulerGammaconst IntegerRing zz = IntegerRing()const RationalField qq = RationalField()final FunctionDef crootofCRootOf(p, k): the k-th root of the irreducible polynomial p (SymPy's order: real roots ascending, then complex roots by real part); numeric with evalf.
Classes
Expr
abstract base class Expr implements Comparable<Expr>
A symbolic expression. Instances are immutable; build them with the operators, Sym, Num, the function helpers (sin, exp, …) or Expr.parse.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = e('(x + 1)^2');
print('$f → ${f.expand()} → d/dx ${f.diff(x)}');
}(x + 1)**2 → x**2 + 2*x + 1 → d/dx 2*x + 2
Static
static Expr from(Object o)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${Expr.from(3)}, ${Expr.from(0.5)}, ${Expr.from('x + 1')}');
}3, 0.500000000000000, x + 1
static Expr parse(String s, {Map<String, Expr>? locals})Parses "x^2 + sin(y)/3" (also **, implicit 2x, pi, E, I, oo, any function name).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final e = Expr.parse('(x + 1)^2 - 2*x');
print('parsed: $e');
print('expanded: ${e.expand()}');
print('free symbols: ${e.freeSymbols}');
print('at x = 3: ${e.subs({Sym('x'): 3})}');
}parsed: -2*x + (x + 1)**2
expanded: x**2 + 1
free symbols: {x}
at x = 3: 10Properties
final int hashCodebool get isAtomSet<Sym> get freeSymbolsThe symbols occurring in this expression (bound variables of Derivative included).
bool? get isPositivebool? get isNegativebool? get isZerobool? get isRealbool? get isIntegerbool? get isNonNegativebool? get isNonPositiveMethods
Expr rebuild(List<Expr> args)Rebuilds this node from new args, re-running the automatic simplification.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = e('sin(x)');
print(f.rebuild([y]));
}sin(y)
Expr pow(Object e)this ^ e.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x.pow(3), );
print((x + 1).pow(e('1/2')));
}x**3 sqrt(x + 1)
bool has(Expr sub)Whether sub occurs as a subtree.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${e('sin(x) + y').has(x)}, ${e('y^2').has(x)}');
}true, false
bool hasWhere(bool Function(Expr) test)Whether any subtree satisfies test.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('sin(x) + 3').hasWhere((s) => s is Num));
}true
bool isFreeOf(Iterable<Expr> syms)Whether this expression is free of every symbol in syms.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${e('y^2 + 1').isFreeOf([x])}');
}true
Expr subs(Map<Expr, Object> map)Simultaneous structural substitution: every subtree equal to a key is replaced by its value.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('x^2 + y').subs({x: 3, y: e('z')}));
}z + 9
Expr transform(Expr Function(Expr) f)Rebuilds bottom-up applying f to every node (after its children).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('sin(x) + sin(y)').transform((s) => s is Sym ? s * 2 : s));
}sin(2*x) + sin(2*y)
(Expr, Expr) asCoeffMul()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('3*x*y').asCoeffMul());
}(3, x*y)
(Expr, Expr) asCoeffAdd()(c, rest) with this == c + rest and c the numeric constant term.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('x + 5').asCoeffAdd());
}(5, x)
(Expr, Expr) asBaseExp()(base, exponent).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('x^3').asBaseExp());
}(x, 3)
(Expr, Expr) asNumerDenom()The expression as a numerator and denominator (x/y -> (x, y)), without expanding.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('(x + 1)/(x - 1)').asNumerDenom());
}(x + 1, x - 1)
bool couldExtractMinusSign()SymPy's could_extract_minus_sign: true when -this is "nicer" (negative coefficient, mostly negative sum). Exactly one of e and -e returns true unless e == 0.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${e('-x').couldExtractMinusSign()}, ${x.couldExtractMinusSign()}');
}true, false
Expr diff(Sym x, [int n = 1])The n-th derivative with respect to x.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
final f = Expr.parse('x^3 * sin(x)');
print('f = $f');
print("f' = ${f.diff(x)}");
print("f'' = ${f.diff(x).diff(x)}");
print("LaTeX: ${f.diff(x).toLatex()}");
}f = x**3*sin(x)
f' = x**3*cos(x) + 3*x**2*sin(x)
f'' = -x**3*sin(x) + 6*x**2*cos(x) + 6*x*sin(x)
LaTeX: x^{3} \cos{\left(x \right)} + 3 x^{2} \sin{\left(x \right)}Expr expand()Distributes products over sums and expands integer powers of sums (multinomial).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
print('(x + 1)^4 = ${Expr.parse('(x + 1)^4').expand()}');
print('(x + y)^3 = ${Expr.parse('(x + y)^3').expand()}');
print('(a - b)(a + b) = ${Expr.parse('(a - b)*(a + b)').expand()}');
}(x + 1)^4 = x**4 + 4*x**3 + 6*x**2 + 4*x + 1 (x + y)^3 = x**3 + 3*x**2*y + 3*x*y**2 + y**3 (a - b)(a + b) = a**2 - b**2
Expr evalf([int digits = 15])Numeric value to digits significant decimal digits (symbols are left in place).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${e('pi').evalf(40)}, ${e('sqrt(2)').evalf()}');
}3.141592653589793238462643383279502884197, 1.41421356237310
BigFloat toBigFloat({int prec = 53})Numeric value as a real BigFloat with prec bits (throws if not real-numeric).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('E').toBigFloat(prec: 120));
}2.7182818284590452353602874713526624979
double toDouble()Numeric value as a double (throws if not real-numeric).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('sqrt(2) + pi').toDouble());
}4.555806215962888
String toLatex()LaTeX in SymPy's latex style (x^{2} + \frac{\sin{\left(y \right)}}{3}).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x');
final e = integrate(Expr.parse('1/(x^2 + 1)'), x);
print('∫ 1/(x² + 1) dx = $e');
print('LaTeX: ${Expr.parse('sqrt(x)/(1 + x^2)').toLatex()}');
}∫ 1/(x² + 1) dx = atan(x)
LaTeX: \frac{\sqrt{x}}{x^{2} + 1}String srepr()Tree form for debugging (Add(Pow(Symbol('x'), Integer(2)), …)).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('x^2 + 1').srepr());
}Add(Integer(1), Pow(Symbol('x'), Integer(2)))int compareTo(Expr other)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x.compareTo(y));
}-1
Operators
Expr operator +(Object o)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x + 1 + x);
}2*x + 1
Expr operator -(Object o)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x - x);
}0
Expr operator *(Object o)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x * x * 3);
}3*x**2
Expr operator /(Object o)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x * y) / x);
}y
Expr operator -()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(-(x - y));
}-x + y
bool operator ==(Object other)Add
final class Add extends Expr
A sum. Build with Add.of (or +), which flattens, collects numeric terms and combines like terms.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final s = Add.of([x, y, x]);
print('$s, terms ${s.args}');
}2*x + y, terms [y, 2*x]
Static
static Expr of(Iterable<Expr> input)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Add.of([x, Num.int_(2), -x]));
}2
Properties
final List<Expr> argsbool? get isPositivebool? get isNegativebool? get isZerobool? get isRealbool? get isIntegerMethods
Expr rebuild(List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x + y).rebuild([x, x]));
}2*x
(Expr, Expr) asCoeffAdd()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x + 3).asCoeffAdd());
}(3, x)
bool couldExtractMinusSign()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(e('-x - y').couldExtractMinusSign());
}true
Mul
final class Mul extends Expr
A product. Build with Mul.of (or *), which flattens, multiplies numbers, combines like bases ($x \cdot x$**$2 \to x$**3), combines exp factors, reduces numeric radicals and distributes a rational coefficient over a single sum.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Mul.of([x, x, Num.int_(3)]));
}3*x**2
Static
static Expr factored(Iterable<Expr> input)Like of but keeps c * (a + b) as a product instead of distributing (used for factored output).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Mul.factored([x + 1, x + 1]));
}(x + 1)**2
static Expr of(Iterable<Expr> input, {bool distribute = true})import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${Mul.of([Num.int_(2), x + 1])}, ${Mul.of([Num.int_(2), x + 1], distribute: false)}');
}2*x + 2, 2*(x + 1)
Properties
final List<Expr> argsbool? get isPositivebool? get isNegativebool? get isNonNegativebool? get isZerobool? get isRealbool? get isIntegerMethods
Expr rebuild(List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x * y).rebuild([y, y]));
}y**2
(Expr, Expr) asCoeffMul()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x * 5).asCoeffMul());
}(5, x)
(Expr, Expr) asNumerDenom()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x / y).asNumerDenom());
}(x, y)
bool couldExtractMinusSign()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print((x * -2).couldExtractMinusSign());
}true
Pow
final class Pow extends Expr
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Pow.of(x, Num.int_(2)) * Pow.of(x, Num.int_(3)));
}x**5
Static
static Expr of(Expr b, Expr e)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${Pow.of(Num.int_(4), Num.frac(1, 2))}, ${Pow.of(x, Num.int_(0))}');
}2, 1
Properties
final Expr basefinal Expr expList<Expr> get argsbool? get isPositivebool? get isNegativebool? get isNonNegativebool? get isZerobool? get isRealbool? get isIntegerMethods
Expr rebuild(List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x.pow(2).rebuild([y, Num.int_(3)]));
}y**3
(Expr, Expr) asBaseExp()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(x.pow(5).asBaseExp());
}(x, 5)
Num
final class Num extends Expr
An exact rational number (SymPy's Integer / Rational).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.frac(1, 3) + Num.frac(1, 6));
}1/2
Constructors
Num(this.value)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num(Rational.fromInt(22, 7)));
}22/7
factory Num.int_(int i)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.int_(42) * x);
}42*x
factory Num.frac(int p, int q)p / q.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.frac(6, 8));
}3/4
Static
static final Num zerostatic final Num onestatic final Num twostatic final Num negOnestatic final Num halfProperties
final Rational valuebool get isIntBigInt get numerBigInt get denombool? get isPositivebool? get isNegativebool? get isZerobool? get isRealbool? get isIntegerbool get isRationalNumberMethods
bool couldExtractMinusSign()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.int_(-3).couldExtractMinusSign());
}true
(Expr, Expr) asCoeffMul()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.int_(5).asCoeffMul());
}(5, 1)
(Expr, Expr) asCoeffAdd()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.int_(5).asCoeffAdd());
}(5, 0)
(Expr, Expr) asNumerDenom()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Num.frac(3, 7).asNumerDenom());
}(3, 7)
Flt
final class Flt extends Expr
An arbitrary-precision binary floating-point number (SymPy's Float).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Flt(BigFloat.parse('0.1')) + Num.int_(1));
}1.10000000000000
Constructors
Flt(this.value)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Flt(BigFloat.parse('2.5')));
}2.50000000000000
Properties
final BigFloat valuebool? get isPositivebool? get isNegativebool? get isZerobool? get isRealMethods
bool couldExtractMinusSign()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Flt(BigFloat.parse('-2.5')).couldExtractMinusSign());
}true
(Expr, Expr) asCoeffMul()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Flt(BigFloat.parse('2.5')).asCoeffMul());
}(2.50000000000000, 1)
(Expr, Expr) asCoeffAdd()import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Flt(BigFloat.parse('2.5')).asCoeffAdd());
}(2.50000000000000, 0)
Sym
final class Sym extends Expr
A symbol with optional assumptions. Two symbols are equal when their names and assumptions agree.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
// A symbol is a named variable; expressions are built from symbols.
final f = x.pow(2) * y + sin(x);
print('f = $f, ∂f/∂x = ${f.diff(x)}, ∂f/∂y = ${f.diff(y)}');
}f = x**2*y + sin(x), ∂f/∂x = 2*x*y + cos(x), ∂f/∂y = x**2
Constructors
Sym(this.name, {bool positive = false, bool real = false, bool integer = false, bool nonnegative = false})import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final a = Sym('a', positive: true);
print('√(a²) = ${sqrt(a.pow(2))}, √(x²) = ${sqrt(x.pow(2))}');
}√(a²) = a, √(x²) = sqrt(x**2)
Properties
final String namebool? get isPositivebool? get isNegativebool? get isZerobool? get isRealbool? get isIntegerbool? get isNonNegativeConstKind
enum ConstKind
Values
piioozoonaneulerGammaConst
final class Const extends Expr
The named constants \pi, i, \infty, complex infinity, NaN and Euler's \gamma. E is exp(1).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print('${e('pi')}, ${e('E')}, ${e('pi').evalf(20)}');
}pi, E, 3.1415926535897932385
Static
static final Const pistatic final Const istatic final Const oostatic final Const zoostatic final Const nanstatic final Const eulerGammaProperties
final ConstKind kindbool? get isPositivebool? get isNegativebool? get isZerobool? get isRealbool? get isIntegerDerivative
final class Derivative extends Expr
An unevaluated derivative of expr with respect to vars (a multiset, sorted), used for undefined functions.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = function('f');
print(Derivative.of(f([x]), [x, x]));
}Derivative(f(x), (x, 2))
Constructors
factory Derivative.of(Expr expr, List<Sym> vars)d^n expr / d vars, evaluating when possible.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = function('f');
print(Derivative.of(f([x, y]), [x, y]));
}Derivative(f(x, y), x, y)
Properties
final Expr exprfinal List<Sym> varsList<Expr> get argsMethods
Expr rebuild(List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final f = function('f');
print(Derivative.of(f([x]), [x]).rebuild([f([y]), y]));
}Derivative(f(y), y)
FunctionDef
final class FunctionDef
A function symbol: its name, arity, automatic simplification (eval) and partial derivatives (partials).
Built-ins live in Functions; FunctionDef.undefined makes an uninterpreted function f (derivatives stay as Derivative); FunctionDef.custom makes one with your own rules.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
final g = FunctionDef.undefined('g');
print(g([x]).diff(x));
}Derivative(g(x), x)
Constructors
factory FunctionDef.undefined(String name)An uninterpreted function name(args…) (f(x)), cached by name.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(FunctionDef.undefined('h')([x, y]));
}h(x, y)
factory FunctionDef.custom(String name, {int? nargs, Expr? Function(List<Expr> args)? eval, List<Expr?> Function(List<Expr> args)? partials, double Function(List<double> args)? numeric})A user function with optional simplification, derivative rules and a double-precision numeric value.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
// A function that evaluates itself on numbers.
final sq = FunctionDef.custom('sq', nargs: 1, eval: (a) => a[0] is Num ? a[0] * a[0] : null);
print('${sq([Num.int_(7)])}, ${sq([x])}');
}49, sq(x)
Properties
final String namefinal Expr? Function(List<Expr> args)? evalAutomatic simplification: returns the simplified value or null to keep name(args).
final List<Expr?> Function(List<Expr> args)? partialsPartial derivatives with respect to each argument (null entries are not differentiable symbolically).
final double Function(List<double> args)? numericA double-precision value for custom functions (built-ins evaluate at any precision in evalf).
final bool isUndefinedMethods
Expr call(List<Object> args)Applies the function: f.call([x]).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(function('f')([x, Num.int_(2)]));
}f(x, 2)
String toString()Fn
final class Fn extends Expr
A function application f(args…).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Fn.of(function('f'), [x]));
}f(x)
Static
static Expr of(FunctionDef def, List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(Fn.of(function('f'), [x + 1]).diff(x));
}Derivative(f(x + 1), x)
Properties
final FunctionDef deffinal List<Expr> argsString get namebool? get isRealbool? get isPositivebool? get isNegativebool? get isNonNegativebool? get isZerobool? get isIntegerMethods
Expr rebuild(List<Expr> args)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(sin(x).rebuild([y]));
}sin(y)
Functions
abstract final class Functions
The built-in functions.
Static
static final FunctionDef expstatic final FunctionDef logstatic final FunctionDef sinstatic final FunctionDef cosstatic final FunctionDef tanstatic final FunctionDef cotstatic final FunctionDef secstatic final FunctionDef cscstatic final FunctionDef asinstatic final FunctionDef acosstatic final FunctionDef atanstatic final FunctionDef acotstatic final FunctionDef sinhstatic final FunctionDef coshstatic final FunctionDef tanhstatic final FunctionDef cothstatic final FunctionDef asinhstatic final FunctionDef acoshstatic final FunctionDef atanhstatic final FunctionDef absstatic final FunctionDef signstatic final FunctionDef restatic final FunctionDef imstatic final FunctionDef conjugatestatic final FunctionDef gammastatic final FunctionDef polygammastatic final FunctionDef erfstatic final FunctionDef erfcstatic final FunctionDef factorialstatic final FunctionDef binomialstatic final FunctionDef legendrestatic final FunctionDef assocLegendrestatic final FunctionDef laguerrestatic final FunctionDef assocLaguerrestatic final FunctionDef hermitestatic final FunctionDef ynmstatic final FunctionDef zetaThe Riemann zeta function (exact at even positive and all non-positive integers).
static final FunctionDef integralAn unevaluated integral Integral(f, x) (or Integral(f, x, a, b)); \frac{d}{dx} \operatorname{Integral}(f, x) = f.
static final Map<String, FunctionDef> byNameEvery built-in by name (the parser and printers use this).
PolynomialError
final class PolynomialError implements Exception
The expression is not a polynomial in the requested generators.
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
try {
polyFromExpr(e('sin(x)'), [x]);
} on PolynomialError catch (err) {
print('PolynomialError: ${err.message}');
}
}PolynomialError: sin(x) is not a polynomial term in [x]
Constructors
PolynomialError(this.message)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(PolynomialError('not a polynomial').message);
}not a polynomial
Properties
final String messageMethods
String toString()Domain
abstract class Domain<T>
A commutative coefficient ring (an integral domain; a field when isField).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('${d.name()}: a + b = ${d.add(a, b)}, a·b = ${d.mul(a, b)}, gcd ${d.gcd(a, b)}');
}QQ: a + b = 11/12, a·b = 1/8, gcd 1
Constructors
const Domain()Properties
T get zeroT get onebool get isFieldMethods
T add(T a, T b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('add: ${d.add(a, b)} (a = $a, b = $b in ${d.name()})');
}add: 11/12 (a = 3/4, b = 1/6 in QQ)
T sub(T a, T b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('sub: ${d.sub(a, b)} (a = $a, b = $b in ${d.name()})');
}sub: 7/12 (a = 3/4, b = 1/6 in QQ)
T mul(T a, T b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('mul: ${d.mul(a, b)} (a = $a, b = $b in ${d.name()})');
}mul: 1/8 (a = 3/4, b = 1/6 in QQ)
T neg(T a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('neg: ${d.neg(a)} (a = $a, b = $b in ${d.name()})');
}neg: -3/4 (a = 3/4, b = 1/6 in QQ)
bool isZero(T a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('isZero: ${d.isZero(d.sub(a, a))} (a = $a, b = $b in ${d.name()})');
}isZero: true (a = 3/4, b = 1/6 in QQ)
bool isOne(T a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('isOne: ${d.isOne(d.div(a, a))} (a = $a, b = $b in ${d.name()})');
}isOne: true (a = 3/4, b = 1/6 in QQ)
T fromInt(int n)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('fromInt: ${d.fromInt(-3)} (a = $a, b = $b in ${d.name()})');
}fromInt: -3 (a = 3/4, b = 1/6 in QQ)
T? exquo(T a, T b)A / b when b divides a exactly, else null.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('exquo: ${d.exquo(d.mul(a, b), b)} (a = $a, b = $b in ${d.name()})');
}exquo: 3/4 (a = 3/4, b = 1/6 in QQ)
T inv(T a)The inverse (fields only).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('inv: ${d.inv(b)} (a = $a, b = $b in ${d.name()})');
}inv: 6 (a = 3/4, b = 1/6 in QQ)
T div(T a, T b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('div: ${d.div(a, b)} (a = $a, b = $b in ${d.name()})');
}div: 9/2 (a = 3/4, b = 1/6 in QQ)
T gcd(T a, T b)Gcd of two elements (1 in a field unless both are zero).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('gcd: ${d.gcd(a, b)} (a = $a, b = $b in ${d.name()})');
}gcd: 1 (a = 3/4, b = 1/6 in QQ)
bool isNegative(T a)Whether a is "negative" (for normalising signs; false in GF(p)).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('isNegative: ${d.isNegative(d.neg(a))} (a = $a, b = $b in ${d.name()})');
}isNegative: true (a = 3/4, b = 1/6 in QQ)
Expr toExpr(T a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('toExpr: ${d.toExpr(a)} (a = $a, b = $b in ${d.name()})');
}toExpr: 3/4 (a = 3/4, b = 1/6 in QQ)
T? fromRational(Rational r)Converts an exact number, or null.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('fromRational: ${d.fromRational(Rational.fromInt(1, 2))} (a = $a, b = $b in ${d.name()})');
}fromRational: 1/2 (a = 3/4, b = 1/6 in QQ)
String name()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField() as Domain<Rational>;
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('name: ${d.name()} (a = $a, b = $b in ${d.name()})');
}name: QQ (a = 3/4, b = 1/6 in QQ)
String toString()IntegerRing
final class IntegerRing extends Domain<BigInt>
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('${d.name()}: a + b = ${d.add(a, b)}, a·b = ${d.mul(a, b)}, gcd ${d.gcd(a, b)}');
}ZZ: a + b = 30, a·b = 216, gcd 6
Constructors
const IntegerRing()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
print(d.name());
}ZZ
Properties
BigInt get zeroBigInt get onebool get isFieldMethods
BigInt add(BigInt a, BigInt b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('add: ${d.add(a, b)} (a = $a, b = $b in ${d.name()})');
}add: 30 (a = 12, b = 18 in ZZ)
BigInt sub(BigInt a, BigInt b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('sub: ${d.sub(a, b)} (a = $a, b = $b in ${d.name()})');
}sub: -6 (a = 12, b = 18 in ZZ)
BigInt mul(BigInt a, BigInt b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('mul: ${d.mul(a, b)} (a = $a, b = $b in ${d.name()})');
}mul: 216 (a = 12, b = 18 in ZZ)
BigInt neg(BigInt a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('neg: ${d.neg(a)} (a = $a, b = $b in ${d.name()})');
}neg: -12 (a = 12, b = 18 in ZZ)
bool isZero(BigInt a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('isZero: ${d.isZero(d.sub(a, a))} (a = $a, b = $b in ${d.name()})');
}isZero: true (a = 12, b = 18 in ZZ)
BigInt fromInt(int n)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('fromInt: ${d.fromInt(-3)} (a = $a, b = $b in ${d.name()})');
}fromInt: -3 (a = 12, b = 18 in ZZ)
BigInt? exquo(BigInt a, BigInt b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('exquo: ${d.exquo(d.mul(a, b), b)} (a = $a, b = $b in ${d.name()})');
}exquo: 12 (a = 12, b = 18 in ZZ)
BigInt inv(BigInt a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('inv: ${d.inv(BigInt.from(-1))} (a = $a, b = $b in ${d.name()})');
}inv: -1 (a = 12, b = 18 in ZZ)
BigInt gcd(BigInt a, BigInt b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('gcd: ${d.gcd(a, b)} (a = $a, b = $b in ${d.name()})');
}gcd: 6 (a = 12, b = 18 in ZZ)
bool isNegative(BigInt a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('isNegative: ${d.isNegative(d.neg(a))} (a = $a, b = $b in ${d.name()})');
}isNegative: true (a = 12, b = 18 in ZZ)
Expr toExpr(BigInt a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('toExpr: ${d.toExpr(a)} (a = $a, b = $b in ${d.name()})');
}toExpr: 12 (a = 12, b = 18 in ZZ)
BigInt? fromRational(Rational r)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('fromRational: ${d.fromRational(Rational.fromInt(1, 2))} (a = $a, b = $b in ${d.name()})');
}fromRational: null (a = 12, b = 18 in ZZ)
String name()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const IntegerRing();
final a = BigInt.from(12), b = BigInt.from(18);
print('name: ${d.name()} (a = $a, b = $b in ${d.name()})');
}name: ZZ (a = 12, b = 18 in ZZ)
RationalField
final class RationalField extends Domain<Rational>
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('${d.name()}: a + b = ${d.add(a, b)}, a·b = ${d.mul(a, b)}, gcd ${d.gcd(a, b)}');
}QQ: a + b = 11/12, a·b = 1/8, gcd 1
Constructors
const RationalField()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
print(d.name());
}Properties
Rational get zeroRational get onebool get isFieldMethods
Rational add(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('add: ${d.add(a, b)} (a = $a, b = $b in ${d.name()})');
}add: 11/12 (a = 3/4, b = 1/6 in QQ)
Rational sub(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('sub: ${d.sub(a, b)} (a = $a, b = $b in ${d.name()})');
}sub: 7/12 (a = 3/4, b = 1/6 in QQ)
Rational mul(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('mul: ${d.mul(a, b)} (a = $a, b = $b in ${d.name()})');
}mul: 1/8 (a = 3/4, b = 1/6 in QQ)
Rational neg(Rational a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('neg: ${d.neg(a)} (a = $a, b = $b in ${d.name()})');
}neg: -3/4 (a = 3/4, b = 1/6 in QQ)
bool isZero(Rational a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('isZero: ${d.isZero(d.sub(a, a))} (a = $a, b = $b in ${d.name()})');
}isZero: true (a = 3/4, b = 1/6 in QQ)
Rational fromInt(int n)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('fromInt: ${d.fromInt(-3)} (a = $a, b = $b in ${d.name()})');
}fromInt: -3 (a = 3/4, b = 1/6 in QQ)
Rational? exquo(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('exquo: ${d.exquo(d.mul(a, b), b)} (a = $a, b = $b in ${d.name()})');
}exquo: 3/4 (a = 3/4, b = 1/6 in QQ)
Rational inv(Rational a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('inv: ${d.inv(b)} (a = $a, b = $b in ${d.name()})');
}inv: 6 (a = 3/4, b = 1/6 in QQ)
Rational div(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('div: ${d.div(a, b)} (a = $a, b = $b in ${d.name()})');
}div: 9/2 (a = 3/4, b = 1/6 in QQ)
Rational gcd(Rational a, Rational b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('gcd: ${d.gcd(a, b)} (a = $a, b = $b in ${d.name()})');
}gcd: 1 (a = 3/4, b = 1/6 in QQ)
bool isNegative(Rational a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('isNegative: ${d.isNegative(d.neg(a))} (a = $a, b = $b in ${d.name()})');
}isNegative: true (a = 3/4, b = 1/6 in QQ)
Expr toExpr(Rational a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('toExpr: ${d.toExpr(a)} (a = $a, b = $b in ${d.name()})');
}toExpr: 3/4 (a = 3/4, b = 1/6 in QQ)
Rational? fromRational(Rational r)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('fromRational: ${d.fromRational(Rational.fromInt(1, 2))} (a = $a, b = $b in ${d.name()})');
}fromRational: 1/2 (a = 3/4, b = 1/6 in QQ)
String name()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const RationalField();
final a = Rational.fromInt(3, 4), b = Rational.fromInt(1, 6);
print('name: ${d.name()} (a = $a, b = $b in ${d.name()})');
}name: QQ (a = 3/4, b = 1/6 in QQ)
PrimeField
final class PrimeField extends Domain<int>
The prime field GF(p) on machine ints (p < 2^{26} keeps products exact on every platform).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('${d.name()}: a + b = ${d.add(a, b)}, a·b = ${d.mul(a, b)}, gcd ${d.gcd(a, b)}');
}GF(7): a + b = 1, a·b = 1, gcd 1
Constructors
const PrimeField(this.p)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
print(d.name());
}GF(7)
Properties
final int pint get zeroint get onebool get isFieldint get characteristicint get hashCodeMethods
int add(int a, int b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('add: ${d.add(a, b)} (a = $a, b = $b in ${d.name()})');
}add: 1 (a = 5, b = 3 in GF(7))
int sub(int a, int b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('sub: ${d.sub(a, b)} (a = $a, b = $b in ${d.name()})');
}sub: 2 (a = 5, b = 3 in GF(7))
int mul(int a, int b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('mul: ${d.mul(a, b)} (a = $a, b = $b in ${d.name()})');
}mul: 1 (a = 5, b = 3 in GF(7))
int neg(int a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('neg: ${d.neg(a)} (a = $a, b = $b in ${d.name()})');
}neg: 2 (a = 5, b = 3 in GF(7))
bool isZero(int a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('isZero: ${d.isZero(d.sub(a, a))} (a = $a, b = $b in ${d.name()})');
}isZero: true (a = 5, b = 3 in GF(7))
int fromInt(int n)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('fromInt: ${d.fromInt(-3)} (a = $a, b = $b in ${d.name()})');
}fromInt: 4 (a = 5, b = 3 in GF(7))
int? exquo(int a, int b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('exquo: ${d.exquo(d.mul(a, b), b)} (a = $a, b = $b in ${d.name()})');
}exquo: 5 (a = 5, b = 3 in GF(7))
int inv(int a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('inv: ${d.inv(b)} (a = $a, b = $b in ${d.name()})');
}inv: 5 (a = 5, b = 3 in GF(7))
int gcd(int a, int b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('gcd: ${d.gcd(a, b)} (a = $a, b = $b in ${d.name()})');
}gcd: 1 (a = 5, b = 3 in GF(7))
Expr toExpr(int a)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('toExpr: ${d.toExpr(a)} (a = $a, b = $b in ${d.name()})');
}toExpr: -2 (a = 5, b = 3 in GF(7))
int? fromRational(Rational r)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('fromRational: ${d.fromRational(Rational.fromInt(1, 2))} (a = $a, b = $b in ${d.name()})');
}fromRational: 4 (a = 5, b = 3 in GF(7))
String name()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final d = const PrimeField(7);
final a = 5, b = 3;
print('name: ${d.name()} (a = $a, b = $b in ${d.name()})');
}name: GF(7) (a = 5, b = 3 in GF(7))
Operators
bool operator ==(Object other)GroebnerMethod
enum GroebnerMethod
Values
buchbergerf4Mono
final class Mono
An exponent vector, immutable, with cached hash and total degree.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final m = Mono([2, 1]);
print('x²y as an exponent vector: $m, exponent of y ${m[1]}');
}x²y as an exponent vector: [2, 1], exponent of y 1
Constructors
Mono(List<int> e)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([3, 0, 1]));
}[3, 0, 1]
factory Mono.zero(int n)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono.zero(3));
}[0, 0, 0]
Properties
final List<int> efinal int degfinal int hashCodeint get lengthbool get isOneMethods
bool divides(Mono o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print('${Mono([1, 1]).divides(Mono([2, 1]))}, ${Mono([0, 2]).divides(Mono([2, 1]))}');
}true, false
Mono lcm(Mono o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([2, 0]).lcm(Mono([1, 3])));
}[2, 3]
Mono gcd(Mono o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([2, 5]).gcd(Mono([1, 3])));
}[1, 3]
String toString()Operators
int operator [](int i)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([4, 7])[1]);
}7
Mono operator *(Mono o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([1, 2]) * Mono([3, 0]));
}[4, 2]
Mono operator /(Mono o)This / o (assumes o divides this).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(Mono([3, 2]) / Mono([1, 1]));
}[2, 1]
bool operator ==(Object other)MonoOrder
enum MonoOrder
Monomial orders. compare(a, b) > 0 when a is greater.
Values
lexgrlexgrevlexMethods
int compare(Mono a, Mono b)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final a = Mono([1, 2]), b = Mono([2, 0]);
for (final o in MonoOrder.values) print('$o: compare(xy², x²) = ${o.compare(a, b)}');
}MonoOrder.lex: compare(xy², x²) = -1 MonoOrder.grlex: compare(xy², x²) = 1 MonoOrder.grevlex: compare(xy², x²) = 1
PolyRing
final class PolyRing<T>
A polynomial ring domain[gens] with a monomial order.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print('ℚ[x, y]: ${r.gen(0) * r.gen(1) + r.fromInt(3)}');
}ℚ[x, y]: x*y + 3
Constructors
PolyRing(this.domain, List<Expr> gens, {this.order = MonoOrder.lex})import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final z = PolyRing(const IntegerRing(), [x], order: MonoOrder.grevlex);
print((z.gen(0) + z.fromInt(1)).pow(3));
}x**3 + 3*x**2 + 3*x + 1
Properties
final Domain<T> domainfinal List<Expr> gensfinal MonoOrder orderint get nlate final Mono one_late final MPoly<T> zerolate final MPoly<T> oneMethods
MPoly<T> constant(T c)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(r.constant(Rational.fromInt(5, 2)));
}5/2
MPoly<T> fromInt(int c)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(r.fromInt(-4));
}-4
MPoly<T> gen(int i)The i-th generator.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print('${r.gen(0)}, ${r.gen(1)}');
}x, y
MPoly<T> term(Mono m, T c)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(r.term(Mono([2, 3]), Rational.fromInt(-7)));
}-7*x**2*y**3
MPoly<T> fromMap(Map<Mono, T> terms)From a monomial -> coefficient map (zeros dropped).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(r.fromMap({Mono([1, 0]): Rational.one, Mono([0, 2]): Rational.fromInt(3)}));
}x + 3*y**2
PolyRing<T> withOrder(MonoOrder o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final g = r.withOrder(MonoOrder.grlex);
print((g.gen(0) + g.gen(1).pow(3)).toExpr());
}x + y**3
PolyRing<S> withDomain<S>(Domain<S> d)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final f7 = r.withDomain(const PrimeField(7));
print((f7.gen(0) + f7.fromInt(1)).pow(7));
}x**7 + 1
String toString()MPoly
final class MPoly<T>
A polynomial: terms sorted by decreasing monomial (in the ring's order), no zero coefficients.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final f = p('x^2 + 2*x*y + y^2');
print('$f, as an expression ${f.toExpr()}');
}x**2 + 2*x*y + y**2, as an expression x**2 + 2*x*y + y**2
Properties
final PolyRing<T> ringfinal List<Mono> monosfinal List<T> coeffsbool get isZerobool get isConstantbool get isOneint get lengthMono get lmT get lcMPoly<T> get ltint get totalDegreeint get hashCodeMethods
Map<Mono, T> toMap()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('3*x^2*y - y').toMap());
}{[2, 1]: 3, [0, 1]: -1}int degree(int i)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print('${p('x^3*y + y^5').degree(0)}, ${p('x^3*y + y^5').degree(1)}');
}3, 5
MPoly<T> mulTerm(Mono m, T c)This * c \cdot m.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x + 1').mulTerm(Mono([0, 2]), Rational.fromInt(3)));
}3*x*y**2 + 3*y**2
MPoly<T> scale(T c)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x + y').scale(Rational.fromInt(1, 2)));
}x/2 + y/2
MPoly<T> pow(int k)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x + y').pow(4).toExpr());
}x**4 + 4*x**3*y + 6*x**2*y**2 + 4*x*y**3 + y**4
MPoly<T> exquoScalar(T c)Divides every coefficient by c exactly (throws if not exact).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('6*x + 4*y').exquoScalar(Rational.fromInt(2)));
}3*x + 2*y
MPoly<T> monic()Monic (fields only).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('3*x^2 + 6*y').monic());
}x**2 + 2*y
T content()Gcd of the coefficients (for ZZ; 1 over a field).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final z = polyFromExpr(Expr.parse('6*x + 4*y'), [x, y]);
print(clearDenominators(z).$2.content());
}2
MPoly<T> primitive()This divided by its content (positive leading coefficient over ZZ, monic over a field).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(clearDenominators(p('6*x + 4*y')).$2.primitive());
}3*x + 2*y
MPoly<T>? exquo(MPoly<T> g)Exact quotient this / g, or null when g does not divide this.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print('${p('x^2 - y^2').exquo(p('x - y'))}, ${p('x^2 + y^2').exquo(p('x - y'))}');
}x + y, null
MPoly<T> rem(List<MPoly<T>> gs)Full reduction (normal form) modulo gs by the multivariate division algorithm (fields).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2*y + 1').rem([p('x*y - 1')]));
}x + 1
(List<MPoly<T>>, MPoly<T>) divmod(List<MPoly<T>> gs, {bool wantQuotients = true})Multivariate division: this == sum q_i g_i + r with no term of r divisible by any LM(g_i).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final (q, rem) = p('x^3 + y').divmod([p('x - y')]);
print('q = $q, r = $rem');
}q = [x**2 + x*y + y**2], r = y**3 + y
MPoly<T> diff(int i)Partial derivative with respect to generator i.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^3*y^2').diff(0));
}3*x**2*y**2
MPoly<T> compose(int i, MPoly<T> v)Substitutes the polynomial v for generator i.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2 + y').compose(0, p('y + 1')).toExpr());
}y**2 + 3*y + 1
MPoly<T> evaluate(int i, T c)Substitutes the constant c for generator i.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2 + y').evaluate(0, Rational.fromInt(3)));
}y + 9
Map<int, MPoly<T>> coefficientsIn(int i)Coefficients with respect to generator i: degree -> coefficient (a polynomial free of x_{i}).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2*y + x*y^2 + 3').coefficientsIn(0));
}{2: y, 1: y**2, 0: 3}MPoly<T> lcIn(int i)Leading coefficient with respect to generator i (a polynomial free of x_{i}).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('2*x^2*y + x*y^2 + x^2').lcIn(0));
}2*y + 1
MPoly<T> shift(int i, int k)Multiplies by x_{i}^{k}.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2').shift(0, 1).toExpr());
}x**3
MPoly<S> mapCoeffs<S>(PolyRing<S> to, S Function(T) f)Maps coefficients into another ring with the same generators.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final f7 = r.withDomain(const PrimeField(7));
print(p('8*x + 15*y').mapCoeffs(f7, (c) => c.numerator.toInt() % 7));
}x + y
MPoly<T> reorder(PolyRing<T> to)The same polynomial in a ring with another order.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2 + y').reorder(PolyRing(const RationalField(), [y, x])));
}x + y**2
Expr toExpr()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x^2 - 2*x*y').toExpr().diff(x));
}2*x - 2*y
String toString()Operators
MPoly<T> operator +(MPoly<T> o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x + 1') + p('y - 1'));
}x + y
MPoly<T> operator -(MPoly<T> o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(p('x + y') - p('x'));
}y
MPoly<T> operator -()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(-p('x - y'));
}-x + y
MPoly<T> operator *(MPoly<T> o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print((p('x - y') * p('x + y')).toExpr());
}x**2 - y**2
bool operator ==(Object other)LimitError
final class LimitError implements Exception
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(LimitError('no limit').message);
}no limit
Constructors
LimitError(this.message)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(LimitError('oscillates').message);
}oscillates
Properties
final String messageMethods
String toString()SeriesError
final class SeriesError implements Exception
Thrown when an expansion does not exist in this framework (essential singularity, oscillation...).
import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(SeriesError('essential singularity').message);
}essential singularity
Constructors
SeriesError(this.message)import 'package:riptide_cas/riptide_cas.ray';
import 'raya:convert';
void main() {
final x = Sym('x'), y = Sym('y');
Expr e(String s) => Expr.parse(s);
print(SeriesError('demo').message);
}demo
Properties
final String messageMethods
String toString()PSeries
final class PSeries
A truncated series sum c_k x^k + O(x^order); exponents are rationals, coefficients are expressions free of x (they may contain log(x) for logarithmic terms).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final s = seriesAt0(Expr.parse('sin(x)'), x, 8);
print(s.toExpr(x));
}x - x**3/6 + x**5/120 - x**7/5040 + O(x**8)
Constructors
PSeries(Map<Rational, Expr> terms, this.order)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final s = PSeries({Rational.zero: Num.int_(1), Rational.one: Num.int_(-1)}, Rational.fromInt(3));
print(s.toExpr(x));
}1 - x + O(x**3)
factory PSeries.constant(Expr c, Rational order)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(PSeries.constant(Num.int_(7), Rational.fromInt(4)).toExpr(x));
}7 + O(x**4)
Static
static PSeries compose(List<Expr> a, PSeries h)sum_k a_k h^k for a series h with positive valuation, given coefficients a_{0} \cdots a_{n}.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
// exp(sin x) from the coefficients of exp composed with the series of sin x.
final h = seriesAt0(Expr.parse('sin(x)'), x, 6);
final a = [for (var k = 0; k < 6; k++) Num(Rational(BigInt.one, factorialBig(k)))];
print(PSeries.compose(a, h).toExpr(x));
}1 + x + x**2/2 - x**4/8 - x**5/15 + O(x**6)
Properties
final Map<Rational, Expr> termsfinal Rational orderbool get isZeroRational get valuationLowest exponent present (the valuation), or order when zero to this order.
Methods
Expr coeff(Rational k)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(seriesAt0(Expr.parse('exp(x)'), x, 8).coeff(Rational.fromInt(5)));
}1/120
PSeries scale(Expr c)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(seriesAt0(Expr.parse('exp(x)'), x, 4).scale(Num.int_(2)).toExpr(x));
}2 + 2*x + x**2 + x**3/3 + O(x**4)
PSeries shift(Rational r)Multiplies by x^{r}.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(seriesAt0(Expr.parse('exp(x)'), x, 4).shift(Rational.fromInt(2)).toExpr(x));
}x**2 + x**3 + x**4/2 + x**5/6 + O(x**6)
(Expr, Rational, PSeries) normalized()(c, v, h) with this == c x^{v} (1 + h), h of positive valuation.
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print(seriesAt0(Expr.parse('x^2*exp(x)'), x, 5).normalized());
}(1, 2, PSeries({1: 1, 2: 1/2}, O(3)))Expr toExpr(Expr x, {bool withOrder = true})The series as an expression in x with an O(x^order) term (no O term when withOrder is false).
import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
final s = seriesAt0(Expr.parse('cos(x)'), x, 7);
print('${s.toExpr(x)} | ${s.toExpr(x, withOrder: false)}');
}1 - x**2/2 + x**4/24 - x**6/720 + O(x**7) | -x**6/720 + x**4/24 - x**2/2 + 1
String toString()Operators
PSeries operator +(PSeries o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print((seriesAt0(Expr.parse('sin(x)'), x, 6) + seriesAt0(Expr.parse('cos(x)'), x, 6)).toExpr(x));
}1 + x - x**2/2 - x**3/6 + x**4/24 + x**5/120 + O(x**6)
PSeries operator -()import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print((-seriesAt0(Expr.parse('sin(x)'), x, 6)).toExpr(x));
}-x + x**3/6 - x**5/120 + O(x**6)
PSeries operator -(PSeries o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
print((seriesAt0(Expr.parse('exp(x)'), x, 5) - seriesAt0(Expr.parse('cos(x)'), x, 5)).toExpr(x));
}x + x**2 + x**3/6 + O(x**5)
PSeries operator *(PSeries o)import 'package:riptide_cas/riptide_cas.ray';
void main() {
final x = Sym('x'), y = Sym('y');
final r = PolyRing(const RationalField(), [x, y]);
MPoly<Rational> p(String s) => polyFromExpr(Expr.parse(s), [x, y]);
// sin·cos = sin(2x)/2.
print((seriesAt0(Expr.parse('sin(x)'), x, 7) * seriesAt0(Expr.parse('cos(x)'), x, 7)).toExpr(x));
}x - 2*x**3/3 + 2*x**5/15 + O(x**7)