Re: [Jprogramming] Finding integers:

2018-06-13 Thread Linda Alvord
b=:%: i.14 f=: 13 :'(=<.)y' g=: 13 :'y=<.y' f = <. g ] = <. (f b)-:g b 1 Maybe J could simplify the display of function g. Linda -Original Message- From: Programming On Behalf Of 'Bo Jacoby' via Programming Sent: Tuesday, June 12, 2018 6:13 PM To: programm...@jsoftware.

Re: [Jprogramming] Finding integers:

2018-06-13 Thread Raul Miller
J should not simplify display of the function g because with different arguments they give different results. For example, think about what happens with 2 for a left argument. Thanks, — Raul On Wednesday, June 13, 2018, Linda Alvord wrote: > b=:%: i.14 >f=: 13 :'(=<.)y' >g=: 13 :'y=<.

Re: [Jprogramming] Finding integers:

2018-06-13 Thread Martin Kreuzer
-1- For "I want to find the integers in a vector of floating point numbers" this will do: inr=: =<. NB. boolean 'is not real' ] v=. 1r3 1r2 1,(%:3),2 2.99 3 1p1 0.33 0.5 1 1.73205 2 2.99 3 3.14159 inr v 0 0 1 0 1 0 1 0 (inr v) # v 1 2 3 fi=: (=<.) # ] fi v 1 2

Re: [Jprogramming] Finding integers:

2018-06-13 Thread Skip Cave
Thanks to all for the helpful replies to my question about finding integers in a string of floating point numbers. I find that finding the boolean mark array (derived tolerantly) indicating the location of the integers in an array of floating point numbers is most useful for the majority of my app

[Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
Here's another problem similar to my previous one about finding integers in a floating point array: Find the irrational numbers in a floating-point array: Given the vector a: ]a =. % 1+i.20 1 0.5 0.33 0.25 0.2 0.17 0.142857 0.125 0.11 0.1 0.0909091 0.083 0.0769231 0.0714286 0.06

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Roger Hui
What's an irrational number in this context? Your list a are reciprocals of integers and so are all rational. On the other hand, going just by the display, 0.5 is a rational number (1%2), but since the display is to 6 significant digits, for all you know 0.5 could be 0.50314159265358979... (0

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
Roger, You're right. The array i generated was all rational numbers. I'll try again: ]a=.(20?20){(100*%1+i.10),(10?20)*o.1 6.28319 10 11. 16.6667 25.1327 100 0 21.9911 33. 56.5487 12.5 31.4159 53.4071 14.2857 25 43.9823 50 12.5664 59.6903 20 Is that a better combination of rational and

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Roger Hui
Mathematically, all finite precision floating point numbers (e.g. 64-bit floats) are rational since they are all ratios of integers. You have to specify something (size of repeating pattern? size of denominator? relative size of numerator/denominator? ??) before the question can be answered. For

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
Ok. I see. We know pi is an irrational number. However, in J: x: o.1 1285290289249r409120605684 J converts pi to a rational fraction approximation of pi. So I'm not sure how to generate a vector of truly irrational numbers in J. Can it be done, or is there no way to define/create true irration

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread William Tanksley, Jr
Irrational numbers cannot be represented by floats, rationals, or integers. You'd have to make a special type to represent irrationals, and of course it would only represent as many of them as you choose to assign values to (for example, your type might represent a floating point number times the s

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Roger Hui
> On a similar note, is there a way to detect which numbers in a vector of > rational fractions will result in infinitely repeating floating-point > numbers? All rational fractions result in infinitely repeating floating point numbers. They are the same sets. On Wed, Jun 13, 2018 at 11:44 AM, Sk

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
Skip said: Given the vector a: ]a =. % 1+i.20 1 0.5 0.33 0.25 0.2 0.17 0.142857 0.125 0.11 0.1 0.0909091 0.083 0.0769231 0.0714286 0.067 0.0625 0.0588235 0.056 0.0526316 0.05 Roger said: Your list a are reciprocals of integers and so are all rational. Roger also said: Al

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Henry Rich
The trailing 0 repeats forever. Henry Rich On 6/13/2018 3:05 PM, Skip Cave wrote: Skip said: Given the vector a: ]a =. % 1+i.20 1 0.5 0.33 0.25 0.2 0.17 0.142857 0.125 0.11 0.1 0.0909091 0.083 0.0769231 0.0714286 0.067 0.0625 0.0588235 0.056 0.0526316 0.05 Roger said:

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
Ok. Then I redefine my question: Given the vector a: ]a =. % 1+i.20 1 0.5 0.33 0.25 0.2 0.17 0.142857 0.125 0.11 0.1 0.0909091 0.083 0.0769231 0.0714286 0.067 0.0625 0.0588235 0.056 0.0526316 0.05 Define a verb that will find all the floating-point numbers in a that wil

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Raul Miller
To see the literal structure of a floating point number, you can use: fpdigits=:3 :'(1 j.0 11 e.~i.64)#'' ''-.~":,(8#2)#:a.i.|._8{.3!:1 y+1.1-1.1'"0 NB. sign (1 is negative), mantissa+1023, exponent with implied leading 1 Here, I'm going to use it to illustrate two issues: a) floating point repr

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Raul Miller
Floating point numbers implicitly terminate in infinitely repeating zeros after the 52 expressed bits of mantissa. Or, put differently, when we need to represent numbers which have non-zero bits that can't be represented, we approximate. Or, another view of floating point numbers is that they each

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread William Tanksley, Jr
You could do this with rational numbers, since whether or not they terminate IS an interesting puzzle. Of course, you have to specify a "decimal" base -- 1/3 doesn't terminate base 10, but does terminate base 60. On Wed, Jun 13, 2018 at 12:26 PM Raul Miller wrote: > Floating point numbers implic

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Raul Miller
You would also have to specify the precision of the result. Put different: if that specification is too precise (pushing the limits of what floating point numbers can represent), the algorithm would degrade to meaninglessness because of floating point inaccuracies. And, if that specification was n

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread William Tanksley, Jr
No need to specify the precision if the input is actually rational numbers, not floating point numbers. On Wed, Jun 13, 2018 at 12:47 PM Raul Miller wrote: > You would also have to specify the precision of the result. > > Put different: if that specification is too precise (pushing the > limits

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Skip Cave
So I'm thinking something like this, to find exact numbers in a floating point array: pps 15 NB. Set the print precision. Create a mixed floating point vector b: ]b=:(,3? 10^1+i.4),%a=:1+i.20 0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.333 0.25 0.2 0.167 0.1

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Raul Miller
Oh, I see - yes, as long as the values are represented precisely, yes. Basically: terminates=:4 :0 (q:x) -:&(*./) x ,&q: {:2 x:y ) 60 terminates 1r120 1 60 terminates 1r121 0 Thanks, -- Raul On Wed, Jun 13, 2018 at 3:51 PM William Tanksley, Jr wrote: > > No need to specify the prec

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Raul Miller
So, something like this? fe=:4 :0 p=. 9!:10'' vi=. _. ve=. y try. 9!:11 x ve=. ":&.>y 9!:11]15 vi=. ":&.>y catch. end. 9!:11 p ve=vi ) Thanks, -- Raul On Wed, Jun 13, 2018 at 4:22 PM Skip Cave wrote: > > So I'm thinking something like this, to find exact numbers

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Linda Alvord
I wrote a definition with only one argument. Linda Get Outlook for Android From: Programming on behalf of Raul Miller Sent: Wednesday, June 13, 2018 4:36:31 PM To: Programming forum Subject: Re: [Jprogramming] Finding Irrational Numbers