Thanks, folks. I had a senior moment here. I was browsing my code (TABULA in fact) and posted my question based on a morning's head-scratching. Then I discovered 2 weeks ago I'd written up a literature search I'd done on rational precision -- and there was (x:) and what it could and could not do for me, all nicely laid out.
But it's a serendipitous senior moment. If I'd remembered what I'd noted down about (x:) I'd not have posted -- and I'd have missed the fascinating references everyone's proffered me. Thank you all! I'll have to study some of them deeply when I come to write my own rational trig functions -- though most of the work seems to have been done for me in Roger Hui's https://code.jsoftware.com/wiki/Essays/Extended_Precision_Functions (…thanks Ric, I'd missed that one.) I will still employ my "mickey-mouse" method, because it's easily checked once it's coded. I need built-into TABULA a number of physical constants which the SI defines exactly, e.g. • The thermodynamic temperature of the triple point of water, Ttpw , is 273.16 K *exactly*. • The speed of light in vacuo is 299792458 m/s *exactly*. The first I can generate and handle as: 27316r100 -whereas (x: 273.16) is 6829r25 . If you multiply top and bottom by 4 you get my numeral. But (x:) will round decimal numerals with more than 15 sig figs and so lose the exactness. Wildberger's paper is intriguing. At first sight it seems to offer a way of sidestepping TABULA's current dependence on radians as a basic dimension of angular quantities, which could allow me to avoid dependence on π as a fundamental constant. This would be nice because π can only ever be approximated by a rational number. Thank you, William. Ian Clark On Tue, 26 Mar 2019 at 19:34, William Tanksley, Jr <wtanksle...@gmail.com> wrote: > Good point, Raul. Depending on what you're doing, there are more or > less unconventional ways to compute triangle geometry. Probably the > one best supported by the existing library is the best one to use :) . > > Found some links: > > Here's a link to Wildberger's own intro (I personally recommend > ignoring his explanation of how awesome rational trig is, it's fun but > you have a job to do): > https://web.maths.unsw.edu.au/~norman/papers/RationalTrig.pdf > > Here's someone else's paper on how to compute using it (compared to > how to compute using alternate methods): > http://www.cs.utep.edu/vladik/2008/olg08-01.pdf > > Here's a quick little page giving you a rational triangle calculator > which might just solve your problem in the first place. > http://rationaltrigcalc.azurewebsites.net/ > > -Wm > > On Tue, Mar 26, 2019 at 12:21 PM Raul Miller <rauldmil...@gmail.com> > wrote: > > > > Or often you can avoid using angles entirely and use mechanisms based > > on cross product for contexts that demand "sine" and dot product for > > cosine... > > > > (Not always, though - especially if you're working through someone > > else's math notes which were explicitly about angles.) > > > > Thanks, > > > > -- > > Raul > > > > On Tue, Mar 26, 2019 at 3:16 PM William Tanksley, Jr > > <wtanksle...@gmail.com> wrote: > > > > > > Does J provide rational trig functions? If not, you'll want to check > > > out N.J. Wildberger's rational trigonometry, based on "quadrance" (an > > > unsquare-rooted distance) and "spread" (like a relative slope of > > > quadrances). That way your rational numbers will stay rational until > > > it's time to convert them to display values. > > > > > > -Wm > > > > > > On Tue, Mar 26, 2019 at 12:12 PM Raul Miller <rauldmil...@gmail.com> > wrote: > > > > > > > > The x: verb makes a best effort, converting floating point to > rational. > > > > > > > > x:3.14 > > > > 157r50 > > > > > > > > It's limited, of course, by both floating point precision and its own > > > > internal concepts of epsilon. > > > > > > > > I hope this helps, > > > > > > > > -- > > > > Raul > > > > > > > > On Tue, Mar 26, 2019 at 3:08 PM Ian Clark <earthspo...@gmail.com> > wrote: > > > > > > > > > > I'm doing trigonometry with very small angles and I want to keep > all my > > > > > calculations in rational precision. Is there a J-supported way of > > > > > converting from floating-point precision to rational, or > reasonably speedy > > > > > verbs to do the job routinely? > > > > > > > > > > My problem is this. Let PIa be π expressed as a rational number to > 50 > > > > > places of decimals (…or more!!) > > > > > > > > > > PIa > > > > > > 31415926535897932384626433832795028841971693993751r10000000000000000000000000000000000000000000000000 > > > > > datatype PIa > > > > > rational > > > > > datatype y=: 1.23 > > > > > floating > > > > > datatype PIa + y NB. loses precision... > > > > > floating > > > > > datatype sin PIa NB. likewise loses precision... > > > > > floating > > > > > > > > > > In other words, adding in (or otherwise combining) a number (y) > which is > > > > > defined *exactly* as a decimal numeral (the sort of thing the SI > system of > > > > > units does often) results in an avoidable loss of precision. > > > > > > > > > > (In case anyone's thinking at this point: aren't 64 bits good > enough for > > > > > this guy? -- no, they aren't.) > > > > > > > > > > At present I'm using a mickey-mouse scheme of converting the > decimal > > > > > numeral (":1.23) to a rational value by omitting the decimal point > to get > > > > > '123', then reintroducing it as a denominator: '123r100' -- which > I then > > > > > evaluate using (".) to give, in effect: > > > > > datatype ya=: 123r100 > > > > > rational > > > > > datatype PIa + ya NB. --now it behaves itself... > > > > > rational > > > > > > > > > > And of course I'm going to have to write my own sin and cosine > verbs. > > > > > > > > > > The general purpose engine I'm writing not only needs a way of > converting > > > > > an inputted numeral '1.23' to a rational number (a trivial task by > the > > > > > above method) but also to check my results accumulator at every > step to > > > > > stop it lapsing into floating-point precision, and maybe to > convert it back > > > > > into rational precision. > > > > > > > > > > This last task is inefficient, the way I'm doing it. Does J have a > built-in > > > > > way, or a standard way, that's faster than how I'm doing it? > > > > > > > > > > Ian Clark > > > > > > ---------------------------------------------------------------------- > > > > > For information about J forums see > http://www.jsoftware.com/forums.htm > > > > > ---------------------------------------------------------------------- > > > > For information about J forums see > http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm