A formula engine for JavaScript and Java

Excel-like formulas, checked before they run

fxEngine is a statically typed formula engine you build into your own software. Your users write the formulas they know from spreadsheets.

It infers the type of each formula, catches mistakes as soon as they're entered and explains exactly what's wrong.

Get early access

The shell runs in your browser. There is nothing to install.

fxEngine Shell
  1. Price = 49.5Price = 49,5
    49.549,5 Number
  2. Quantity = 120Quantity = 120
    120120 Number
  3. Total = Price * QuantityTotal = Price * Quantity
    59405940 Number
  4. Threshold = "5000"Threshold = "5000"
    "5000""5000" Text
  5. Total > ThresholdTotal > Threshold

    Das ist eine Textzeichenfolge, aber auf der anderen Seite von > steht eine Zahl

    This is a text string, but the other side of > is a number

    Esto es una cadena de texto, pero al otro lado de > hay un número

    C'est une chaîne de texte, mais de l'autre côté de >, il y a un nombre

    Qui c'è una stringa di testo, ma dall'altro lato di > c'è un numero

    Dit is een tekenreeks, maar aan de andere kant van > staat een getal

    Isto é uma cadeia de texto, mas do outro lado de > há um número

    Detta är en textsträng, men på andra sidan > finns ett tal

    Das ist eine Textzeichenfolge, aber auf der anderen Seite von > steht eine Zahl

    This is a text string, but the other side of > is a number

    Esto es una cadena de texto, pero al otro lado de > hay un número

    C'est une chaîne de texte, mais de l'autre côté de >, il y a un nombre

    Qui c'è una stringa di testo, ma dall'altro lato di > c'è un numero

    Dit is een tekenreeks, maar aan de andere kant van > staat een getal

    Isto é uma cadeia de texto, mas do outro lado de > há um número

    Detta är en textsträng, men på andra sidan > finns ett tal

  • 2008 The year work on fxEngine began, as the formula engine of Calcapp, an app designer for people who don't program.
  • 50,000 Apps that customers have built with Calcapp. fxEngine checks and calculates every formula in each one of them.
  • 1,594 Worked examples in the function reference, every one checked by the compiler whenever the reference is generated.

Why static typing

Formulas are written once and run for years

In a spreadsheet, a bad formula shows #VALUE! the moment it is typed, and its author fixes it. In your software, a formula is written once and runs weeks or months later, on someone else's data, far from whoever wrote it.

fxEngine moves every check it can to the moment the formula is written. Declare the type of a formula, and a mistake is reported where the formula is defined, not where its value is used.

Total is 5940, Threshold is the text "5000", as read from a CSV file, and Due is March 31, 2026.

Formula A spreadsheet answers fxEngine answers
Total + ThresholdTotal + Threshold A spreadsheet answers 10940 The text is quietly converted to a number. fxEngine answers
Expected a number but found a text string insteadExpected a number but found a text string instead
Total > ThresholdTotal > Threshold A spreadsheet answers FALSE All text is ordered after all numbers. fxEngine answers
This is a text string, but the other side of > is a numberThis is a text string, but the other side of > is a number
Due / 2Due / 2 A spreadsheet answers 23056 A date is a number of days since 1900. fxEngine answers
Expected a number but found a date or time insteadExpected a number but found a date or time instead
  • Caught as it is typed

    A formula is checked as a whole before it runs, so a mistake in a branch that rarely runs is caught too.

  • Messages for people

    A message names what is wrong, what was expected and what was found, and can be worded for spreadsheet users rather than programmers.

  • The whole model at once

    Names that no longer exist and circular references are caught across every formula of a model, not one formula at a time.

Domain models

Your business objects, reachable from formulas

Every name in a formula is checked against a model. Describe a few named values in a couple of lines, or expose your own classes as a domain model.

  • Typed properties

    Amount.MaximumAmount,Maximum and Term.OptionsTerm,Options are properties of your containers, with types of their own. Properties are reached with ., and children with !, as in Form.StartupParameters!InterestRateForm,StartupParameters!InterestRate.

  • Implicit casts

    A number field stands in for its value, so users write Amount > 100 rather than Amount.Value > 100Amount,Value > 100. The compiler inserts the cast.

  • Ranges

    Containers that know their neighbors support ranges, such as SUM(Field1:Field10)SUM(Field1:Field10), or A1:D10 in a grid.

  • Built for live editing

    Values are added, renamed and removed as the author types, several changes can be made as one, and only what a change affects is checked again.

LoanApplication Form
Every field .Value,Value .Valid,Valid .Visible,Visible .Enabled,Enabled
  • Amount Number field .Minimum,Minimum .Maximum,Maximum .TrailingUnit,TrailingUnit
  • Term Drop-down .Options,Options
  • StartDate Date field .Earliest,Earliest .Latest,Latest
  • Employed Switch .ThumbColor,ThumbColor
  • Employer Text field .MaximumLength,MaximumLength .Multiline,Multiline
  • SendToBank Report button .Recipients,Recipients .SubjectLine,SubjectLine .Format,Format
  • Amount.MaximumAmount,Maximum IF(Employed, 50000, 10000)IF(Employed; 50000; 10000)
  • Term.OptionsTerm,Options IF(Amount > 20000, {12, 24, 36, 60}, {12, 24})IF(Amount > 20000; {12; 24; 36; 60}; {12; 24})
  • StartDate.EarliestStartDate,Earliest TODAY() + 7TODAY() + 7
  • Employer.VisibleEmployer,Visible EmployedEmployed
  • SendToBank.EnabledSendToBank,Enabled Amount.Valid && StartDate.ValidAmount,Valid && StartDate,Valid
  • SendToBank.EnabledSendToBank,Enabled Amount.Valid && StartDateAmount,Valid && StartDate Expected a logical value (TRUE or FALSE) but found a date or time instead

The type system

A real type system, made for formulas

Numbers, text, logical values, dates, colors, arrays, records and types of your own. Declare a type where you want one, and fxEngine infers the rest.

The language has been designed around its type system since 2008, and it reads like the formulas your users already write.

  • Type inference

    Declaring a type is optional. Adding days to a date gives a date, and subtracting two dates gives a number of days.

    DATE(2026, 3, 31) + 30DATE(2026; 3; 31) + 30
    DATE(2026, 4, 30)DATE(2026; 4; 30) Temporal
  • Arrays and lifting

    A function taking a number also takes an array of numbers, and returns an array.

    ABS({ -4, 4 })ABS({ -4; 4 })
    { 4, 4 }{ 4; 4 } Array<Number>
  • Lambdas

    FILTER, SUMIF and their kin can take a condition written as a formula, with a name of your choosing for each element.

    FILTER({ 5, 11, 13, 20 }, P -> (P > 10) && ISODD(P))FILTER({ 5; 11; 13; 20 }; P -> (P > 10) && ISODD(P))
    { 11, 13 }{ 11; 13 } Array<Number>
  • Enumerated values

    Where Excel takes a magic number, fxEngine also takes a named value, checked like any other.

    XMATCH(13, { 5, 13, 20 }, MatchMode.Exact)XMATCH(13; { 5; 13; 20 }; MatchMode,Exact)
    22 Number
  • Union types

    A parameter may accept more than one type, here an enumerated value or one of Excel's numbers.

    XMATCH(13, { 5, 13, 20 }, Color.Red)XMATCH(13; { 5; 13; 20 }; Color,Red)
    Expected something like MatchMode.Exact or a number but found a color insteadExpected something like MatchMode,Exact or a number but found a color instead
  • Named parameters

    Every parameter of every function can be given by name, so optional ones can be skipped.

    SEQUENCE(3, StepValue: 2)SEQUENCE(3; StepValue: 2)
    { 1, 3, 5 }{ 1; 3; 5 } Array<Number>
  • Decimal commas

    Formulas can also be written with decimal commas and semicolons, and converted from one convention to the other.

    ROUND(2,567; 2)
    2,57 Number
  • Decimal points

    Formulas can also be written with decimal points and commas, and converted from one convention to the other.

    ROUND(2.567, 2)
    2.57 Number
  • Imperative mode

    Formulas run by buttons and rules may assign values and call functions with side effects.

    Total := Price * Quantity; RESET(Notes)Total := Price * Quantity;; RESET(Notes)

Runtime and platforms

Change a value and the formulas follow

fxEngine Compiler turns your formulas into a model, as JSON. fxEngine Runtime calculates the model where your code runs, and recalculates only the formulas that depend on a value that changes.

In your code

Describe a model, read a value, change another and read again.

Describing and calculating a model
const root = liveModel(new MutableModel({
  UnitPrice: 10,
  Quantity: 3,
  Total: { numberFormula: "UnitPrice * Quantity" }
}));

getMemberValue(root, "Total", Namespace.CHILDREN);   // 30

setMemberValue(root, "Quantity", 4, Namespace.CHILDREN);
getMemberValue(root, "Total", Namespace.CHILDREN);   // 40
const root = liveModel(
  new MutableModel({
    UnitPrice: 10,
    Quantity: 3,
    Total: {
      numberFormula:
        "UnitPrice * Quantity"
    }
  }));

// 30
getMemberValue(root, "Total",
  Namespace.CHILDREN);

setMemberValue(root, "Quantity", 4,
  Namespace.CHILDREN);
// 40
getMemberValue(root, "Total",
  Namespace.CHILDREN);

On this page

The runtime calculates this model in your browser. Move a slider.

A live model Calculated by fxEngine Runtime
  • UnitPrice 49.5 49,5 Number
  • Quantity 20 20 Number
  • Subtotal =UnitPrice * QuantityUnitPrice * Quantity 990 990 Number
  • Discount =IF(Quantity >= 25, 10%, 0)IF(Quantity >= 25; 10%; 0) 0 0 Number
  • Total =Subtotal * (1 - Discount)Subtotal * (1 - Discount) 990 990 Number
  • FreeShipping =Total >= 1000Total >= 1000 FALSE FALSE Logical

Move a slider to change the model.

Changing UnitPrice recalculated Subtotal, Total and FreeShipping. Discount does not depend on UnitPrice and was not recalculated.

Changing Quantity recalculated Subtotal, Discount, Total and FreeShipping.

fxEngine Compiler runs in
  • JavaScript
  • WebAssembly
  • Java 11+
fxEngine Runtime runs in
  • Browsers
  • Node
  • Bun
  • Java 17+, through GraalVM

A REST API, for every other language, is planned.

AI agents

Exact answers, and errors an agent can act on

A language model estimates. A formula calculates: the same formula on the same data gives the same answer, every time. Have an agent write the formula rather than the answer, and the compiler checks its work before anything runs.

  • Checkable

    The model tells an agent which names exist and what type each one has, and an error names exactly what to fix.

  • Ready for coding agents

    fxEngine Shell comes with a skill for coding agents, which runs every formula through the shell before the agent offers it.

  1. 1

    The agent writes a formula

    Total > ThresholdTotal > Threshold
  2. 2

    The compiler refuses it

    This is a text string, but the other side of > is a numberThis is a text string, but the other side of > is a number
  3. 3

    The agent corrects it

    Total > TONUMBER(Threshold)Total > TONUMBER(Threshold)
    TRUETRUE Logical

Build or license

Could you write this yourself?

An AI agent writes a parser and an evaluator for formulas in a day. Then your users ask for the functions they miss, for errors they can understand and for an editor that helps them. These parts took us years.

  • The type system

    Type inference, union types, lambdas and functions that take arrays in place of single values. An agent builds what you ask for, and these have to be asked for by name.

  • The function library

    410 functions with the names and the parameters your users know from spreadsheets, each with its handling of blank values, dates and arrays.

  • The error messages

    Messages that say what is wrong and where, written for people who do not program, in 8 languages.

  • Completion and reference

    A formula that is only half typed still gets suggestions, and every function has a reference page, with 1,594 examples that the compiler checks.

Will an assistant write formulas for your users?

An assistant makes mistakes that look plausible. A compiler that checks each formula against your fields catches them before the formula is stored, and its error message says what the assistant should correct. A parser without a type checker cannot do this.

See the early-access offer

An honest answer

Is fxEngine right for you?

We would rather tell you now than after you have built on it.

A good fit if

  • Your customers write the formulas, in a form builder, a low-code tool, a database with formula columns, a pricing engine or a reporting tool.
  • An error message is better than a wrong number.
  • Formulas also run actions, such as those of buttons, not only calculations.
  • Formulas can name objects of your own, such as fields, line items or sensors, and their properties, as well as cells.
  • You are building a formula editor, with completion for formulas that are only half typed.
  • Your own functions should be documented like the built-in ones, with every example checked.

Not the right tool if you need to

  • Open Excel workbooks and calculate them. Try Apache POI, IronCalc, Aspose.Cells, or SheetJS with HyperFormula.
  • Match Excel's results exactly, even for formulas that mix types, such as Price > "10".
  • Give your users a ready-made spreadsheet. Try Handsontable, SpreadJS or Univer.
  • Offer a syntax made for programmers rather than spreadsheet users. Try CEL.
  • Calculate formulas from .NET, Python or other languages. A REST API is planned. On .NET, try Power Fx. In Python, try pycel.
  • Use an open-source engine in production. fxEngine requires a commercial license there.

The ecosystem

One engine, and the tools around it

The compiler and the runtime have been in production for years and are being prepared for release. The shell is here today. Subscribers to the newsletter get early access.

  • fxEngine Compiler

    Coming

    Parses, type-checks and compiles formulas, and validates whole models, circular references included.

    Runs on
    JavaScript, WebAssembly, Java 11+
    License
    Source-available
  • fxEngine Runtime

    Coming

    Calculates compiled models and recalculates only what a change affects.

    Runs on
    TypeScript, Java 17+ through GraalVM
    License
    Source-available
  • fxEngine Shell

    Available now

    The language at a prompt, with tutorials and the documentation built in, and CSV files imported and exported.

    Runs on
    Web, terminal (soon)
    License
    Free to use
    Open the shell full screen →
  • fxEngine Editor

    Coming

    A formula editor for the web, with completion and the signature of the function being typed.

    Runs on
    TypeScript, CodeMirror 6
    License
    MIT
  • fxEngine Validator

    Coming

    Constraint-driven validation of Java object graphs, generated at build time, with no reflection.

    Runs on
    Java
    License
    Apache 2.0
  • fxEngine API

    Planned

    Compiles, validates and calculates formulas over HTTP, from any language.

    Runs on
    REST
    License
    Hosted service

The compiler and the runtime are source-available: free for study, evaluation and personal use, with a commercial license for production. The editor and the validator are open source.

The shell is free for any purpose when a person uses it, and its own source code is open source under the Apache License 2.0.

fxEngine Shell Want this in your own terminal? A standalone version is coming.
Loading fxEngine Shell

fxEngine Shell for your terminal

A version you install on your own computer is coming. Subscribe to the newsletter to hear when it's ready.