-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This was an error in the implementation #2336
base: master
Are you sure you want to change the base?
Conversation
Besides being equivalent to 1 that way, you need to go no further than the formula.
code-experiments/src/f_katsuura.c
Outdated
@@ -43,7 +43,7 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) | |||
} | |||
/*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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answering the question... Before it could be reduced to what @nikohansen said. Now it does not.
code-experiments/src/f_katsuura.c
Outdated
@@ -43,7 +43,7 @@ static double f_katsuura_raw(const double *x, const size_t number_of_variables) | |||
} | |||
/*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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.