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³/3

Specialized 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 :ilaplace

Z-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 result

Equation 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) ~ -2

All type combinations are supported: HeldCmd ~ GiacExpr, GiacExpr ~ HeldCmd, HeldCmd ~ HeldCmd, HeldCmd ~ Number, and Number ~ HeldCmd.

API Reference

Giac.HeldCmdType
HeldCmd

Represents 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 from hold_cmd call

Specialized LaTeX Rendering

The following commands render with standard mathematical notation:

  • integrate: ∫ f dx
  • diff: d/dx f (Leibniz notation)
  • laplace: ℒ{f}(s)
  • invlaplace: ℒ⁻¹{F}(t)
  • ztransform: 𝒵{f}(z)
  • invztransform: 𝒵⁻¹{F}(n)
  • limit: lim_{x→a} f
  • sum: Σ_{n=a}^{b} f
  • product: Π_{k=a}^{b} f
  • sum_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³/3

See also

source
Giac.Commands.hold_cmdFunction
hold_cmd(cmd::Symbol, args...) -> HeldCmd

Create 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³/3

See also

source
Giac.Commands.releaseFunction
release(held::HeldCmd) -> GiacExpr

Execute 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³/3

See also

source