Author Topic: One statement SIN table  (Read 15306 times)

Tomaaz

  • Guest
Re: One statement SIN table
« Reply #15 on: August 29, 2018, 04:07:21 PM »
Euphoria (no variable name):

Code: [Select]
include std/math.e
include std/sequence.e

print(1, sin(series(1, 1, 100000)))


I know - the topic is ancient, but I was gone for some time.  ;)

B+

  • Guest
Re: One statement SIN table
« Reply #16 on: August 29, 2018, 07:28:06 PM »
Quote
I know - the topic is ancient, but I was gone for some time.  ;)

Well it was addressed to you and I see I used a variable, dang!

But you used 3 statements, 2 for libraries.

Oh wait, I did do it in one statement, no variables, the brute force way! reply #14 not very elegant.
« Last Edit: August 29, 2018, 07:39:46 PM by B+ »

Tomaaz

  • Guest
Re: One statement SIN table
« Reply #17 on: August 29, 2018, 08:58:00 PM »
Oh wait, I did do it in one statement, no variables, the brute force way! reply #14 not very elegant.

Can you post a code that will calculate and display sin for every number between 1 and 1000000? ;D Here it is in Phix:

Code: [Select]
print(1, sq_sin(tagset(1000000, 1, 1)))

Pretty elegant, I would say. Quite fast, too. :)
« Last Edit: August 29, 2018, 09:00:49 PM by Tomaaz »

ScriptBasic

  • Guest
Re: One statement SIN table
« Reply #18 on: August 29, 2018, 09:16:53 PM »
Quote
Pretty elegant, I would say. Quite fast, too

Here is the Script BASIC version. Not sure what Tomaaz defines as quite fast.

Code: [Select]
OPEN "sinout" FOR OUTPUT AS #1
FOR s = 1 TO 1000000
  PRINT #1,SIN(s),"\n"
NEXT
CLOSE(#1)


jrs@jrs-laptop:~/sb/examples/test$ time scriba sinout.sb

real   0m3.930s
user   0m1.880s
sys   0m1.923s
jrs@jrs-laptop:~/sb/examples/test$ tail -n20 sinout
-0.486438
0.472382
0.996897
0.604869
-0.343273
-0.975811
-0.711193
0.207292
0.935194
0.803283
-0.067163
-0.875859
-0.879294
-0.074310
0.798994
0.937707
0.214296
-0.706138
-0.977352
-0.349994
jrs@jrs-laptop:~/sb/examples/test$


Tomaaz

  • Guest
Re: One statement SIN table
« Reply #19 on: August 30, 2018, 01:49:58 PM »
John, this  topic in not about speed, nor it is about writing a FOR/NEXT loop.

ScriptBasic

  • Guest
Re: One statement SIN table
« Reply #20 on: August 30, 2018, 03:49:39 PM »
Oh, It's about languages that allow multiple statements per line.

B+

  • Guest
Re: One statement SIN table
« Reply #21 on: August 30, 2018, 05:27:04 PM »
One statement, no variables... Tomaaz is winning!

Wait, D might create a SpecBas custom built-in... ;D

Phix sq_(func or operator) is interesting. :)

I think Basic's "Core" structure is variables, so ask Phix to do something without using objects.
« Last Edit: August 30, 2018, 05:33:18 PM by B+ »

Tomaaz

  • Guest
Re: One statement SIN table
« Reply #22 on: August 30, 2018, 05:41:20 PM »
Oh, It's about languages that allow multiple statements per line.

No, it's not. Also, it's not about using one statement. It's about calculating and printing sin for each elements in a range, without using a variable. I don't want to play someone smarter than I am, but possibly we are entering functional programming here, while your code is an example (very obvious and boring) of imperative style.

B+

  • Guest
Re: One statement SIN table
« Reply #23 on: August 30, 2018, 06:11:20 PM »
Well this thread, that I started with the title One Statement SIN table, was about One statement, though Tomaaz quote, that I started the thread with, did not mention one statement.

I was going for the elegance of one-liner without : colons for statement separators.

But go ahead and post anything closely related, as you will anyway! ;)

I enjoyed very much Peter's method of using the clock! and learning about other languages by comparing to Basic.

ZXDunny

  • Guest
Re: One statement SIN table
« Reply #24 on: August 31, 2018, 09:34:44 AM »
One statement, no variables... Tomaaz is winning!

Wait, D might create a SpecBas custom built-in... ;D

I wouldn't hold your breath :)

To be honest, there's really no need to add this sort of functionality to SpecBAS - as Tomaaz points out, we're heading into functional coding territory here and that's not what my BASIC is about - it's a toy language built to scratch my retro-BASIC itch :)

Tomaaz

  • Guest
Re: One statement SIN table
« Reply #25 on: August 31, 2018, 04:07:40 PM »
Not sure what Tomaaz defines as quite fast.

Jut for curiosity.

OpenEuphoria:

Code: [Select]
include std/math.e
include std/sequence.e

object plik = open("sinusy.txt", "w")
print(plik, sin(series(1, 1, 1000000)))
close(plik)

Quote
tom@helium:~/Downloads$ time eui untitled.ex

real   0m1.103s
user   0m1.044s
sys   0m0.044s

Already, almost 4 times faster that ScriptBasic, but you need to consider that I run it on 5 years old extremely cheap laptop that runs 32-bit OS,

ScriptBasic

  • Guest
Re: One statement SIN table
« Reply #26 on: August 31, 2018, 05:47:28 PM »
My understanding is Open Euphoria is a compiler not an interpreter like Script BASIC.

Aurel

  • Guest
Re: One statement SIN table
« Reply #27 on: August 31, 2018, 05:51:46 PM »
Open Euphoria is a bytecode interpreter and well maybe is fast but not as old original Euphoria[/b].

ScriptBasic

  • Guest
Re: One statement SIN table
« Reply #28 on: August 31, 2018, 05:59:50 PM »
Thanks Aurel for the correction. I just noticed that after visiting the site. I was about to delete my post.  :-X

Tomaaz

  • Guest
Re: One statement SIN table
« Reply #29 on: August 31, 2018, 06:17:24 PM »
Well, that was more about the speed of this example and, in theory, it should be faster than a procedural code doing the same thing, so no surprise that ScriptBasic lost. OpenEuphoria can also translate to C and then compile C code to standalone executables, however the resulting binaries are not much faster than the interpreter, especially on 32-bit Linux distros. All I can get is max 2x. On 64-bit system some examples are 10x faster after compilation. I don't have a Windows machine, so have no idea how it performs under Windows.