evaluate_sage
Execute arbitrary SageMath code for any mathematical computation, including algebra, calculus, number theory, and graph theory, with state persisting between calls.
Instructions
Execute arbitrary SageMath code within a persistent session. Variables and definitions persist across calls. Use this for any computation not covered by the specialized helpers. Examples by domain:
Combinatorics: binomial(10, 3); Permutations(4).cardinality(); Combinations([1,2,3,4], 2).list() Graph theory: G = graphs.PetersenGraph(); G.chromatic_number() Number theory: prime_range(100); euler_phi(60); continued_fraction(pi, nterms=10) Geometry: polytopes.cube().volume(); EllipticCurve([0,0,1,-1,0]).rank() Probability: RealDistribution('gaussian', 1).cum_distribution_function(1.96) Group theory: SymmetricGroup(5).order(); AlternatingGroup(4).is_abelian() Polynomial rings: R.<a,b> = PolynomialRing(QQ); (a+b)^3 Coding theory: codes.HammingCode(GF(2), 3).minimum_distance() Symbolic sums: var('n'); sum(1/n^2, n, 1, oo) Transforms: laplace(sin(t), t, s); inverse_laplace(1/(s^2+1), s, t) Modular arithmetic: Mod(17, 5); power_mod(3, 100, 97) Vector calculus: var('x y z'); f = x^2+y^2+z^2; diff(f,x), diff(f,y), diff(f,z) Numeric root finding: find_root(x - cos(x), 0, 1) Recurrences: desolve_rsolve(f(n+2)-f(n+1)-f(n), f, [0, 1])
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | SageMath code to execute | |
| timeout | No | Override the evaluation timeout in seconds | |
| want_latex | No | Return LaTeX representation when possible | |
| capture_stdout | No | Capture stdout emitted by Sage code |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latex | No | LaTeX serialization of the result when requested and supported. | |
| result | No | String representation of the expression result if available. | |
| stdout | No | Captured stdout emitted during execution. | |
| elapsed_ms | Yes | Wall-clock execution time in milliseconds. | |
| result_type | Yes |