mathnet-symbolics
mathnet-symbolics copied to clipboard
Suggestion: Hardcoding more than once is error prone
I think hardcoding "x" more than once should be avoided because it is error prone. It potentially causes runtime errors.
var x = Expr.Variable("x");
Func<double, double> f = (x * x + x - 6).Compile("x");
Console.WriteLine(f(0));
My suggestion is as follows:
var x = Expr.Variable("x");
Func<double, double> f = (x * x + x - 6).Compile(x);
Console.WriteLine(f(0));
Any comments are welcome. Thank you.
It would also be more consistent with the rest of the API.
Technically, if we'd change the argument to expect a SymbolicExpression, the former notation with a string would still work due to the implicit cast from string to the expression. We'd need to verify it also works with the params array overload though.