Skip to content

GhostScience DSL Syntax Guide ​

The GhostScience DSL parser normalizes mathematical input from four notations into executable SymPy-oriented Python. The parser detects syntax automatically and supports mixed notation within a single query.

Supported Syntaxes ​

LaTeX ​

Detected when the input contains LaTeX commands (\int, \frac, \sqrt, Greek letters like \alpha, operators like \cdot, \times, etc.).

LaTeX InputParsed Output
\int x^2 dxintegrate(x**2, x)
\frac{a}{b}((a)/(b))
\sqrt{x + 1}sqrt(x + 1)
\alpha + \betaalpha + beta
\sum_{n=0}^{\infty}Sum(
\lim_{x \to 0}Limit(

The parser first attempts conversion via SymPy's parse_latex(). On failure, it falls back to a rule-based regex normalizer that handles:

  • Greek letter commands (30+ symbols)
  • \cdot and \times to *
  • \infty to oo
  • \partial to Derivative
  • \sqrt{}, \frac{}{} (recursive nested braces)
  • Integral, sum, and limit notation
  • ^ to ** (exponentiation)

MATLAB ​

Detected when the input contains element-wise operators (.*, ./, .^), MATLAB keywords (function, end, elseif), or MATLAB-specific functions (linspace, zeros, ones, eye, eps).

MATLAB InputParsed Output
A .* BA * B
A .^ 2A ** 2
linspace(0, 1, 100)numpy.linspace(0, 1, int(100))
zeros(3, 3)numpy.zeros(3, 3)
eye(4)numpy.eye(4)
epsnumpy.finfo(float).eps
pinumpy.pi
Inf / NaNnumpy.inf / numpy.nan
% comment# comment
transpose(A)numpy.transpose(A)

Natural Language ​

Detected when the input contains English math phrases (integrate, differentiate, solve, simplify, factor, expand, limit).

Natural Language InputParsed Output
integrate x squared with respect to xintegrate(x**2, x)
derivative of sin(x) w.r.t. xdiff(sin(x), x)
solve x^2 - 4 for xsolve(x**2 - 4, x)
simplify (x^2 - 1)/(x - 1)simplify((x**2 - 1)/(x - 1))
factor x^2 + 2x + 1factor(x**2 + 2*x + 1)
expand (x + 1)^3expand((x + 1)**3)
limit of sin(x)/x as x approaches 0limit(sin(x)/x, x, 0)
limit of e^x as x approaches infinitylimit(e**x, x, oo)

The parser uses pattern matching on phrases like "with respect to", "w.r.t.", "over", "for", "as ... approaches". When no variable is specified, the parser guesses the most frequent single letter in the expression.

Python ​

Detected when the input contains import, from, def, class, lambda, sympy, sp., np., numpy, or math. statements. Python input is passed through directly with no transformation.

Confidence: 0.95 (highest, since no conversion is needed).

Syntax Detection ​

The parser checks patterns in this priority order:

  1. LaTeX -- backslash commands (\int, \alpha, etc.)
  2. Python -- import/def/class statements or library references
  3. MATLAB -- element-wise operators or MATLAB function names
  4. Natural language -- English math verbs
  5. Fallback -- treated as Python

Parse Result ​

Every parse returns a ParseResult with:

FieldTypeDescription
python_codestringThe normalized SymPy-oriented Python fragment
original_inputstringThe user's original text
detected_syntaxstringOne of: latex, matlab, python, natural
confidencefloat0.0-1.0 confidence score
warningslist[string]Any issues encountered during parsing

Confidence Scores ​

SyntaxTypical Confidence
Python (passthrough)0.95
LaTeX0.85
MATLAB0.85
Natural language0.70
Parse error0.0

Using the DSL with the API ​

The DSL parser is used internally by the scientific orchestrator when processing chat tool calls. For programmatic use, the syntax_hint parameter can override auto-detection:

python
from ghostscience import GhostScienceClient

client = GhostScienceClient(api_key="gst_...")

result = client.symbolic_math(
    expression=r"\int_0^1 x^2 dx",
    operation="integrate",
)

When using the chat interface, simply type your expression in any supported notation. The LLM and DSL parser handle the rest.

SOC 2 Type II Certified | BAA Available | HIPAA-Ready