RUB-EP1 / amplitude-serialization

Prototype for the amplitude model serialization format
https://rub-ep1.github.io/amplitude-serialization
MIT License
2 stars 1 forks source link

`generic_function` with named parameters #77

Open mmikhasenko opened 1 week ago

mmikhasenko commented 1 week ago

Base on a few recent discussions, I am getting convinced that construction of the generic functions is the key feature that will be unitized extensively.

We want to make it nice and convenient. One step toward it would be introduction of named parameters to the generic functions

https://github.com/RUB-EP1/amplitude-serialization/blob/main/models/x2pipipi-compass-1391643.json#L988-L992

becomes

    {
      "type": "generic_function",
      "expression": "sqrt(sqrt(m_12_sq)) / (m_rho^2 - m_12_sq - 1im * m_rho * Gamma_rho)",
      "m_rho": 1.69,
      "Gamma_rho": 0.19,
      "name": "R(1690)"
    },

I'd know how to generate it in julia

redeboer commented 1 week ago
"expression": "sqrt(sqrt(m_12_sq)) / (m_rho^2 - m_12_sq - 1im * m_rho * Gamma_rho)",

I'd know how to generate it in julia

The difficulty is that this expression string is not (afaik) following a common mathematical markup standard, so I expect that for any language, you will need to write your own parser.

This example string follows ROOT's TFormula, right? Do you know if ROOT is following some common math markup standard? Or if the ROOT team has defined a format specification?

redeboer commented 1 week ago

A requirement may also be to allow for nested definitions. In this case, that you can write e.g. my_func(m_rho, Gamma_rho, Gamma_rho). But that requires defining function argument order etc (so that you can insert other parameter names).

mmikhasenko commented 1 week ago

Why it does not follow? I do not know the standards, but would expect that a simple expression with * and / works in any standard

redeboer commented 1 week ago

Why it does not follow?

I guess the example follows TFormula (but it's a simple example with sqrt, /, *, and - operators only). What I mean is, does ROOT provide a mathematics markup standard? Like, if I write a parser, should I use ^ or ** for power operators? Or both? And are there standalone (Julia,C++,Python) libraries that can parse and unparse?

mmikhasenko commented 1 week ago

Well, I do not use TFormula and do not think of ROOT.

mmikhasenko commented 1 week ago

In Julia it's Meta.parse

In python, I'd use parse_expr

redeboer commented 1 week ago

That means the expression string is limited to the intersection of Python and Julia syntax?

mmikhasenko commented 1 week ago

There are possible manipulations that you can do with the string before parsing, so I would say no limitations