Closed frabert closed 6 years ago
It's really great PR for me. Although I am not sure if these (atan2
, log
) functions should be "independent". Maybe better use it like sqrt
or something, at least for atan2
?
I thought about that, but it would require quite an extensive pattern matching in the respective functions - namely Ln
and Atan
, since you need to recognize when they are instantiated with a fractional argument and handle it as needed. Also, due to the way expressions are simplified, you might get that some fractions get divided, e.g. atan(3x + 2, x) -> atan(3 + 2/x)
which would not be recognized.
Another interesting thought from Wikipedia:
The purpose of using two arguments instead of one, i.e. just computing atan(y/x), is to gather information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument arctangent function. It also avoids the problem of division by zero, as atan2(y, 0) will return a valid answer as long as y is non-zero.
For me both of approach has strengths. Anyway, something is better than nothing =)
I read more about atan2
. Yeah, now I agree - current way more simple and convenient
I need to rethink whether we really want to allow such variations in simplified expressions (since they may explode pattern matching complexity in algebraic functions), but I'm merging it in for now. Thanks!
Adds the support for two-argument functions Atan and Log, also adds support for single-argument Log function, that is equivalent to Log10
atan(x,y)
acts as an alternative syntax toatan(x/y)
,log(x)
is algebrically equivalent toln(x)/ln(10)
,log(b,x)
is algebrically equivalent toln(x)/ln(b)
.Rationale
While all three of these functions could be translated into equivalent expressions using identities, the usage of such alternative syntaxes can lead to different results when evaluating the expressions due to fewer floating point operations, because the .NET Framework provides special methods for such cases.