[ add ] Natural number square root#3023
Conversation
gallais
left a comment
There was a problem hiding this comment.
Does it really need to be in its own module as opposed to just being in Data.Nat.Base?
No, surely not. But like I think this perhaps should be marked |
|
As |
JacquesCarette
left a comment
There was a problem hiding this comment.
My suggestion is not a deal-breaker.
| sqrt (suc n) = if (0 <ᵇ d) then √n else suc √n | ||
| module Sqrt where | ||
| -- helper functions to compute d | ||
| 2*_ : ℕ → ℕ |
There was a problem hiding this comment.
Maybe 2*_ should be a function in Data.Nat.Base that is exported?
There was a problem hiding this comment.
Note that the generated code will be slower than simply using 2 * m.
|
Thanks for all the commentary. I suppose I'd opted for Goodstein out of a failure to write a 'nice' odd/even mutual recursion by wf-induction which starts with |
Have you considered doing an induction of the |
Well, wouldn't that be a thing to try!? But no, until you suggested it, no, I hadn't. A case of too-narrowly-bounded brainwidth! |
|
I think you're aware of the issues here, but I don't think we should merge this as-is. The current definition is neither (to me) obviously correct, nor is it fast (I'm actually surprised with how slow it is! something seems wrong there). I had a little go doing something Newton-y, but it's tricky |
|
Thanks @Taneb . Two things:
Oh, and a third: I'm sure the definitions are "obviously correct", but YMMV ;-) and irrational convictions on the part of authors, human and/or otherwise, are part of what our processes are designed to catch! |
Fixes #2231 for
Nat.