Re: irrational nubmer?

2020-03-11 Thread Todd Chester via perl6-users




On 2020-03-11 01:23, Todd Chester via perl6-users wrote:



On 2020-03-10 22:55, Shlomi Fish wrote:

Speaking of trivia, and off topic, did you know that
√2 caused a major religious upheaval when the result
of a 1,1,√2 triangle came out?  The poor Pythagoreans:
all numbers had to be rational.  Hippasus even
got murdered for blowing the whistle on √2.

Seehttps://en.wikipedia.org/wiki/Hippasus  for what we more accurately 
know

about that.


Hi Shlomi,

That is a trip down memory lane!

More years ago that I like to admit, wrote a college
paper on the Pythagoreans.  The only real thing I
really remember about it is the "Harmony of the Spheres"
(Musica universalis).

https://en.wikipedia.org/wiki/Musica_universalis

I don't know how I ever got a A on the paper.  The
stuff on Wikipedia is 20 times better than anything
I wrote.

Thank you for sharing!

-T



Who would have thought √2 would have caused so much consternation?

In my days as a Radio Frequency designer, √2÷2 was a big deal.
Fortunately, no one got tossed overboard for using it!


Re: irrational nubmer?

2020-03-11 Thread Todd Chester via perl6-users




On 2020-03-10 22:55, Shlomi Fish wrote:

Speaking of trivia, and off topic, did you know that
√2 caused a major religious upheaval when the result
of a 1,1,√2 triangle came out?  The poor Pythagoreans:
all numbers had to be rational.  Hippasus even
got murdered for blowing the whistle on √2.


Seehttps://en.wikipedia.org/wiki/Hippasus  for what we more accurately know
about that.


Hi Shlomi,

That is a trip down memory lane!

More years ago that I like to admit, wrote a college
paper on the Pythagoreans.  The only real thing I
really remember about it is the "Harmony of the Spheres"
(Musica universalis).

https://en.wikipedia.org/wiki/Musica_universalis

I don't know how I ever got a A on the paper.  The
stuff on Wikipedia is 20 times better than anything
I wrote.

Thank you for sharing!

-T


Re: irrational nubmer?

2020-03-11 Thread Shlomi Fish
Hi Todd!

On Wed, 26 Feb 2020 12:32:57 -0800
ToddAndMargo via perl6-users  wrote:

> On 2020-02-26 12:14, Tobias Boege wrote:
> > On Wed, 26 Feb 2020, ToddAndMargo via perl6-users wrote:  
>  $ p6 'say (99/70).base-repeating();'
>  (1.4 142857)
> 
>  means that 142857 also repeats (it does not), but
>  that it is best it can figure out with the precision
>  it has?
>   
> >>>
> >>> What are you talking about? It does repeat. I suggest you take a piece
> >>> of paper and compute the decimal digits of 99/70 by hand until you are
> >>> convinced that it is 1.4 and then an endless stream of 142857 repeating.  
> >>
> >> I used gnome calculator to 20 digits:
> >>  665857/470832
> >>  1.41421356237468991063
> >> Sorry.  Not seeing any repeating patterns.
> >>  
> > 
> > Todd, you were asking about 99/70, so I answered you about 99/70.
> > I even quoted it. Now you come with 665857/470832. For that number,
> > you will see the repetition after about 580 decimal digits.
> >   
> >> Here is NAS doing it to 1 million digits (they have too
> >> much time on their hands):
> >>  https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
> >> No repeats.
> >>
> >> So why does base-repeating tell me there is a repeating
> >> pattern when there is not?
> >>  
> > 
> > Sigh. We already settled that Rat and Num in Raku are rational numbers
> > and that √2 is an irrational number. So what can you definitely not apply
> > the base-repeating method to in Raku? -- The honest value of √2.
> > 
> > NASA apparently computed the first million digits of √2 and you see no
> > repeated digits. Good. In fact a real number is irrational if and only
> > if its decimal expansion has no repeating pattern. You can view this as
> > a reason for why they are not super easy to deal with on a computer.
> > 
> > But that has nothing to do with the numbers we looked at above. Those were
> > obviously rational numbers. They were obviously different from √2 because
> > that number is not rational -- and we were looking at rational numbers.
> > We were looking at rational numbers close to √2. What makes you think that
> > NASA computing digits of the number √2 has any bearing on the correctness
> > of `(99/70).base-repeating`? Because √2 and 99/70 are obviously not the
> > same number.
> > 
> > We are not working out the decimal expansion of √2. We are working out
> > decimal expansions of rational numbers close to, but different from, √2.
> > Even though they are close, structural properties of the expansions,
> > like the existence of a repeating pattern, are radically different.
> >   
> >> Ah ha, 99/70 does have a repeat:
> >> 1.4142857 142857 142857 1
> >>
> >> Maybe 665857/470832 I just do not go out enough digits to
> >> see a repeat.
> >>
> >> √2 does not repeat though, but I am thinking that
> >> I am stretching the poor machines abilities a bit too far
> >> and that is where the repeat comes from
> >>
> >> $ p6 'say sqrt(2).Rat.base-repeating();'  
>  (1.4
>  14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)
>   
> >>
> >> So, with the technology on hand, the approximation of √2
> >> does have a repeating pattern of
> >>
> >> 14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076
> >>
> >> (And in engineering terms, is meaningless)
> >>  
> > 
> > Yes, √2 has no repeating decimal pattern and the repetition returned to
> > you is the one of the rational approximation to √2 that Raku computed
> > when you asked for `sqrt(2).Rat`.
> > 
> > (Somehow it seems like you understood halfway through writing your
> > response but decided to keep the first half anyway. I don't know why.)
> >   
>  And what are the unboxing rules for (665857/470832)?
>   
> >>>
> >>> No idea what you mean.  
> >>
> >> When is <665857/470832> unboxed to a Real number to
> >> operate on it?  Or is it never unboxed?
> >>  
> > 
> > I'm no boxing expert, but I know that Rat has high-level arithmetic
> > defined for it and there is no native rational type to unbox to.
> > That would have to go through Num, I suppose. So I see neither a need
> > nor a target for unboxing a Rat. But I still have no idea what kind
> > of operations you have in mind. That said, Rat is not a NativeCall-
> > related type.
> >   
> 
> Thank you!
> 
> The more I learn about Raku, the more fascinating I find it.
> 
> All trivia aside, sqrt(2) has way more precision for any
> real world application I throw at it.
> 
> Speaking of trivia, and off topic, did you know that
> √2 caused a major religious upheaval when the result
> of a 1,1,√2 triangle came out?  The poor Pythagoreans:
> all numbers had to be rational.  Hippasus even
> got murdered for blowing the whistle on √2.
> 

See https://en.wikipedia.org/wiki/Hippasus for what we more accurately know
about that.


> Now-a-days, we just torture our computers with it.
> 
> :-)
> 
> -T



-- 

Shlomi Fish 

Re: irrational nubmer?

2020-02-26 Thread ToddAndMargo via perl6-users

On 2020-02-26 12:14, Tobias Boege wrote:

On Wed, 26 Feb 2020, ToddAndMargo via perl6-users wrote:

$ p6 'say (99/70).base-repeating();'
(1.4 142857)

means that 142857 also repeats (it does not), but
that it is best it can figure out with the precision
it has?



What are you talking about? It does repeat. I suggest you take a piece
of paper and compute the decimal digits of 99/70 by hand until you are
convinced that it is 1.4 and then an endless stream of 142857 repeating.


I used gnome calculator to 20 digits:
 665857/470832
 1.41421356237468991063
Sorry.  Not seeing any repeating patterns.



Todd, you were asking about 99/70, so I answered you about 99/70.
I even quoted it. Now you come with 665857/470832. For that number,
you will see the repetition after about 580 decimal digits.


Here is NAS doing it to 1 million digits (they have too
much time on their hands):
 https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
No repeats.

So why does base-repeating tell me there is a repeating
pattern when there is not?



Sigh. We already settled that Rat and Num in Raku are rational numbers
and that √2 is an irrational number. So what can you definitely not apply
the base-repeating method to in Raku? -- The honest value of √2.

NASA apparently computed the first million digits of √2 and you see no
repeated digits. Good. In fact a real number is irrational if and only
if its decimal expansion has no repeating pattern. You can view this as
a reason for why they are not super easy to deal with on a computer.

But that has nothing to do with the numbers we looked at above. Those were
obviously rational numbers. They were obviously different from √2 because
that number is not rational -- and we were looking at rational numbers.
We were looking at rational numbers close to √2. What makes you think that
NASA computing digits of the number √2 has any bearing on the correctness
of `(99/70).base-repeating`? Because √2 and 99/70 are obviously not the
same number.

We are not working out the decimal expansion of √2. We are working out
decimal expansions of rational numbers close to, but different from, √2.
Even though they are close, structural properties of the expansions,
like the existence of a repeating pattern, are radically different.


Ah ha, 99/70 does have a repeat:
1.4142857 142857 142857 1

Maybe 665857/470832 I just do not go out enough digits to
see a repeat.

√2 does not repeat though, but I am thinking that
I am stretching the poor machines abilities a bit too far
and that is where the repeat comes from

$ p6 'say sqrt(2).Rat.base-repeating();'

(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


So, with the technology on hand, the approximation of √2
does have a repeating pattern of

14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076

(And in engineering terms, is meaningless)



Yes, √2 has no repeating decimal pattern and the repetition returned to
you is the one of the rational approximation to √2 that Raku computed
when you asked for `sqrt(2).Rat`.

(Somehow it seems like you understood halfway through writing your
response but decided to keep the first half anyway. I don't know why.)


And what are the unboxing rules for (665857/470832)?



No idea what you mean.


When is <665857/470832> unboxed to a Real number to
operate on it?  Or is it never unboxed?



I'm no boxing expert, but I know that Rat has high-level arithmetic
defined for it and there is no native rational type to unbox to.
That would have to go through Num, I suppose. So I see neither a need
nor a target for unboxing a Rat. But I still have no idea what kind
of operations you have in mind. That said, Rat is not a NativeCall-
related type.



Thank you!

The more I learn about Raku, the more fascinating I find it.

All trivia aside, sqrt(2) has way more precision for any
real world application I throw at it.

Speaking of trivia, and off topic, did you know that
√2 caused a major religious upheaval when the result
of a 1,1,√2 triangle came out?  The poor Pythagoreans:
all numbers had to be rational.  Hippasus even
got murdered for blowing the whistle on √2.

Now-a-days, we just torture our computers with it.

:-)

-T


Re: irrational nubmer?

2020-02-26 Thread ToddAndMargo via perl6-users

On 2020-02-26 12:21, William Michels via perl6-users wrote:

This code below seems to accurately return the number of "repeating
digits" (576) using Perl6 alone:

mbook: homedir$  perl6 -e 'say
(665857000/470832).base-repeating()>>.chars;'
(1173 576)
mbook: homedir$

HTH, Bill.





On Wed, Feb 26, 2020 at 12:09 PM ToddAndMargo via perl6-users
 wrote:


On 2020-02-26 11:34, Peter Scott wrote:


On 2/26/2020 11:14 AM, ToddAndMargo via perl6-users wrote:

I used gnome calculator to 20 digits:
 665857/470832
 1.41421356237468991063
Sorry.  Not seeing any repeating patterns.

Here is NAS doing it to 1 million digits (they have too
much time on their hands):
https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
No repeats.


As well there shouldn't be in an irrational number.  sqrt(2) !=
665857/470832


So why does base-repeating tell me there is a repeating
pattern when there is not?

Ah ha, 99/70 does have a repeat:
1.4142857 142857 142857 1

Maybe 665857/470832 I just do not go out enough digits to
see a repeat.


Correct.  As a really disgustingly quick and dirty way of proving that
the expansion has a repeating cycle of 576 digits:

$ perl6 -e 'say
665857000/470832'
| perl -lne '/(\d{4,})\1/ and print length $1, ": $1"'
576:
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267



Hi Peter,

Thank you!  The more I learn about Raku, the more
fascinating I find it!

:-)

-T


Fascinating!



Re: irrational nubmer?

2020-02-26 Thread William Michels via perl6-users
This code below seems to accurately return the number of "repeating
digits" (576) using Perl6 alone:

mbook: homedir$  perl6 -e 'say
(665857000/470832).base-repeating()>>.chars;'
(1173 576)
mbook: homedir$

HTH, Bill.





On Wed, Feb 26, 2020 at 12:09 PM ToddAndMargo via perl6-users
 wrote:
>
> On 2020-02-26 11:34, Peter Scott wrote:
> >
> > On 2/26/2020 11:14 AM, ToddAndMargo via perl6-users wrote:
> >> I used gnome calculator to 20 digits:
> >> 665857/470832
> >> 1.41421356237468991063
> >> Sorry.  Not seeing any repeating patterns.
> >>
> >> Here is NAS doing it to 1 million digits (they have too
> >> much time on their hands):
> >> https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
> >> No repeats.
> >
> > As well there shouldn't be in an irrational number.  sqrt(2) !=
> > 665857/470832
> >>
> >> So why does base-repeating tell me there is a repeating
> >> pattern when there is not?
> >>
> >> Ah ha, 99/70 does have a repeat:
> >> 1.4142857 142857 142857 1
> >>
> >> Maybe 665857/470832 I just do not go out enough digits to
> >> see a repeat.
> >
> > Correct.  As a really disgustingly quick and dirty way of proving that
> > the expansion has a repeating cycle of 576 digits:
> >
> > $ perl6 -e 'say
> > 665857000/470832'
> > | perl -lne '/(\d{4,})\1/ and print length $1, ": $1"'
> > 576:
> > 135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267
> >
>
> Hi Peter,
>
> Thank you!  The more I learn about Raku, the more
> fascinating I find it!
>
> :-)
>
> -T


Re: irrational nubmer?

2020-02-26 Thread Tobias Boege
On Wed, 26 Feb 2020, ToddAndMargo via perl6-users wrote:
> > > $ p6 'say (99/70).base-repeating();'
> > > (1.4 142857)
> > > 
> > > means that 142857 also repeats (it does not), but
> > > that it is best it can figure out with the precision
> > > it has?
> > > 
> > 
> > What are you talking about? It does repeat. I suggest you take a piece
> > of paper and compute the decimal digits of 99/70 by hand until you are
> > convinced that it is 1.4 and then an endless stream of 142857 repeating.
> 
> I used gnome calculator to 20 digits:
> 665857/470832
> 1.41421356237468991063
> Sorry.  Not seeing any repeating patterns.
> 

Todd, you were asking about 99/70, so I answered you about 99/70.
I even quoted it. Now you come with 665857/470832. For that number,
you will see the repetition after about 580 decimal digits.

> Here is NAS doing it to 1 million digits (they have too
> much time on their hands):
> https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
> No repeats.
> 
> So why does base-repeating tell me there is a repeating
> pattern when there is not?
> 

Sigh. We already settled that Rat and Num in Raku are rational numbers
and that √2 is an irrational number. So what can you definitely not apply
the base-repeating method to in Raku? -- The honest value of √2.

NASA apparently computed the first million digits of √2 and you see no
repeated digits. Good. In fact a real number is irrational if and only
if its decimal expansion has no repeating pattern. You can view this as
a reason for why they are not super easy to deal with on a computer.

But that has nothing to do with the numbers we looked at above. Those were
obviously rational numbers. They were obviously different from √2 because
that number is not rational -- and we were looking at rational numbers.
We were looking at rational numbers close to √2. What makes you think that
NASA computing digits of the number √2 has any bearing on the correctness
of `(99/70).base-repeating`? Because √2 and 99/70 are obviously not the
same number.

We are not working out the decimal expansion of √2. We are working out
decimal expansions of rational numbers close to, but different from, √2.
Even though they are close, structural properties of the expansions,
like the existence of a repeating pattern, are radically different.

> Ah ha, 99/70 does have a repeat:
> 1.4142857 142857 142857 1
> 
> Maybe 665857/470832 I just do not go out enough digits to
> see a repeat.
> 
> √2 does not repeat though, but I am thinking that
> I am stretching the poor machines abilities a bit too far
> and that is where the repeat comes from
> 
> $ p6 'say sqrt(2).Rat.base-repeating();'
> >> (1.4 
> >> 14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)
> 
> So, with the technology on hand, the approximation of √2
> does have a repeating pattern of
> 
> 14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076
> 
> (And in engineering terms, is meaningless)
> 

Yes, √2 has no repeating decimal pattern and the repetition returned to
you is the one of the rational approximation to √2 that Raku computed
when you asked for `sqrt(2).Rat`.

(Somehow it seems like you understood halfway through writing your
response but decided to keep the first half anyway. I don't know why.)

> > > And what are the unboxing rules for (665857/470832)?
> > > 
> > 
> > No idea what you mean.
> 
> When is <665857/470832> unboxed to a Real number to
> operate on it?  Or is it never unboxed?
> 

I'm no boxing expert, but I know that Rat has high-level arithmetic
defined for it and there is no native rational type to unbox to.
That would have to go through Num, I suppose. So I see neither a need
nor a target for unboxing a Rat. But I still have no idea what kind
of operations you have in mind. That said, Rat is not a NativeCall-
related type.

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


Re: irrational nubmer?

2020-02-26 Thread ToddAndMargo via perl6-users

On 2020-02-26 11:34, Peter Scott wrote:


On 2/26/2020 11:14 AM, ToddAndMargo via perl6-users wrote:

I used gnome calculator to 20 digits:
    665857/470832
    1.41421356237468991063
Sorry.  Not seeing any repeating patterns.

Here is NAS doing it to 1 million digits (they have too
much time on their hands):
https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
No repeats.


As well there shouldn't be in an irrational number.  sqrt(2) != 
665857/470832


So why does base-repeating tell me there is a repeating
pattern when there is not?

Ah ha, 99/70 does have a repeat:
1.4142857 142857 142857 1

Maybe 665857/470832 I just do not go out enough digits to
see a repeat. 


Correct.  As a really disgustingly quick and dirty way of proving that 
the expansion has a repeating cycle of 576 digits:


$ perl6 -e 'say 
665857000/470832' 
| perl -lne '/(\d{4,})\1/ and print length $1, ": $1"'
576: 
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267 



Hi Peter,

Thank you!  The more I learn about Raku, the more
fascinating I find it!

:-)

-T


Re: irrational nubmer?

2020-02-26 Thread Peter Scott



On 2/26/2020 11:14 AM, ToddAndMargo via perl6-users wrote:

I used gnome calculator to 20 digits:
    665857/470832
    1.41421356237468991063
Sorry.  Not seeing any repeating patterns.

Here is NAS doing it to 1 million digits (they have too
much time on their hands):
https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
No repeats.


As well there shouldn't be in an irrational number.  sqrt(2) != 
665857/470832


So why does base-repeating tell me there is a repeating
pattern when there is not?

Ah ha, 99/70 does have a repeat:
1.4142857 142857 142857 1

Maybe 665857/470832 I just do not go out enough digits to
see a repeat. 


Correct.  As a really disgustingly quick and dirty way of proving that 
the expansion has a repeating cycle of 576 digits:


$ perl6 -e 'say 
665857000/470832' 
| perl -lne '/(\d{4,})\1/ and print length $1, ": $1"'
576: 
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267


Re: irrational nubmer?

2020-02-26 Thread ToddAndMargo via perl6-users

On 2020-02-26 08:20, Tobias Boege wrote:

On Wed, 26 Feb 2020, Todd Chester via perl6-users wrote:

Hi Tobias,

I am confused as to as to what you mean by numerator and
denominator.



Rational numbers can always be written as the ratio of two integers:
a/b with b non-zero. One calls a the numerator and b the denominator.

In Raku the types Int, Rat, FatRat and Num are all rational numbers,
as they all can be written as the ratio of two integers (up to Infs
and NaNs).


When I say:
$ p6 'say (99/70).base-repeating();'
(1.4 142857)

$ p6 'say (665857/470832).base-repeating();'
(1.4142 
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267)

$ p6 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)

How does Raku know √2 is approximated by 99/70 or 665857/470832?
Does not Raku just throw a binary algorithm at any number you
feed sqrt?



The floating point unit in your computer receives the 2 and returns
a floating point approximation of √2. Raku then uses the algorithm
I linked to in my last email to give you the 99/70.


also, what exactly am I look at with (1.4 142857)?   Is
this a way of saying that 1.4 is the rational part and
142857 the irrational part?



No, Raku doesn't know anything about irrational numbers. As soon as
you obtain the return value of `sqrt(2)` in Raku, you got a rational
approximation to √2 and no part of the program knows that you wanted
to compute an irrational number. The irrationality is gone, it was
all in your head. You are dealing with this rational number that is
"close" to √2.


That is what I thought.  And from an engineering standpoint,
the values used by √2 is limited by the tolerance of
the other numbers around it.

A 1.0,1.00,√2 triangle would be a tolerance of
the smaller or ±0,5, so who care how many extra digits
√2 gives me.




What is also confusing is when a number does not repeat,
what is .base-repeating() trying to tell me?  Is does not repeat?

2/3 is 0.666.
$ p6 'say (2/3).Rat.base-repeating();'
(0. 6)

Does that mean that the 6 repeats?



Yes.


and

$ p6 'say (99/70).base-repeating();'
(1.4 142857)

means that 142857 also repeats (it does not), but
that it is best it can figure out with the precision
it has?



What are you talking about? It does repeat. I suggest you take a piece
of paper and compute the decimal digits of 99/70 by hand until you are
convinced that it is 1.4 and then an endless stream of 142857 repeating.


I used gnome calculator to 20 digits:
665857/470832
1.41421356237468991063
Sorry.  Not seeing any repeating patterns.

Here is NAS doing it to 1 million digits (they have too
much time on their hands):
https://apod.nasa.gov/htmltest/gifcity/sqrt2.1mil
No repeats.

So why does base-repeating tell me there is a repeating
pattern when there is not?

Ah ha, 99/70 does have a repeat:
1.4142857 142857 142857 1

Maybe 665857/470832 I just do not go out enough digits to
see a repeat.

√2 does not repeat though, but I am thinking that
I am stretching the poor machines abilities a bit too far
and that is where the repeat comes from

$ p6 'say sqrt(2).Rat.base-repeating();'
>> (1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


So, with the technology on hand, the approximation of √2
does have a repeating pattern of

14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076

(And in engineering terms, is meaningless)




If afterwards you trust Raku again, try `(99/70).base(10, 1000)` to get
the first thousand decimal digits of that fraction printed.


And it it can not find a repeat, why does it not say so?



If you did the pen and paper exercise above, you know how the algorithm
goes and that it is very easy to see when you've found the repeat and
when you haven't. Above, there was a repeat that was easily found.
The documentation says that if the repeat cannot be found within a
thousand digits, the repeating part in the return value of 
will be "???".

I've found this to be false. The source code of the method does not have
such precautions and the limit is certainly not 1000 decimals. Try for
example 1/1019 which has a group of 1018 repeating decimals. [ Maybe
the number-theoretically inclined subscribers here will figure out how
I found this example. ]

Curiously, the old design docs [1] mandate a buffer of 100_000 to look
for 

Re: irrational nubmer?

2020-02-26 Thread Tobias Boege
On Wed, 26 Feb 2020, Todd Chester via perl6-users wrote:
> Hi Tobias,
> 
> I am confused as to as to what you mean by numerator and
> denominator.
> 

Rational numbers can always be written as the ratio of two integers:
a/b with b non-zero. One calls a the numerator and b the denominator.

In Raku the types Int, Rat, FatRat and Num are all rational numbers,
as they all can be written as the ratio of two integers (up to Infs
and NaNs).

> When I say:
> $ p6 'say (99/70).base-repeating();'
> (1.4 142857)
> 
> $ p6 'say (665857/470832).base-repeating();'
> (1.4142 
> 135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267)
> 
> $ p6 'say sqrt(2).Rat.base-repeating();'
> (1.4 
> 14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)
> 
> How does Raku know √2 is approximated by 99/70 or 665857/470832?
> Does not Raku just throw a binary algorithm at any number you
> feed sqrt?
> 

The floating point unit in your computer receives the 2 and returns
a floating point approximation of √2. Raku then uses the algorithm
I linked to in my last email to give you the 99/70.

> also, what exactly am I look at with (1.4 142857)?   Is
> this a way of saying that 1.4 is the rational part and
> 142857 the irrational part?
> 

No, Raku doesn't know anything about irrational numbers. As soon as
you obtain the return value of `sqrt(2)` in Raku, you got a rational
approximation to √2 and no part of the program knows that you wanted
to compute an irrational number. The irrationality is gone, it was
all in your head. You are dealing with this rational number that is
"close" to √2.

> What is also confusing is when a number does not repeat,
> what is .base-repeating() trying to tell me?  Is does not repeat?
> 
> 2/3 is 0.666.
> $ p6 'say (2/3).Rat.base-repeating();'
> (0. 6)
> 
> Does that mean that the 6 repeats?
> 

Yes.

> and
> 
> $ p6 'say (99/70).base-repeating();'
> (1.4 142857)
> 
> means that 142857 also repeats (it does not), but
> that it is best it can figure out with the precision
> it has?
> 

What are you talking about? It does repeat. I suggest you take a piece
of paper and compute the decimal digits of 99/70 by hand until you are
convinced that it is 1.4 and then an endless stream of 142857 repeating.

If afterwards you trust Raku again, try `(99/70).base(10, 1000)` to get
the first thousand decimal digits of that fraction printed.

> And it it can not find a repeat, why does it not say so?
> 

If you did the pen and paper exercise above, you know how the algorithm
goes and that it is very easy to see when you've found the repeat and
when you haven't. Above, there was a repeat that was easily found.
The documentation says that if the repeat cannot be found within a
thousand digits, the repeating part in the return value of 
will be "???".

I've found this to be false. The source code of the method does not have
such precautions and the limit is certainly not 1000 decimals. Try for
example 1/1019 which has a group of 1018 repeating decimals. [ Maybe
the number-theoretically inclined subscribers here will figure out how
I found this example. ]

Curiously, the old design docs [1] mandate a buffer of 100_000 to look
for repeating digits. Pre-christmas versions of Rakudo apparently did
have this check but "sanity", as a comment in the Rakudo sources called
it, was removed in March 2015 [2] :-)

As it currently stands [3], Rakudo will exhaust all memory to try to
find the repeating group if it has to. (Note that all rational numbers
have this repeating group -- you know this if you did the exercise --
so the search is never in vain, but it *is* attack surface for a DoS.)

> And why am I getting zero back from
> $ p6 'say sqrt(2).Rat.base-repeating() - (665857/470832).base-repeating();'
> 0
> 

The return value of  is a list. You are subtracting
two lists which actually gets you the difference of their lengths.
Since both lists have two elements (all lists returned by that
function do) you get zero:

  > sqrt(2).Rat.base-repeating - sqrt(1000).Rat.base-repeating
  0

> Also, what is the algebraic precedence of the operation?  In
> (665857/470832).base-repeating()
> 
> is (665857/470832) solved first or is (665857/470832) a special
> number (Rat) that is fed to .base-repeating?
> 

What happens here is that the expression `665857/470832` is a
Rat literal. You take this literal Rat object and call a method
on it. It is not converted to a Num first if you 

Re: irrational nubmer?

2020-02-26 Thread Todd Chester via perl6-users




On 2020-02-20 22:32, Tobias Boege wrote:

On Thu, 20 Feb 2020, ToddAndMargo via perl6-users wrote:

On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

 $ perl6 -e 'say sqrt(2).base-repeating();'
 No such method 'base-repeating' for invocant of type 'Num'
 in block  at -e line 1



On 2020-02-20 19:07, Norman Gaywood wrote:


perl6 -e 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


Hi Norman,

Much better!

Question: Rat:
https://docs.raku.org/type/Rat

   Rat objects store rational numbers as a pair
   of a numerator and denominator. Number literals
   with a dot but without exponent produce Rats.

What does Rat do to sqrt(2) to give it a numerator
and a denominator?



I'm not sure if you have digested what others have said, so I'll repeat it:
sqrt(2) already has a numerator and denominator. sqrt(2) takes the integer
2 and computes its square root as a floating point number using magic IEEE
powder. If you look up the IEEE 754 float representations, you'll notice
that every (non-NaN, non-Inf) float is a rational number. So sqrt(2) is
already a rational number approximating the positive real number whose
square is 2.

That said, just taking the obvious numerator and denominator from the float
might give you unnecessarily large numbers, and the Rat conversion on Num
has to support a user-supplied tolerance as well. Reading the documentation,
it seems that Raku does not require IEEE 754 to be in effect at all.

So what Rakudo does (I recommend reading the source code [1]) is a variant
of finding a continued fraction for the Num [2], except that it computes
the Rat instead and stops when it reached the requested accuracy. It starts
from scratch and iteratively approximates the Num, which has the advantage
that you can stop when you don't have to continue and that it only relies
on arithmetic on the Num working, not that it is represented according to
some standard internally.

Note also that Num.Rat supports a :fat argument to give you a FatRat back,
but you cannot actually increase the precision of your rational approximation
of √2 beyond the source you put in, which is a double precision float:

   > sqrt(2).Rat.nude # precision 1e-6, the default
   (1393 985)
   > sqrt(2).Rat(1e-8).nude   # a bit better requested, request granted
   (19601 13860)
   > sqrt(2).Rat(1e-16).nude  # still better but 1e-16 is ca. the limit
   (131836323 93222358)

   > sqrt(2).Rat(1e-20).nude  # no improvement
   (131836323 93222358)
   > sqrt(2).Rat(1e-100, :fat).nude  # fatter but not better, because
   (131836323 93222358)  # the source sqrt(2) is too lossy

Regards,
Tobias

[1] https://github.com/rakudo/rakudo/blob/cdbd60c1/src/core.c/Num.pm6#L46
[2] 
https://en.wikipedia.org/wiki/Continued_fraction#Calculating_continued_fraction_representations



Hi Tobias,

I am confused as to as to what you mean by numerator and
denominator.

When I say:
$ p6 'say (99/70).base-repeating();'
(1.4 142857)

$ p6 'say (665857/470832).base-repeating();'
(1.4142 
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267)


$ p6 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


How does Raku know √2 is approximated by 99/70 or 665857/470832?
Does not Raku just throw a binary algorithm at any number you
feed sqrt?

also, what exactly am I look at with (1.4 142857)?   Is
this a way of saying that 1.4 is the rational part and
142857 the irrational part?

What is also confusing is when a number does not repeat,
what is .base-repeating() trying to tell me?  Is does not repeat?

2/3 is 0.666.
$ p6 'say (2/3).Rat.base-repeating();'
(0. 6)

Does that mean that the 6 repeats?

and

$ p6 'say (99/70).base-repeating();'
(1.4 142857)

means that 142857 also repeats (it does not), but
that it is best it can figure out with the precision
it has?

And it it can not find a repeat, why does it not say so?

And why am I getting zero back from
$ p6 'say sqrt(2).Rat.base-repeating() - (665857/470832).base-repeating();'
0

Also, what is the algebraic precedence of the operation?  In
(665857/470832).base-repeating()

is (665857/470832) solved first or is (665857/470832) a special
number (Rat) that is fed to .base-repeating?

And what are the unboxing rules for 

Re: irrational nubmer?

2020-02-26 Thread Todd Chester via perl6-users




On 2020-02-23 03:07, Shlomi Fish wrote:

Hi,

just for the record - I was not talking about Raku, just about a hypothetical
language with CAS-like capabilities (see
https://en.wikipedia.org/wiki/Computer_algebra_system  ) that would be able to
do it. I was just using Raku-like syntax for familiarity. I am aware that the
functionality is not built in in Raku.


Interesting!


Re: irrational nubmer?

2020-02-23 Thread Shlomi Fish
On Thu, 20 Feb 2020 16:27:27 -0800
William Michels  wrote:

> On Thu, Feb 20, 2020 at 2:25 PM ToddAndMargo via perl6-users
>  wrote:
> >
> > On 2020-02-19 23:21, Shlomi Fish wrote:  
> > > Hi Paul,
> > >  
> >  
> > > Well, it is not unthinkable that a
> > > https://en.wikipedia.org/wiki/Computer_algebra_system (CAS)-like system
> > > will be able to tell that the abstract number sqrt(2) is irrational, as
> > > well as some derivative numbers such as 3 + sqrt(2). E.g:  
> >
> > Hi Shlomi,
> >
> > Those "academic exercises" where enterprising college
> > students run pi out to a bazillion digits to see if they
> > can find a repeating patterns came up with some
> > way of handling an "unbounded" number.  A "Real" (Cap R)
> > perhaps?
> >
> > -T  
> 
> You can identify repeating patterns in decimal fractions using the
> method "base-repeating":
> 
> mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating();'
> (0. 142857)
> mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10);'
> (0. 142857)
> mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10).perl;'
> ("0.", "142857")
> mbook:~ homedir$ perl6 -e 'say (5/2).base-repeating(10).perl;'
> ("2.5", "")
> mbook:~ homedir$
> 
> According to the Raku docs, "If no repetition occurs, the second
> string is empty... ."
> And the docs say: "The precision for determining the repeating group
> is limited to 1000 characters, above that, the second string is ???."
> https://docs.raku.org/type/Rational#method_base-repeating
> 
> HTH, Bill.
> 
> PS For those following along at home--unless it's been added since
> Rakudo 2019.07--I don't see the "is_irrational()" function in the Raku
> language referred to by Shlomi Fish. Or maybe I/we was/were to
> understand that there isn't an "is_irrational()" function in the Raku
> language as of yet.
> 

Hi,

just for the record - I was not talking about Raku, just about a hypothetical
language with CAS-like capabilities (see
https://en.wikipedia.org/wiki/Computer_algebra_system ) that would be able to
do it. I was just using Raku-like syntax for familiarity. I am aware that the
functionality is not built in in Raku.

> https://stackoverflow.com/questions/42302488/identify-a-irrational-or-complex-number
> https://mathoverflow.net/questions/91915/detecting-recognizing-irrational-number-by-computers
> https://reference.wolfram.com/language/guide/ContinuedFractionsAndRationalApproximations.html
> https://www.wolframalpha.com/examples/mathematics/numbers/irrational-numbers/
> https://www.wolframalpha.com/examples/mathematics/number-theory/continued-fractions/


Re: irrational nubmer?

2020-02-22 Thread ToddAndMargo via perl6-users

On 2020-02-22 01:58, Darren Duncan wrote:

What would the practical value of that be?


None that I know of.  Did you miss the "complete
trivia question" part in my original question.


Re: irrational nubmer?

2020-02-22 Thread Darren Duncan

On 2020-02-20 2:22 p.m., ToddAndMargo via perl6-users wrote:

On 2020-02-20 00:41, Darren Duncan wrote:

On 2020-02-20 12:10 a.m., Tobias Boege wrote:

Granted, Todd would not have anticipated this answer if he calls
arbitrary length integers "magic powder" and the question "I have
computed this Int/Num/Rat in Raku, is it rational?" does indeed
not make any sense.  But there are computer languages that can do
better.  Given FatRats, such modules can be written for Raku today.


Actually the question "is it rational" DOES make sense, however its answer is 
trivial, the answer is always "yes"; EVERY (not-NaN/Inf/etc) number a 
language-defined Raku data type can represent is exactly expressible as the 
ratio of 2 integers. -- Darren Duncan


Well, I wonder if there is an overflow bit that would
tell your is the number was going on and on after
you did an operation on it.


What would the practical value of that be?  The only commonly used numeric types 
that have bits for tracking exceptional cases are IEEE floating point numbers, 
and it is already explicitly known that most typical operations producing 
results of that type are producing inexact rounded results.  So if they are 
already expected to be inexact or rounded, it doesn't matter if the exact answer 
would have been rational or irrational. -- Darren Duncan


Re: irrational nubmer?

2020-02-20 Thread Tobias Boege
On Thu, 20 Feb 2020, ToddAndMargo via perl6-users wrote:
> > > On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users
> > > mailto:perl6-users@perl.org>> wrote:
> > > 
> > > $ perl6 -e 'say sqrt(2).base-repeating();'
> > > No such method 'base-repeating' for invocant of type 'Num'
> > > in block  at -e line 1
> > > 
> 
> On 2020-02-20 19:07, Norman Gaywood wrote:
> > 
> > perl6 -e 'say sqrt(2).Rat.base-repeating();'
> > (1.4 
> > 14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)
> 
> Hi Norman,
> 
> Much better!
> 
> Question: Rat:
> https://docs.raku.org/type/Rat
> 
>   Rat objects store rational numbers as a pair
>   of a numerator and denominator. Number literals
>   with a dot but without exponent produce Rats.
> 
> What does Rat do to sqrt(2) to give it a numerator
> and a denominator?
> 

I'm not sure if you have digested what others have said, so I'll repeat it:
sqrt(2) already has a numerator and denominator. sqrt(2) takes the integer
2 and computes its square root as a floating point number using magic IEEE
powder. If you look up the IEEE 754 float representations, you'll notice
that every (non-NaN, non-Inf) float is a rational number. So sqrt(2) is
already a rational number approximating the positive real number whose
square is 2.

That said, just taking the obvious numerator and denominator from the float
might give you unnecessarily large numbers, and the Rat conversion on Num
has to support a user-supplied tolerance as well. Reading the documentation,
it seems that Raku does not require IEEE 754 to be in effect at all.

So what Rakudo does (I recommend reading the source code [1]) is a variant
of finding a continued fraction for the Num [2], except that it computes
the Rat instead and stops when it reached the requested accuracy. It starts
from scratch and iteratively approximates the Num, which has the advantage
that you can stop when you don't have to continue and that it only relies
on arithmetic on the Num working, not that it is represented according to
some standard internally.

Note also that Num.Rat supports a :fat argument to give you a FatRat back,
but you cannot actually increase the precision of your rational approximation
of √2 beyond the source you put in, which is a double precision float:

  > sqrt(2).Rat.nude # precision 1e-6, the default
  (1393 985)
  > sqrt(2).Rat(1e-8).nude   # a bit better requested, request granted
  (19601 13860)
  > sqrt(2).Rat(1e-16).nude  # still better but 1e-16 is ca. the limit
  (131836323 93222358)

  > sqrt(2).Rat(1e-20).nude  # no improvement
  (131836323 93222358)
  > sqrt(2).Rat(1e-100, :fat).nude  # fatter but not better, because
  (131836323 93222358)  # the source sqrt(2) is too lossy

Regards,
Tobias

[1] https://github.com/rakudo/rakudo/blob/cdbd60c1/src/core.c/Num.pm6#L46
[2] 
https://en.wikipedia.org/wiki/Continued_fraction#Calculating_continued_fraction_representations

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


Re: irrational nubmer?

2020-02-20 Thread ToddAndMargo via perl6-users
On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


$ perl6 -e 'say sqrt(2).base-repeating();'
No such method 'base-repeating' for invocant of type 'Num'
in block  at -e line 1



On 2020-02-20 19:07, Norman Gaywood wrote:


perl6 -e 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


Hi Norman,

Much better!

Question: Rat:
https://docs.raku.org/type/Rat

  Rat objects store rational numbers as a pair
  of a numerator and denominator. Number literals
  with a dot but without exponent produce Rats.

What does Rat do to sqrt(2) to give it a numerator
and a denominator?

And I see base-repeating wants to be fed a Rational:
https://docs.raku.org/routine/base-repeating

Also I much prefer:
$ perl6 -e 'say <1/7>.base-repeating();'
(0. 142857)
over
$ perl6 -e 'say (1/7).base-repeating();'
(0. 142857)

As to me (1/7) means solve the equation and then
send it on.

Also, what is base-repeating telling me?  Where the
repeat is?  What the repeat is?

And what if I only want to see if a repeat occurs
in a single number, not a Rat/Rational?

$ perl6 -e 'say <0.9876123412341234/1>.base-repeating();'
(0.9876123412341234 )

I am doing something wrong.

Many thanks,
-T


Re: irrational nubmer?

2020-02-20 Thread Norman Gaywood
On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> $ perl6 -e 'say sqrt(2).base-repeating();'
> No such method 'base-repeating' for invocant of type 'Num'
>in block  at -e line 1
>

perl6 -e 'say sqrt(2).Rat.base-repeating();'
(1.4
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)

-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


Re: irrational nubmer?

2020-02-20 Thread ToddAndMargo via perl6-users

On 2020-02-20 16:27, William Michels via perl6-users wrote:

mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating();'
(0. 142857)
mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10);'
(0. 142857)
mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10).perl;'
("0.", "142857")
mbook:~ homedir$ perl6 -e 'say (5/2).base-repeating(10).perl;'
("2.5", "")
mbook:~ homedir$


Hi William,

   I love it!  Thank you!

-T


$ perl6 -e 'say (1/7).base-repeating();'
(0. 142857)



Oh now this ain't fair!

$ perl6 -e 'say sqrt(2).base-repeating();'
No such method 'base-repeating' for invocant of type 'Num'
  in block  at -e line 1


Re: irrational nubmer?

2020-02-20 Thread William Michels via perl6-users
On Thu, Feb 20, 2020 at 2:25 PM ToddAndMargo via perl6-users
 wrote:
>
> On 2020-02-19 23:21, Shlomi Fish wrote:
> > Hi Paul,
> >
>
> > Well, it is not unthinkable that a
> > https://en.wikipedia.org/wiki/Computer_algebra_system (CAS)-like system 
> > will be
> > able to tell that the abstract number sqrt(2) is irrational, as well as some
> > derivative numbers such as 3 + sqrt(2). E.g:
>
> Hi Shlomi,
>
> Those "academic exercises" where enterprising college
> students run pi out to a bazillion digits to see if they
> can find a repeating patterns came up with some
> way of handling an "unbounded" number.  A "Real" (Cap R)
> perhaps?
>
> -T

You can identify repeating patterns in decimal fractions using the
method "base-repeating":

mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating();'
(0. 142857)
mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10);'
(0. 142857)
mbook:~ homedir$ perl6 -e 'say (1/7).base-repeating(10).perl;'
("0.", "142857")
mbook:~ homedir$ perl6 -e 'say (5/2).base-repeating(10).perl;'
("2.5", "")
mbook:~ homedir$

According to the Raku docs, "If no repetition occurs, the second
string is empty... ."
And the docs say: "The precision for determining the repeating group
is limited to 1000 characters, above that, the second string is ???."
https://docs.raku.org/type/Rational#method_base-repeating

HTH, Bill.

PS For those following along at home--unless it's been added since
Rakudo 2019.07--I don't see the "is_irrational()" function in the Raku
language referred to by Shlomi Fish. Or maybe I/we was/were to
understand that there isn't an "is_irrational()" function in the Raku
language as of yet.

https://stackoverflow.com/questions/42302488/identify-a-irrational-or-complex-number
https://mathoverflow.net/questions/91915/detecting-recognizing-irrational-number-by-computers
https://reference.wolfram.com/language/guide/ContinuedFractionsAndRationalApproximations.html
https://www.wolframalpha.com/examples/mathematics/numbers/irrational-numbers/
https://www.wolframalpha.com/examples/mathematics/number-theory/continued-fractions/


Re: irrational nubmer?

2020-02-20 Thread ToddAndMargo via perl6-users

On 2020-02-19 23:21, Shlomi Fish wrote:

Hi Paul,




Well, it is not unthinkable that a
https://en.wikipedia.org/wiki/Computer_algebra_system (CAS)-like system will be
able to tell that the abstract number sqrt(2) is irrational, as well as some
derivative numbers such as 3 + sqrt(2). E.g:


Hi Shlomi,

Those "academic exercises" where enterprising college
students run pi out to a bazillion digits to see if they
can find a repeating patterns came up with some
way of handling an "unbounded" number.  A "Real" (Cap R)
perhaps?

-T


Re: irrational nubmer?

2020-02-20 Thread ToddAndMargo via perl6-users

On 2020-02-20 00:41, Darren Duncan wrote:

On 2020-02-20 12:10 a.m., Tobias Boege wrote:

Granted, Todd would not have anticipated this answer if he calls
arbitrary length integers "magic powder" and the question "I have
computed this Int/Num/Rat in Raku, is it rational?" does indeed
not make any sense.  But there are computer languages that can do
better.  Given FatRats, such modules can be written for Raku today.


Actually the question "is it rational" DOES make sense, however its 
answer is trivial, the answer is always "yes"; EVERY (not-NaN/Inf/etc) 
number a language-defined Raku data type can represent is exactly 
expressible as the ratio of 2 integers. -- Darren Duncan


Well, I wonder if there is an overflow bit that would
tell your is the number was going on and on after
you did an operation on it.


Re: Rational numbers... was Re: irrational nubmer?

2020-02-20 Thread ToddAndMargo via perl6-users

On 2020-02-20 05:53, Richard Hainsworth wrote:
However, my question to you is: when would you come across an irrational 
number in a computer? How would you express it? Suppose I gave you a 
function  sub irrational( $x ) which returns true for an irrational 
number. What would you put in for $x? Bear in mind that anything like pi 
or sqrt(2) is either going to be infinitely long or a rational 
approximation.


Hi Richard,

The question was meant as trivia.  Raku never ceased
to amaze me in its capabilities, so I though it had
come up with some elegant/impressive way (also
known as Magic Larry Powder) of handling it.
And yes, UInt and Int do fall into that category
with me.

On the practical side, I am an engineer and what
I am interested is the "tolerance" of a number.
For example, 1.0 and 1.000 are not the same
number.  The first one is 1.0 ± 0.05 and the
second one is 1.000 ± 0.0005.  And when
doing math on such numbers, the tolerance
of the result always takes on the worst tolerance
of the numbers being manipulated.

So it is the square root of two taken to
the length of the tolerance of the other
variables.

So rational or irrational has no practical
meaning to me.  And why the rounding in Raku
is so adored.

Oh and if I wanted to run the trivia up the flag
pole, I'd remark on the difference between
common rounding and scientific rounding.  Scientific
routing is actually the correct way, as it is
balanced, but few understand what it is so using
common rounding keeps you on their good side.

-T


Re: irrational nubmer?

2020-02-20 Thread Paul Procacci
Every system that uses a fixed finite number of bits to represent numbers
has to represent them as implicit rationals...that is
unless it goes through the trouble of having a finite list of irrational
constants that it represented specially.

sqrt is not equivalent to the mathematical definition of √.  It's an
approximation of the latter.
Most computer languages except for CAS work this way.

Truth by told, a lot of what I'm saying is general knowledge and shouldn't
be news to anyone.
Somewhat kiddingly, Raku should introduce the LazilyComputableReal datatype
which returns True to maybe_irrational ... until it isn't.  ;)


On Thu, Feb 20, 2020 at 2:21 AM Shlomi Fish  wrote:

> Hi Paul,
>
> On Thu, 20 Feb 2020 00:22:34 -0500
> Paul Procacci  wrote:
>
> > If you wouldn't mind, please stop referring things as being "magical".
> > There's nothing magical about Raku/Perl6 other than the devs that put in
> > their time to give you that perception.
> > They are to be commended for their time and effort.
> >
> > Also, being condescending as in "he gave up" is uncalled for.
> >
> > It's an IMPOSSIBILITY using today's technology to tell you whether a
> number
> > is irrationalperiod.
>
> Well, it is not unthinkable that a
> https://en.wikipedia.org/wiki/Computer_algebra_system (CAS)-like system
> will be
> able to tell that the abstract number sqrt(2) is irrational, as well as
> some
> derivative numbers such as 3 + sqrt(2). E.g:
>
> ```
> > my $num = sqrt(2);
> > say $num.is_irrational()
> True
> ```
>
> It won't be able to give its exact value, but may still be able to reason
> about
> it.
>
> --
>
> Shlomi Fish   https://www.shlomifish.org/
> Perl Elems to Avoid - https://perl-begin.org/tutorials/bad-elements/
>
> The cool thing about Vim is — you find something interesting with every
> typo.
> — Su‐Shee on Freenode’s #perl .
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>


-- 
__

:(){ :|:& };:


Rational numbers... was Re: irrational nubmer?

2020-02-20 Thread Richard Hainsworth
Hi Todd,

This is going to be hard for an intuitive guy like you, but it can be
proven that 100% of all numbers are irrational (see
https://math.stackexchange.com/questions/1556670/100-of-the-real-numbers-between-0-and-1-are-irrational
).

Except the ones that a computer can do operations on, which are by
definition Rational, as others in the list have already said.

The apparent paradox between these statements arises because of the logic
of infinities.

However, my question to you is: when would you come across an irrational
number in a computer? How would you express it? Suppose I gave you a
function  sub irrational( $x ) which returns true for an irrational number.
What would you put in for $x? Bear in mind that anything like pi or sqrt(2)
is either going to be infinitely long or a rational approximation.

So I could argue that raku already has a function irrational. It is called
False.

Regards,
Richard

On Thu, Feb 20, 2020, 02:58 ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> This is a complete trivia question.
>
> Is there a test to see if a number is irrational,
> such as the square root of two?
>
> And how does Int handle a irrational number?  Is
> there a limit to magic Larry powder?
>
> Many thanks,
> -T
>


Re: irrational nubmer?

2020-02-20 Thread Darren Duncan

On 2020-02-20 12:10 a.m., Tobias Boege wrote:

Granted, Todd would not have anticipated this answer if he calls
arbitrary length integers "magic powder" and the question "I have
computed this Int/Num/Rat in Raku, is it rational?" does indeed
not make any sense.  But there are computer languages that can do
better.  Given FatRats, such modules can be written for Raku today.


Actually the question "is it rational" DOES make sense, however its answer is 
trivial, the answer is always "yes"; EVERY (not-NaN/Inf/etc) number a 
language-defined Raku data type can represent is exactly expressible as the 
ratio of 2 integers. -- Darren Duncan


Re: irrational nubmer?

2020-02-20 Thread Tobias Boege
On Wed, 19 Feb 2020, Paul Procacci wrote:
>  >> Is there a test to see if a number is irrational
> There is no such thing as an irrational number in computing.
> 
> Surely there are "close approximations", but that's the best any computer
> language can currently do.
> 

It all depends on representation.  Of course there are ways to write
algebraic numbers as their minimal polynomials over the rationals.
You may not call that a "number", but you can do effective arithmetic
with such a representation, so for many purposes it's as good as a
"chunk of bits" number and it is an exact symbolic representation of
a (possibly irrational) number from which you can extract rational
approximations of any wanted precision.  And in that representation,
a number is irrational if and only if the minimal polynomial has
degree at least two, very easy to check.  (Note, however, that you
do not get all irrationals in this way. π and e are still out of
reach, for example.)

Granted, Todd would not have anticipated this answer if he calls
arbitrary length integers "magic powder" and the question "I have
computed this Int/Num/Rat in Raku, is it rational?" does indeed
not make any sense.  But there are computer languages that can do
better.  Given FatRats, such modules can be written for Raku today.

There seems to be a slogan of some sort that, if you search IRC logs
or the documentation, pops up a number of times: "Perl 6 (Raku) is not
a computer algebra system" ("RINACAS"?).  I don't know what happened
in the history of Perl 6 development, but it seems that irrationals
were sought in core at some point and it was Larry who stopped that
motion [1].

Regards,
Tobias

[1] https://github.com/Raku/problem-solving/issues/4#issuecomment-474892811

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


Re: irrational nubmer?

2020-02-19 Thread Shlomi Fish
Hi Paul,

On Thu, 20 Feb 2020 00:22:34 -0500
Paul Procacci  wrote:

> If you wouldn't mind, please stop referring things as being "magical".
> There's nothing magical about Raku/Perl6 other than the devs that put in
> their time to give you that perception.
> They are to be commended for their time and effort.
> 
> Also, being condescending as in "he gave up" is uncalled for.
> 
> It's an IMPOSSIBILITY using today's technology to tell you whether a number
> is irrationalperiod.

Well, it is not unthinkable that a
https://en.wikipedia.org/wiki/Computer_algebra_system (CAS)-like system will be
able to tell that the abstract number sqrt(2) is irrational, as well as some
derivative numbers such as 3 + sqrt(2). E.g:

```
> my $num = sqrt(2);
> say $num.is_irrational()
True
```

It won't be able to give its exact value, but may still be able to reason about
it.

-- 

Shlomi Fish   https://www.shlomifish.org/
Perl Elems to Avoid - https://perl-begin.org/tutorials/bad-elements/

The cool thing about Vim is — you find something interesting with every typo.
— Su‐Shee on Freenode’s #perl .

Please reply to list if it's a mailing list post - http://shlom.in/reply .


Re: irrational nubmer?

2020-02-19 Thread Darren Duncan

Hello ToddAndMargo,

The answer to your question depends on how the number is represented.

If you are using a symbolic data type, meaning one that represents a number as a 
logical formula akin to program source code, and the operators on that data type 
work by manipulating tree expressions into other tree expressions, then you can 
easily represent an irrational number, and you can determine if a number is 
irrational, using mathematical proofs.  Eg, programming languages like Wolfram 
Mathematica or their ilk probably work in exactly this fashion.


Otherwise, if you are using a non-symbolic data type like typical integer or 
floating-point data types, then even if they support arbitrarily large 
precision, they still can only represent rationals, and the test for irrational 
is easy, the answer is always "not irrational" for these types.


All the numeric types built into Raku are non-symbolic, so the test is simply 
"false".


There probably are or probably can be symbolic numeric types, but they wouldn't 
be core.


-- Darren Duncan

On 2020-02-19 6:57 p.m., ToddAndMargo via perl6-users wrote:

Hi All,

This is a complete trivia question.

Is there a test to see if a number is irrational,
such as the square root of two?

And how does Int handle a irrational number?  Is
there a limit to magic Larry powder?

Many thanks,
-T



Re: irrational nubmer?

2020-02-19 Thread ToddAndMargo via perl6-users

On 2020-02-19 21:22, Paul Procacci wrote:

If you wouldn't mind, please stop referring things as being "magical".


That is not an insult.  I am using it as term of admiration.

And I did not dream it up myself.  I have had several of
the developers use both magical and Magic Larry powder
on me, which is where I got it from.

Plus it gets to the point instantly and is also a fun way
of stating that somethings is very technical and very
brilliantly executed.

It also tells me that when the explanation is way,
way over my head, to take it at face value.  AND
IN THREE WORDS!

There's nothing magical about Raku/Perl6 other than the devs that put in 
their time to give you that perception.


Of course not.  Raku can not break the laws of nature.


They are to be commended for their time and effort.


You mean admired for their work, which is the way I
mean it.  I am not sure where you got the opposite.
Maybe you are having a bad day?


Also, being condescending as in "he gave up" is uncalled for.


Oh no I am not.  I am teasing him.  I think the guy is
beyond brilliant.

It's an IMPOSSIBILITY using today's technology to tell you whether a 
number is irrationalperiod.


If ANYONE on the face of this earth can figure it out,
It would be Larry!  And I am not joking either!

Also, when it comes to Magic Larry Powder, never, never,
never ever say "IMPOSSIBLE".

-T


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: irrational nubmer?

2020-02-19 Thread Paul Procacci
If you wouldn't mind, please stop referring things as being "magical".
There's nothing magical about Raku/Perl6 other than the devs that put in
their time to give you that perception.
They are to be commended for their time and effort.

Also, being condescending as in "he gave up" is uncalled for.

It's an IMPOSSIBILITY using today's technology to tell you whether a number
is irrationalperiod.

The reason why a Raku/Perl6 Int can perform operations on numbers greater
than the cpu architecture allows
is because that single addition operator you use is actually more than just
a single addition.  You said you were
familiar with assembly language so let me give it to you that way.
Perhaps that will allow you to understand it better.

###
SECTION .data
mem: DQ 0
 DQ 0x7FFF

SECTION .text
add:
mov rax, qword [mem + 8]
add rax, 1
jno .ok
mov qword [mem + 8], 0
inc qword [mem]
.ok:
###

There's obviously more involved than this small snippet, but it shows how
storing values greater than 64-bits (in my case) is possible.
No magic needed, just a bit of comp-sci knowledge.  Obviously I'm leaving
out a display routine but that'd be for you to finish.  ;)
Also, the above is limited to a 128 bit value but with a proper allocator
the sky is the limit (unless you run out of memory).

Here's an experiment 

Write a program to tell you whether PI is irrational.
Respond once it returns with your answer.
A forewarning however, your response will fall on deaf ears as I'll be long
gone as will all others receiving this message.

On Wed, Feb 19, 2020 at 11:15 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> >> On Wed, Feb 19, 2020 at 9:58 PM ToddAndMargo via perl6-users
> >> mailto:perl6-users@perl.org>> wrote:
> >>
> >> Hi All,
> >>
> >> This is a complete trivia question.
> >>
> >> Is there a test to see if a number is irrational,
> >> such as the square root of two?
> >>
> >> And how does Int handle a irrational number?  Is
> >> there a limit to magic Larry powder?
> >>
> >> Many thanks,
> >> -T
> >
>
> On 2020-02-19 19:20, Paul Procacci wrote:
> >  >> Is there a test to see if a number is irrational
> > There is no such thing as an irrational number in computing.
> >
> > Surely there are "close approximations", but that's the best any
> > computer language can currently do.
> >
>
> Hi Paul,
>
> $ perl6 -e 'my num $x=sqrt(2); say $x;'
> 1.4142135623730951
>
> No Magic Larry "Num" that has no set length?
> And I thought Larry was unstoppable!  Guess
> he gave up at UInt and Int.
>
> :-)
>
> -T
>


-- 
__

:(){ :|:& };:


Re: irrational nubmer?

2020-02-19 Thread ToddAndMargo via perl6-users
On Wed, Feb 19, 2020 at 9:58 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

This is a complete trivia question.

Is there a test to see if a number is irrational,
such as the square root of two?

And how does Int handle a irrational number?  Is
there a limit to magic Larry powder?

Many thanks,
-T




On 2020-02-19 19:20, Paul Procacci wrote:

 >> Is there a test to see if a number is irrational
There is no such thing as an irrational number in computing.

Surely there are "close approximations", but that's the best any 
computer language can currently do.




Hi Paul,

$ perl6 -e 'my num $x=sqrt(2); say $x;'
1.4142135623730951

No Magic Larry "Num" that has no set length?
And I thought Larry was unstoppable!  Guess
he gave up at UInt and Int.

:-)

-T


Re: irrational nubmer?

2020-02-19 Thread Paul Procacci
 >> Is there a test to see if a number is irrational
There is no such thing as an irrational number in computing.

Surely there are "close approximations", but that's the best any computer
language can currently do.

On Wed, Feb 19, 2020 at 9:58 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> This is a complete trivia question.
>
> Is there a test to see if a number is irrational,
> such as the square root of two?
>
> And how does Int handle a irrational number?  Is
> there a limit to magic Larry powder?
>
> Many thanks,
> -T
>


-- 
__

:(){ :|:& };:


irrational nubmer?

2020-02-19 Thread ToddAndMargo via perl6-users

Hi All,

This is a complete trivia question.

Is there a test to see if a number is irrational,
such as the square root of two?

And how does Int handle a irrational number?  Is
there a limit to magic Larry powder?

Many thanks,
-T