Hello, I’ve tried to look at the documentation, but I cannot find a way to check if a TFormula is valid or not. Is there a method to do that?
What do you mean by “valid” ? syntactically ?
yes
It looks like “Compile()” does the job:
root [1] TFormula f1("f1","x*x")
root [2] f1.Compile();
root [4] printf("%d\n",f1.Compile());
0
root [5] TFormula f2("f2","si(x)")
Error in <TFormula::Compile>: Bad numerical expression : "si(x)"
root [6] printf("%d\n",f2.Compile());
Error in <TFormula::Compile>: Bad numerical expression : "si(x)"
1
root [7]
is the compilation lazy? I mean if I call it manually then it is redone?
[quote=“couet”]It looks like “Compile()” does the job:
root [1] TFormula f1("f1","x*x")
root [2] f1.Compile();
root [4] printf("%d\n",f1.Compile());
0
root [5] TFormula f2("f2","si(x)")
Error in <TFormula::Compile>: Bad numerical expression : "si(x)"
root [6] printf("%d\n",f2.Compile());
Error in <TFormula::Compile>: Bad numerical expression : "si(x)"
1
root [7]
[/quote]
I guess it is… just try.
Hi,
Im using ROOT v6.02/12. I tried:
and also:
And both compile, If I call:
form.Compile()
or
I get zero, despite these formulae are wrong, also If I evaluate, they do evaluate, however the wrong part (Sin(x[1]) or Tin(x[1]) ) evaluates to one. Why does it happen? I want to put a “if” somewhere that alerts me of a nonsensical function introduced by mistake, before I evaluate and get wrong results. But that “if” would not work here which makes this a very dangerous piece of code.
Hi,
You should upgrade ROOT to the latest version, 6.04.06 and use the new TFormula based on Cling, which will compile the expression using a real compiler.
Lorenzo
Hi,
Yes, I tried it and it works in ROOT 6.04/06.
Thanks.