Re: [Jprogramming] Finding Irrational Numbers

2018-06-15 Thread Cliff Reiter
My first reaction to Bo's remarks (far below) was "well said and very 
sensible" although my instinct was to use 1e8 near half the precision of 
floats. I started playing with tacit versions and got to observe what I 
thought was a surprising number of false positives.

First some tacit fun:

   rat1=:13 : '1e9>1{"1]2 x: y'
   rat2=:1e9 > 1 {"1 (2:)
   rat3=:1e9 > 1 {"1 x:~&2
   rat1
10 > 1 {"1 [: ] 2 x: ]
   rat2
10 > 1 ({"1) 2:
   rat3
10 > 1 {"1 x:~&2
   ts=:6!:2 , 7!:2@]
   100 ts 'rat1 1r3^~i.1'
0.118844 1.00918e7
   100 ts 'rat2 1r3^~i.1'
0.117574 1.02228e7
   100 ts 'rat3 1r3^~i.1'
0.117814 1.02228e7
All very close in performance. I think rat2 is the most readable but 
rat3 is a character shorter. Now some experiments where I had some 
expectations.


   +/rat3 1r3^~i.1
109

I expected around

   3%:1-1
21.5436

poke around for a small false positive
   i#~rat3 1r3^~i=:i.1000
0 1 8 27 64 89 125 216 343 441 512 607 729
   89^1r3
4.46475
   x: 89^1r3
1344576733r301154199
   rat3 89^1r3
1

How about using 1e5 instead of 1e9:
   rat4=:1e5 > 1 {"1 x:~&2
   +/rat4 1r3^~i.1
26
   +/rat4 1r2^~i.1
100
   +/rat4 o.i.1000
4

And a couple more experiments
   +/rat3 o.i.1000
289
   +/rat3 0.01*1r3^~i.1
28

So, as previously noted by others, beware. But if you are going to use a 
test for rational, you might do better with something less than 1e9.


On 6/14/2018 7:00 PM, 'Bo Jacoby' via Programming wrote:

I completely agree with Raul. We all agree that the problem of identifying 
irrational floating point numbers is unsolvable, simply because any floating 
point number is rational. Critics need not show that a proposed algorithm is 
imperfect, but rather suggest improvements.
    rational=.3 : '1e9>1{"1]2 x: y'
    rational 10^_8 _9 NB. useless result
1 0
    rational (%3)^~i.9 NB. useful result
1 1 0 0 0 0 0 0 1

/Bo..

  


 Den 16:37 torsdag den 14. juni 2018 skrev Raul Miller 
:
  


  Or, put different, it's a heuristic:

It's likely to be right significantly more often than it's wrong for a
variety of likely contexts.

But it's going to be wrong some of the time, also, and it's useful to
understand why that would be.

Thanks,



--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread 'Bo Jacoby' via Programming
I completely agree with Raul. We all agree that the problem of identifying 
irrational floating point numbers is unsolvable, simply because any floating 
point number is rational. Critics need not show that a proposed algorithm is 
imperfect, but rather suggest improvements.
   rational=.3 : '1e9>1{"1]2 x: y'
   rational 10^_8 _9 NB. useless result
1 0
   rational (%3)^~i.9 NB. useful result
1 1 0 0 0 0 0 0 1

/Bo.. 

 

Den 16:37 torsdag den 14. juni 2018 skrev Raul Miller 
:
 

 Or, put different, it's a heuristic:

It's likely to be right significantly more often than it's wrong for a
variety of likely contexts.

But it's going to be wrong some of the time, also, and it's useful to
understand why that would be.

Thanks,

-- 
Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm

   
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread Raul Miller
Or, put different, it's a heuristic:

It's likely to be right significantly more often than it's wrong for a
variety of likely contexts.

But it's going to be wrong some of the time, also, and it's useful to
understand why that would be.

Thanks,

-- 
Raul
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread Henry Rich

What Bo means is that if you execute

a =: irrational_number

and then convert the approximation a to rational, the denominator will 
be large.


Not necessarily true: first of all, x: uses tolerant comparison:

   x: 1.001
1

so to look at all the bits of a you need

   (x:!.0) 1.001
900719925474100r900719925474099

[and note: that was a perfectly respectable rational number, but it 
comes out with a large denominator]


Moreover,

   x: 1.00014973485793   NB. It's an irrational number, 
I just got tired of typing

1

Henry Rich




On 6/14/2018 10:12 AM, William Tanksley, Jr wrote:

I have no idea why you're saying that. Irrationals don't have denominators;
they cannot be written as fractions. And no floating point numbers are
irrationals.

On Thu, Jun 14, 2018 at 12:18 AM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:


If a floating point number (a) , is irrational, then (x:a) has a
denominator greater than 1e10.
Some rational and irrational numbers are:
x:%%:>:i.5
1 676982533219r957397879968 9943229281777r17222178307344 1r2
8728368286235r19517224820674
The denominators are:
 1 957397879968 17222178307344 2 19517224820674
1 9.57398e11 1.7e13 2 1.95172e13
So the problem of identifying irrational numbers is reduced to the problem
of finding the denominator in x:a
/Bo.

 Den 23:42 onsdag den 13. juni 2018 skrev Linda Alvord <
lindaalvor...@outlook.com>:



I wrote a definition with only one argument.

Linda

Get Outlook for Android<https://aka.ms/ghei36>


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

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 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.142857142857143 0.125 0.111 0.1
0.0909090909090909 0.0833 0.0769230769230769

0.0714285714285714

0.0667 0.0625 0.0588235294117...


Create a "find exact" verb 'fe' where x=the number of digits max that can
be exact, and y is the vector to be tested (boolean result):


fe=. 4 : 'x> ># each ": each <"1,.y'


]c=.9 fe b

1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1


Show exact:

c#b

0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
0.05


Show inexact:

(-.c)#b

0.333 0.167 0.142857142857143 0.111
0.0909090909090909 0.0833 0.0769230769230769

0.0714285714285714

0.0667 0.0588235294117647 0.0556

0.0526315789473684

#b

32

#c#b

20


I'm sure this scheme has some holes, but it is a reasonable first cut.


Skip
--
For information about J forums see

https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
For information about J forums see
https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
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



---
This email has been checked for viruses by AVG.
https://www.avg.com

--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread William Tanksley, Jr
I have no idea why you're saying that. Irrationals don't have denominators;
they cannot be written as fractions. And no floating point numbers are
irrationals.

On Thu, Jun 14, 2018 at 12:18 AM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:

> If a floating point number (a) , is irrational, then (x:a) has a
> denominator greater than 1e10.
> Some rational and irrational numbers are:
>x:%%:>:i.5
> 1 676982533219r957397879968 9943229281777r17222178307344 1r2
> 8728368286235r19517224820674
> The denominators are:
> 1 957397879968 17222178307344 2 19517224820674
> 1 9.57398e11 1.7e13 2 1.95172e13
> So the problem of identifying irrational numbers is reduced to the problem
> of finding the denominator in x:a
> /Bo.
>
> Den 23:42 onsdag den 13. juni 2018 skrev Linda Alvord <
> lindaalvor...@outlook.com>:
>
>
>
> I wrote a definition with only one argument.
>
> Linda
>
> Get Outlook for Android<https://aka.ms/ghei36>
>
> 
> 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
>
> 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 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.142857142857143 0.125 0.111 0.1
> > 0.0909090909090909 0.0833 0.0769230769230769
> 0.0714285714285714
> > 0.0667 0.0625 0.0588235294117...
> >
> >
> > Create a "find exact" verb 'fe' where x=the number of digits max that can
> > be exact, and y is the vector to be tested (boolean result):
> >
> >
> >fe=. 4 : 'x> ># each ": each <"1,.y'
> >
> >
> >]c=.9 fe b
> >
> > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1
> >
> >
> > Show exact:
> >
> >c#b
> >
> > 0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
> > 0.05
> >
> >
> > Show inexact:
> >
> >(-.c)#b
> >
> > 0.333 0.167 0.142857142857143 0.111
> > 0.0909090909090909 0.0833 0.0769230769230769
> 0.0714285714285714
> > 0.0667 0.0588235294117647 0.0556
> 0.0526315789473684
> >
> >#b
> >
> > 32
> >
> >#c#b
> >
> > 20
> >
> >
> > I'm sure this scheme has some holes, but it is a reasonable first cut.
> >
> >
> > Skip
> > --
> > For information about J forums see
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
> --
> For information about J forums see
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
> --
> 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

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread 'Bo Jacoby' via Programming
   1e9<1{"1]2 x: %:i.26
0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0

1{   is better than   }.   .

   1{"1]2 x: %:14
6286063111
This denominator is <1e10
/Bo.
 

Den 11:44 torsdag den 14. juni 2018 skrev Skip Cave 
:
 

 ​​
OK. Thanks to Bo, sizing the denominators looks like the way to go. Here's
a verb that looks at the denominators of extended/rational numbers and
determine if the denominator is too big, and thus the number is inexact:

NB. First generate some exact & inexact numbers:

]t=.x:%%:>:i.5

1 676982533219r957397879968 9943229281777r17222178307344 1r2
8728368286235r19517224820674


NB. Now get the denominators, & check the size - too big=0, small enough -
1:

-.,1e10<}."1(2:)t

1 0 0 1 0


NB. Use the selection vector to pick out the exact values:

t#~-.,1e10<}."1(2:)t

1 1r2


]b=.x:%%:>:i.15

1 676982533219r957397879968 9943229281777r17222178307344 1r2
8728368286235r19517224820674 250258529119r613005700122
12895459543967r34118178995231 1532495590117r4334552095641 1r3
16884524975r53393556131 535761049157r1776918377341
3208086930518r313911750...

b#~ -.,1e10<}."1(2:)b

1 1r2 1r3

Skip


On Thu, Jun 14, 2018 at 2:18 AM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:

> If a floating point number (a) , is irrational, then (x:a) has a
> denominator greater than 1e10.
> Some rational and irrational numbers are:
>    x:%%:>:i.5
> 1 676982533219r957397879968 9943229281777r17222178307344 1r2
> 8728368286235r19517224820674
> The denominators are:
>    1 957397879968 17222178307344 2 19517224820674
> 1 9.57398e11 1.7e13 2 1.95172e13
> So the problem of identifying irrational numbers is reduced to the problem
> of finding the denominator in x:a
> /Bo.
>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

   
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread Skip Cave
​​
OK. Thanks to Bo, sizing the denominators looks like the way to go. Here's
a verb that looks at the denominators of extended/rational numbers and
determine if the denominator is too big, and thus the number is inexact:

NB. First generate some exact & inexact numbers:

]t=.x:%%:>:i.5

1 676982533219r957397879968 9943229281777r17222178307344 1r2
8728368286235r19517224820674


NB. Now get the denominators, & check the size - too big=0, small enough -
1:

-.,1e10<}."1(2:)t

1 0 0 1 0


NB. Use the selection vector to pick out the exact values:

t#~-.,1e10<}."1(2:)t

1 1r2


]b=.x:%%:>:i.15

1 676982533219r957397879968 9943229281777r17222178307344 1r2
8728368286235r19517224820674 250258529119r613005700122
12895459543967r34118178995231 1532495590117r4334552095641 1r3
16884524975r53393556131 535761049157r1776918377341
3208086930518r313911750...

b#~ -.,1e10<}."1(2:)b

1 1r2 1r3

Skip


On Thu, Jun 14, 2018 at 2:18 AM 'Bo Jacoby' via Programming <
programm...@jsoftware.com> wrote:

> If a floating point number (a) , is irrational, then (x:a) has a
> denominator greater than 1e10.
> Some rational and irrational numbers are:
>x:%%:>:i.5
> 1 676982533219r957397879968 9943229281777r17222178307344 1r2
> 8728368286235r19517224820674
> The denominators are:
> 1 957397879968 17222178307344 2 19517224820674
> 1 9.57398e11 1.7e13 2 1.95172e13
> So the problem of identifying irrational numbers is reduced to the problem
> of finding the denominator in x:a
> /Bo.
>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-14 Thread 'Bo Jacoby' via Programming
If a floating point number (a) , is irrational, then (x:a) has a denominator 
greater than 1e10.
Some rational and irrational numbers are:
   x:%%:>:i.5
1 676982533219r957397879968 9943229281777r17222178307344 1r2 
8728368286235r19517224820674
The denominators are:
    1 957397879968 17222178307344 2 19517224820674
1 9.57398e11 1.7e13 2 1.95172e13
So the problem of identifying irrational numbers is reduced to the problem of 
finding the denominator in x:a
/Bo. 

Den 23:42 onsdag den 13. juni 2018 skrev Linda Alvord 
:
 

 
I wrote a definition with only one argument.

Linda

Get Outlook for Android<https://aka.ms/ghei36>


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

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 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.142857142857143 0.125 0.111 0.1
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0625 0.0588235294117...
>
>
> Create a "find exact" verb 'fe' where x=the number of digits max that can
> be exact, and y is the vector to be tested (boolean result):
>
>
>    fe=. 4 : 'x> ># each ": each <"1,.y'
>
>
>    ]c=.9 fe b
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1
>
>
> Show exact:
>
>    c#b
>
> 0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
> 0.05
>
>
> Show inexact:
>
>    (-.c)#b
>
> 0.333 0.167 0.142857142857143 0.111
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0588235294117647 0.0556 0.0526315789473684
>
>    #b
>
> 32
>
>    #c#b
>
> 20
>
>
> I'm sure this scheme has some holes, but it is a reasonable first cut.
>
>
> Skip
> --
> For information about J forums see 
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
For information about J forums see 
https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
For information about J forums see http://www.jsoftware.com/forums.htm

   
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Finding Irrational Numbers

2018-06-13 Thread Linda Alvord

I wrote a definition with only one argument.

Linda

Get Outlook for Android<https://aka.ms/ghei36>


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

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 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.142857142857143 0.125 0.111 0.1
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0625 0.0588235294117...
>
>
> Create a "find exact" verb 'fe' where x=the number of digits max that can
> be exact, and y is the vector to be tested (boolean result):
>
>
>fe=. 4 : 'x> ># each ": each <"1,.y'
>
>
>]c=.9 fe b
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1
>
>
> Show exact:
>
>c#b
>
> 0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
> 0.05
>
>
> Show inexact:
>
>(-.c)#b
>
> 0.333 0.167 0.142857142857143 0.111
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0588235294117647 0.0556 0.0526315789473684
>
>#b
>
> 32
>
>#c#b
>
> 20
>
>
> I'm sure this scheme has some holes, but it is a reasonable first cut.
>
>
> Skip
> --
> For information about J forums see 
> https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
For information about J forums see 
https://nam02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm=02%7C01%7C%7C41ac47c72e1441cc1f0b08d5d16d6b12%7C84df9e7fe9f640afb435%7C1%7C0%7C636645190246397362=C%2B8YZ2EAW533k4brRJj7gZXQzxUXVbnCthCXYM1YZ1I%3D=0
--
For information about J forums see http://www.jsoftware.com/forums.htm

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 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.142857142857143 0.125 0.111 0.1
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0625 0.0588235294117...
>
>
> Create a "find exact" verb 'fe' where x=the number of digits max that can
> be exact, and y is the vector to be tested (boolean result):
>
>
>fe=. 4 : 'x> ># each ": each <"1,.y'
>
>
>]c=.9 fe b
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1
>
>
> Show exact:
>
>c#b
>
> 0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
> 0.05
>
>
> Show inexact:
>
>(-.c)#b
>
> 0.333 0.167 0.142857142857143 0.111
> 0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
> 0.0667 0.0588235294117647 0.0556 0.0526315789473684
>
>#b
>
> 32
>
>#c#b
>
> 20
>
>
> I'm sure this scheme has some holes, but it is a reasonable first cut.
>
>
> Skip
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

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 ,: {: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 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 of what floating point numbers can represent), the algorithm
> > would degrade to meaninglessness because of floating point
> > inaccuracies. And, if that specification was not precise enough then
> > you wouldn't be able to represent many values.
> >
> > Something like six digits of decimal (base 10 (base 10 (base 10
> > (... precision might be a sweet spot.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> > On Wed, Jun 13, 2018 at 3:34 PM William Tanksley, Jr
> >  wrote:
> > >
> > > 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 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 represent an infinity
> > > > of values which divide the number line between the preceding and
> > > > following values (with a few special cases, like the ininities).
> > > >
> > > > I hope this helps in your efforts to express what you are looking
> > for...
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > > On Wed, Jun 13, 2018 at 3:23 PM Skip Cave 
> > wrote:
> > > > >
> > > > > 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
> > > > will
> > > > > eventually terminate in infinitely repeating zeros.
> > > > >
> > > > >
> > > > > Skip
> > > > >
> > > > >
> > > > > On Wed, Jun 13, 2018 at 2:12 PM Henry Rich 
> > wrote:
> > > > >
> > > > > > The trailing 0 repeats forever.
> > > > > >
> > > > > > Henry Rich
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > --
> > > > > 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

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.142857142857143 0.125 0.111 0.1
0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
0.0667 0.0625 0.0588235294117...


Create a "find exact" verb 'fe' where x=the number of digits max that can
be exact, and y is the vector to be tested (boolean result):


   fe=. 4 : 'x> ># each ": each <"1,.y'


   ]c=.9 fe b

1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1


Show exact:

   c#b

0 2 7 36 93 57 808 875 559 4674 8635 6196 1 0.5 0.25 0.2 0.125 0.1 0.0625
0.05


Show inexact:

   (-.c)#b

0.333 0.167 0.142857142857143 0.111
0.0909090909090909 0.0833 0.0769230769230769 0.0714285714285714
0.0667 0.0588235294117647 0.0556 0.0526315789473684

   #b

32

   #c#b

20


I'm sure this scheme has some holes, but it is a reasonable first cut.


Skip
--
For information about J forums see http://www.jsoftware.com/forums.htm

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 of what floating point numbers can represent), the algorithm
> would degrade to meaninglessness because of floating point
> inaccuracies. And, if that specification was not precise enough then
> you wouldn't be able to represent many values.
>
> Something like six digits of decimal (base 10 (base 10 (base 10
> (... precision might be a sweet spot.
>
> Thanks,
>
> --
> Raul
>
> On Wed, Jun 13, 2018 at 3:34 PM William Tanksley, Jr
>  wrote:
> >
> > 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 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 represent an infinity
> > > of values which divide the number line between the preceding and
> > > following values (with a few special cases, like the ininities).
> > >
> > > I hope this helps in your efforts to express what you are looking
> for...
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > > On Wed, Jun 13, 2018 at 3:23 PM Skip Cave 
> wrote:
> > > >
> > > > 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
> > > will
> > > > eventually terminate in infinitely repeating zeros.
> > > >
> > > >
> > > > Skip
> > > >
> > > >
> > > > On Wed, Jun 13, 2018 at 2:12 PM Henry Rich 
> wrote:
> > > >
> > > > > The trailing 0 repeats forever.
> > > > >
> > > > > Henry Rich
> > > > >
> > > > >
> > > > >
> > > >
> --
> > > > 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

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 not precise enough then
you wouldn't be able to represent many values.

Something like six digits of decimal (base 10 (base 10 (base 10
(... precision might be a sweet spot.

Thanks,

-- 
Raul

On Wed, Jun 13, 2018 at 3:34 PM William Tanksley, Jr
 wrote:
>
> 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 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 represent an infinity
> > of values which divide the number line between the preceding and
> > following values (with a few special cases, like the ininities).
> >
> > I hope this helps in your efforts to express what you are looking for...
> >
> > Thanks,
> >
> > --
> > Raul
> > On Wed, Jun 13, 2018 at 3:23 PM Skip Cave  wrote:
> > >
> > > 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
> > will
> > > eventually terminate in infinitely repeating zeros.
> > >
> > >
> > > Skip
> > >
> > >
> > > On Wed, Jun 13, 2018 at 2:12 PM Henry Rich  wrote:
> > >
> > > > The trailing 0 repeats forever.
> > > >
> > > > Henry Rich
> > > >
> > > >
> > > >
> > > --
> > > 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

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 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 represent an infinity
> of values which divide the number line between the preceding and
> following values (with a few special cases, like the ininities).
>
> I hope this helps in your efforts to express what you are looking for...
>
> Thanks,
>
> --
> Raul
> On Wed, Jun 13, 2018 at 3:23 PM Skip Cave  wrote:
> >
> > 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
> will
> > eventually terminate in infinitely repeating zeros.
> >
> >
> > Skip
> >
> >
> > On Wed, Jun 13, 2018 at 2:12 PM Henry Rich  wrote:
> >
> > > The trailing 0 repeats forever.
> > >
> > > Henry Rich
> > >
> > >
> > >
> > --
> > 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

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 represent an infinity
of values which divide the number line between the preceding and
following values (with a few special cases, like the ininities).

I hope this helps in your efforts to express what you are looking for...

Thanks,

-- 
Raul
On Wed, Jun 13, 2018 at 3:23 PM Skip Cave  wrote:
>
> 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 will
> eventually terminate in infinitely repeating zeros.
>
>
> Skip
>
>
> On Wed, Jun 13, 2018 at 2:12 PM Henry Rich  wrote:
>
> > The trailing 0 repeats forever.
> >
> > Henry Rich
> >
> >
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm

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 representation is not a decimal notation.

   fpdigits 0.2
0 000 1001100110011001100110011001100110011001100110011010

b) as Henry Rich pointed out, the zeros repeat for otherwise exact
binary fractions:

   fpdigits 0.5
0 010 

There are a few other tricks and issues related to floating point
numbers, but this should help?

Thanks,

-- 
Raul
On Wed, Jun 13, 2018 at 3:06 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:
> Your list a are reciprocals of integers and so are all rational.
>
> Roger also said:
> All rational fractions result in infinitely repeating floating point
> numbers.  They are the same sets.
>
> Skip says:
> So all the numbers in a are rational, and infinitely repeating? Like 0.5,
> 0.25. 0.2, 0.1? I'm confused. These examples don't seem to have infinitely
> repeating decimals.
>
> Skip
>
>
> On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
> wrote:
>
> > 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.5+ pi*1e_7) and irrational.
> >
> >
> > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> > wrote:
> >
> > > 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.067 0.0625 0.0588235 0.056
> > > 0.0526316 0.05
> > >
> > >
> > > Create a function that will generate a boolean array indicating the
> > > locations of the irrational numbers in a.
> > >
> > >
> > > Skip
> > > --
> > > 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

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 will
eventually terminate in infinitely repeating zeros.


Skip


On Wed, Jun 13, 2018 at 2:12 PM Henry Rich  wrote:

> The trailing 0 repeats forever.
>
> Henry Rich
>
>
>
--
For information about J forums see http://www.jsoftware.com/forums.htm

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:
Your list a are reciprocals of integers and so are all rational.

Roger also said:
All rational fractions result in infinitely repeating floating point
numbers.  They are the same sets.

Skip says:
So all the numbers in a are rational, and infinitely repeating? Like 0.5,
0.25. 0.2, 0.1? I'm confused. These examples don't seem to have infinitely
repeating decimals.

​Skip


On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
wrote:


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.5+ pi*1e_7) and irrational.


On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
wrote:


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.067 0.0625 0.0588235 0.056
0.0526316 0.05


Create a function that will generate a boolean array indicating the
locations of the irrational numbers in a.


Skip
--
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



---
This email has been checked for viruses by AVG.
https://www.avg.com

--
For information about J forums see http://www.jsoftware.com/forums.htm

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:
All rational fractions result in infinitely repeating floating point
numbers.  They are the same sets.

Skip says:
So all the numbers in a are rational, and infinitely repeating? Like 0.5,
0.25. 0.2, 0.1? I'm confused. These examples don't seem to have infinitely
repeating decimals.

​Skip


On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
wrote:

> 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.5+ pi*1e_7) and irrational.
>
>
> On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> wrote:
>
> > 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.067 0.0625 0.0588235 0.056
> > 0.0526316 0.05
> >
> >
> > Create a function that will generate a boolean array indicating the
> > locations of the irrational numbers in a.
> >
> >
> > Skip
> > --
> > 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

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, Skip Cave  wrote:

> 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 irrational numbers in J? I expest
> it would be hard to support irrational numbers on a finite word-size
> machine, but then I also thought extended integers would be impossible. I'm
> guessing you might have to create a new noun type - irrational?
>
>
> 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?
>
>
> Skip
>
>
> On Wed, Jun 13, 2018 at 1:17 PM Roger Hui 
> wrote:
>
> > 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 example, with your second vector a,
> >
> >]a=.(20?.20){(100*%1+i.10),(10?.20)*o.1
> > 15.708 18.8496 37.6991 9.42478 16.6667 50 25 100 14.2857 50.2655 10
> 11.
> > 3.14159 0 33. 43.9823 12.5 20 40.8407 56.5487
> >
> >x: a
> > 5646741500662r359482728877 4414041858589r234172193603
> > 376716722090r9992721411 4414041858589r468344387206 50r3 50 25 100 100r7
> > 1681140150209r33445220617 10 100r9 1285290289249r409120605684 0 100r3
> > 10299431003375r234172193603 25r2 20 15619071123724r382438827...
> >
> >x: 4 5$a
> >  5646741500662r359482728877 4414041858589r234172193603
> > 376716722090r9992721411  4414041858589r468344387206
> > 50r3
> >  50 25
> >   100   100r7 1681140150209r33445220617
> >  10  100r9
> > 1285290289249r409120605684   0
> >  100r3
> > 10299431003375r234172193603   25r2
> >20 15619071123724r382438827053   188358361045r3330907137
> >
> >x:!.0 ]4 5$a
> > 4421398595017775r281474976710656 2652839157010665r140737488355328
> > 2652839157010665r70368744177664 2652839157010665r281474976710656
> > 2345624805922133r140737488355328
> >   50   25
> >100100r7
> >  884279719003555r17592186044416
> >   10100r9
> > 884279719003555r2814749767106560
> > 2345624805922133r70368744177664
> >  3094979016512443r70368744177664 25r2
> > 20  1436954543380777r35184372088832
> > 1989629367757999r35184372088832
> >
> > Some are "obviously" rational and some aren't but all are mathematically
> > rational.
> >
> >
> >
> > On Wed, Jun 13, 2018 at 11:06 AM, Skip Cave 
> > wrote:
> >
> > > 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 irrational numbers?
> > >
> > >
> > > I think I was originally thinking that floating-point numbers that have
> > > infinitely repeating patterns after the decimal are irrational. but
> that
> > is
> > > not the correct definition of irrational. However, a verb that could
> find
> > > those kinds of numbers (infinitely repeating pattern) in a vector of
> > > floating point numbers could be useful.
> > >
> > >
> > > Skip
> > >
> > >
> > >
> > >
> > > On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
> > > wrote:
> > >
> > > > 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.5+ pi*1e_7) and irrational.
> > > >
> > > >
> > > > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave  >
> > > > wrote:
> > > >
> > > > > 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
> > > > >
> > > 

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
square root of two -- all of the values of that type would be irrational as
well except for its NaN, zeros, and infinities.

On Wed, Jun 13, 2018 at 11:17 AM Roger Hui 
wrote:

> 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 example, with your second vector a,
>
>]a=.(20?.20){(100*%1+i.10),(10?.20)*o.1
> 15.708 18.8496 37.6991 9.42478 16.6667 50 25 100 14.2857 50.2655 10 11.
> 3.14159 0 33. 43.9823 12.5 20 40.8407 56.5487
>
>x: a
> 5646741500662r359482728877 4414041858589r234172193603
> 376716722090r9992721411 4414041858589r468344387206 50r3 50 25 100 100r7
> 1681140150209r33445220617 10 100r9 1285290289249r409120605684 0 100r3
> 10299431003375r234172193603 25r2 20 15619071123724r382438827...
>
>x: 4 5$a
>  5646741500662r359482728877 4414041858589r234172193603
> 376716722090r9992721411  4414041858589r468344387206
> 50r3
>  50 25
>   100   100r7 1681140150209r33445220617
>  10  100r9
> 1285290289249r409120605684   0
>  100r3
> 10299431003375r234172193603   25r2
>20 15619071123724r382438827053   188358361045r3330907137
>
>x:!.0 ]4 5$a
> 4421398595017775r281474976710656 2652839157010665r140737488355328
> 2652839157010665r70368744177664 2652839157010665r281474976710656
> 2345624805922133r140737488355328
>   50   25
>100100r7
>  884279719003555r17592186044416
>   10100r9
> 884279719003555r2814749767106560
> 2345624805922133r70368744177664
>  3094979016512443r70368744177664 25r2
> 20  1436954543380777r35184372088832
> 1989629367757999r35184372088832
>
> Some are "obviously" rational and some aren't but all are mathematically
> rational.
>
>
>
> On Wed, Jun 13, 2018 at 11:06 AM, Skip Cave 
> wrote:
>
> > 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 irrational numbers?
> >
> >
> > I think I was originally thinking that floating-point numbers that have
> > infinitely repeating patterns after the decimal are irrational. but that
> is
> > not the correct definition of irrational. However, a verb that could find
> > those kinds of numbers (infinitely repeating pattern) in a vector of
> > floating point numbers could be useful.
> >
> >
> > Skip
> >
> >
> >
> >
> > On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
> > wrote:
> >
> > > 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.5+ pi*1e_7) and irrational.
> > >
> > >
> > > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> > > wrote:
> > >
> > > > 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.067 0.0625 0.0588235 0.056
> > > > 0.0526316 0.05
> > > >
> > > >
> > > > Create a function that will generate a boolean array indicating the
> > > > locations of the irrational numbers in a.
> > > >
> > > >
> > > > Skip
> > > >
> --
> > > > 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
> 

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 irrational numbers in J? I expest
it would be hard to support irrational numbers on a finite word-size
machine, but then I also thought extended integers would be impossible. I'm
guessing you might have to create a new noun type - irrational?


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?


Skip


On Wed, Jun 13, 2018 at 1:17 PM Roger Hui  wrote:

> 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 example, with your second vector a,
>
>]a=.(20?.20){(100*%1+i.10),(10?.20)*o.1
> 15.708 18.8496 37.6991 9.42478 16.6667 50 25 100 14.2857 50.2655 10 11.
> 3.14159 0 33. 43.9823 12.5 20 40.8407 56.5487
>
>x: a
> 5646741500662r359482728877 4414041858589r234172193603
> 376716722090r9992721411 4414041858589r468344387206 50r3 50 25 100 100r7
> 1681140150209r33445220617 10 100r9 1285290289249r409120605684 0 100r3
> 10299431003375r234172193603 25r2 20 15619071123724r382438827...
>
>x: 4 5$a
>  5646741500662r359482728877 4414041858589r234172193603
> 376716722090r9992721411  4414041858589r468344387206
> 50r3
>  50 25
>   100   100r7 1681140150209r33445220617
>  10  100r9
> 1285290289249r409120605684   0
>  100r3
> 10299431003375r234172193603   25r2
>20 15619071123724r382438827053   188358361045r3330907137
>
>x:!.0 ]4 5$a
> 4421398595017775r281474976710656 2652839157010665r140737488355328
> 2652839157010665r70368744177664 2652839157010665r281474976710656
> 2345624805922133r140737488355328
>   50   25
>100100r7
>  884279719003555r17592186044416
>   10100r9
> 884279719003555r2814749767106560
> 2345624805922133r70368744177664
>  3094979016512443r70368744177664 25r2
> 20  1436954543380777r35184372088832
> 1989629367757999r35184372088832
>
> Some are "obviously" rational and some aren't but all are mathematically
> rational.
>
>
>
> On Wed, Jun 13, 2018 at 11:06 AM, Skip Cave 
> wrote:
>
> > 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 irrational numbers?
> >
> >
> > I think I was originally thinking that floating-point numbers that have
> > infinitely repeating patterns after the decimal are irrational. but that
> is
> > not the correct definition of irrational. However, a verb that could find
> > those kinds of numbers (infinitely repeating pattern) in a vector of
> > floating point numbers could be useful.
> >
> >
> > Skip
> >
> >
> >
> >
> > On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
> > wrote:
> >
> > > 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.5+ pi*1e_7) and irrational.
> > >
> > >
> > > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> > > wrote:
> > >
> > > > 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.067 0.0625 0.0588235 0.056
> > > > 0.0526316 0.05
> > > >
> > > >
> > > > Create a function that will generate a boolean array indicating the
> > > > locations of the irrational numbers in a.
> > > >
> > > >
> > > > Skip
> > > >
> --
> > > > For information about J forums see
> http://www.jsoftware.com/forums.htm
> > > 

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 example, with your second vector a,

   ]a=.(20?.20){(100*%1+i.10),(10?.20)*o.1
15.708 18.8496 37.6991 9.42478 16.6667 50 25 100 14.2857 50.2655 10 11.
3.14159 0 33. 43.9823 12.5 20 40.8407 56.5487

   x: a
5646741500662r359482728877 4414041858589r234172193603
376716722090r9992721411 4414041858589r468344387206 50r3 50 25 100 100r7
1681140150209r33445220617 10 100r9 1285290289249r409120605684 0 100r3
10299431003375r234172193603 25r2 20 15619071123724r382438827...

   x: 4 5$a
 5646741500662r359482728877 4414041858589r234172193603
376716722090r9992721411  4414041858589r468344387206
50r3
 50 25
  100   100r7 1681140150209r33445220617
 10  100r9
1285290289249r409120605684   0
 100r3
10299431003375r234172193603   25r2
   20 15619071123724r382438827053   188358361045r3330907137

   x:!.0 ]4 5$a
4421398595017775r281474976710656 2652839157010665r140737488355328
2652839157010665r70368744177664 2652839157010665r281474976710656
2345624805922133r140737488355328
  50   25
   100100r7
 884279719003555r17592186044416
  10100r9
884279719003555r2814749767106560
2345624805922133r70368744177664
 3094979016512443r70368744177664 25r2
20  1436954543380777r35184372088832
1989629367757999r35184372088832

Some are "obviously" rational and some aren't but all are mathematically
rational.



On Wed, Jun 13, 2018 at 11:06 AM, Skip Cave  wrote:

> 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 irrational numbers?
>
>
> I think I was originally thinking that floating-point numbers that have
> infinitely repeating patterns after the decimal are irrational. but that is
> not the correct definition of irrational. However, a verb that could find
> those kinds of numbers (infinitely repeating pattern) in a vector of
> floating point numbers could be useful.
>
>
> Skip
>
>
>
>
> On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
> wrote:
>
> > 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.5+ pi*1e_7) and irrational.
> >
> >
> > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> > wrote:
> >
> > > 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.067 0.0625 0.0588235 0.056
> > > 0.0526316 0.05
> > >
> > >
> > > Create a function that will generate a boolean array indicating the
> > > locations of the irrational numbers in a.
> > >
> > >
> > > Skip
> > > --
> > > 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

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 irrational numbers?


I think I was originally thinking that floating-point numbers that have
infinitely repeating patterns after the decimal are irrational. but that is
not the correct definition of irrational. However, a verb that could find
those kinds of numbers (infinitely repeating pattern) in a vector of
floating point numbers could be useful.


Skip




On Wed, Jun 13, 2018 at 12:44 PM Roger Hui 
wrote:

> 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.5+ pi*1e_7) and irrational.
>
>
> On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave 
> wrote:
>
> > 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.067 0.0625 0.0588235 0.056
> > 0.0526316 0.05
> >
> >
> > Create a function that will generate a boolean array indicating the
> > locations of the irrational numbers in a.
> >
> >
> > Skip
> > --
> > 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

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.5+ pi*1e_7) and irrational.


On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave  wrote:

> 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.067 0.0625 0.0588235 0.056
> 0.0526316 0.05
>
>
> Create a function that will generate a boolean array indicating the
> locations of the irrational numbers in a.
>
>
> Skip
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm