Held Commands
Held commands let you build and display mathematical expressions without evaluating them. This is useful for:
- Showing what computation will be performed before running it
- Educational presentations with proper mathematical notation
- Step-by-step mathematical exploration in notebooks
Basic Usage
using Giac
using Giac.Commands: hold_cmd, release
@giac_var x t s n z
# Hold a command (no execution occurs)
h = hold_cmd(:integrate, x^2, x)
# In notebooks: renders as ∫ x² dx
# Execute when ready
result = release(h)
# Returns: x³/3Specialized LaTeX Rendering
The following commands render with standard mathematical notation in LaTeX-capable environments (Jupyter, Pluto):
Integration
# Indefinite integral: ∫ f dx
hold_cmd(:integrate, sin(x), x)
# Definite integral: ∫₀¹ f dx
hold_cmd(:integrate, x^2, x, 0, 1)Differentiation (Leibniz notation)
# First derivative: d/dx f
hold_cmd(:diff, x^3, x)
# Higher-order: d²/dx² f
hold_cmd(:diff, x^3, x, 2)Laplace Transform
# Forward: ℒ{f}(s)
hold_cmd(:laplace, exp(-t), t, s)
# Inverse: ℒ⁻¹{F}(t)
hold_cmd(:invlaplace, 1/(s+1), s, t)
# Also works with :ilaplaceZ-Transform
# Forward: 𝒵{f}(z)
hold_cmd(:ztrans, n^2, n, z)
# Inverse: 𝒵⁻¹{F}(n)
hold_cmd(:invztrans, z/(z-1), z, n)Limits
# Basic limit: lim_{x→0} sin(x)/x
hold_cmd(:limit, sin(x)/x, x, 0)
# Limit at infinity: lim_{x→+∞} 1/x
hold_cmd(:limit, 1/x, x, Inf)
# One-sided limits (direction: 1 for right, -1 for left)
hold_cmd(:limit, sign(x), x, 0, 1) # lim_{x→0⁺}
hold_cmd(:limit, sign(x), x, 0, -1) # lim_{x→0⁻}Sums and Products
# Finite sum: Σ_{n=1}^{17} 1/n²
hold_cmd(:sum, 1/n^2, n, 1, 17)
# Infinite sum (Basel problem): Σ_{n=1}^{∞} 1/n²
hold_cmd(:sum, 1/n^2, n, 1, Inf)
# Product: Π_{k=1}^{n} k
hold_cmd(:product, k, k, 1, n)Riemann Sums
# Renders as: lim_{n→+∞} Σ_{k=0}^{n-1} 1/(n+k)
hold_cmd(:sum_riemann, 1/(n+k), [n, k])Generic Commands
Commands without specialized rendering use function-call notation:
hold_cmd(:factor, x^2 - 1) # Renders as: factor(x² - 1)
hold_cmd(:simplify, sin(x)^2) # Renders as: simplify(sin²(x))Hold-Display-Release Workflow
# Step 1: Build the expression
h = hold_cmd(:integrate, exp(-t) * sin(t), t)
# Step 2: Display it (automatic in notebooks)
display(h) # Shows: ∫ e⁻ᵗ sin(t) dt
# Step 3: Execute when ready
result = release(h) # Computes the integral
display(result) # Shows the evaluated resultEquation Display with ~
Held commands support the ~ (tilde) equation operator, enabling side-by-side display of unevaluated and evaluated forms:
using Giac
using Giac.Commands: hold_cmd, release, eigenvals
M = GiacMatrix([[1, 2], [3, 4]])
# Show "eigenvals([[1,2],[3,4]]) = [computed result]"
h = hold_cmd(:eigenvals, M)
eq = h ~ eigenvals(M)
# Also works with the held command on the right
eq = eigenvals(M) ~ h
# Between two held commands
eq = hold_cmd(:factor, x^2 - 1) ~ hold_cmd(:expand, (x-1)*(x+1))
# With numbers
eq = hold_cmd(:det, M) ~ -2All type combinations are supported: HeldCmd ~ GiacExpr, GiacExpr ~ HeldCmd, HeldCmd ~ HeldCmd, HeldCmd ~ Number, and Number ~ HeldCmd.
API Reference
Giac.HeldCmd — Type
HeldCmdRepresents an unevaluated GIAC command with its arguments.
A HeldCmd stores a command name and arguments without executing the command. It provides rich display (LaTeX for notebooks, plain text for terminal) and can be executed later via release.
Fields
cmd::Symbol: GIAC command name (e.g.,:integrate,:diff)args::Tuple: Original arguments, preserved as-is fromhold_cmdcall
Specialized LaTeX Rendering
The following commands render with standard mathematical notation:
integrate:∫ f dxdiff:d/dx f(Leibniz notation)laplace:ℒ{f}(s)invlaplace:ℒ⁻¹{F}(t)ztransform:𝒵{f}(z)invztransform:𝒵⁻¹{F}(n)limit:lim_{x→a} fsum:Σ_{n=a}^{b} fproduct:Π_{k=a}^{b} fsum_riemann:lim_{n→+∞} Σ_{k=0}^{n-1} f
All other commands use generic function-call notation.
Examples
using Giac
using Giac.Commands: hold_cmd, release
@giac_var x
h = hold_cmd(:integrate, x^2, x) # Creates HeldCmd, no execution
display(h) # Renders ∫ x² dx in notebooks
result = release(h) # Executes: returns x³/3See also
hold_cmd: Create a HeldCmdrelease: Execute a HeldCmdinvoke_cmd: Direct command execution
Giac.Commands.hold_cmd — Function
hold_cmd(cmd::Symbol, args...) -> HeldCmdCreate a held (unevaluated) representation of a GIAC command.
Like invoke_cmd, but does NOT execute the command. Instead, returns a HeldCmd object that can be displayed with LaTeX rendering in notebooks and executed later via release.
Arguments
cmd::Symbol: GIAC command name (e.g.,:integrate,:diff,:factor)args...: Command arguments (GiacExpr, String, Number, Symbol, AbstractVector)
Returns
HeldCmd: An unevaluated command object with rich display
Throws
GiacError(:eval): If command name is not a valid GIAC command
Examples
using Giac
using Giac.Commands: hold_cmd, release
@giac_var x
h = hold_cmd(:integrate, x^2, x) # No execution — returns HeldCmd
display(h) # Renders ∫ x² dx in notebooks
result = release(h) # Now executes: returns x³/3See also
invoke_cmd: Execute a command immediatelyrelease: Execute a HeldCmdHeldCmd: The held command type
Giac.Commands.release — Function
release(held::HeldCmd) -> GiacExprExecute a held command and return the result.
Takes a HeldCmd created by hold_cmd and executes it via invoke_cmd, returning the computed GiacExpr result.
Arguments
held::HeldCmd: A held command to execute
Returns
GiacExpr: Result of executing the held command
Examples
using Giac
using Giac.Commands: hold_cmd, release
@giac_var x
h = hold_cmd(:integrate, x^2, x)
result = release(h) # Returns x³/3See also
hold_cmd: Create a HeldCmdinvoke_cmd: Direct command execution