Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Those who can, do; those who can't, simulate.


devel / comp.lang.forth / EPR experiment simulator in Forth

SubjectAuthor
* EPR experiment simulator in ForthKrishna Myneni
`* Re: EPR experiment simulator in ForthKrishna Myneni
 `* Re: EPR experiment simulator in ForthAnton Ertl
  +* Re: EPR experiment simulator in ForthS Jack
  |`- Re: EPR experiment simulator in ForthAnton Ertl
  `* Re: EPR experiment simulator in ForthKrishna Myneni
   `- Re: EPR experiment simulator in ForthKrishna Myneni

1
EPR experiment simulator in Forth

<sghfdb$apg$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14374&group=comp.lang.forth#14374

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: EPR experiment simulator in Forth
Date: Sun, 29 Aug 2021 21:22:33 -0500
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <sghfdb$apg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 02:22:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7a407f5b12b18e350439345639aef94f";
logging-data="11056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vaq/PN6YtJEpQbvgPMWs0"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:eIbzyHQu+qZS6/7s7T2MFY6BOpA=
Content-Language: en-US
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Krishna Myneni - Mon, 30 Aug 2021 02:22 UTC

A preliminary version of a simulator for the Einstein-Podolsky-Rosen
experiment, written in Forth, may be found at the link below. It runs as
is under kForth-64 (please use latest development version, or update the
mini-oof.4th file from the kForth-64 repo). It also runs under Gforth
with a minimal, and mostly obvious, set of compatibility definitions,
below. Please see notes in the source for use with Gforth.

For those who are interested in this program, but not familiar with the
EPR thought experiment, please see the source, Refs. 1--3. Currently,
the article may be freely downloaded from the publisher's page linked
for Ref. 1.

Ref. 2 discusses the modern version of the EPR experiment, which is
simulated in the Forth program. It may be downloaded from its link.

Ref. 3's link points to the publisher's page, from which it is not
freely downloadable.

Finally, another interesting and readable paper dealing with the subject
of this program may be downloaded from here:

https://hal.archives-ouvertes.fr/jpa-00220688/document

--
Krishna Myneni

https://github.com/mynenik/kForth-64/blob/master/forth-src/qm/epr-sim.4th

Compatibility definitions for Gforth:
---------
\ kforth-compat.fs
\ \ kForth compatibility defns. for gforth
\ \ Revised: 2021-08-26

utime 2constant start_time

base @
: deg>rad ( F: r1 -- r2 ) PI f* 180.0e0 f/ ;
: rad>deg ( F: r1 -- r2 ) 180.0e0 f* PI f/ ;
: fround>s ( F: r -- ) ( -- s ) fround f>s ;
: ftrunc>s ( F: r -- ) ( -- s ) ftrunc f>s ;
: allot? ( u -- a ) here swap allot ;
: 2+ 2 + ;
: 2- 2 - ;
: ms@ ( -- u ) utime start_time d- 1000 um/mod nip ;
: us2@ ( -- ud ) utime start_time d- ;
: usleep ( u -- ) 1000 / 1 max ms ;
: nondeferred ( -- ) ;

synonym a@ @
base !
---------

Re: EPR experiment simulator in Forth

<sgiihq$9t7$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14378&group=comp.lang.forth#14378

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: EPR experiment simulator in Forth
Date: Mon, 30 Aug 2021 07:22:16 -0500
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <sgiihq$9t7$1@dont-email.me>
References: <sghfdb$apg$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 12:22:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7a407f5b12b18e350439345639aef94f";
logging-data="10151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZJ17ckkESvhdKg2xaIRoj"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:stx0I7YKspiwg/lGrQ1/39wBMMo=
In-Reply-To: <sghfdb$apg$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Mon, 30 Aug 2021 12:22 UTC

On 8/29/21 9:22 PM, Krishna Myneni wrote:

> Compatibility definitions for Gforth:
> ---------
> \ kforth-compat.fs
> \
> \ kForth compatibility defns. for gforth
> \
> \ Revised: 2021-08-26
>
> utime 2constant start_time
>
> base @

Insert DECIMAL after the above line.

> : deg>rad ( F: r1 -- r2 ) PI f* 180.0e0 f/ ;
> : rad>deg ( F: r1 -- r2 ) 180.0e0 f* PI f/ ;
> : fround>s ( F: r -- ) ( -- s ) fround f>s ;
> : ftrunc>s ( F: r -- ) ( -- s ) ftrunc f>s ;
> : allot?  ( u -- a ) here swap allot ;
> : 2+  2 + ;
> : 2-  2 - ;
> : ms@ ( -- u )  utime start_time d- 1000 um/mod nip ;
> : us2@ ( -- ud ) utime start_time d- ;
> : usleep ( u -- ) 1000 / 1 max ms ;

The compatibility definition for kForth's USLEEP is a quick hack. MS
provides a delay in milliseconds, but it does not call the operating
system's sleep function. I don't know how to do the equivalent call to
USLEEP in Gforth, and, although it doesn't appear to make much
difference for the program mentioned here, in general MS is not a
substitute for putting the process to sleep.

> : nondeferred ( -- ) ;
>
> synonym a@ @
> base !
> ---------
>
>

KM

Re: EPR experiment simulator in Forth

<2021Aug30.164912@mips.complang.tuwien.ac.at>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14382&group=comp.lang.forth#14382

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: EPR experiment simulator in Forth
Date: Mon, 30 Aug 2021 14:49:12 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 44
Message-ID: <2021Aug30.164912@mips.complang.tuwien.ac.at>
References: <sghfdb$apg$1@dont-email.me> <sgiihq$9t7$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="a299dbf7380ba492227c2860e9027c9a";
logging-data="21688"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a3UJ2hXRpoWMPsmL5vN4p"
Cancel-Lock: sha1:aiHEP1y4TWhpH1OvTac9OigyGdQ=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Mon, 30 Aug 2021 14:49 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> : usleep ( u -- ) 1000 / 1 max ms ;
>
>The compatibility definition for kForth's USLEEP is a quick hack. MS
>provides a delay in milliseconds, but it does not call the operating
>system's sleep function. I don't know how to do the equivalent call to
>USLEEP in Gforth, and, although it doesn't appear to make much
>difference for the program mentioned here, in general MS is not a
>substitute for putting the process to sleep.

Why do you think that Gforth's MS does not put the process to sleep?

[~:124110] time gforth -e "500 ms bye"

real 0m0.511s
user 0m0.008s
sys 0m0.004s

Looks to me like it slept for 500ms.

What does MS call? Let's see:

[~:124111] strace gforth -e "500 ms bye"
....
nanosleep({0, 500000000}, 0x7fffc81ff230) = 0
rt_sigaction(SIGPIPE, {SIG_IGN, [], SA_RESTORER|SA_NODEFER, 0x7f6717ea00e0}, {0x412ab0, [], SA_RESTORER|SA_NODEFER, 0x7f6717ea00e0}, 8) = 0
exit_group(0) = ?
+++ exited with 0 +++

So MS calls nanosleep() on Gforth 0.7.

On development Gforth I see:

pselect6(0, NULL, NULL, NULL, {0, 499999838}, {NULL, 8}) = 0 (Timeout)

This is on Linux, other calls will be used on systems that do not have
these system calls.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021

Re: EPR experiment simulator in Forth

<4b1ad0b9-80ed-4d59-89c1-608122f9a5dfn@googlegroups.com>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14385&group=comp.lang.forth#14385

 copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:ac8:6b8b:: with SMTP id z11mr21406290qts.153.1630340571572;
Mon, 30 Aug 2021 09:22:51 -0700 (PDT)
X-Received: by 2002:a05:620a:4549:: with SMTP id u9mr16531848qkp.466.1630340571410;
Mon, 30 Aug 2021 09:22:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!usenet.pasdenom.info!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Mon, 30 Aug 2021 09:22:51 -0700 (PDT)
In-Reply-To: <2021Aug30.164912@mips.complang.tuwien.ac.at>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:3f7a:20d0:7925:e32b:f46c:7f5e;
posting-account=V5nGoQoAAAC_P2U0qnxm2kC0s1jNJXJa
NNTP-Posting-Host: 2600:1700:3f7a:20d0:7925:e32b:f46c:7f5e
References: <sghfdb$apg$1@dont-email.me> <sgiihq$9t7$1@dont-email.me> <2021Aug30.164912@mips.complang.tuwien.ac.at>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4b1ad0b9-80ed-4d59-89c1-608122f9a5dfn@googlegroups.com>
Subject: Re: EPR experiment simulator in Forth
From: sdwjac...@gmail.com (S Jack)
Injection-Date: Mon, 30 Aug 2021 16:22:51 +0000
Content-Type: text/plain; charset="UTF-8"
 by: S Jack - Mon, 30 Aug 2021 16:22 UTC

On Monday, August 30, 2021 at 9:56:26 AM UTC-5, Anton Ertl wrote:
> So MS calls nanosleep() on Gforth 0.7.

Just curious. Does nonosleep put the program to sleep such that no Forth task
will run during the MS interval; something a multi-tasker needs to consider?
--
me

Re: EPR experiment simulator in Forth

<2021Aug30.183857@mips.complang.tuwien.ac.at>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14386&group=comp.lang.forth#14386

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ant...@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: EPR experiment simulator in Forth
Date: Mon, 30 Aug 2021 16:38:57 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 27
Message-ID: <2021Aug30.183857@mips.complang.tuwien.ac.at>
References: <sghfdb$apg$1@dont-email.me> <sgiihq$9t7$1@dont-email.me> <2021Aug30.164912@mips.complang.tuwien.ac.at> <4b1ad0b9-80ed-4d59-89c1-608122f9a5dfn@googlegroups.com>
Injection-Info: reader02.eternal-september.org; posting-host="a299dbf7380ba492227c2860e9027c9a";
logging-data="28199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UvHfZj1W73IvdpNyXwNeP"
Cancel-Lock: sha1:VIEcdvD7nwiAnIeCmCpt5hH1TwE=
X-newsreader: xrn 10.00-beta-3
 by: Anton Ertl - Mon, 30 Aug 2021 16:38 UTC

S Jack <sdwjack69@gmail.com> writes:
>On Monday, August 30, 2021 at 9:56:26 AM UTC-5, Anton Ertl wrote:
>> So MS calls nanosleep() on Gforth 0.7.
>
>Just curious. Does nonosleep put the program to sleep such that no Forth task
>will run during the MS interval;

man nanosleep says:

|nanosleep() suspends the execution of the calling thread until either
|at least the time specified in *req has elapsed, or the delivery of a
|signal [...]

>something a multi-tasker needs to consider?

So yes, if you have several Forth tasks in an OS thread, you need to
use a different system call, e.g., pselect(). However, while
development Gforth uses pselect() and supports multi-tasking, it only
waits for the timeout (or signal) with pselect. I guess each task
gets its own thread.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2021: https://euro.theforth.net/2021

Re: EPR experiment simulator in Forth

<sgjain$g3a$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14389&group=comp.lang.forth#14389

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: EPR experiment simulator in Forth
Date: Mon, 30 Aug 2021 14:12:21 -0500
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <sgjain$g3a$1@dont-email.me>
References: <sghfdb$apg$1@dont-email.me> <sgiihq$9t7$1@dont-email.me>
<2021Aug30.164912@mips.complang.tuwien.ac.at>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 19:12:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7a407f5b12b18e350439345639aef94f";
logging-data="16490"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195ZGJd738iLZU6dn+omUGB"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:QTNHlBLKQaI7mEHH0rwOI5MbXO0=
In-Reply-To: <2021Aug30.164912@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Krishna Myneni - Mon, 30 Aug 2021 19:12 UTC

On 8/30/21 9:49 AM, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>>> : usleep ( u -- ) 1000 / 1 max ms ;
>>
>> The compatibility definition for kForth's USLEEP is a quick hack. MS
>> provides a delay in milliseconds, but it does not call the operating
>> system's sleep function. I don't know how to do the equivalent call to
>> USLEEP in Gforth, and, although it doesn't appear to make much
>> difference for the program mentioned here, in general MS is not a
>> substitute for putting the process to sleep.
>
> Why do you think that Gforth's MS does not put the process to sleep?
>

I did not look at the source code for Gforth's implementation of MS. In
kForth we found that we can use a polling loop to obtain higher
precision delays for MS, rather than using a call to put the process to
sleep. This is why we have a separate word, USLEEP.

For example, on the same system,

$ time kforth64 -e "500 ms bye"
Goodbye.

real 0m0.506s
user 0m0.503s
sys 0m0.003s

$ time ./gforth -e "500 ms bye"

real 0m0.515s
user 0m0.006s
sys 0m0.006s

$ time kforth64 -e "1000 ms bye"
Goodbye.

real 0m1.006s
user 0m1.002s
sys 0m0.003s

$ time ./gforth -e "10000 ms bye"

real 0m10.024s
user 0m0.004s
sys 0m0.003s

--
Krishna

Re: EPR experiment simulator in Forth

<sgjamu$g3a$2@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14390&group=comp.lang.forth#14390

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: EPR experiment simulator in Forth
Date: Mon, 30 Aug 2021 14:14:38 -0500
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <sgjamu$g3a$2@dont-email.me>
References: <sghfdb$apg$1@dont-email.me> <sgiihq$9t7$1@dont-email.me>
<2021Aug30.164912@mips.complang.tuwien.ac.at> <sgjain$g3a$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 19:14:38 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7a407f5b12b18e350439345639aef94f";
logging-data="16490"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+edrnwJRfGHfaCriefYHM9"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:b03jIyTKLKeBTDLnbTq75hYQh9A=
In-Reply-To: <sgjain$g3a$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Mon, 30 Aug 2021 19:14 UTC

On 8/30/21 2:12 PM, Krishna Myneni wrote:
> On 8/30/21 9:49 AM, Anton Ertl wrote:
>> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>>>> : usleep ( u -- ) 1000 / 1 max ms ;
>>>
>>> The compatibility definition for kForth's USLEEP is a quick hack. MS
>>> provides a delay in milliseconds, but it does not call the operating
>>> system's sleep function. I don't know how to do the equivalent call to
>>> USLEEP in Gforth, and, although it doesn't appear to make much
>>> difference for the program mentioned here, in general MS is not a
>>> substitute for putting the process to sleep.
>>
>> Why do you think that Gforth's MS does not put the process to sleep?
>>
>
> I did not look at the source code for Gforth's implementation of MS. In
> kForth we found that we can use a polling loop to obtain higher
> precision delays for MS, rather than using a call to put the process to
> sleep. This is why we have a separate word, USLEEP.
>
> For example, on the same system,
>
> $ time kforth64 -e "500 ms bye"
> Goodbye.
>
> real    0m0.506s
> user    0m0.503s
> sys    0m0.003s
>
> $ time ./gforth -e "500 ms bye"
>
> real    0m0.515s
> user    0m0.006s
> sys    0m0.006s
>
> $ time kforth64 -e "1000 ms bye"
> Goodbye.
>
> real    0m1.006s
> user    0m1.002s
> sys    0m0.003s
>
> $ time ./gforth -e "10000 ms bye"
>
> real    0m10.024s
> user    0m0.004s
> sys    0m0.003s
>

Sorry, I copied the wrong instance for the 10000 ms test for kForth. But
the result is unchanged.

$ time kforth64 -e "10000 ms bye"
Goodbye.

real 0m10.006s
user 0m9.997s
sys 0m0.001s

--
KM

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor