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

This was an error in the implementation #2336

wants to merge 4 commits into from

Conversation

JJ
Copy link

@JJ JJ commented Nov 13, 2024

Captura de pantalla de 2024-11-13 17-34-02
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.

Besides being equivalent to 1 that way, you need to go no further than the formula.
@@ -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.

Copy link
Author

@JJ JJ left a 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.

@@ -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
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)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants