DSL::English::IntegrationWorkflows ā README
DSL::English::IntegrationWorkflows
Raku package for making (computational) integration workflows using natural language commands (in English.)
The package uses fundamental grammar-, execution-, and error handling functionalities of the package "DSL::Shared", [AAp1]. The package can be used to produce code for the Raku package "Math::NIntegrate", [AAp2], and for the Wolfram Language function NIntegrate, [WRI1].
Installation
From Zef ecosystem:
zef install DSL::English::IntegrationWorkflowsFrom GitHub:
zef install https://github.com/antononcube/Raku-DSL-English-IntegrationWorkflows.gitExample command parsing
Parse integration specifications to Wolfram Language code:
use DSL::English::IntegrationWorkflows;
my @commands =
'integrate 1/x^2 over the range [1,2] with a local adaptive strategy and precision goal 5',
'numericlly integrate $\frac{1}{\sqrt{x}}$ over the range [0,1] without singularity handling with up to 20 recursion levels',
'do symbolic integration of $\frac{1}{\sqrt{x}}$ over the range [0,1]',
'integrate numerically exp(-(x^2 + y^2)) over the domain [-Inf, Inf] x [-Inf, Inf] using unite cube rescaling';
for @commands -> $cmd {
say ToIntegrationWorkflowCode($cmd)
}#ERROR: Possible misspelling of 'numerically' as 'numericlly'.
#ERROR: Possible misspelling of 'unitcuberescaling' as 'unitecuberescaling'.
# NIntegrate[1/x^2, {x,1,2}, Method -> "LocalAdaptive", PrecisionGoal -> 5]
# NIntegrate[ToExpression["\\frac{1}{\\sqrt{x}}", TeXForm], {x,0,1}, Method -> {"GlobalAdaptive", "SingularityHandler" -> None}, MaxRecursion -> 20]
# Integrate[ToExpression["\\frac{1}{\\sqrt{x}}", TeXForm], {x,0,1}]
# NIntegrate[exp(-(x^2 + y^2)), {x,-Infinity,Infinity}, {y,-Infinity,Infinity}, Method -> "UnitCubeRescaling"]Remark: The grammar handles misspellings of command words and method names. For method names the word separators are dropped and lower case is used. Hence, the warning messages might be hard to read.
Evaluation
Raku
Generate numerical integration Raku code and evaluate it:
my $cmd= 'numerically integrate 1/sqrt(x) over the range [0,1] without singularity handling with up to 20 recursion levels';
my $res = ToIntegrationWorkflowCode($cmd, 'Raku::Ecosystem');# nintegrate({1/sqrt($^x)}, ['x',0,1], singularity-handler => "none", max-recursion => 20)use Math::NIntegrate;
use MONKEY-SEE-NO-EVAL;
EVAL $res;#ERROR: Failed to converge to prescribed accuracy after 20 recursive bisections in near 5.93674981608222e-08.
# 1.999989210746633Wolfram Language (WL)
Using package's Command Line Interface (CLI) script check that valid, executable code is obtained by pipelining the interpretation result to wolframscript:
cmd='numerically integrate $\frac{1}{\sqrt{x}}$ over the range [0,1] without singularity handling with up to 20 recursion levels'
ToIntegrationWorkflowCode $cmd | wolframscript# Wolfram 15.0.1 Kernel for Mac OS X ARM (64-bit)
# Copyright 1988-2026 Wolfram Research, Inc.
#
# In[1]:=
# NIntegrate::ncvb:
# NIntegrate failed to converge to prescribed accuracy after 20
# -7
# recursive bisections in x near {x} = {9.46086 10 }. NIntegrate obtained
# 1.99994 and 0.0000936659 for the integral and error estimates.
#
# Out[1]= 1.99994
#
# In[2]:=Development
The original Extended Backus-Naur Form (EBNF) grammar for the computational integration workflows was developed 12+ years ago, [AA1], and used in presentations and blog posts discussing and demonstrating the Mathematica (or Wolfram Language) Functional Parsers implementation, [AAp3]. It was both interesting and instructive to reproduce those demos using the Raku package FunctionalParsers, [AAp4] -- see the Jupyter notebook "Integration-language.ipynb".
With "FunctionalParser" the original EBNF grammar was converted to a Raku grammar and demo commands were converted to Raku tests. This was MVP0.
After that the grammar and actions were implemented using a mixture of manual (or human mind) programming and AI-agent programming. See the prompts in "prompts.md" -- the sections order reflects the way the development proceeded.
Of course, the experience and know-how of the implementation of grammars and interpreters of "DSL::English::*" constellation of packages was leveraged. For example, the general package structure, its "top-level" subs, and fuzzy matching.
TODO
Symbolic integration for Raku
Via the package "CortexJS"
Proper interpretation of LaTeX integrands for Raku
Via the package "LaTeX::Grammar"
If the user has it installed
This should be parsed:
integrate $\sin{x^2}\log{x/5}$ in [0,100] using the local adaptive strategy
Proper interpreting of Mathematica syntax integrands for Raku
Via the package "Mathematica::Grammar"
If the user has it installed
Parsing of functional boundaries
Comprehensive method option parsing.
Currently, the parsed method option spec is "shallow" -- only a method name can be used
See the grammar in "Math::NIntegrate"
This should be parsed:
integrate Sin[x^2] in [0,100] using the local adaptive strategy with Clenshaw-Curtis rule with 7 points
Handling syntax of ranges and integrand mistakes
For example, having two right brackets:
integrate $\sin{x^2}\log{x/5}$ in [0,100]],
References
Articles, blog posts
[AA1] Anton Antonov, "Natural language processing with functional parsers", (2014), MathematicaForPrediction at WordPress.
[WRI1] Wolfram Research (1988), NIntegrate, Wolfram Language function, https://reference.wolfram.com/language/ref/NIntegrate.html (updated 2014).
Packages
[AAp1] Anton Antonov, DSL::Shared, Raku package, (2020-2025), GitHub/antononcube.
[AAp2] Anton Antonov, Math::NIntegrate, Raku package, (2026), GitHub/antononcube.
[AAp3] Anton Antonov, FunctionalParsers, Wolfram Language paclet, (2023), Wolfram Language Paclet Repository.
[AAp4] Anton Antonov, FunctionalParsers, Raku package, (2023-2026), GitHub/antononcube.