Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #57604
| From | rickman <gnuarm@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: real to rational number |
| Date | 2017-04-19 15:36 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <od8e2g$430$1@dont-email.me> (permalink) |
| References | <d34926ea-ca84-4918-aa2f-82ebb21c6470@googlegroups.com> <ca01c066-3b47-4138-8ff2-558bea6d1db8@googlegroups.com> |
On 4/18/2017 9:48 AM, lehs wrote: > Den tisdag 18 april 2017 kl. 13:49:31 UTC+2 skrev krishna...@ccreweb.org: >> Rosetta Code has a number of entries for code to converting a (computer representation) of a real number into a rational number, or to the nearest expressible fraction, a/b, where both a and b are integers. There is even a Forth entry! >> >> https://rosettacode.org/wiki/Convert_decimal_number_to_rational >> >> However, it seems like many of the algorithms expressed there are brute force searches, and don't make use of the fundamental theorem of arithmetic to find the suitable integers a and b (though the code which uses library functions may do so). >> >> This particular problem has been in the back of my mind for some time, and it is one that comes up from time to time. For example, in the quantum physics of angular momentum, the Wigner 3-j symbols are real numbers between zero and one, expressible as +/-sqrt(a/b), and if one computes the quantities as real numbers, it would be nice to find (a/b) in an efficient manner. In tables of these symbols, the rational number a/b is expressed as a series of powers of prime numbers and a sign term, e.g. -1 [1 -3 0 -1] represents >> >> r = -sqrt(2/(3^3*7)). >> >> When the finite representation of the real value is given, say to double precision, a smart algorithm to find a and b, or the prime powers representation would be handy. The real to rational code is certainly useful, but I think the algorithms should be able to take advantage of the fact that |r| <= 1. It's an interesting inversion problem. >> >> Incidentally, here is Forth code to compute Wigner 3j symbols -- it is somewhat limited in the range of usable angular momentum quantum numbers, though. >> >> ftp://ccreweb.org/software/kforth/examples/fsl/extras/cg.4th >> >> and accompanying test code, >> >> ftp://ccreweb.org/software/kforth/examples/fsl/extras/cg-test.4th >> >> Krishna > > To find an algorithm, shouldn't there be a "norm" of some kind? What is to prefer: small a and b or small difference or what? Simplest form. Here is my solution. : Rational ( F: f1 -- ) ( -- n1 n2 ) FDROP 1 1 ; It may not have the best accuracy, but it is hard to beat for simplest form. -- Rick C
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
real to rational number krishna.myneni@ccreweb.org - 2017-04-18 04:49 -0700
Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-18 06:48 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:09 -0700
Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-18 22:53 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:43 -0700
Re: real to rational number rickman <gnuarm@gmail.com> - 2017-04-19 15:41 -0400
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 13:03 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:26 +0000
Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 14:29 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-19 23:44 +0000
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 19:30 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:08 +0000
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-20 11:46 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:47 +0000
Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-20 20:49 -0700
Re: real to rational number rickman <gnuarm@gmail.com> - 2017-04-19 15:36 -0400
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 18:44 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-18 07:06 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:17 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:45 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:57 -0700
Re: real to rational number anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-19 05:35 +0000
Re: real to rational number hughaguilar96@gmail.com - 2017-04-18 23:42 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:53 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-19 11:32 -0700
Re: real to rational number minforth@arcor.de - 2017-04-18 08:23 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:24 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:48 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 20:01 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-18 19:39 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 19:56 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-19 00:41 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 04:48 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-19 11:30 -0700
Re: real to rational number albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-04-20 20:15 +0200
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 15:23 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-20 18:52 -0700
Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-18 19:58 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-18 20:05 -0700
Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:30 -0700
Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:35 -0700
Re: real to rational number Pablo Hugo Reda <pabloreda@gmail.com> - 2017-04-19 05:41 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 19:39 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-19 23:16 +0000
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-19 19:42 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-20 17:15 +0000
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 15:11 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 15:49 -0700
Re: real to rational number Alex <alex@rivadpm.com> - 2017-04-21 00:20 +0100
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 18:49 -0700
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-21 03:18 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-21 18:39 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-21 18:46 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-21 21:55 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-22 08:33 -0700
Re: real to rational number Paul Rubin <no.email@nospam.invalid> - 2017-04-22 13:35 -0700
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-24 00:58 -0700
Re: real to rational number minforth@arcor.de - 2017-04-24 01:08 -0700
Re: real to rational number minforth@arcor.de - 2017-04-23 02:28 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-21 18:43 -0700
rationalising reality, was Re: real to rational number Jan Coombs <jenfhaomndgfwutc@murmic.plus.com> - 2017-04-22 10:28 +0100
Re: rationalising reality, was Re: real to rational number Mark Wills <markwills1970@gmail.com> - 2017-04-22 02:33 -0700
Re: real to rational number krishna.myneni@ccreweb.org - 2017-04-20 16:22 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-20 22:02 -0700
Re: real to rational number Julian Fondren <julian.fondren@gmail.com> - 2017-04-21 00:12 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:55 +0000
Re: real to rational number hughaguilar96@gmail.com - 2017-04-25 10:52 -0700
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-29 03:16 +0000
Re: real to rational number "Rudy Velthuis" <newsgroups@rvelthuis.de> - 2017-04-21 09:52 +0000
Re: real to rational number lehs <skydda.barnen@gmail.com> - 2017-04-21 05:35 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-21 19:05 -0700
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-24 01:14 -0700
Re: real to rational number Cecil Bayona <cbayona@cbayona.com> - 2017-04-24 11:31 -0500
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 00:52 -0700
Re: real to rational number hughaguilar96@gmail.com - 2017-04-24 11:43 -0700
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 00:35 -0700
Re: real to rational number The Beez <the.beez.speaks@gmail.com> - 2017-04-25 01:09 -0700
Re: real to rational number minforth@arcor.de - 2017-04-26 01:55 -0700
csiph-web