Re: irrational nubmer?

2020-03-10 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: stashing an array in a hash and yanking it back out

2020-03-10 Thread William Michels via perl6-users
Hi Joe,

So I had a chance to play with hashes further, and I noticed something
that you might be interested in. It seems that 'bare' declaration of a
hash with a "my" lexical scope enables you to stash away multiple
'hash' elements at the top level using a 'curly brace' syntax. However
using the 'fat arrow' syntax will overwrite any previously stashed
'top level' hash elements.

Hopefully the REPL code below illustrates. First, 'curly brace' syntax:

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my %stash
{}
> %stash{'monsters'} = @monsters
[godzilla grendel wormface blob fingfangfoom tingler]
> say %stash
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash{'rocks'} = @rocks
[marble sandstone granite chert pumice limestone]
> say %stash
{monsters => [godzilla grendel wormface blob fingfangfoom tingler],
rocks => [marble sandstone granite chert pumice limestone]}
> exit
mbook:~ homedir$

[and now try 'fat arrow' syntax]

mbook:~ homedir$ perl6
To exit type 'exit' or '^D'
> my @monsters = << godzilla grendel wormface blob fingfangfoom tingler >>;
[godzilla grendel wormface blob fingfangfoom tingler]
> my @rocks = << marble sandstone granite chert pumice limestone >>
[marble sandstone granite chert pumice limestone]
> my %stash
{}
> %stash = monsters => @monsters
{monsters => [godzilla grendel wormface blob fingfangfoom tingler]}
> %stash = rocks => @rocks
{rocks => [marble sandstone granite chert pumice limestone]}
> say %stash
{rocks => [marble sandstone granite chert pumice limestone]}
> say %stash
(Any)
> exit
mbook:~ homedir$ perl6 -v
This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
implementing Perl 6.d.

HTH, Bill.



On Thu, Mar 5, 2020 at 6:10 PM Joseph Brenner  wrote:
>
> William Michels  wrote:
>
> > Yes, since I was working in the REPL, I tried compacting Joe's code by
> > eliminating the "my %stash" line at the top, and adding "my" to the third
> > line.
>
> I noticed the additional "my" in there, but I wouldn't have been able
> to tell you why it was behaving like it was...
>
> On the plus side, I see that if you tried to do that in a script, it
> would warn you:
>
> Potential difficulties:
>Redeclaration of symbol '%stash'