Lisp programming and Emacs



2011/10/14 Stavros Macrakis <macrakis at alum.mit.edu>

> Could you provide a minimal example that reproduces the problem you/re
> having?  It sounds like you're doing fairly complicated things with dynamic
> function definitions etc.


My function, "rkf45", implements the Runge-Kutta-Fehleberg (4th-5th order)
algorithm for solving initial-value problems. I was thinking it would be
nice if it is added in maxima/share, as it supports automatic step size and
error control. As far I can tell, Maxima lacks a good ODE numerical
integrator at the moment (there is rk, but it is a simple fixed-size
Runge-Kutta implementation - definitely not appropriate for serious work.)
I have tested the Maxima code for rkf45 rather extensively, and it seems
capable of solving difficult problems pretty well, with minimal computation
effort (the algorithm increases the step size whenever this is safe.)
Results returned satisfy a prescribed accuracy criterion, given by the user.
Tests of the code included several complex initial value problems found in
the literature, and the results I get are highly accurate. I also wrote
extensive documentation with lots of examples (the pdf file documenting
rkf45 is more than 40 pages at the moment, and it's not finished yet.)

Dynamic function definition is used only once in the code. It can be
avoided, but that would make the call of rkf45 more complicated, not
"natural" for a computer algebra system, and different from that of rk. I
tried to make the code compatible with rk, so that users won't get confused.

Code execution depends on the problem being solved, of course, but in
general rkf45 needs a few seconds to solve an initial value problem (way
less than one second for simple problems.) However, I was thinking that
translating it to lisp would make it much faster.


> You should probably not declare list-valued variables at all.
>

Unfortunately, that's impossible. Actually, all dummy variables are (and
must be) lists. So the question is, how can I mode_declare a list? And, if
that's not possible, how can I get the same functionality?


>
>
>
            -s
>
> On Fri, Oct 14, 2011 at 13:21, Panagiotis Papasotiriou <
> p.j.papasot at gmail.com> wrote:
>
>> Stavro,
>> (I won't use my native language as you will understand but everybody else
>> will blame me)
>>
>> Sometime ago, I already tried to translate my Maxima functions, without
>> success. Following your suggestion, I decided to give it a second try. I
>> declared all variables using mode_declare, but translation fails. The
>> function I am trying to translate has the form
>>
>> rkf45(odes,funcs,interval):=block(
>>   [<local variables>],<mode declarations>,<body of the function>
>> )
>>
>> Now, "funcs" is a dummy variable, which is supposed to be a list.
>> Somewhere in the code, the following line causes an error:
>>
>> define(funmake(f_rhs,cons(interval[1],funcs)),odes),
>>
>> It says "cons: 2nd argument must be a non-atomic expression; found funcs".
>> I suppose translator doesn't know funcs is a non-atomic expression. I tried
>> to mode_declare funcs as a float, any, or even list (the latter is
>> undocumented though). I still get the same error when I try to translate the
>> code.
>> Note that in the original Maxima code, function f_rhs is declared as
>> local, but translator complains that "local" doesn't work well, so I removed
>> local(f_rhs).
>>
>>
>> 2011/10/14 Stavros Macrakis <macrakis at alum.mit.edu>
>>
>>> Panagioti,
>>>
>>> I certainly don't want to discourage you from learning Lisp, but I'm not
>>> sure that rewriting numerical Maxima code by hand in Lisp will teach you
>>> much.  Working on symbolic computations in Lisp may be more educational and
>>> productive.
>>>
>>> Have you tried using mode_declare, compile, and arrays (rather than
>>> Maxima lists and matrices) for your numerical code?  With proper
>>> declarations and use of arrays, compiled Maxima code should be almost as
>>> fast as hand-written Lisp numerical code or even scalar Fortran code.
>>>
>>>            -s
>>>
>>> On Fri, Oct 14, 2011 at 05:48, Panagiotis Papasotiriou <
>>> p.j.papasot at gmail.com> wrote:
>>>
>>>> Dear community, my question is only implicitly related to Maxima, but I
>>>> am sure someone could help:
>>>>
>>>> I wrote some Numerical Analysis functions in Maxima, and they perform
>>>> very well. However, I guess a Lisp implementation of those functions would
>>>> be faster (and I wonder how faster it will be.) So I decided to rewrite the
>>>> functions in Lisp (good opportunity to learn Lisp as well.) I am a big fan
>>>> of Emacs, which I use extensively for Maxima sessions, gnuplot sessions, and
>>>> as an IDE for Fortran 90 or C/C++ programming. As far I can tell, "Slime" is
>>>> the Emacs package for Lisp programming. I installed Slime and SBCL (directly
>>>> from Debian GNU/Linux repositories) but somehow those two are not connected,
>>>> so I cannot, for example, mark a region of a Lisp program and execute it in
>>>> SBCL with keystrokes like C-c C-b, as I do with Maxima programs. In fact,
>>>> the Lisp program edited in Emacs seems completely on its own, not connected
>>>> with SBCL in any way, although Slime is supposed to support SBCL. I tried
>>>> several solutions which I found on the Internet, suggesting adding things in
>>>> .emacs configuration file. However, none of those suggestions worked. So my
>>>> question is, which is the "best" Lisp implementation I should use for
>>>> Maxima-oriented Lisp programming, and how can I use it in Emacs?
>>>>
>>>> _______________________________________________
>>>> Maxima mailing list
>>>> Maxima at math.utexas.edu
>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> Maxima mailing list
>> Maxima at math.utexas.edu
>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>
>>
>