RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya docs · Exact and higher mathematics

Computer algebra

Symbolic expressions, simplification, expansion and factorisation, differentiation, integration, series, multivariate polynomials, Gröbner bases, solving and LaTeX output.

import 'package:riptide_cas/riptide_cas.ray';
26 classes374 functions and methods150 of 509 documented285 runnable examplesWhat SymPy does

Overview

A computer algebra system. Exact coefficients are riptide_precision Rationals; numeric values are BigFloats.

What's in it

AreaAPI
ExpressionsImmutable 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 simplificationSymPy'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.
Functionsexp 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.
Algorithmssubs, diff (any order, chain rule, Derivative for undefined functions), expand (multinomial), freeSymbols, has, transform, assumptions (isPositive, isReal...).
Numericevalf(digits) to any precision in the complex plane (leaves symbols in place), toBigFloat, toDouble.
PolynomialsMPoly<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 basesgroebner(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.
Simplificationtogether, cancel, apart (partial fractions over QQ), collect, trigsimp, powsimp, radsimp, simplify (tries the rewrites and keeps the fewest operations), countOps.
Calculusintegrate(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 algebrasolveRational (Bareiss), bareissDet, linsolve (Gauss–Jordan over expressions), linearCoefficients.
Solvingsolve(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.
TextExpr.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

  • evalf evaluates twice at increasing guard precision; results are accurate but not proven bounds. zeta is 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)) raise LimitError.
  • solve returns 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.
  • apart is univariate over QQ (no symbolic parameters, no algebraic extensions).
  • simplify is a heuristic like SymPy's; it does not try factor-heavy or exptrigsimp strategies.
  • 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

isNumberfunction
bool isNumber(Expr e)
Example
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'))}');
}
Output
true, false, false
numAddfunction
Expr numAdd(Expr a, Expr b)
Example
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'))}');
}
Output from the Raya VM
1/2
numMulfunction
Expr numMul(Expr a, Expr b)
Example
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'))}');
}
Output from the Raya VM
3/2
symbolsfunction
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').

Example
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)');
}
Output from the Raya VM
[a, b, c]; √(a²) = a (a is positive)
expfunction
Expr exp(Object x)
Example
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)}');
}
Output
exp(1) and exp(log(x)): E, x
derivative in x: 1
logfunction
Expr log(Object x, [Object? base])

Natural logarithm, or log(x)/log(base) when base is given.

Example
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)}');
}
Output from the Raya VM
log(e), log(8, 2): 1, log(8)/log(2)
sqrtfunction
Expr sqrt(Object x)
Example
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)}');
}
Output from the Raya VM
√8, √(x²): 2*sqrt(2), sqrt(x**2)
derivative in x: x/sqrt(x**2)
rootfunction
Expr root(Object x, int n)

The principal n-th root.

Example
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)}');
}
Output from the Raya VM
∛27, ∜16: 3, 2
sinfunction
Expr sin(Object x)
Example
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)}');
}
Output from the Raya VM
sin(π/6), sin(−x): 1/2, -sin(x)
derivative in x: -cos(x)
cosfunction
Expr cos(Object x)
Example
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)}');
}
Output
cos(π/3), cos(−x): 1/2, cos(x)
derivative in x: -sin(x)
tanfunction
Expr tan(Object x)
Example
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)}');
}
Output from the Raya VM
tan(π/4): 1, tan(x)
derivative in x: tan(x)**2 + 1
cotfunction
Expr cot(Object x)
Example
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)}');
}
Output
cot(π/4): cot(pi/4), cot(x)
derivative in x: -cot(x)**2 - 1
secfunction
Expr sec(Object x)
Example
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)}');
}
Output from the Raya VM
sec(0): 1, sec(x)
derivative in x: tan(x)*sec(x)
cscfunction
Expr csc(Object x)
Example
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)}');
}
Output
csc(π/2): csc(pi/2), csc(x)
derivative in x: -cot(x)*csc(x)
asinfunction
Expr asin(Object x)
Example
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)}');
}
Output
asin(1/2): pi/6, asin(x)
derivative in x: 1/sqrt(-x**2 + 1)
acosfunction
Expr acos(Object x)
Example
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)}');
}
Output
acos(1/2): pi/3, acos(x)
derivative in x: -1/sqrt(-x**2 + 1)
atanfunction
Expr atan(Object x)
Example
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)}');
}
Output
atan(1): pi/4, atan(x)
derivative in x: 1/(x**2 + 1)
sinhfunction
Expr sinh(Object x)
Example
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)}');
}
Output from the Raya VM
sinh(0): 0, sinh(x)
derivative in x: cosh(x)
coshfunction
Expr cosh(Object x)
Example
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)}');
}
Output
cosh(0): 1, cosh(x)
derivative in x: sinh(x)
tanhfunction
Expr tanh(Object x)
Example
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)}');
}
Output from the Raya VM
tanh(0): 0, tanh(x)
derivative in x: -tanh(x)**2 + 1
asinhfunction
Expr asinh(Object x)
Example
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)}');
}
Output
asinh(0): 0, asinh(x)
derivative in x: 1/sqrt(x**2 + 1)
acoshfunction
Expr acosh(Object x)
Example
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)}');
}
Output
acosh(1): 0, acosh(x)
derivative in x: 1/(sqrt(x - 1)*sqrt(x + 1))
atanhfunction
Expr atanh(Object x)
Example
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)}');
}
Output
atanh(0): 0, atanh(x)
derivative in x: 1/(-x**2 + 1)
absEfunction
Expr absE(Object x)
Example
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)}');
}
Output
|−3|, |x|: 3, Abs(x)
derivative in x: sign(x)
signEfunction
Expr signE(Object x)
Example
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)}');
}
Output from the Raya VM
sign(−5): -1, sign(x)
derivative in x: 0
refunction
Expr re(Object x)
Example
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)}');
}
Output from the Raya VM
re(3 + 4i): 3, re(x)
derivative in x: Derivative(re(x), x)
imfunction
Expr im(Object x)
Example
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)}');
}
Output
im(3 + 4i): 4, im(x)
derivative in x: Derivative(im(x), x)
conjugatefunction
Expr conjugate(Object x)
Example
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)}');
}
Output
conj(3 + 4i): 3 - 4*I, conjugate(x)
derivative in x: Derivative(conjugate(x), x)
gammafunction
Expr gamma(Object x)
Example
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'))}');
}
Output
Γ(5), Γ(1/2): 24, sqrt(pi)
erffunction
Expr erf(Object x)
Example
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)}');
}
Output
erf(0): 0, erf(x)
derivative in x: 2*exp(-x**2)/sqrt(pi)
erfcfunction
Expr erfc(Object x)
Example
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)}');
}
Output
erfc(0): 1, erfc(x)
derivative in x: -2*exp(-x**2)/sqrt(pi)
factorialfunction
Expr factorial(Object n)
Example
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)}');
}
Output
5!, 20!: 120, 2432902008176640000
binomialfunction
Expr binomial(Object n, Object k)
Example
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()}');
}
Output
C(10, 3) = 120, C(n, 2) expanded: binomial(n, 2)
legendrefunction
Expr legendre(Object n, Object x)
Example
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');
}
Output
P₃(x) = 5*x**3/2 - 3*x/2
Expr assocLegendre(Object n, Object m, Object x)
Example
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)}');
}
Output
P₂¹(x) = -3*x*sqrt(-x**2 + 1)
laguerrefunction
Expr laguerre(Object n, Object x)
Example
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');
}
Output
L₃(x) = -x**3/6 + 3*x**2/2 - 3*x + 1
Expr assocLaguerre(Object n, Object a, Object x)
Example
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()}');
}
Output
L₂^(1)(x) = x**2/2 - 3*x + 3
hermitefunction
Expr hermite(Object n, Object x)
Example
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');
}
Output
H₄(x) = 16*x**4 - 48*x**2 + 12
ynmfunction
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.

Example
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)}');
}
Output from the Raya VM
Y₁⁰ = sqrt(3)*cos(theta)/(2*sqrt(pi))
functionfunction
FunctionDef function(String name)

An uninterpreted function: final f = function('f'); f([x]).

Example
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)}');
}
Output
d/dx f(x²) = Derivative(f(x**2), x)
integerRootfunction
BigInt integerRoot(BigInt n, int k)

Floor of the k-th root of n \ge 0 (Newton's method on BigInt).

Example
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)}');
}
Output
10000000000
perfectPowerfunction
(BigInt, int) perfectPower(BigInt n)

(b, k) with n == b^k and k maximal (k = 1 when n is not a perfect power).

Example
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))}');
}
Output from the Raya VM
(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.

Example
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'))}');
}
Output
{71: 1, 839: 1, 1471: 1, 6857: 1}
factorialBigfunction
BigInt factorialBig(int n)
Example
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)}');
}
Output
30! = 265252859812191058636308480000000
binomialBigfunction
BigInt binomialBig(int n, int k)
Example
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)}');
}
Output
C(100, 50) = 100891344545564193334812497256
compareExprfunction
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.

Example
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)}');
}
Output
-1, 1, 0
printOrderfunction
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.

Example
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)]));
}
Output from the Raya VM
[x**3, x**2, x, 1]
polyGensfunction
List<Expr> polyGens(Iterable<Expr> es)

The generators of e (after expansion): symbols sorted by name, then other non-numeric atoms (sin(x)).

Example
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')]));
}
Output from the Raya VM
[x, y, sin(z)]
polyFromExprfunction
MPoly<Rational> polyFromExpr(Expr e, List<Expr> gens, {MonoOrder order = MonoOrder.lex})

e as a polynomial over QQ in gens.

Example
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)}');
}
Output from the Raya VM
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.

Example
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)');
}
Output
6 · (3*x + 2*y)
toQQfunction
MPoly<Rational> toQQ(MPoly<BigInt> f, PolyRing<Rational> ring)
Example
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));
}
Output from the Raya VM
3*x + 2*y
gcdfunction
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.

Example
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'))}');
}
Output
gcd(x² − y², x² + 2xy + y²) = x + y
lcmfunction
Expr lcm(Expr a, Expr b)

Least common multiple (same normalisation as gcd).

Example
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'))}');
}
Output
x**3 + x**2 - x - 1
divfunction
(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.

Example
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');
}
Output
q = x**2 + x + 3, r = 4
resultantfunction
Expr resultant(Expr a, Expr b, Sym x)

The resultant of a and b with respect to x.

Example
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)}');
}
Output from the Raya VM
Res(x² − 2, x² − y) = y**2 - 4*y + 4
discriminantfunction
Expr discriminant(Expr a, Sym x)

The discriminant of a with respect to x.

Example
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)}');
}
Output
disc(ax² + bx + c) = -4*a*c + b**2
sqfListfunction
(Rational, List<(Expr, int)>) sqfList(Expr a, {List<Expr>? gens})

Square-free decomposition a = c · Π g_k^k over QQ.

Example
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')));
}
Output from the Raya VM
(1, [(x - 1, 2), (x, 3)])
sqffunction
Expr sqf(Expr a, {List<Expr>? gens})

The square-free form as a product.

Example
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')));
}
Output from the Raya VM
(x - 1)**2*(x + 2)**3
factorListfunction
(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).

Example
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')));
}
Output
(2, [(x + 1, 1), (x - 1, 1), (x**2 + 1, 1)])
factorfunction
Expr factor(Expr a, {List<Expr>? gens})

Factors a polynomial, or numerator and denominator of a rational function, over the rationals.

Example
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'))}');
}
Output
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)
groebnerfunction
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.

Example
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])}');
}
Output from the Raya VM
Gröbner basis (lex, x > y): [x - 2*y + 5, y**2 - 4*y]
intersections: [{y: 0, x: -5}, {y: 4, x: 3}]
inIdealfunction
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).

Example
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])}');
}
Output
true, false
eliminatefunction
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).

Example
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]));
}
Output
[x**3 - y**2]
reducedfunction
(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.

Example
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]));
}
Output from the Raya VM
([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).

Example
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());
}
Output
[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).

Example
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)');
}
Output
true (finitely many solutions)
fglmfunction
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.

Example
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());
}
Output
[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.

Example
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]))}');
}
Output
true
togetherfunction
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).

Example
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')));
}
Output from the Raya VM
(x + y)/(x*y)
cancelfunction
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.

Example
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)')));
}
Output
x + 1
collectfunction
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.

Example
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));
}
Output
x**2*(c + d) + x*(a + b)
apartfunction
Expr apart(Expr e, Sym x)

Partial fraction decomposition of a rational function in x over the rationals.

Example
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));
}
Output
-1/(2*(x + 1)) + 1/(2*(x - 1))
countOpsfunction
int countOps(Expr e)

A complexity measure: the number of nodes, with powers and functions weighted like SymPy's count_ops.

Example
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'))}');
}
Output
8 vs 3
trigsimpfunction
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.

Example
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)')));
}
Output from the Raya VM
1
sin(2*x)
powsimpfunction
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).

Example
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')));
}
Output from the Raya VM
x**(a + b)
radsimpfunction
Expr radsimp(Expr e)

Rationalises denominators with square roots: 1/(a + b*sqrt(c)) -> (a - b*sqrt(c))/(a^2 - b^2*c).

Example
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))')));
}
Output from the Raya VM
sqrt(2) - 1
simplifyfunction
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.

Example
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'))}');
}
Output from the Raya VM
sin²x + cos²x       = 1
cancel (x² − 1)/(x − 1) = x + 1
apart 1/(x(x + 1))  = -1/(x + 1) + 1/x
integratefunction
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.

Example
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)}');
}
Output from the Raya VM
∫ 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
ratintfunction
Expr ratint(Expr n, Expr d, Sym x)

\int \frac{n}{d} dx for polynomials over QQ in x.

Example
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));
}
Output from the Raya VM
atan(x)
rischNormanfunction
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.

Example
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));
}
Output from the Raya VM
x*exp(x) - exp(x)
limitfunction
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).

Example
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'))}');
}
Output
lim x→0 sin(x)/x       = 1
lim x→0 (1 − cos x)/x² = 1/2
lim x→∞ (1 + 1/x)^x    = E
seriesAt0function
PSeries seriesAt0(Expr e, Sym x, int n)

Expands e at x = 0 to absolute order n (terms below x^{n} are exact).

Example
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));
}
Output from the Raya VM
1 + x + x**2/2 + x**3/6 + x**4/24 + x**5/120 + O(x**6)
seriesfunction
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}.

Example
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)}');
}
Output from the Raya VM
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.

Example
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));
}
Output from the Raya VM
{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.

Example
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)]));
}
Output from the Raya VM
[4/5, 7/5]
bareissDetfunction
BigInt bareissDet(List<List<BigInt>> a)

Determinant of an integer matrix by Bareiss' algorithm.

Example
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()));
}
Output
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).

Example
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]));
}
Output
([3, -2], 7)
linsolvefunction
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).

Example
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]));
}
Output
{x: 2, y: 1}
solvefunction
List<Expr> solve(Expr eq, Sym x)

The distinct solutions of eq = 0 for x (SymPy's solve for a single equation).

Example
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)}');
}
Output from the Raya VM
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.

Example
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));
}
Output from the Raya VM
[-sqrt(5)/2 + 1/2, sqrt(5)/2 + 1/2]
solveSystemfunction
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

pivariable
final Expr pi
Ivariable
final Expr I
oovariable
final Expr oo
zoovariable
final Expr zoo
nanvariable
final Expr nan
eulerGammavariable
final Expr eulerGamma
Evariable
final Expr E

Euler's number, represented as exp(1).

zzconstant
const IntegerRing zz = IntegerRing()
qqconstant
const RationalField qq = RationalField()
crootofvariable
final FunctionDef crootof

CRootOf(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

class

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.

Example
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)}');
}
Output
(x + 1)**2 → x**2 + 2*x + 1 → d/dx 2*x + 2

Static

fromstaticmethod
static Expr from(Object o)

Converts int, BigInt, Rational, double (exact), String (parsed) or Expr to an expression.

Example
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')}');
}
Output
3, 0.500000000000000, x + 1
parsestaticmethod
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).

Example
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})}');
}
Output
parsed:   -2*x + (x + 1)**2
expanded: x**2 + 1
free symbols: {x}
at x = 3: 10

Properties

final int hashCode
argsgetter
List<Expr> get args

The child expressions (empty for atoms).

isAtomgetter
bool get isAtom
Set<Sym> get freeSymbols

The symbols occurring in this expression (bound variables of Derivative included).

preordergetter
Iterable<Expr> get preorder

All subtrees, pre-order.

bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger
bool? get isNonNegative
bool? get isNonPositive
bool get isRationalNumber

A rational number with no symbols.

bool get isConstant

No free symbols (numbers, constants, functions of those).

Methods

rebuildmethod
Expr rebuild(List<Expr> args)

Rebuilds this node from new args, re-running the automatic simplification.

Example
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]));
}
Output
sin(y)
powmethod
Expr pow(Object e)

this ^ e.

Example
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')));
}
Output
x**3
sqrt(x + 1)
hasmethod
bool has(Expr sub)

Whether sub occurs as a subtree.

Example
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)}');
}
Output
true, false
hasWheremethod
bool hasWhere(bool Function(Expr) test)

Whether any subtree satisfies test.

Example
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));
}
Output
true
isFreeOfmethod
bool isFreeOf(Iterable<Expr> syms)

Whether this expression is free of every symbol in syms.

Example
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])}');
}
Output
true
subsmethod
Expr subs(Map<Expr, Object> map)

Simultaneous structural substitution: every subtree equal to a key is replaced by its value.

Example
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')}));
}
Output
z + 9
transformmethod
Expr transform(Expr Function(Expr) f)

Rebuilds bottom-up applying f to every node (after its children).

Example
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));
}
Output
sin(2*x) + sin(2*y)
(Expr, Expr) asCoeffMul()

(c, rest) with this == c * rest and c the numeric coefficient (a Num or Flt).

Example
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());
}
Output
(3, x*y)
(Expr, Expr) asCoeffAdd()

(c, rest) with this == c + rest and c the numeric constant term.

Example
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());
}
Output
(5, x)
asBaseExpmethod
(Expr, Expr) asBaseExp()

(base, exponent).

Example
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());
}
Output
(x, 3)
(Expr, Expr) asNumerDenom()

The expression as a numerator and denominator (x/y -> (x, y)), without expanding.

Example
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());
}
Output
(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.

Example
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()}');
}
Output
true, false
diffmethod
Expr diff(Sym x, [int n = 1])

The n-th derivative with respect to x.

Example
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()}");
}
Output
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)}
expandmethod
Expr expand()

Distributes products over sums and expands integer powers of sums (multinomial).

Example
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()}');
}
Output
(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
evalfmethod
Expr evalf([int digits = 15])

Numeric value to digits significant decimal digits (symbols are left in place).

Example
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()}');
}
Output
3.141592653589793238462643383279502884197, 1.41421356237310
BigFloat toBigFloat({int prec = 53})

Numeric value as a real BigFloat with prec bits (throws if not real-numeric).

Example
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));
}
Output
2.7182818284590452353602874713526624979
toDoublemethod
double toDouble()

Numeric value as a double (throws if not real-numeric).

Example
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());
}
Output
4.555806215962888
toStringmethod
String toString()

SymPy-style plain text (x**2 + sin(y)/3).

toLatexmethod
String toLatex()

LaTeX in SymPy's latex style (x^{2} + \frac{\sin{\left(y \right)}}{3}).

Example
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()}');
}
Output from the Raya VM
∫ 1/(x² + 1) dx = atan(x)
LaTeX: \frac{\sqrt{x}}{x^{2} + 1}
sreprmethod
String srepr()

Tree form for debugging (Add(Pow(Symbol('x'), Integer(2)), …)).

Example
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());
}
Output
Add(Integer(1), Pow(Symbol('x'), Integer(2)))
compareTomethod
int compareTo(Expr other)
Example
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));
}
Output
-1

Operators

operator +operator
Expr operator +(Object o)
Example
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);
}
Output
2*x + 1
operator -operator
Expr operator -(Object o)
Example
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);
}
Output
0
operator *operator
Expr operator *(Object o)
Example
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);
}
Output
3*x**2
operator /operator
Expr operator /(Object o)
Example
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);
}
Output
y
operator -operator
Expr operator -()
Example
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));
}
Output
-x + y
operator ==operator
bool operator ==(Object other)
class

Add

final class Add extends Expr

A sum. Build with Add.of (or +), which flattens, collects numeric terms and combines like terms.

Example
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}');
}
Output
2*x + y, terms [y, 2*x]

Static

ofstaticmethod
static Expr of(Iterable<Expr> input)
Example
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]));
}
Output
2

Properties

argsfield
final List<Expr> args
bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger

Methods

rebuildmethod
Expr rebuild(List<Expr> args)
Example
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]));
}
Output
2*x
(Expr, Expr) asCoeffAdd()
Example
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());
}
Output
(3, x)
bool couldExtractMinusSign()
Example
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());
}
Output
true
class

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.

Example
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)]));
}
Output
3*x**2

Static

factoredstaticmethod
static Expr factored(Iterable<Expr> input)

Like of but keeps c * (a + b) as a product instead of distributing (used for factored output).

Example
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]));
}
Output
(x + 1)**2
ofstaticmethod
static Expr of(Iterable<Expr> input, {bool distribute = true})
Example
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)}');
}
Output
2*x + 2, 2*(x + 1)

Properties

argsfield
final List<Expr> args
bool? get isPositive
bool? get isNegative
bool? get isNonNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger

Methods

rebuildmethod
Expr rebuild(List<Expr> args)
Example
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]));
}
Output
y**2
(Expr, Expr) asCoeffMul()
Example
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());
}
Output
(5, x)
(Expr, Expr) asNumerDenom()
Example
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());
}
Output
(x, y)
bool couldExtractMinusSign()
Example
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());
}
Output
true
class

Pow

final class Pow extends Expr

A power base ^ exp. Build with Pow.of (or Expr.pow).

Example
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)));
}
Output
x**5

Static

ofstaticmethod
static Expr of(Expr b, Expr e)
Example
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))}');
}
Output
2, 1

Properties

basefield
final Expr base
expfield
final Expr exp
argsgetter
List<Expr> get args
bool? get isPositive
bool? get isNegative
bool? get isNonNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger

Methods

rebuildmethod
Expr rebuild(List<Expr> args)
Example
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)]));
}
Output
y**3
asBaseExpmethod
(Expr, Expr) asBaseExp()
Example
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());
}
Output
(x, 5)
class

Num

final class Num extends Expr

An exact rational number (SymPy's Integer / Rational).

Example
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));
}
Output
1/2

Constructors

Numconstructor
Num(this.value)
Example
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)));
}
Output
22/7
Num.int_factory
factory Num.int_(int i)
Example
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);
}
Output
42*x
Num.fracfactory
factory Num.frac(int p, int q)

p / q.

Example
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));
}
Output
3/4

Static

zerostaticfield
static final Num zero
onestaticfield
static final Num one
twostaticfield
static final Num two
negOnestaticfield
static final Num negOne
halfstaticfield
static final Num half

Properties

valuefield
final Rational value
isIntgetter
bool get isInt
numergetter
BigInt get numer
denomgetter
BigInt get denom
intValuegetter
int get intValue

The value as an int (throws when not a machine integer).

bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger
bool get isRationalNumber

Methods

bool couldExtractMinusSign()
Example
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());
}
Output
true
(Expr, Expr) asCoeffMul()
Example
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());
}
Output
(5, 1)
(Expr, Expr) asCoeffAdd()
Example
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());
}
Output
(5, 0)
(Expr, Expr) asNumerDenom()
Example
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());
}
Output
(3, 7)
class

Flt

final class Flt extends Expr

An arbitrary-precision binary floating-point number (SymPy's Float).

Example
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));
}
Output
1.10000000000000

Constructors

Fltconstructor
Flt(this.value)
Example
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')));
}
Output
2.50000000000000

Properties

valuefield
final BigFloat value
bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal

Methods

bool couldExtractMinusSign()
Example
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());
}
Output
true
(Expr, Expr) asCoeffMul()
Example
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());
}
Output
(2.50000000000000, 1)
(Expr, Expr) asCoeffAdd()
Example
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());
}
Output
(2.50000000000000, 0)
class

Sym

final class Sym extends Expr

A symbol with optional assumptions. Two symbols are equal when their names and assumptions agree.

Example
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)}');
}
Output
f = x**2*y + sin(x), ∂f/∂x = 2*x*y + cos(x), ∂f/∂y = x**2

Constructors

Symconstructor
Sym(this.name, {bool positive = false, bool real = false, bool integer = false, bool nonnegative = false})
Example
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))}');
}
Output
√(a²) = a, √(x²) = sqrt(x**2)

Properties

namefield
final String name
bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger
bool? get isNonNegative
enum ConstKind

Values

pivalue
pi
ivalue
i
oovalue
oo
zoovalue
zoo
nanvalue
nan
eulerGamma
class

Const

final class Const extends Expr

The named constants \pi, i, \infty, complex infinity, NaN and Euler's \gamma. E is exp(1).

Example
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)}');
}
Output
pi, E, 3.1415926535897932385

Static

pistaticfield
static final Const pi
istaticfield
static final Const i
oostaticfield
static final Const oo
zoostaticfield
static final Const zoo
nanstaticfield
static final Const nan
eulerGammastaticfield
static final Const eulerGamma

Properties

kindfield
final ConstKind kind
bool? get isPositive
bool? get isNegative
isZerogetter
bool? get isZero
isRealgetter
bool? get isReal
isIntegergetter
bool? get isInteger
final class Derivative extends Expr

An unevaluated derivative of expr with respect to vars (a multiset, sorted), used for undefined functions.

Example
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]));
}
Output
Derivative(f(x), (x, 2))

Constructors

factory Derivative.of(Expr expr, List<Sym> vars)

d^n expr / d vars, evaluating when possible.

Example
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]));
}
Output
Derivative(f(x, y), x, y)

Properties

exprfield
final Expr expr
varsfield
final List<Sym> vars
argsgetter
List<Expr> get args

Methods

rebuildmethod
Expr rebuild(List<Expr> args)
Example
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]));
}
Output
Derivative(f(y), y)
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.

Example
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));
}
Output
Derivative(g(x), x)

Constructors

factory FunctionDef.undefined(String name)

An uninterpreted function name(args…) (f(x)), cached by name.

Example
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]));
}
Output
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.

Example
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])}');
}
Output
49, sq(x)

Properties

namefield
final String name
nargsfield
final int? nargs

Number of arguments, or null for any.

evalfield
final Expr? Function(List<Expr> args)? eval

Automatic simplification: returns the simplified value or null to keep name(args).

final List<Expr?> Function(List<Expr> args)? partials

Partial derivatives with respect to each argument (null entries are not differentiable symbolically).

numericfield
final double Function(List<double> args)? numeric

A double-precision value for custom functions (built-ins evaluate at any precision in evalf).

final bool isUndefined

Methods

callmethod
Expr call(List<Object> args)

Applies the function: f.call([x]).

Example
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)]));
}
Output
f(x, 2)
toStringmethod
String toString()
class

Fn

final class Fn extends Expr

A function application f(args…).

Example
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]));
}
Output
f(x)

Static

ofstaticmethod
static Expr of(FunctionDef def, List<Expr> args)
Example
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));
}
Output
Derivative(f(x + 1), x)

Properties

deffield
final FunctionDef def
argsfield
final List<Expr> args
namegetter
String get name
isRealgetter
bool? get isReal
bool? get isPositive
bool? get isNegative
bool? get isNonNegative
isZerogetter
bool? get isZero
isIntegergetter
bool? get isInteger

Methods

rebuildmethod
Expr rebuild(List<Expr> args)
Example
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]));
}
Output
sin(y)
abstract final class Functions

The built-in functions.

Static

expstaticfield
static final FunctionDef exp
logstaticfield
static final FunctionDef log
sinstaticfield
static final FunctionDef sin
cosstaticfield
static final FunctionDef cos
tanstaticfield
static final FunctionDef tan
cotstaticfield
static final FunctionDef cot
secstaticfield
static final FunctionDef sec
cscstaticfield
static final FunctionDef csc
asinstaticfield
static final FunctionDef asin
acosstaticfield
static final FunctionDef acos
atanstaticfield
static final FunctionDef atan
acotstaticfield
static final FunctionDef acot
sinhstaticfield
static final FunctionDef sinh
coshstaticfield
static final FunctionDef cosh
tanhstaticfield
static final FunctionDef tanh
cothstaticfield
static final FunctionDef coth
asinhstaticfield
static final FunctionDef asinh
acoshstaticfield
static final FunctionDef acosh
atanhstaticfield
static final FunctionDef atanh
absstaticfield
static final FunctionDef abs
signstaticfield
static final FunctionDef sign
restaticfield
static final FunctionDef re
imstaticfield
static final FunctionDef im
conjugatestaticfield
static final FunctionDef conjugate
gammastaticfield
static final FunctionDef gamma
polygammastaticfield
static final FunctionDef polygamma
erfstaticfield
static final FunctionDef erf
erfcstaticfield
static final FunctionDef erfc
factorialstaticfield
static final FunctionDef factorial
binomialstaticfield
static final FunctionDef binomial
legendrestaticfield
static final FunctionDef legendre
assocLegendrestaticfield
static final FunctionDef assocLegendre
laguerrestaticfield
static final FunctionDef laguerre
assocLaguerrestaticfield
static final FunctionDef assocLaguerre
hermitestaticfield
static final FunctionDef hermite
ynmstaticfield
static final FunctionDef ynm
zetastaticfield
static final FunctionDef zeta

The Riemann zeta function (exact at even positive and all non-positive integers).

integralstaticfield
static final FunctionDef integral

An unevaluated integral Integral(f, x) (or Integral(f, x, a, b)); \frac{d}{dx} \operatorname{Integral}(f, x) = f.

orderstaticfield
static final FunctionDef order

The order term O(x**n) of a truncated series.

byNamestaticfield
static final Map<String, FunctionDef> byName

Every built-in by name (the parser and printers use this).

final class PolynomialError implements Exception

The expression is not a polynomial in the requested generators.

Example
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}');
  }
}
Output
PolynomialError: sin(x) is not a polynomial term in [x]

Constructors

PolynomialErrorconstructor
PolynomialError(this.message)
Example
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);
}
Output
not a polynomial

Properties

messagefield
final String message

Methods

toStringmethod
String toString()
class

Domain

abstract class Domain<T>

A commutative coefficient ring (an integral domain; a field when isField).

Example
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)}');
}
Output
QQ: a + b = 11/12, a·b = 1/8, gcd 1

Constructors

Domainconstructor
const Domain()

Properties

zerogetter
T get zero
onegetter
T get one
isFieldgetter
bool get isField
int get characteristic

Characteristic (0 for ZZ and QQ).

Methods

addmethod
T add(T a, T b)
Example
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()})');
}
Output
add: 11/12  (a = 3/4, b = 1/6 in QQ)
submethod
T sub(T a, T b)
Example
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()})');
}
Output
sub: 7/12  (a = 3/4, b = 1/6 in QQ)
mulmethod
T mul(T a, T b)
Example
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()})');
}
Output
mul: 1/8  (a = 3/4, b = 1/6 in QQ)
negmethod
T neg(T a)
Example
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()})');
}
Output
neg: -3/4  (a = 3/4, b = 1/6 in QQ)
isZeromethod
bool isZero(T a)
Example
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()})');
}
Output
isZero: true  (a = 3/4, b = 1/6 in QQ)
isOnemethod
bool isOne(T a)
Example
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()})');
}
Output
isOne: true  (a = 3/4, b = 1/6 in QQ)
fromIntmethod
T fromInt(int n)
Example
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()})');
}
Output
fromInt: -3  (a = 3/4, b = 1/6 in QQ)
exquomethod
T? exquo(T a, T b)

A / b when b divides a exactly, else null.

Example
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()})');
}
Output
exquo: 3/4  (a = 3/4, b = 1/6 in QQ)
invmethod
T inv(T a)

The inverse (fields only).

Example
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()})');
}
Output
inv: 6  (a = 3/4, b = 1/6 in QQ)
divmethod
T div(T a, T b)
Example
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()})');
}
Output
div: 9/2  (a = 3/4, b = 1/6 in QQ)
gcdmethod
T gcd(T a, T b)

Gcd of two elements (1 in a field unless both are zero).

Example
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()})');
}
Output
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)).

Example
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()})');
}
Output
isNegative: true  (a = 3/4, b = 1/6 in QQ)
toExprmethod
Expr toExpr(T a)
Example
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()})');
}
Output
toExpr: 3/4  (a = 3/4, b = 1/6 in QQ)
T? fromRational(Rational r)

Converts an exact number, or null.

Example
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()})');
}
Output
fromRational: 1/2  (a = 3/4, b = 1/6 in QQ)
namemethod
String name()
Example
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()})');
}
Output
name: QQ  (a = 3/4, b = 1/6 in QQ)
toStringmethod
String toString()
final class IntegerRing extends Domain<BigInt>
Example
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)}');
}
Output
ZZ: a + b = 30, a·b = 216, gcd 6

Constructors

IntegerRingconstructor
const IntegerRing()
Example
import 'package:riptide_cas/riptide_cas.ray';

void main() {
  final d = const IntegerRing();
  print(d.name());
}
Output
ZZ

Properties

zerogetter
BigInt get zero
onegetter
BigInt get one
isFieldgetter
bool get isField

Methods

addmethod
BigInt add(BigInt a, BigInt b)
Example
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()})');
}
Output
add: 30  (a = 12, b = 18 in ZZ)
submethod
BigInt sub(BigInt a, BigInt b)
Example
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()})');
}
Output
sub: -6  (a = 12, b = 18 in ZZ)
mulmethod
BigInt mul(BigInt a, BigInt b)
Example
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()})');
}
Output
mul: 216  (a = 12, b = 18 in ZZ)
negmethod
BigInt neg(BigInt a)
Example
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()})');
}
Output
neg: -12  (a = 12, b = 18 in ZZ)
isZeromethod
bool isZero(BigInt a)
Example
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()})');
}
Output
isZero: true  (a = 12, b = 18 in ZZ)
fromIntmethod
BigInt fromInt(int n)
Example
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()})');
}
Output
fromInt: -3  (a = 12, b = 18 in ZZ)
exquomethod
BigInt? exquo(BigInt a, BigInt b)
Example
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()})');
}
Output
exquo: 12  (a = 12, b = 18 in ZZ)
invmethod
BigInt inv(BigInt a)
Example
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()})');
}
Output
inv: -1  (a = 12, b = 18 in ZZ)
gcdmethod
BigInt gcd(BigInt a, BigInt b)
Example
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()})');
}
Output
gcd: 6  (a = 12, b = 18 in ZZ)
bool isNegative(BigInt a)
Example
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()})');
}
Output
isNegative: true  (a = 12, b = 18 in ZZ)
toExprmethod
Expr toExpr(BigInt a)
Example
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()})');
}
Output
toExpr: 12  (a = 12, b = 18 in ZZ)
BigInt? fromRational(Rational r)
Example
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()})');
}
Output
fromRational: null  (a = 12, b = 18 in ZZ)
namemethod
String name()
Example
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()})');
}
Output
name: ZZ  (a = 12, b = 18 in ZZ)
final class RationalField extends Domain<Rational>
Example
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)}');
}
Output
QQ: a + b = 11/12, a·b = 1/8, gcd 1

Constructors

RationalFieldconstructor
const RationalField()
Example
import 'package:riptide_cas/riptide_cas.ray';

void main() {
  final d = const RationalField();
  print(d.name());
}
Output
QQ

Properties

zerogetter
Rational get zero
onegetter
Rational get one
isFieldgetter
bool get isField

Methods

addmethod
Rational add(Rational a, Rational b)
Example
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()})');
}
Output
add: 11/12  (a = 3/4, b = 1/6 in QQ)
submethod
Rational sub(Rational a, Rational b)
Example
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()})');
}
Output
sub: 7/12  (a = 3/4, b = 1/6 in QQ)
mulmethod
Rational mul(Rational a, Rational b)
Example
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()})');
}
Output
mul: 1/8  (a = 3/4, b = 1/6 in QQ)
negmethod
Rational neg(Rational a)
Example
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()})');
}
Output
neg: -3/4  (a = 3/4, b = 1/6 in QQ)
isZeromethod
bool isZero(Rational a)
Example
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()})');
}
Output
isZero: true  (a = 3/4, b = 1/6 in QQ)
fromIntmethod
Rational fromInt(int n)
Example
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()})');
}
Output
fromInt: -3  (a = 3/4, b = 1/6 in QQ)
exquomethod
Rational? exquo(Rational a, Rational b)
Example
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()})');
}
Output
exquo: 3/4  (a = 3/4, b = 1/6 in QQ)
invmethod
Rational inv(Rational a)
Example
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()})');
}
Output
inv: 6  (a = 3/4, b = 1/6 in QQ)
divmethod
Rational div(Rational a, Rational b)
Example
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()})');
}
Output
div: 9/2  (a = 3/4, b = 1/6 in QQ)
gcdmethod
Rational gcd(Rational a, Rational b)
Example
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()})');
}
Output
gcd: 1  (a = 3/4, b = 1/6 in QQ)
bool isNegative(Rational a)
Example
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()})');
}
Output
isNegative: true  (a = 3/4, b = 1/6 in QQ)
toExprmethod
Expr toExpr(Rational a)
Example
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()})');
}
Output
toExpr: 3/4  (a = 3/4, b = 1/6 in QQ)
Rational? fromRational(Rational r)
Example
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()})');
}
Output
fromRational: 1/2  (a = 3/4, b = 1/6 in QQ)
namemethod
String name()
Example
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()})');
}
Output
name: QQ  (a = 3/4, b = 1/6 in QQ)
final class PrimeField extends Domain<int>

The prime field GF(p) on machine ints (p < 2^{26} keeps products exact on every platform).

Example
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)}');
}
Output
GF(7): a + b = 1, a·b = 1, gcd 1

Constructors

PrimeFieldconstructor
const PrimeField(this.p)
Example
import 'package:riptide_cas/riptide_cas.ray';

void main() {
  final d = const PrimeField(7);
  print(d.name());
}
Output
GF(7)

Properties

pfield
final int p
zerogetter
int get zero
onegetter
int get one
isFieldgetter
bool get isField
int get characteristic
hashCodegetter
int get hashCode

Methods

addmethod
int add(int a, int b)
Example
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()})');
}
Output
add: 1  (a = 5, b = 3 in GF(7))
submethod
int sub(int a, int b)
Example
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()})');
}
Output
sub: 2  (a = 5, b = 3 in GF(7))
mulmethod
int mul(int a, int b)
Example
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()})');
}
Output
mul: 1  (a = 5, b = 3 in GF(7))
negmethod
int neg(int a)
Example
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()})');
}
Output
neg: 2  (a = 5, b = 3 in GF(7))
isZeromethod
bool isZero(int a)
Example
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()})');
}
Output
isZero: true  (a = 5, b = 3 in GF(7))
fromIntmethod
int fromInt(int n)
Example
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()})');
}
Output
fromInt: 4  (a = 5, b = 3 in GF(7))
exquomethod
int? exquo(int a, int b)
Example
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()})');
}
Output
exquo: 5  (a = 5, b = 3 in GF(7))
invmethod
int inv(int a)
Example
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()})');
}
Output
inv: 5  (a = 5, b = 3 in GF(7))
gcdmethod
int gcd(int a, int b)
Example
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()})');
}
Output
gcd: 1  (a = 5, b = 3 in GF(7))
toExprmethod
Expr toExpr(int a)
Example
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()})');
}
Output
toExpr: -2  (a = 5, b = 3 in GF(7))
int? fromRational(Rational r)
Example
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()})');
}
Output
fromRational: 4  (a = 5, b = 3 in GF(7))
namemethod
String name()
Example
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()})');
}
Output
name: GF(7)  (a = 5, b = 3 in GF(7))

Operators

operator ==operator
bool operator ==(Object other)
enum GroebnerMethod

Values

buchberger
f4value
f4
class

Mono

final class Mono

An exponent vector, immutable, with cached hash and total degree.

Example
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]}');
}
Output
x²y as an exponent vector: [2, 1], exponent of y 1

Constructors

Monoconstructor
Mono(List<int> e)
Example
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]));
}
Output
[3, 0, 1]
Mono.zerofactory
factory Mono.zero(int n)
Example
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));
}
Output
[0, 0, 0]

Properties

efield
final List<int> e
degfield
final int deg
final int hashCode
lengthgetter
int get length
isOnegetter
bool get isOne

Methods

dividesmethod
bool divides(Mono o)
Example
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]))}');
}
Output
true, false
lcmmethod
Mono lcm(Mono o)
Example
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])));
}
Output
[2, 3]
gcdmethod
Mono gcd(Mono o)
Example
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])));
}
Output
[1, 3]
toStringmethod
String toString()

Operators

operator []operator
int operator [](int i)
Example
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]);
}
Output
7
operator *operator
Mono operator *(Mono o)
Example
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]));
}
Output
[4, 2]
operator /operator
Mono operator /(Mono o)

This / o (assumes o divides this).

Example
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]));
}
Output
[2, 1]
operator ==operator
bool operator ==(Object other)
enum MonoOrder

Monomial orders. compare(a, b) > 0 when a is greater.

Values

lexvalue
lex
grlexvalue
grlex
grevlexvalue
grevlex

Methods

comparemethod
int compare(Mono a, Mono b)
Example
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)}');
}
Output
MonoOrder.lex: compare(xy², x²) = -1
MonoOrder.grlex: compare(xy², x²) = 1
MonoOrder.grevlex: compare(xy², x²) = 1
final class PolyRing<T>

A polynomial ring domain[gens] with a monomial order.

Example
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)}');
}
Output
ℚ[x, y]: x*y + 3

Constructors

PolyRingconstructor
PolyRing(this.domain, List<Expr> gens, {this.order = MonoOrder.lex})
Example
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));
}
Output
x**3 + 3*x**2 + 3*x + 1

Properties

domainfield
final Domain<T> domain
gensfield
final List<Expr> gens
orderfield
final MonoOrder order
ngetter
int get n
one_field
late final Mono one_
zerofield
late final MPoly<T> zero
onefield
late final MPoly<T> one

Methods

constantmethod
MPoly<T> constant(T c)
Example
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)));
}
Output
5/2
fromIntmethod
MPoly<T> fromInt(int c)
Example
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));
}
Output
-4
genmethod
MPoly<T> gen(int i)

The i-th generator.

Example
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)}');
}
Output
x, y
termmethod
MPoly<T> term(Mono m, T c)
Example
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)));
}
Output
-7*x**2*y**3
fromMapmethod
MPoly<T> fromMap(Map<Mono, T> terms)

From a monomial -> coefficient map (zeros dropped).

Example
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)}));
}
Output
x + 3*y**2
withOrdermethod
PolyRing<T> withOrder(MonoOrder o)
Example
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());
}
Output
x + y**3
PolyRing<S> withDomain<S>(Domain<S> d)
Example
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));
}
Output
x**7 + 1
toStringmethod
String toString()
class

MPoly

final class MPoly<T>

A polynomial: terms sorted by decreasing monomial (in the ring's order), no zero coefficients.

Example
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()}');
}
Output
x**2 + 2*x*y + y**2, as an expression x**2 + 2*x*y + y**2

Properties

ringfield
final PolyRing<T> ring
monosfield
final List<Mono> monos
coeffsfield
final List<T> coeffs
isZerogetter
bool get isZero
bool get isConstant
isOnegetter
bool get isOne
lengthgetter
int get length
lmgetter
Mono get lm
lcgetter
T get lc
ltgetter
MPoly<T> get lt
T get constantTerm

The constant coefficient (zero if none).

int get totalDegree
variablesgetter
Set<int> get variables

Indices of the generators that occur.

hashCodegetter
int get hashCode

Methods

toMapmethod
Map<Mono, T> toMap()
Example
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());
}
Output
{[2, 1]: 3, [0, 1]: -1}
degreemethod
int degree(int i)
Example
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)}');
}
Output
3, 5
mulTermmethod
MPoly<T> mulTerm(Mono m, T c)

This * c \cdot m.

Example
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)));
}
Output
3*x*y**2 + 3*y**2
scalemethod
MPoly<T> scale(T c)
Example
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)));
}
Output
x/2 + y/2
powmethod
MPoly<T> pow(int k)
Example
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());
}
Output
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).

Example
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)));
}
Output
3*x + 2*y
monicmethod
MPoly<T> monic()

Monic (fields only).

Example
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());
}
Output
x**2 + 2*y
contentmethod
T content()

Gcd of the coefficients (for ZZ; 1 over a field).

Example
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());
}
Output
2
primitivemethod
MPoly<T> primitive()

This divided by its content (positive leading coefficient over ZZ, monic over a field).

Example
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());
}
Output
3*x + 2*y
exquomethod
MPoly<T>? exquo(MPoly<T> g)

Exact quotient this / g, or null when g does not divide this.

Example
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'))}');
}
Output
x + y, null
remmethod
MPoly<T> rem(List<MPoly<T>> gs)

Full reduction (normal form) modulo gs by the multivariate division algorithm (fields).

Example
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')]));
}
Output
x + 1
divmodmethod
(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).

Example
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');
}
Output
q = [x**2 + x*y + y**2], r = y**3 + y
diffmethod
MPoly<T> diff(int i)

Partial derivative with respect to generator i.

Example
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));
}
Output
3*x**2*y**2
composemethod
MPoly<T> compose(int i, MPoly<T> v)

Substitutes the polynomial v for generator i.

Example
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());
}
Output
y**2 + 3*y + 1
evaluatemethod
MPoly<T> evaluate(int i, T c)

Substitutes the constant c for generator i.

Example
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)));
}
Output
y + 9
Map<int, MPoly<T>> coefficientsIn(int i)

Coefficients with respect to generator i: degree -> coefficient (a polynomial free of x_{i}).

Example
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));
}
Output
{2: y, 1: y**2, 0: 3}
lcInmethod
MPoly<T> lcIn(int i)

Leading coefficient with respect to generator i (a polynomial free of x_{i}).

Example
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));
}
Output
2*y + 1
shiftmethod
MPoly<T> shift(int i, int k)

Multiplies by x_{i}^{k}.

Example
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());
}
Output
x**3
mapCoeffsmethod
MPoly<S> mapCoeffs<S>(PolyRing<S> to, S Function(T) f)

Maps coefficients into another ring with the same generators.

Example
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));
}
Output
x + y
reordermethod
MPoly<T> reorder(PolyRing<T> to)

The same polynomial in a ring with another order.

Example
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])));
}
Output
x + y**2
toExprmethod
Expr toExpr()
Example
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));
}
Output
2*x - 2*y
toStringmethod
String toString()

Operators

operator +operator
MPoly<T> operator +(MPoly<T> o)
Example
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'));
}
Output
x + y
operator -operator
MPoly<T> operator -(MPoly<T> o)
Example
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'));
}
Output
y
operator -operator
MPoly<T> operator -()
Example
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'));
}
Output
-x + y
operator *operator
MPoly<T> operator *(MPoly<T> o)
Example
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());
}
Output
x**2 - y**2
operator ==operator
bool operator ==(Object other)
final class LimitError implements Exception
Example
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);
}
Output
no limit

Constructors

LimitErrorconstructor
LimitError(this.message)
Example
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);
}
Output
oscillates

Properties

messagefield
final String message

Methods

toStringmethod
String toString()
final class SeriesError implements Exception

Thrown when an expansion does not exist in this framework (essential singularity, oscillation...).

Example
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);
}
Output
essential singularity

Constructors

SeriesErrorconstructor
SeriesError(this.message)
Example
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);
}
Output
demo

Properties

messagefield
final String message

Methods

toStringmethod
String toString()
class

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).

Example
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));
}
Output
x - x**3/6 + x**5/120 - x**7/5040 + O(x**8)

Constructors

PSeriesconstructor
PSeries(Map<Rational, Expr> terms, this.order)
Example
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));
}
Output
1 - x + O(x**3)
factory PSeries.constant(Expr c, Rational order)
Example
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));
}
Output
7 + O(x**4)

Static

composestaticmethod
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}.

Example
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));
}
Output
1 + x + x**2/2 - x**4/8 - x**5/15 + O(x**6)

Properties

termsfield
final Map<Rational, Expr> terms
orderfield
final Rational order
isZerogetter
bool get isZero
valuationgetter
Rational get valuation

Lowest exponent present (the valuation), or order when zero to this order.

Methods

coeffmethod
Expr coeff(Rational k)
Example
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)));
}
Output
1/120
scalemethod
PSeries scale(Expr c)
Example
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));
}
Output
2 + 2*x + x**2 + x**3/3 + O(x**4)
shiftmethod
PSeries shift(Rational r)

Multiplies by x^{r}.

Example
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));
}
Output
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.

Example
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());
}
Output
(1, 2, PSeries({1: 1, 2: 1/2}, O(3)))
toExprmethod
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).

Example
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)}');
}
Output
1 - x**2/2 + x**4/24 - x**6/720 + O(x**7)  |  -x**6/720 + x**4/24 - x**2/2 + 1
toStringmethod
String toString()

Operators

operator +operator
PSeries operator +(PSeries o)
Example
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));
}
Output
1 + x - x**2/2 - x**3/6 + x**4/24 + x**5/120 + O(x**6)
operator -operator
PSeries operator -()
Example
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));
}
Output
-x + x**3/6 - x**5/120 + O(x**6)
operator -operator
PSeries operator -(PSeries o)
Example
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));
}
Output
x + x**2 + x**3/6 + O(x**5)
operator *operator
PSeries operator *(PSeries o)
Example
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));
}
Output
x - 2*x**3/3 + 2*x**5/15 + O(x**7)