No, I tested it on Linux Mint, I've updated my post above which shows gst clearly has a problem with certain LargeInteger maths on the PC (possibly a 64-bit problem?), will have to look at the source code for gst later.
No, I tested it on Linux Mint, I've updated my post above which shows gst clearly has a problem with certain LargeInteger maths on the PC (possibly a 64-bit problem?), will have to look at the source code for gst later.
About 20 years ago I was working on a mathematical model in which certain Bessel and hypergeometric functions appeared in awkward combinations with respect to loss of precision due to rounding error. I tried a well-known computer algebra system that supported arbitrary precision evaluation of those functions and soon discovered for the choice of parameters I needed that most of the 200 digits of precision the software computed were wrong and sometimes all of them. That was commercial software.
The most likely bug I can think of is that you probably don't know that Smalltalk does *not* futz around with arithmetic stuff for precedence rules. Its strictly left to right sending messages. Why? Because it's simpler to read when non-arithmetic stuff can be mixed in as well. Consistency internally, as it were. Yes, it annoys some people. No it doesn't cause pimples.
Code: Select all
fastDoublingFib
"derived from https://www.nayuki.io/page/fast-fibonacci-algorithms"
"(1 to: 20) collect:[:i| i fastDoublingFib]"
| a b c |
a := 0.
b := 1.
self highBit to: 1 by: -1 do:[:i|
|d e|
d := (b bitShift: 1) - a * a.
e := a squared + b squared.
a := d.
b := e.
(self bitAt: i) = 1 ifTrue:[
c := a + b.
a := b.
b := c]
].
^a
Code: Select all
$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 72723460248141 * 72723460248141
5288701670462944237293955881
>>> 7272346024814 * 7272346024814
52887016704627987903734596
>>> 727234602481 * 727234602481
528870167045698091355361
>>> 72723460248 * 72723460248
5288701670442436221504
>>> 100000000000000 * 100000000000000
10000000000000000000000000000
>>>
Code: Select all
$ gst
"Global garbage collection... done"
GNU Smalltalk ready
st> 72723460248141 * 72723460248141
685887298156391209 ,<---------- WRONG
st> 7272346024814 * 7272346024814
-1468882107384405180 <---- WRONG Negative WTF?!
st> 727234602481 * 727234602481
2014452445246524641 <---- WRONG
st> 72723460248 * 72723460248
5288701670442436221504 <---- CORRECT
st>
st> 100000000000000 * 100000000000000
4477988020393345024 <---- WRONG
I am old enough, ugly enough and been around the block enough to know not to trust operator precedence rules unless I know the language really well, then one always forgets..The most likely bug I can think of is that you probably don't know that Smalltalk does *not* futz around with arithmetic stuff for precedence rules.
Code: Select all
st> 2 * 2
4
st> 200000000000000 * 200000000000000
-534791992136171520
st>
Code: Select all
## -------------------------------- ##
## GNU Smalltalk 3.2.91 test suite. ##
## -------------------------------- ##
Regression tests.
1: arrays.st ok
2: classes.st ok
3: blocks.st ok
4: sets.st ok
5: processes.st ok
6: exceptions.st ok
7: intmath.st FAILED (testsuite.at:33)
8: floatmath.st FAILED (testsuite.at:34)
I did, and I didn't. If you see what I mean. The only advantage of Forth is that it makes the syntax of Smalltalk, Haskell, Erlang etc look tolerable.Perhaps I needed to learn a dozen language to see the advantages of Forth
Long ago I had a Jupiter Ace computer. This was basically a Sinclair zx81 that ran Forth instead of BASIC (which was why I bought it).
Code: Select all
/*
* Calculate the 24th fibonacci term using A64
*
* as fibo.s -o fibo.o && ld -s fibo.o -o fibo
*/
.globl _start
.text
_start:
/*
* Fibonacci loop, result in X0
*/
mov w3,23 // target fibo term - 1
mov x1,1
mov x2,0
loop:
add x0,x2,x1
mov x2,x1
mov x1,x0
sub w3,w3,1
cbnz w3,loop
/*
* Print the result to a decimal string
*/
adr x1,message
add x4,x1,1 // save end of buffer (and include the LF)
mov w2,10
digit:
udiv x3,x0,x2 // n / 10
msub x0,x3,x2,x0 // n % 10
orr w0,w0,48 // convert to ascii
strb w0,[x1,-1]! // write byte and dec ptr
mov x0,x3
cbnz x3,digit
/*
* Display result in X1
*/
mov w8,64 // write syscall number
mov w0,1 // fd
sub x2,x4,x1 // length
svc 0
/*
* Exit the program
*/
mov w8,93
svc 0
.data
/*
* Space for the result as an ascii string
* Increase for larger terms (fibo(93) needs 20 bytes)
*/
.zero 5
message:
.byte 10
The fact that there are regression tests which fail suggests the Debian maintainer might also have known something was wrong and shipped the package anyway. Still, one can never fully know what things led to this and other misfortunes. Is it possible that GNU Smalltalk links to a library like GMP which has also burned? If Linux Subsystem for Windows had a GUI with a mouse you could try Squeak.Heater wrote: ↑Tue Apr 16, 2019 6:52 amI thought I'd download and build a gst from the latest sources at gnu.org. http://smalltalk.gnu.org/download
The build tests fail on integer and float maths:So that is not getting installed.Code: Select all
## -------------------------------- ## ## GNU Smalltalk 3.2.91 test suite. ## ## -------------------------------- ## Regression tests. 1: arrays.st ok 2: classes.st ok 3: blocks.st ok 4: sets.st ok 5: processes.st ok 6: exceptions.st ok 7: intmath.st FAILED (testsuite.at:33) 8: floatmath.st FAILED (testsuite.at:34)
That seems to be the end of the line for Smalltalk for me. The only language so far that fails the challenge.
Or has anyone got a Smalltalk fibo(4784969) running on Raspbian/Debian?
Code: Select all
n := 1
10000 timesRepeat: [ | a b |
n printNl.
a := n fibo printNl.
b := n fibIterative printNl.
(a = b) printNl.
n := n + 1
]
The suggestion by the Squeak folks is to install an X server in Windows and have Squeak in the LSW display on it.If Linux Subsystem for Windows had a GUI with a mouse you could try Squeak.
It is also a problem on headless Pi's (like mine).
I'm certainly not going to defend the specific gnu implementation of Smalltalk - it's clearly sorely lacking. Generalising that to "Smalltalk can't do it" is a bit silly though.
Well let's see, Squeak is updated somewhat almost every day as people work on things, ditto the Pharo fork (aimed more at commercial needs), VA Smalltalk from Instantiations is still under active development and has recent product releases, GemTalk (a yuuuuugedatabase system in Smalltalk) has recent updates, Smalltalk/X is activley developed, and there must be another half-dozen implementations active out there.
I did not say that. I'm sure it can be done in Smalltalk.Generalising that to "Smalltalk can't do it" is a bit silly though.
I don't have much experience in trying to do commandline run stuff but I do know that some people do; I'll ask on the squeak forums to see if anyone has a plausible solution that won't use up too much effort.
Any sort of display stuff ? Even a framebuffer ?
Code: Select all
$ cat fibo.gst
Integer extend [
fibIterative [ | a b |
a := b := 1.
(self - 1) timesRepeat: [
a := b + (b := a)
].
^b
]
]
4784969 fibIterative printNl.
$ time gst -g fibo.st > results.txt
real 382m27.801s
user 301m9.922s
sys 80m48.891s
$ head results.txt -c 32
10727395641800477229364813596225
$ tail results.txt -c 32
4856539211500699706378405156269
I can only reach my Pi via SSH. Or there is the LSW terminal on my PC.Any sort of display stuff ? Even a framebuffer ?
Crikey; that does rather show up the difference in algorithms.
Wait a minute - I thought you were trying to run this stuff on a bare-metal-RISC-V-thing?