LargeIntegers atRandom more analysis

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

LargeIntegers atRandom more analysis

Jerome Peace
LargeIntegers atRandom more analysis


Hi Tim, Hi Randal

Nothing like a little coding to go

>From confident Ignorance:
http://www.sacred-texts.com/tarot/pkt/img/ar00.jpg 
To humble Understanding:
http://www.sacred-texts.com/tarot/pkt/img/ar01.jpg

Playing and trying to debug my notion of large integer randoms,
 show that what I had proposed as a decomposition for the problem
 had bigger problems than I first thought.
I did not get far enough to blame the generator.
But ran into problems with convincing myself
 that with the decomposition I could get an evenly distributed probility
 for numbers from 1 to large n.

I still believe that LargeInteger has the responsibility for giving back a good random.

Along the way, or actually while I slept,
 I realized that the limitation is not necessarily in the generator
 but in the combining of the floating point and large integer in nextInt: .

 This is a problem.

24 factorial + 1000000 = (24 factorial * 1.0)
will answer true.

while
( 24 factorial - (24 factorial * 1.0 ) asInteger ) = 0
will answer false.

There is a truncation difficulty with floats.

I say difficulty rather than bug because it is not spec'ed to work otherwise.

With this knowledge some relief can be had by gening up a large random number
and treating it as a fraction.

So a step towards the solution would be to define:
LargePositiveInteger>>
   atRandom: aGenerator
        "Answer a random integer from 1 to self picked from aGenerator.
        To handle Large integers the arithmetic must use integer arithmetic.
        This will work if the generator is up to multiple uses."

| nHigits numerator radix maxSigBits nextLargeInteger  denominator |

maxSigBits := 53 . " aGenerator class maxSignificantBits. "
radix := radix :=  ( 2 raisedTo:  maxSigBits ) .
nHigits :=
 (self  highBit // maxSigBits ) + 1 .
numerator := 0 .

nextLargeInteger := [ ( aGenerator next * radix ) asInteger ] .

nHigits timesRepeat: [ numerator := numerator * radix + nextLargeInteger value ] .

denominator := radix raisedTo: nHigits .

^ self * numerator // denominator + 1 .




This leaves the problem of the usable/reusalbe generator to be solved.
I would also want a way for the generator classes to return maxSigBits.

The pleasing thing about the above code is that with the method in place
I did not have to change anything else to get atRandom to work better.
So #atRandom: proves itself a useful hook.

This solution passes the oddity test. That is a very low threshold test.
This is also a fragile solution.
There are probably some places that it fails.
It would be interesting to find a test that it couldn't pass.
Then use that to vet the next iteration of the fix.

Yours in curiosity and service, --Jerome Peace




     
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

How to delete a category?

John Chandler-3
I mistakenly created a category with a misspelled name.

It's easy to delete the Class Browser, but not clear (to me) how to  
delete this misspelled category.

-jmc

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to delete a category?

Yoshiki Ohshima-2
> I mistakenly created a category with a misspelled name.

  There are class categories and method categories.  Which one was it?

  With a 5 pane browser (the standard one), right-clicking on the
appropriate pane (either the left most of the top half or the third
one from the left in the top half) should give you the context menu,
and you can choose "rename" or "remove" from there.

> It's easy to delete the Class Browser, but not clear (to me) how to  
> delete this misspelled category.

  What do you mean by "delete the Class Browser"?

-- Yoshiki
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to delete a category?

John Chandler-3

On Aug 11, 2008, at 10:21 AM, Yoshiki Ohshima wrote:

>> I mistakenly created a category with a misspelled name.
>
>   There are class categories and method categories.  Which one was it?
>
I'd have to say "class category," because in the 5-pane
browser (launched with Open->Class Browser and displaying
"System Browser" in its title-bar), when I create a new one,
I am presented in the lower pane with a dummy class
definition.

>   With a 5 pane browser (the standard one), right-clicking on the
> appropriate pane (either the left most of the top half or the third
> one from the left in the top half) should give you the context menu,
> and you can choose "rename" or "remove" from there.

OK, I found what you're talking about, but for me, on a
1-button Mac trackpad (I don't have my 3-button mouse with
me here), the combo is alt-click, which is inoperative in
most programs.  The right-click options are usually called
up with ctrl-click.  And yes, this is a side issue.

>
>> It's easy to delete the Class Browser, but not clear (to me) how to
>> delete this misspelled category.
>
>   What do you mean by "delete the Class Browser"?

When I right-click (ctrl-click) anywhere in the Browser, I
get a menu offering a "delete" option, which makes the
Browser disappear.

Rename or remove.  Alt-click.  Thanks.

>
> -- Yoshiki
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

NOTICE: Due to Presidential Executive Orders, the National Security  
Agency may have read this email without warning, warrant, or notice.  
They may do  this without any judicial or legislative oversight. You  
have little recourse nor protection except to call for the  
impeachment of the current President.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners