Re: [Jprogramming] Numerator and Denominator

2016-03-11 Thread Martin Kreuzer
mming [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Martin Kreuzer Sent: Friday, March 11, 2016 7:30 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Numerator and Denominator btw (and as expected) D.E. Knuth, The Art of Computer Programming, 2nd, vol 2, pages 339 ff uses

Re: [Jprogramming] Numerator and Denominator

2016-03-11 Thread Linda A Alvord
Would this be helpful? ,v,.($v)#1 0 1 1 1 2 1 3 1 Linda -Original Message- From: Programming [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Martin Kreuzer Sent: Friday, March 11, 2016 7:30 AM To: programm...@jsoftware.com Subject: Re: [Jprogramming] Numerator and

Re: [Jprogramming] Numerator and Denominator

2016-03-11 Thread Martin Kreuzer
btw (and as expected) D.E. Knuth, The Art of Computer Programming, 2nd, vol 2, pages 339 ff uses this convention as a shorthand to describe a regular continued fraction: / x1, x2, ...,xn / like in these examples 8/29 = / 3, 1, 1, 1, 2 / e = 2 + / 1, 2, 1, 1, 4, 1, 1, 6, 1,... / -M At 2016-03-10

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Mike Day
[ a0 ; a1 a2 a3 ... ] ? Usage seems to vary - the ";" appears to be optional, but if used, it can be thought of as the integer part: a0 + 1 % (a1 + 1 % ( a2 + 1 % (a3 +... ) ) ) The notation may be extended to use a comma (",") to indicate repeated groups, so, dropping the ";" rt2 = [1 2 2 2

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Kip Murray
Your question is too hard for me. If I wanted to look into it, I would start with paragraph 3.10 Theorems on Continued Fractions on page 10 of the Handbook of Mathematical Functions edited by Abramowitz and Stegun. The matrix theorem shown there may help. What does your notation [ a0 ; a1 a2 a3

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Mike Day
So how do you add [a0; a1 a2 a3 ...] and [b0; b1 b2 b3 b4] to yield [c0;c1 c2 c3 c4...] using just their encodings as cfs? For example, 3r11 + 1r2 = 17r22 ; or, as c.f. [1;5 2] + [0;2] = [1;1 2 7] How would you do the latter directly? Mike On 10/03/2016 17:18, Kip Murray wrote: J Continued

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Kip Murray
J Continued Fractions Let us consider the continued fraction 1 + 2 % 3 + 4 % 5 + 6 % 7 + … This represents the infinite list 1 , (1+2%3), (1 + 2%3 + 4 % 5), … I follow the convention that each term after the first ends with a denominator. We can calculate 1 + 2 % 3 + 4 % 5 using. +`% / 1 2 3

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Mike Day
Thanks, Bo. I was going to reply saying "yes, but what about doing arithmetic with cf?" But I see there are methods for addition etc with such representations. They're fairly formidable, and I don't quite see yet how to control the precision of such operations. Unlike p-adics, they're not

Re: [Jprogramming] Numerator and Denominator

2016-03-10 Thread Bo Jacoby
The standard approach to get rational approximations to irrational numbers is that of continued fractions.  Den 0:23 torsdag den 10. marts 2016 skrev Mike Day : I'm not at all sure that you'll find this relevant,  but here goes,  anyway: I recently solved Euler problem 541 which conc

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Mike Day
I'm not at all sure that you'll find this relevant, but here goes, anyway: I recently solved Euler problem 541 which concerns harmonic numbers: https://projecteuler.net/problem=541 I started out, in J of course, with rationals, but the size of the problem is against at least my naive appli

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Marshall Lochbaum
The best rational approximations to a number can be obtained from its continued fraction representation. Simply truncating the continued fraction gives a smaller list of approximants which are accurate relative to the size of their denominators, and truncating and possibly reducing the last number

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Don Guinn
Rational numbers have always fascinated me. I wanted to build a gear train for a science fair where the gears form a loop where the gear train does not mesh. But only after many thousands of revolutions. Then a sign on the front asking people to break the gears by turning the crank. Long ago the H

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Raul Miller
That seems a bit underspecified, or open-ended, at the moment. For example, pi could be 1p1 (or o.1) or pi could be any of a number of algorithms: https://en.wikipedia.org/wiki/Category:Pi_algorithms Meanwhile, there's also the precision aspect - that could also be specified in a variety of ways.

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Don Guinn
How about rounding to a rational of some precision like pi rounded to 22r7 ? On Mar 9, 2016 8:52 AM, "Kip Murray" wrote: > Thanks, Roger and Raul. Not understanding GCD +. I had a Rube Goldberg > solution involving Format ": and Do ". --Kip > > On Wednesday, March 9, 2016, Roger Hui wrot

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Kip Murray
Thanks, Roger and Raul. Not understanding GCD +. I had a Rube Goldberg solution involving Format ": and Do ". --Kip On Wednesday, March 9, 2016, Roger Hui wrote: > den and num illustrate different ways of computing the same thing, > hopefully in so doing improves understanding. If you w

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Roger Hui
den and num illustrate different ways of computing the same thing, hopefully in so doing improves understanding. If you want speed 2&x: is going to be faster. Also, watch this: 2 x: o. 1 1285290289249 409120605684 x: o. 1 1285290289249r409120605684 2 x:!.0 o. 1 884279719003555 28147497

Re: [Jprogramming] Numerator and Denominator

2016-03-09 Thread Mike Day
Roger, are these (among) recommended and preferred methods for recovering num & den, or do they just show an elegant way of avoiding 2 x: ? Thanks, Mike On 09/03/2016 04:32, Roger Hui wrote: x=: %/?2$10^8x x 69904549r40669028 den=: [: % 1 +. ] num=: * den den x 40669028

Re: [Jprogramming] Numerator and Denominator

2016-03-08 Thread Linda A Alvord
ubject: Re: [Jprogramming] Numerator and Denominator x=: %/?2$10^8x x 69904549r40669028 den=: [: % 1 +. ] num=: * den den x 40669028 num x 69904549 On Tue, Mar 8, 2016 at 7:28 PM, Kip Murray wrote: > That's great! It's still a nice puzzle to write your own. --Ki

Re: [Jprogramming] Numerator and Denominator

2016-03-08 Thread Roger Hui
x=: %/?2$10^8x x 69904549r40669028 den=: [: % 1 +. ] num=: * den den x 40669028 num x 69904549 On Tue, Mar 8, 2016 at 7:28 PM, Kip Murray wrote: > That's great! It's still a nice puzzle to write your own. --Kip > > On Tuesday, March 8, 2016, Raul Miller wrote: > > >

Re: [Jprogramming] Numerator and Denominator

2016-03-08 Thread Raul Miller
Oh... well... if it's a puzzle and you don't want the built in, I suppose you could do this: s p o i l e r s p a c e . . . nd=: (%, %@])1&+. -- Raul On Tue, Mar 8, 2016 at 10:28 PM, Kip Murray wrote: > That's great! It's still a nice puzzle to write your own. --Kip > > O

Re: [Jprogramming] Numerator and Denominator

2016-03-08 Thread Kip Murray
That's great! It's still a nice puzzle to write your own. --Kip On Tuesday, March 8, 2016, Raul Miller wrote: >2 x: 6r4 > 3 2 > > -- > Raul > > > On Tue, Mar 8, 2016 at 10:04 PM, Kip Murray > wrote: > > How do you find the numerator and denominator in lowest terms of a > rational > > frac

Re: [Jprogramming] Numerator and Denominator

2016-03-08 Thread Raul Miller
2 x: 6r4 3 2 -- Raul On Tue, Mar 8, 2016 at 10:04 PM, Kip Murray wrote: > How do you find the numerator and denominator in lowest terms of a rational > fraction? For example, > > nd 6r4 > 3 2 > > --Kip Murray > > > > -- > Sent from Gmail Mobile > --

[Jprogramming] Numerator and Denominator

2016-03-08 Thread Kip Murray
How do you find the numerator and denominator in lowest terms of a rational fraction? For example, nd 6r4 3 2 --Kip Murray -- Sent from Gmail Mobile -- For information about J forums see http://www.jsoftware.com/forums.