Author Topic: Should we compare ?  (Read 9659 times)

0 Members and 1 Guest are viewing this topic.

jack

  • Guest
Re: Should we compare ?
« Reply #30 on: June 22, 2014, 04:19:42 AM »
hello Robbek

I would like to see your lisp code, the m switch in Clisp does not seem to increase the stack memory, but in sbcl you can increase the stack with --control-stack-size.
« Last Edit: June 22, 2014, 06:05:34 AM by jack »

RobbeK

  • Guest
Re: Should we compare ?
« Reply #31 on: June 22, 2014, 08:05:21 AM »
Hi Jack,

Ran some tests and using -m 100MB , I can get integers with over 200000 cyphers (the documentation says the limit is something as (expt 2 2000000) digits. (the floats go a lot higher)
Wrote a batch file with this -m setting, (without this CLisp claims only 3 Mb it seems).
It runs fine now --  reached the 17 th number in around 20'.
Does this code run in Steel Bank CL without modification ??

best Rob   

.

jack

  • Guest
Re: Should we compare ?
« Reply #32 on: June 22, 2014, 09:21:54 AM »
Hi RobbeK,
I had to replace the hyphen character in the code, apparently it's a unicode character that my system does not understand,
but after that it run OK in sbcl.
clisp time 8.4 seconds
sbcl time 2.1 seconds

the function I used for the timing
Code: [Select]
(defun run-time (n)
  (let ((tm (get-internal-real-time)))
  (eval n)
  (/ (- (get-internal-real-time) tm) 1000l0)))
Quote
(run-time '(printperfect 1000))
there's a difference between clisp  and sbcl get-internal-real-time function, the run-time function above returns milliseconds in clisp but seconds in sbcl.

just in case others have the hyphen problem, the code follows.
Code: [Select]
(defun factor-out (number divisor)
  (do ((e 0 (1+ e))
       (r number (/ r divisor)))
      ((/= (mod r divisor) 0) (values r e))))

(defun mult-mod (x y modulus) (mod (* x y) modulus))

(defun expt-mod (base exponent modulus)
  "Fast modular exponentiation by repeated squaring."
  (labels ((expt-mod-iter (b e p)
             (cond ((= e 0) p)
                   ((evenp e)
                    (expt-mod-iter (mult-mod b b modulus)
                                   (/ e 2)
p))
                   (t
                    (expt-mod-iter b
(1- e)
                                   (mult-mod b p modulus))))))
    (expt-mod-iter base exponent 1)))

(defun random-in-range (lower upper)
  "Return a random integer from the range [lower..upper]."
  (+ lower (random (+ (- upper lower) 1))))

(defun miller-rabin-test (n k)
  "Test N for primality by performing the Miller-Rabin test K
times.
Return NIL if N is composite, and T if N is probably prime."
  (cond ((= n 1) nil)
        ((< n 4) t)
        ((evenp n) nil)
        (t
         (multiple-value-bind (d s) (factor-out (- n 1) 2)
           (labels ((strong-liar? (a)
                      (let ((x (expt-mod a d n)))
                        (or (= x 1)
                            (loop repeat s
                                  for y = x then (mult-mod y y n)
                                  thereis (= y (- n 1)))))))
(loop repeat k
      always (strong-liar? (random-in-range 2 (- n 2)))))))))

(defun perfect (x)
  (let ( (n (- (expt 2 x) 1 )))
     (if (miller-rabin-test n 8)
       (* n (expt 2 (- x 1)))
0 )))

(defun print-bin (x)
  (princ (write-to-string x :base 2))
  (terpri)  )

(defun print-01 (str)
  (let (( n 0) (s (write-to-string str :base 2) ))
    (dotimes (i (length s) t)
      (when (eql #\1 (char s i))
        (incf n)))
    (princ (write-to-string (length s)))
    (princ " / " )
    (princ (write-to-string n))
    (princ " + ") (princ (write-to-string (- (length s) n)))
(terpri)))

(defun printperfect (x)
  (let ( (p 0) )
     (loop for i from 1 to x do
       (setq p (perfect i))
       (when (> p 0)
         (print-bin p)
         (print-01 p)
         (princ p) (terpri) (terpri) ))))
« Last Edit: June 22, 2014, 11:13:49 AM by jack »

RobbeK

  • Guest
Re: Should we compare ?
« Reply #33 on: June 27, 2014, 11:54:24 AM »
Thanks Jack,

I'm used to Clisp in the mean time ,  but some special care is needed with underflow errors , and the number of arguments to a function is much lower than SBCL I think : 4K versus 64K ?

Any special GUI you use ??  ( I setup Japi ..(a suggestion from John)  I think it's good - not too many gadgets, any easy to use ...  )
attached .
(an experiment about divergence/convergence of  an infinite sum of series of surface transformations ..  )

best, Rob

.

JRS

  • Guest
Re: Should we compare ?
« Reply #34 on: June 27, 2014, 01:31:23 PM »
Too cool Rob!

Maybe you and Ron can join forces and phoenix JAPI back to life. Since Google (Chrome / Chrome OS) has abandoned Java in their web solutions (Android is next) JAPI (Java) needs a purpose.  :(

Script BASIC JAPI extension module

« Last Edit: June 27, 2014, 02:58:34 PM by John »

Charles Pegge

  • Guest
Re: Should we compare ?
« Reply #35 on: June 28, 2014, 04:10:08 AM »

Do you find 3d surface visualisations useful, Rob?

RobbeK

  • Guest
Re: Should we compare ?
« Reply #36 on: June 29, 2014, 02:14:22 AM »
Hi John,

Looks very interesting !!   Japi has some strongpoints like "appendtext" on textarea's , and the image related functions are extremely fast (though for setting up an rgb matrix (array) int32's are used and not byte (char)  - i imported these functions in Lisp , but oxygen has to set up the flat memory model  ... (and give back the addresses to lisp , because a few Japi functions need int*  like :
extern  void  j_getimagesource ( int , int , int , int , int , int* , int* , int*  )
(char*  is not problem in Lisp , it has something as c-string , zstring etc ....).
I think it can be done with the Common Lisp CFFI package, however I have severe problems making stand-alone executables when using this interface.
So, looking inside your dll code (I used  Dependency Walker (another good tip ..  from Mike this time ..  I had some problems with name-mangling when creating DLL with freebasic -- ...  in the end Charles showed the correct way ..  )
..  but in your japi.bas(?) , i do not see any return value declarations when importing the functions (__j_ascriba_.....  )  , i'm of course very interested in this ...  (downloaded ScriptBasic now 

Hi Charles,  yes of course ...
The idea behind all this is a kind of question why something as the harmonic series (Zeta(1) ) goes to infinity 1+1/2+1/3.... (even the recipr. of the primes do this 1/2+1/3+1/5+1/7 ...   while something as S=1/2+1/4+1/8 .. only delivers 1 as sum.
This is in mind the "fractal method" came up  :

Start with a square
Make a new square from the mid points of sides
iterate   

this delivers the above mentioned S series (easy to see the new square is half of its previous)

write this analytic and expand it
f(x)=2x(x-1)+1   where x is the location of the new corner point (if this is correct English) between 0 en 1
easy to see it is symmetrical around x=1/2 and has it maxima at 0 and 1  (logical because there is no rotation and the square generates itself ..  the sum is then 1+1+1+  ................ :)
Remarkable is that is formula (obtaining by squaring the hypothenusa of one of the triangles inside the square ) is almost identical to the logistic function which IIRC was used by Feigenbaum to get his two constants which describe chaotic processes.
 ...  it seems everything is related with everything in a way ....   
but it goes further, ...  very interesting series can be build form this starting point --  p.e.  a side of the square x -> sqrt(x).
..   (well, some people like crossword puzzles , .. I prefer these kind of puzzles  8)
I final word about the underflow error in Common Lisp -- it's not that absurd (one can reason , ok if the number is that small we can make it equal with zero , not ???    ...  yes, but the problem is we do not have -0 and +0  , and this may be a huge difference in a calculation / process ...


best, Rob
« Last Edit: June 29, 2014, 03:02:08 AM by RobbeK »

JRS

  • Guest
Re: Should we compare ?
« Reply #37 on: June 29, 2014, 09:08:11 AM »
Hi Rob,

I'm happy to see that you found JAPI of interest. I think its' a gem. The Script BASIC extension module DLLs aren't like normal shared objects and do some initial calls for versioning and pre/post load logic. All calls to the extension modules are done with variadic functions which allows practically unlimited arguments and of any type supported. (long, double, strings and arrays) SB variables (typeless at the user level) are like variants in a way. Charles has been intimate with SB under the covers and has his own story to tell.  8) He is no longer a virgin and that's all I'm going to say.

Quote from: Rob
and the image related functions are extremely fast

Surprised the hell out of me seeing it's a socket interface to the JRE.

Send me an e-mail to support@scriptbasic.org if you would like to join the Script BASIC forum and contribute to that project as well. It could be fun.

John
« Last Edit: June 29, 2014, 03:53:20 PM by John »

RobbeK

  • Guest
Re: Should we compare ?
« Reply #38 on: June 30, 2014, 01:06:11 PM »
Hi John,

Ah, ok , I understand ...

"are done with variadic functions"  ..  parsing + a parsecount to start ?   ...

 "Surprised the hell out of me seeing it's a socket interface to the JRE"  ... yep, and interesting for languages lacking GET/PUT (some languages do graphics extremely slow )

Attached something written in oxygen (changed something that was in the examples ,  it used the setpixel() method , this is a lot faster ...

---------------------
 for j=1 to 44 
               j_drawimagesource (canvas,0,0,breite,hoehe,@r,@g,@b)
               darken_green()
 next
---------------------   8)   (draws the Mandelbrot and then darkens the greens ....  )

best Rob

.
« Last Edit: June 30, 2014, 01:43:35 PM by RobbeK »

JRS

  • Guest
Re: Should we compare ?
« Reply #39 on: June 30, 2014, 06:01:44 PM »
That's really slick. Nice job!


RobbeK

  • Guest
Re: Should we compare ?
« Reply #40 on: July 01, 2014, 05:40:56 AM »
Hi John,

Even doing the graphics "pixel-wise" seems ok for most applications.
Just testing something  --  a tree-friendly spirograph  ::)  -- maybe the grand-children like it ...
(just - a not so fantastic screen recording - but it gives an idea
..  in CLisp (compiled into byte code /  + GNU Lightning JIT ) 

'll send a mail to sb.org this evening ..  ...

best Rob


.

JRS

  • Guest
Re: Should we compare ?
« Reply #41 on: July 01, 2014, 10:56:19 AM »
Quote
'll send a mail to sb.org this evening ..  ...

We'll keep a light on for ya.  ;)