RE : crazy run-time fluctuations (mostly super-slow) -- a bit more data
Subject: RE : crazy run-time fluctuations (mostly super-slow) -- a bit more data
From: Rupert Swarbrick
Date: Sun, 23 Oct 2011 12:48:09 +0100
Oliver Kullmann <O.Kullmann at swansea.ac.uk> writes:
> However, with each invocation of :lisp seems to start a fresh
> environment, unrelated to the invocation before, so that between two
> Maxima-calls apparently no relation can be established between the
> calls of random??:
>
> (%i447) :lisp (setq ss *random-state*)
> #<random-state 000000000143b000>
> (%i447) :lisp (setq ss2 *random-state*)
> #<random-state 000000000143b000>
> (%i447) :lisp (equal ss ss2)
> T
> (%i447) :lisp (random 1000 ss)
> 808
> (%i447) :lisp (random 1000 ss2)
> 57
> (%i447) :lisp (equal ss ss2)
> T
If you're happy with C-like languages, the best thing is to think that
ss and ss2 are like pointers to a (complicated) structure, which is also
pointed to by *random-state*.
Thus your two calls to random are exactly the same as if you'd called
(random 1000 ss) twice.
In common lisp, equality is a funny thing. You probably meant to use
EQUAL-P here rather than EQUAL, but in fact you'll definitely get T
every time because ss and ss2 are just pointing to the same structure.
See this transcript for a way to do what I think you want:
Maxima 5.25post http://maxima.sourceforge.net
using Lisp SBCL 1.0.52.0.debian
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (defvar *ss1* (make-random-state t))
*SS1*
(%i1) :lisp (defvar *ss2* (make-random-state t))
*SS2*
(%i1) :lisp (setf *random-state* *ss1*)
*** output flushed ***
(I'm throwing away the output because it's big)
(%i1) :lisp (defvar *frozen-ss1* (make-random-state nil))
*FROZEN-SS1*
(%i1) :lisp (eq *ss1* *frozen-ss1*)
NIL
(%i1) :lisp (equalp *ss1* *frozen-ss1*)
T
(This shows that the contents of *ss1* and *frozen-ss1* are the same (as
you'd expect since *frozen-ss1* is supposed to be a copy of *ss1*). But
eq returns NIL, since they aren't in the same place in memory. As a
result when we run the next lines, *ss1* changes but *frozen-ss1* doesn't).
(%i1) :lisp (random 10)
3
(%i1) :lisp (random 10)
6
(%i1) :lisp (random 10)
5
(%i1) :lisp (random 10)
7
(%i1) :lisp (setf *random-state* *frozen-ss1*)
*** output flushed ***
(%i1) :lisp (random 10)
3
(%i1) :lisp (random 10)
6
(%i1) :lisp (random 10)
5
(%i1) :lisp (random 10)
7
(%i1)
(Finally, let's check that *ss2* is just completely different.)
(%i1) :lisp (setf *random-state* *ss2*)
*** output flushed ***
(%i1) :lisp (random 10)
8
(%i1) :lisp (random 10)
9
(%i1) :lisp (random 10)
5
(%i1) :lisp (random 10)
8
Tada! I hope this clears things up for you to some extent.
Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20111023/e4dd5627/attachment.pgp>