Conversation
Besides being equivalent to 1 that way, you need to go no further than the formula.
code-experiments/src/f_katsuura.c
Outdated
| /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) | ||
| * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ | ||
| result = 10. / ((double) number_of_variables) / ((double) number_of_variables) | ||
| result = 10. / ((double) number_of_variables) * ((double) number_of_variables) |
There was a problem hiding this comment.
this line can be reduced to
result = 10.because the operations "/ ((double) number_of_variables)" and "* ((double) number_of_variables)" cancel each other out. This lets me believe the original implementation was correct as it did twice "/ ((double) number_of_variables)", am I wrong?
There was a problem hiding this comment.
Not really, it's 1/D^2, as in the formula. The original implementation was simply 1 (in a roundabout way, because looking at code generated it actually did insert the division of D/D)
There was a problem hiding this comment.
Not really, it's 1/D^2, as in the formula. The original implementation was simply 1 (in a roundabout way, because looking at code generated it actually did insert the division of D/D)
I don't know. @JJ, let me ask a questions such that we may be able to get on the same page. What is the result of 10. / 20. / 20. when executed in C?
There was a problem hiding this comment.
OK, I get it now. Operator associativity actually makes 10/20/20 be equivalent to 10/(2020) and 10/2020 be equivalent to (10/20)*20. What I have done is to use parentheses to make the implementation closer to the formula, and prevent people from applying operator precedence and associativity rules, thus reducing cognitive load.
JJ
left a comment
There was a problem hiding this comment.
Answering the question... Before it could be reduced to what @nikohansen said. Now it does not.
code-experiments/src/f_katsuura.c
Outdated
| /*result = 10. / ((double) number_of_variables) / ((double) number_of_variables) | ||
| * (-1. + pow(result, 10. / pow((double) number_of_variables, 1.2)));*/ | ||
| result = 10. / ((double) number_of_variables) / ((double) number_of_variables) | ||
| result = 10. / ((double) number_of_variables) * ((double) number_of_variables) |
There was a problem hiding this comment.
Not really, it's 1/D^2, as in the formula. The original implementation was simply 1 (in a roundabout way, because looking at code generated it actually did insert the division of D/D)
Although it's actually equivalent to what was there before.
This should be equivalent to what was there before, but now the translation of the formula seems clearer. Don't understand the point of the ((double) x) except if it was to force some kind of precedence (which is not needed if you wrap everything with parentheses)
And avoid making repeated conversions.
Besides being equivalent to 1 that way, you need to go no further than the formula (above). It is now equivalent to D^2; before it was simply 1.