finding rational approximations of pi using #modal, no big deal
9 comments
@neauoire this is using the binary arithmetic rules i wrote (with 0 and 1), but it has to do a TON of division of large numbers, which is slow. @d6 This is very nice! All in native numbers then. I don't know if you saw, but I've started putting a x11 playground to draw modal programs to a framebuffer? Fractals next? @neauoire oh! yes! that would be super fun. i need to port arith.modal to the number device you implemented. i think that should give at least a 10x speed up. @d6 we're still figuring out how to do it right, so it might change still. But yeah, the fib example shows how it works a bit, the ?0-9 registers match values, and ?: on an operator is a kind of bang to evaluate an arithmetic operation. @neauoire i'm cheating -- just using a continued fraction representation: https://git.phial.org/d6/modal/src/branch/d6/binary/arith.modal#L434 i had a GCF implementation using the faster fraction from here: https://en.wikipedia.org/wiki/Generalized_continued_fraction#%CF%80 however the regular CF provides better approximations, so it seemed better to do it that way. |
this is not as cool as i had hoped because it just hardcodes the first 14 terms of the continued fraction for pi, i.e. 3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1
https://oeis.org/A001203
(i did implement a generalized continued fraction which isn't hardcoded, but (A) it converges much more slowly and (B) it doesn't actually find the "best" convergents (e.g. 355/113) so it just didn't seem very useful.)