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

sqrt(x) < x not a valid check #27

Open
CrossEye opened this issue Sep 7, 2015 · 3 comments
Open

sqrt(x) < x not a valid check #27

CrossEye opened this issue Sep 7, 2015 · 3 comments

Comments

@CrossEye
Copy link

CrossEye commented Sep 7, 2015

In examples/dependent.js, we have this contract for a supposed square root function:

@ (x: Pos) -> res: Num | res <= x

And the failing implementation of sqrt is

return x * x;

Both of these have some issues in the range (0, 1). Note that sqrt(0.25); //=> 0.5 and that 0.5 < 0.25; //=> false. Similarly, in the same range 0.7 * 0,7 = 0.49, and 0.49 < 0.7, so this succeeds for range (0, 1).

I'm brand-new here, and don't know if this is acceptable. Obviously, any value that makes such a contract fail is a demonstration that the implementation is wrong, but I don't know what standard you want to set with the examples.

@disnet
Copy link
Owner

disnet commented Sep 7, 2015

Ha, good catch. That contract is definitely not what we want to say.

Maybe something like this is better.

@ (x: Pos) -> res:Num | res > (Math.sqrt(x) - 0.1) &&
                        res < (Math.sqrt(x) + 0.1)

Thanks for letting me know!

disnet added a commit that referenced this issue Sep 7, 2015
@CrossEye
Copy link
Author

CrossEye commented Sep 7, 2015

I would suggest that, since a sqrt function is what you're trying to define, using another one in its contract is perhaps a little odd. Is a syntax like this acceptable?:

@ (x: Pos) -> res:Num | (res * res + 0.1) > x && (res * res - 0.1) < x

@disnet
Copy link
Owner

disnet commented Sep 8, 2015

Good call, that's probably a bit more clear.

disnet added a commit that referenced this issue Sep 8, 2015
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

No branches or pull requests

2 participants