6 Replies - 1432 Views - Last Post: 15 January 2010 - 01:42 PM

#1 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Lisp Mandelbrot set distortion.

Posted 12 January 2010 - 02:07 PM

For a project i have to analyze the effects of changing the language is written in on the execution speed of a program. I chose to compute the Mandelbrot set and output the file into XBM format. Yes, i know everything i'm doing is HIDEOUSLY inefficient. Hence, the Lisp program takes 10 times as long as the python one which takes 10 times as long as Java and C#, which are both slower than C++. My main issue is that the set that the lisp function generates is distorted. All of the others work fine. I've posted the source in a tar.gz archive along with sample xbms. I know for a fact that the XBM class in lisp works as planned (though my CLOS skills kinda suck, i think i hacked together something workable). If you need it in zip format with windows style line endings you can either do it yourself ;) or if you say i can actually transfer everything to windows line endings.

I'm currently running with the settings:
maxiter: 1024
xmin: -2.25
xmax: 0.75
ymin: -1.125
ymax: 1.125
image width: 640
image height: 480

If you intend on a run test to see what the XBMs actually look like you might want to do just 64x48 for the lisp

It's clearly visible that SOMETHING is happening in the LISP code that is making it so slow, i just don't know what. I also don't know why the algorithm is not working

Since i've mainly been working in other languages, the program is pretty procedural by nature. I've tried as best i can to provide direct source-to-source transliteration while allowing for the individual idiosyncrasies of the languages. If somebody that is more fluent in lisp than I read over the lisp code and compared it to the C++, C#, Java, or Python code (which is tested to work) and find the bug it would be much appreciated. I'd try to find it myself but i'm honestly stumped- it was hard enough just to code in LISP, much less actually read it...

Thanks!

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Lisp Mandelbrot set distortion.

#2 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Lisp Mandelbrot set distortion.

Posted 12 January 2010 - 10:13 PM

Something is wrong with the archive. It wont extract.

As a side note, these things come with time. Lisps can be hard to read to someone new to S-Expressions, but over time if using Lisp, you'll come to appreciate sexps. They are part of the reason that Lisp is so powerful. Also, the only reason I knew you were using Common Lisp at this point was because you mentioned CLOS. In future posts, please explicitly what particular Lisp you're using. Not all of them are made equal. I'm a Clojure programmer myself, but I could certainly go over the code and see if I could figure it out.

If I can't, and nobody else on here can, you can always take it to Stackoverflow.com and see if anybody there can answer it.
Was This Post Helpful? 0
  • +
  • -

#3 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Lisp Mandelbrot set distortion.

Posted 13 January 2010 - 12:10 PM

It extracted fine for me, but i've re-archived and is attatched.

I wasn't sure that there was difference between lisp implementations. I'm using CLisp right now. It should be *relatively* clear to most lisp dialect programmers (looking at the code, the only functions that I googled that are non-standard are the CLOS stuff like defclass, defmethod, and some i-o stuff like format semantics and with-open-file stuff, plus a tiny bit of bit twiddling that is hopefully self-explanatory).

Anyway, thanks for enlightening me. And i hope you can help. It's strange- i don't know what's the problem (runtime bugs SUCK). Files attatched.

Attached File(s)

  • Attached File  mset.zip (19.23K)
    Number of downloads: 55

This post has been edited by polymath: 13 January 2010 - 01:59 PM

Was This Post Helpful? 0
  • +
  • -

#4 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Lisp Mandelbrot set distortion.

Posted 13 January 2010 - 12:27 PM

View Postpolymath, on 13 Jan, 2010 - 11:10 AM, said:

It extracted fine for me, but i've re-archived and is attatched.

I wasn't sure that there was difference between lisp implementations. I'm using GNU CLisp right now. It should be *relatively* clear to most lisp dialect programmers (looking at the code, the only functions that I googled that are non-standard are the CLOS stuff like defclass, defmethod, and some i-o stuff like format semantics and with-open-file stuff, plus a tiny bit of bit twiddling that is hopefully self-explanatory).

Anyway, thanks for enlightening me. And i hope you can help. It's strange- i don't know what's the problem (runtime bugs SUCK). Files attatched.


Well, I think I have you a bit confused. :)

Each Lisp dialect is an entirely different language. Clojure, Common Lisp, and Scheme are all entirely different languages that just happen to be dialects of Lisp. There are many different implementations of Common Lisp, but Common Lisp is Common Lisp so the difference in the code is usually minimal, and a CL programmer would definitely be able to understand your code. I'll give it a run over and see if I can spot anything, but since I'm a Clojure programmer and not a CL programmer, I can't promise anything.

EDIT: Yeah, it took me about thirty seconds to realize that I'll never figure that out. I don't know many CL programmers around here, but you might be able to get an answer rather quickly on Stackoverflow.com, as long as you read the rules about how to structure your question if you've never posted there before.

I wouldn't normally recommend going to another site for help, but this might be your best option at this point.

Also, it's not that I can't read the code as much as it is that without me having proper understanding of the Mandelbrot set, and not knowing Common Lisp itself, it would take me forever to figure that out. Lisps are always similar in some ways, but Clojure tends to differ a lot (in good ways, subjectively) from Common Lisp.

This post has been edited by Raynes: 13 January 2010 - 12:38 PM

Was This Post Helpful? 0
  • +
  • -

#5 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Lisp Mandelbrot set distortion.

Posted 13 January 2010 - 01:57 PM

Well, the significance of CLisp over another Lisp was just ignorant me saying "Oh, i need a functional programming language for the project. I'll choose LISP", and i'm-feeling-luckying "open source lisp". Not much significance in that decision. My mantra was "just translate it and make it work". It probably would be easier for you to understand if i had re-coded it in a more lisp-ish accent/style, but that would make my life harder and also mess with the results (the algorithms need to be equivalent so that i can benchmark the programs against each other).

Personally, i find the Python and C++ versions the easiest to understand. The LISP stuff just gave me a headache mostly. Thank god my editor has parentheses matching.

Thanks for your attempt :)

If i'm looking to learn more functional programming (at this point a weakness for me), is there a language that is simpler than clisp that actually has functionality? I tried scheme but found coding anything actually useful difficult.

EDIT: I'll try and work it under a different implementation of CLisp. Maybe clisp has a bug in floating-point representation that gcl doesn't.

This post has been edited by polymath: 13 January 2010 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#6 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Lisp Mandelbrot set distortion.

Posted 14 January 2010 - 02:09 AM

View Postpolymath, on 13 Jan, 2010 - 12:57 PM, said:

Well, the significance of CLisp over another Lisp was just ignorant me saying "Oh, i need a functional programming language for the project. I'll choose LISP", and i'm-feeling-luckying "open source lisp". Not much significance in that decision. My mantra was "just translate it and make it work". It probably would be easier for you to understand if i had re-coded it in a more lisp-ish accent/style, but that would make my life harder and also mess with the results (the algorithms need to be equivalent so that i can benchmark the programs against each other).

Personally, i find the Python and C++ versions the easiest to understand. The LISP stuff just gave me a headache mostly. Thank god my editor has parentheses matching.

Thanks for your attempt :)

If i'm looking to learn more functional programming (at this point a weakness for me), is there a language that is simpler than clisp that actually has functionality? I tried scheme but found coding anything actually useful difficult.

EDIT: I'll try and work it under a different implementation of CLisp. Maybe clisp has a bug in floating-point representation that gcl doesn't.


I suggest checking out Clojure. If you do that, you could go as far as to use your Java code to help you write the program. Clojure is on the JVM so you should feel at home if you've worked with Java.
Was This Post Helpful? 0
  • +
  • -

#7 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Lisp Mandelbrot set distortion.

Posted 15 January 2010 - 01:42 PM

Thanks for the tip. I moved to SBCL to see if clisp was the problem. Just took a few let statements to shut the compiler up about undefined symbols. And five minutes later... the same problem. I'll look back at my code *again*. I'll def look into clojure once I get more spare time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1