From: gregory c wilcox
Subject: Lisp vs. C++ for scientific applications
Date: 
Message-ID: <D7LFJp.J03@world.std.com>
My boss is a C programmer who writes heavy-duty scientific and
mathematical applications. He has heard lots of good things about
object-oriented programming, and he's about to take the plunge into
C++. Before he does, I'd like to give him a short code example of
something you can do with LISP that's harder (or impossible) in C++.

I showed him some code for doing indefinite double integration
(below). He was moderately impressed with it, but not enough to
convince him to switch to LISP. I need something a little more
impressive. Any suggestions?

Gregory C. Wilcox
Arthur D. Little, Inc.
Acorn Park
Room 20/350
Cambridge, MA 02140
RiskWorks home page: http://world.std.com/~wilcox
(617) 498-5476 (work)
(617) 484-7287 (home)


;;; indefinite double integration
 
(defun get-limit (fun vals)
  "Get a numerical function limit."
  (etypecase fun
    (number fun)
    (function (apply fun vals))
    ))
 
(defvar delta 1/512)
 
(defun integrate (fun vals dependent low-fun high-fun)
  "Do indefinite integration on a multi-valued function."
  (let ((sum 0)
        (dependent-on (nthcdr dependent vals))
        (low (get-limit low-fun vals))
        (high (get-limit high-fun vals)))
    (do ((i (+ low (/ delta 2)) (+ i delta)))
        ((>= i high))
      (rplaca dependent-on i)
      (incf sum (apply fun vals)))
    (* sum delta)
    ))
 
(defun double-integrate (fun xlow xhigh ylow yhigh)
  "Do an indefinite double integration."
  (flet ((fx (x y)
             (declare (ignore y))
             (integrate fun (list x 'y) 1 ylow yhigh)))
    (integrate #'fx (list 'x 'y) 0 xlow xhigh)
    ))
 
;;; test functions
 
(defun f (x y) (sin (+ (* 2 x) y)))
 
(defun yleft (x y) (declare (ignore y)) (- 1/2 (/ x 4)))
 
(defun yright (x y) (declare (ignore y)) (+ 1/2 (/ x 4)))
 
(defun test ()
  (double-integrate #'f 0 2 #'yleft #'yright))

-- 
Gregory C. Wilcox
Arthur D. Little, Inc.
Acorn Park
Room 20/350

From: Steve Perryman
Subject: Re: Lisp vs. C++ for scientific applications
Date: 
Message-ID: <3nkvuc$934@bcrkh13.bnr.ca>
In article <··········@world.std.com>,
gregory c wilcox <······@world.std.com> wrote:
>My boss is a C programmer who writes heavy-duty scientific and
>mathematical applications. He has heard lots of good things about
>object-oriented programming, and he's about to take the plunge into
>C++. Before he does, I'd like to give him a short code example of
>something you can do with LISP that's harder (or impossible) in C++.

That is dead easy, but I doubt if it's relevant to your goal.

>I showed him some code for doing indefinite double integration
>(below). He was moderately impressed with it, but not enough to
>convince him to switch to LISP. I need something a little more
>impressive. Any suggestions?

[...]

Is your boss from a Lisp background ??
If he is happy with that, but really wants to go OO then you could at least
recommend CLOS as opposed to vanilla Lisp. CLOS is as OO as C++ will ever be
(in fact better for things such as MOP work and multiple inheritance) , and at
least you'll still have your decent Lisp environment too.

But if he is deeply entrenched in C culture, and pure number-crunching is
required (matrix maths etc) , then IMHO you'd probably have to settle for C++
as Lisp would probably be too much of a paradigm shift for him.

Regards,
Steven Perryman
···@bnr.co.uk
From: Philip Greenspun
Subject: Re: Lisp vs. C++ for scientific applications
Date: 
Message-ID: <PHILG.95Apr30164452@camelot.ai.mit.edu>
In article <··········@world.std.com> ······@world.std.com (gregory c wilcox) writes:

   My boss is a C programmer who writes heavy-duty scientific and
   mathematical applications. He has heard lots of good things about
   object-oriented programming, and he's about to take the plunge into
   C++. Before he does, I'd like to give him a short code example of
   something you can do with LISP that's harder (or impossible) in C++.

   I showed him some code for doing indefinite double integration
   (below). He was moderately impressed with it, but not enough to
   convince him to switch to LISP. I need something a little more
   impressive. Any suggestions?

Gerry Sussman at MIT does a lot of very sophisticated numerical
computation in Scheme.  He has many coherent papers and arguments for
why it is the right thing to do (mostly having to do with higher-order
procedures and abstracting various numerical techniques to make them
available for many different kinds of computation instead of writing a
custom program for everything).  You might find some good stuff on
this near my home page...

http://www-swiss.ai.mit.edu/

--

      -- Philip Greenspun

-------------------------------------------------------------
MIT Department of Electrical Engineering and Computer Science
545 Technology Square, Rm 609, Cambridge, MA 02139, (617) 253-8574
Personal Web URL:  http://www-swiss.ai.mit.edu/philg/
From: Ken Anderson
Subject: Re: Lisp vs. C++ for scientific applications
Date: 
Message-ID: <KANDERSO.95May1121952@bitburg.bbn.com>
In article <···················@camelot.ai.mit.edu> ·····@zurich.ai.mit.edu (Philip Greenspun) writes:

   In article <··········@world.std.com> ······@world.std.com (gregory c wilcox) writes:

      My boss is a C programmer who writes heavy-duty scientific and
      mathematical applications. He has heard lots of good things about
      object-oriented programming, and he's about to take the plunge into
      C++. Before he does, I'd like to give him a short code example of
      something you can do with LISP that's harder (or impossible) in C++.

      I showed him some code for doing indefinite double integration
      (below). He was moderately impressed with it, but not enough to
      convince him to switch to LISP. I need something a little more
      impressive. Any suggestions?

   Gerry Sussman at MIT does a lot of very sophisticated numerical
   computation in Scheme.  He has many coherent papers and arguments for
   why it is the right thing to do (mostly having to do with higher-order
   procedures and abstracting various numerical techniques to make them
   available for many different kinds of computation instead of writing a
   custom program for everything).  You might find some good stuff on
   this near my home page...

   http://www-swiss.ai.mit.edu/

1.  A great paper is:

 Berlin and Weise, Compiling scientific code using partial evaluation, IEEE
 Computer, Jan 1980, p. 25-37.

They use a scheme partial evaluator that produces C code used by the scheme
application.  I have a draft article based on their ideas that implements a
simple partial evaluator in several pages of code.  You could do this in
C++, but with more work.

Making partial evaluation available as part of an object oriented
numberical libary is extremely powerful since it allows abstract
descriptions of an application, and provides an efficient implemenation.  

2. Xlisp-stat (http://www.stat.ucla.edu/) is a Lisp with statistical and
graphical exentions used widely by statisticians.  The real power of lisp
here is in a flexible exploratory environment.

k
--
Ken Anderson 
Internet: ·········@bbn.com
BBN ST               Work Phone: 617-873-3160
10 Moulton St.       Home Phone: 617-643-0157
Mail Stop 6/4a              FAX: 617-873-2794
Cambridge MA 02138
USA