Skip to content

Expression Calculator (v2.2.0)

The expression canvas is the tab added in v2.2.0. It represents expressions, equations and points as draggable, clickable cards, colors formulas by expression-tree depth, and transforms or solves any sub-structure in place.

Open it via "Features → Expression Calculator". The source lives in expr_calculator/:

File Purpose
expr_tree.py Expression tree, LaTeX printer and SymPy conversion (no Qt dependency)
expr_viewer.py Canvas window, HTML/MathJax page and operation dialogs
../ui/expr.py Tab wrapper exposing retranslateUi for language switching

Quick start

  1. Type 2*(x+1) + 1/(x-1) in the top input box and press Enter or click Add; the expression becomes a card;
  2. Click any node in the formula (glyph, operator, fraction bar, parenthesized area) to select it;
  3. Click Transform at the lower right of the selection;
  4. Drag the red circle at a card's upper left to move the card.

Parsing uses evaluate=False, so input order and parentheses are preserved (2*(x+1) is not expanded).

Input support

Input Result
x^2=4, x=y Equation card (Eq node), solvable and usable in systems
(a, b) Point card (coordinates may be numbers or expressions with parameters)
sin(x), ln(x), sqrt(x) Function nodes
2x, 2(x+1) Implicit multiplication

Node-level operations

Operation How
Select a node Click it in the formula; hovering shows a light grey background
Swap adjacent terms Click + / −, or the "⇄ Swap" badge
Expand parentheses Click the parentheses, or the "⤢ Expand" badge
Drag a node Handle at the upper left of the selection; drop on empty canvas to create a card, drop on a card to open the operation dialog
Transform "Transform" at the lower right of the selection

The "Transform" dialog offers 8 SymPy transforms (simplify / expand / factor / cancel / together / apart / trigsimp / radsimp) and 9 node operations (replace, append, multiply, reciprocal, divide, square, square root, power, substitution). The result can overwrite the original or be saved as a copy.

Tip

Choose "Substitution" and fill in a symbol (e.g. t) and an expression (e.g. x+1, i.e. t = x+1). The program solves x = t-1, replaces every x in the card and expands the result.

Common equations and parameter derivation

"Add common equation" supports circle, line, ellipse, hyperbola and parabola templates:

  • Enter parameters: a blank field keeps its symbol (an all-blank circle gives (x−a)²+(y−b)²=r²);
  • Create from conditions: conditions such as through point / parameter relation / slope / intercept / line through the center / radius / eccentricity / axis length / focal distance / directrix / focus are solved jointly — each solution set produces a card.

Example

Center on x=1, radius 2 → (x−1)²+(y−b)²=4 (b is still free)
Ellipse with eccentricity 1/2 and major axis 6 → x²/9+4y²/27=1
Hyperbola with transverse axis 6 and focal distance 10 → x²/9−y²/16=1

Geometric expressions

Quantity Produces
Point-line distance Expression card
Intersection of two lines Point card
Midpoint of the intersection segment Point card
Triangle area (three points / line + conic + point) Expression card

Points, lines and curves can be picked from existing cards or typed directly ((2, 3), y=x+1, x^2/9+y^2/4=1). Results are ordinary cards and can take part in further transforms or geometric computations.

Solving equations and systems

  • Solve equation: select the equation root → "Transform" → choose the variable and domain (a SymPy set, Reals by default) → solve; each root becomes a card.
  • Systems: drag one equation card onto another and choose solve directly (tick free variables; "variable = root" cards are created) or Vieta's formulas (tick one main variable; cards for x₁+x₂, x₁·x₂, |x₁−x₂| and the discriminant).

Cards and canvas

  • Cards can be moved (overlaps are rejected), copied, deleted, folded (no node interaction while folded) and titled by double-clicking the title row;
  • The properties panel shows title, expression, variables and range;
  • Undo / Redo in the toolbar or Ctrl+Z / Ctrl+Y steps through whole-canvas snapshots;
  • The slider at the upper right scales the whole canvas font.

Languages

Every interface string of the Expression Calculator (toolbar, dialogs, status messages, canvas buttons and tooltips) is part of the Qt translation system, under the expr_calculator context. After switching the language in "Settings":

  • the canvas reloads its page in the new language;
  • existing cards are rebuilt at their original positions with titles, notes and folded state intact.

Adding new strings follows the same workflow as the main program; see Internationalization.

Rendering

Formulas are rendered by the bundled local MathJax (mathjax/es5/tex-svg.js) with no network access. The page references it through the relative path ../mathjax/, so do not move the mathjax directory on its own; setup.py copies both expr_calculator/ and mathjax/ into lib/ when packaging.