Algebrite for LiaScript: A Computer Algebra System in the Browser

Algebrite for LiaScript: A Computer Algebra System in the Browser

Symbolic computation is hard to teach without tools. Students write algebraic expressions, simplify them, differentiate, integrate — but verifying their work by hand is slow, and most CAS tools require software installations or paid subscriptions.

The Algebrite template brings Algebrite, a lightweight JavaScript Computer Algebra System, directly into LiaScript. It supports symbolic simplification, differentiation, integration, factoring, and more — entirely in the browser, with no server required.


Quick Start

<!--
import: https://raw.githubusercontent.com/LiaTemplates/Algebrite/master/README.md
-->

The core macro is @Algebrite.eval for computation and a family of @Algebrite.check* macros for quiz integration.


@Algebrite.eval — Evaluate CAS Expressions

Attach @Algebrite.eval to a Maxima-syntax code block to evaluate it. The result is shown below the block.

```Maxima
d(sin(x)^2, x)
```
@Algebrite.eval

The code block is editable — students can modify the expression and re-evaluate.


Quiz Integration — @Algebrite.check

@Algebrite.check(expected) compares the student’s input with the expected value using symbolic equality. Two expressions that are mathematically equivalent (like x^2-1 and (x-1)*(x+1)) are both accepted.

**Simplify $x^2 - 1$ as a product:**

[[x^2-1]]
@Algebrite.check(x^2-1)

Because the comparison is symbolic, students can enter (x-1)*(x+1), -1+x^2, or x^2-1 — all are marked correct.


@Algebrite.check2 — With Tolerance

For numerical answers that might involve rounding, @Algebrite.check2(lower, upper) accepts a tolerance range.

**Compute $\frac{1}{3}$ as a decimal (tolerance ±0.01):**

[[1/3]]
@Algebrite.check2(1/3, 0.01)

For multiple answers (e.g., a system of equations), use lists:

$x=$ [[ 2/5 ]] $\;\;\wedge\;\; y=$ [[ 5/7 ]]
@Algebrite.check2([ 2/5 ; 5/7 ], [0.01 ; 0.01])

@Algebrite.check_margin — Range Check

@Algebrite.check_margin(lower, upper) verifies that the input falls within a given interval. Useful for measurement and engineering tasks where a range of answers is correct.

**Estimate the speed in km/s (between 1.4 and 1.6):**

-> [[ 1.5 ]] km/s
@Algebrite.check_margin(1.4, 1.6)

@Algebrite.check_expression — Equation Equivalence

@Algebrite.check_expression(solution=0) checks whether the student’s equation is equivalent to the given solution.

**Factor and equate to zero:**

[[x^2 - 1 = (x-1)*(x+1)]]
@Algebrite.check_expression(x^2-1-(x-1)*(x+1)=0)

What Algebrite Supports

Algebrite implements a significant subset of the Maxima syntax:

  • Simplification: simplify(...), rationalize(...)
  • Calculus: d(expr, var) (derivative), integral(expr, var), defint(expr, var, a, b) (definite integral)
  • Algebra: factor(...), expand(...), roots(...), gcd(...), lcm(...)
  • Trigonometry: circexp(...), cos(...), sin(...), tan(...)
  • Linear algebra: det(...), inv(...), eigen(...)
  • Arithmetic: exact integer arithmetic, arbitrary-precision factorials

Full reference: algebrite.org/docs


Full Template Demo


Use Cases

Calculus courses — Teach differentiation and integration with live computation. Students type an expression, evaluate it, and compare their manual work with the CAS result.

Algebra exercises — Factoring, simplification, and polynomial arithmetic are all handled symbolically. The @Algebrite.check macro accepts any algebraically equivalent form.

Self-assessment with quizzes — Standard LiaScript text quizzes compare strings. @Algebrite.check compares mathematical meaning — students can write answers in any equivalent form.

Engineering and physics courses — Use @Algebrite.check_margin for numerical results where a tolerance range is appropriate.


Technical Facts

Runs in browserYes
Server requiredNo
CAS languageMaxima-compatible syntax
Quiz integrationYes — 4 check macros
Based onAlgebrite by Davide Della Casa
LicenseMIT
MaintainedYes (version 0.6.3)

Try It

Try in LiaScript Open in LiveEditor View on GitHub
  • GGBScript — GeoGebra-style geometry construction with a JavaScript API
  • JSXGraph — interactive function plots and geometry with a JS API
  • Pyodide — full Python in the browser, includes NumPy and SymPy for symbolic math
  • Vega — chart and data visualization for quantitative results

Related Posts

BiwaScheme for LiaScript: Functional Programming with Scheme in the Browser

Use the BiwaScheme template to run Scheme programs in your LiaScript courses — a complete Scheme interpreter in the browser, with an optional interactive REPL terminal.

Read More

Redis for LiaScript: Explore Key-Value Stores and Data Structures in the Browser

Use the Redis template to teach key-value stores, Redis data structures, TTL, transactions, and caching patterns — directly in your LiaScript courses, with no server needed.

Read More

Tau-Prolog for LiaScript: Interactive Logic Programming in the Browser

Use the Tau-Prolog template to run Prolog programs and queries interactively in your LiaScript courses — full logic programming in the browser, with quiz integration.

Read More