Fparse: Fortran function parser

Another fun AI-assisted project: fparse, a Fortran function parser. Features include:

  • Nested functions, the evaluation order determined automatically by the dependencies.
  • Supports scalar and vector variables.
  • Allows for user-defined functions.
  • First derivative computations (using forward-mode automatic differentiation). This includes scalar, vector, and matrix (Jacobian) derivative outputs.
  • Dependency queries and exporting of the dependencies in various formats.
  • Lots of test cases and comparisons to other parsers.
  • Fortran Package Manager ready

See benchmarks for some comparisons against native Fortran, Python, and other Fortran expression parsers. It’s faster than Python.

4 Likes

Nice library! I really like the integration with AD.

If you want to extend the benchmark, you can probably include evaluate.f. I also benchmarked several equation parsers in benchmark.f, so I will probably add your parser for completeness.

1 Like

Nice project. GPT-6.1-Sol advises adding an fparse page to my Fortran playground. Let me know when it somewhat stable, and I can do it.

Having inspected the local fparse README and API, I think a separate Function parser page would be a useful addition, especially because it supports expression systems, vectors, automatic derivatives and standalone Fortran code generation. fparse documentation

I suggest linking to /function-parser/ from the playground and leaving the existing interfaces unchanged. The initial page could contain:

  • Expressions: one named expression per line, such as z = sin(x) + y**2.
  • Variables: editable scalar or vector values.
  • Evaluate: display named results, with an optional derivatives/Jacobian checkbox.
  • Examples: single expressions, dependent equations, vector calculations and derivatives.
  • Generate Fortran: download the generated module, or open a complete generated program in the regular playground.
  • Share link: restore expressions, input values and settings.

A one-variable range option could also produce a table and plot. Dependency diagrams would be useful later for larger expression systems.

For execution, I recommend a precompiled fparse executable that receives structured input, so changing an expression doesn’t require recompiling Fortran. This would require backend deployment initially, but the separate page and worker could keep its assets and execution work out of the existing modes. Existing service limits would still apply.

The ability to explore equations and then export ordinary Fortran is the strongest reason to add this—it gives the page a purpose beyond being another calculator.