evaluate_sage
Run arbitrary SageMath code in a persistent session for tasks without a dedicated tool. Variables persist across calls for multi-step computations.
Instructions
Run arbitrary SageMath code in a persistent session; variables persist across calls.
LAST RESORT. A dedicated tool exists for most tasks and should be preferred: it validates arguments and returns a typed result instead of a repr string. Reach for one of these first:
calculus: differentiate_expression, integrate_expression, limit_expression, series_expansion, symbolic_sum, solve_ode
algebra: solve_equation, simplify_expression, expand_expression, factor_expression, find_root
linear algebra: matrix_operation (determinant, inverse, eigenvalues, rank, rref, transpose), matrix_multiply
discrete: number_theory_operation, combinatorics_operation (binomial, partitions, catalan, fibonacci, bell), graph_operation, group_operation
specialised: elliptic_curve_operation, coding_theory_operation, polynomial_ring_operation, boolean_algebra_operation, geometry_operation, vector_calculus_operation
data: statistics_summary, distribution_operation
plots: plot_expression, plot3d_expression, plot_multi_expression
Use evaluate_sage only for what those do not cover, for example:
Transforms: var('t s'); laplace(sin(t), t, s); inverse_laplace(1/(s^2+1), s, t) Modular arithmetic: Mod(17, 5); power_mod(3, 100, 97) Recurrences: var('n'); f = function('f'); desolve_rec(f(n+2)-f(n+1)-f(n), f, [0, 1]) Continued fractions: continued_fraction(pi).convergents()[:10] Number fields: K. = NumberField(x^3 - 2); K.class_number() Multi-step work that builds on values defined earlier in the same session.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | SageMath code to execute | |
| session | No | Named workspace to use. Workspaces have independent variables; omit for 'default'. | default |
| 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 |