Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code-experiments/src/f_katsuura.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@nikohansen nikohansen Nov 14, 2024

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?

Copy link
Author

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)

Copy link
Contributor

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?

Copy link
Author

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.

* (-1. + result);

return result;
Expand Down