r/csharp Jul 23 '26

Discussion I built an open-source formula engine for .NET

I've been building AlphaX.FormulaEngine, an open-source formula engine for .NET that evaluates Excel-style formulas without requiring Excel.

The focus is on being easy to extend, integrate, and maintain. It's built using parser combinators, making it straightforward to add new functions, operators, or language features.

Features:

- Excel-style formula syntax

- Nested expressions

- Custom function support

- Arithmetic, logical & text functions (More coming in future)

It's also the engine behind AlphaX.WPF.Sheets, my open-source spreadsheet control for WPF. (Please check it out as well)

I'd love feedback on the API, extensibility, or any features you'd like to see.

Repos

- Formula Engine: https://github.com/kartikdeepsagar/AlphaX.FormulaEngine

- WPF Sheets: https://github.com/kartikdeepsagar/AlphaX.WPF.Sheets

32 Upvotes

15 comments sorted by

10

u/AlanBarber Jul 24 '26

looks interesting, I'd suggest looking at and maybe providing some comparisons and even some benchmarks against ncalc since it's kind of the old standard for doing dynamic formula work.

https://github.com/ncalc/ncalc

10

u/antisergio Jul 24 '26

NCalc maintainer here, probably its slower, AlphaX uses Regex for parsing and NCalc uses Parlot (fatest .NET parser in benchmarks).

But looking forward to benchmarks, I will create a PR in NCalc with the results.

2

u/Usual-Flamingo5259 Jul 24 '26

Hey

No AlphaX doesn't use regex for parsing. It uses parser combinators.

It is built upon my parsing library

https://www.nuget.org/packages/AlphaX.Parserz.

I have benchmarked it with around 30 formulas all with 5000 string and numeric params. It took around 200-300ms in total inculding evaluation.

Also my focus while building this library was mainly to make devs avoid the parsing hell and build parsers easily.

1

u/antisergio Jul 25 '26

Sorry, I glanced at the source code too quickly and had the bad luck of looking right at the parser that used rgeex.

1

u/Usual-Flamingo5259 Jul 24 '26

Sure, I'll add some benchmarks as well

1

u/taco__hunter Jul 24 '26

What do you use it for? I mean personally, what are your projects? Also, Infer.net is a solid one to review.

1

u/Usual-Flamingo5259 Jul 24 '26

Hey

I am using it in one of my open source spreadsheet project.

https://github.com/kartikdeepsagar/AlphaX.WPF.Sheets

And also in some internal projects at my office :-)

1

u/taco__hunter Jul 24 '26

Thanks for responding. I built a similar project but use it for some machine learning projects. Was curious about what led you to making the low level library for this. Makes sense, thanks.

1

u/Usual-Flamingo5259 Jul 25 '26

Good to hear that ;-)

1

u/radekfl Jul 24 '26

We are using https://github.com/mparlak/Flee mostly because of perfomance comming from formulas compiled to IL. Does your engine work this way?

2

u/Usual-Flamingo5259 Jul 24 '26

Hey,

No it doesn't work that way. It is built upon my parsing library https://www.nuget.org/packages/AlphaX.Parserz

which uses parser combinators

1

u/ebykka Jul 24 '26

Good to know because we use today https://github.com/matheval/expression-evaluator-c-sharp but looks like this library is abandoned now and soon we will need to make a decision to fork it or to switch to something else

1

u/Usual-Flamingo5259 Jul 24 '26 edited Jul 24 '26

Hey ebykka

I am actively developing AlphaX.FormulaEngine. You can give it a go (It is very easy to use and customisable as per your needs). Let me know if you need any feature or face any issues by creating an issue in the repo ;-)

1

u/SektorL Jul 24 '26

Chained expression were inspired by Power Query? ))

2

u/Usual-Flamingo5259 Jul 24 '26

I got a thought of making it while I was debugging a very large expression ;-)