On interacttion with C, Fortran, etc (wasRE: [Maxima] High precision)
Subject: On interacttion with C, Fortran, etc (wasRE: [Maxima] High precision)
From: sen1 at math.msu.edu
Date: Wed, 2 Aug 2006 20:49:27 -0400 (EDT)
Thanks for your thoughtful answers.
I use Win XP when necessary, but I prefer Linux for development and
research work.
I noticed that there is a version of Allegro CL for linux. Do you know
anything about it? In particular, what advantages does it have over
GCL?
Is there an open source version of lisp which will allow general calls
to other languages like C, C++, Fortran?
Thanks for any information.
-sen
On Wed, 2 Aug 2006, Richard Fateman wrote:
> I have been using GMP and MPFR, which are free packages for arbitrary
> precision arithmetic and other functions. Also intervals, complex numbers,
> rationals and integers. There is also a package ARPREC. These are all C C++
> or Fortran libraries, and they can all be called from Lisp, and therefore
> from Maxima. The experiments I've done have not yet involved Maxima. Almost
> all issues go away if you decide to stick to one architecture, one operating
> system, one lisp. The choice I've made for my own convenience is Intel(32),
> Windows XP, Allegro CL. There is a foreign-function interface that figures
> out how to build inter-language calls for you.
>
> But if you need to do everything in full generality (e.g. all
> architectures, all OS, all Lisps) then there are many problems. Not the
> least of which is each of these libraries has to be compiled in multiple
> different versions, e.g. different for Pentium 2,3,4 AMD64,..
>
> Some of these algorithms can be translated from C or Fortran into Lisp, and
> thereby resolving the multiple-level implementation issues. Some of the
> translation can be done automatically. Some cannot, at least without
> substantial loss in speed. (there are assembly language routines in GMP).
>
> As for "the best way to implement such things" -- is it known? Well, some
> things have been extensively studied, e.g. multiplication. But they are
> still being studied. Some things, like evaluation of Bessel functions near
> their zeros, are probably not well understood.
>
> So: to interface to C or Fortran, yes it is possible, maybe even easy,
> depending on which lisp you are using, and the demands of the C program you
> wish to call.
>
> RJF
>
>
>> -----Original Message-----
>> From: maxima-admin at math.utexas.edu [mailto:maxima-admin at math.utexas.edu]
>> On Behalf Of sen1 at math.msu.edu
>> Sent: Wednesday, August 02, 2006 1:31 PM
>> To: Richard Fateman
>> Cc: maxima at math.utexas.edu
>> Subject: On interacttion with C, Fortran, etc (wasRE: [Maxima] High
>> precision)
>>
>> Thanks for your answers.
>>
>> In the question of bfloat versions of numerical functions, I have some
>> related questions.
>>
>> 1. Is the mathematics for what may be the best way to implement such
>> things now well understood, or are there interesting mathematical
>> questions related to this?
>>
>> 2. There are obviously many problems which could benefit from tools
>> which permit all (or most) of the calculations being done in high
>> (perhaps varying) precision. There are tools for high
>> precision in fortran, python, maple, etc. I don't have experience
>> with these, so I don't know if they are useful for many things.
>>
>> Perhaps the best way to implement similar tools in maxima (as well
>> as many other things) is to bring in the ability to call in
>> subroutines from some of these other languages.
>>
>> I know that maxima can interface with lisp, but I don't know how
>> easy it is to make in interact with C, C++, fortran, etc.
>>
>> Are they any tools (or plans) for this?
>>
>> TIA,
>>
>> -Sheldon Newhouse
>>
>>
>>
>>
>>
>> On Tue, 1 Aug 2006, Richard Fateman wrote:
>>
>>> Numbers which are introduced as ordinary machine floats like 1.0 are
>> forever
>>> machine floats unless you explicitly convert them. If they are
>> introduced
>>> as bigfloats, say as 1.0b0, then they will be bigfloats. The next time
>> they
>>> are operated on, the result of the calculation will have precision
>> fpprec.
>>>
>>> Oh, integers are left alone as integers, similarly for rationals.
>>> What you can sometimes do is,
>>>
>>> Myprogram(a,b,c):= (a:bfloat(a), b:bfloat(b), c:bfloat(c), .....);
>>>
>>> This is will convert a,b,c to bigfloats of the current fpprec. If they
>> are
>>> already bigfloats, the cost is negligible.
>>>
>>> Oh, maybe your issue is this... if you type this: bfloat(0.1);
>>> Then the error in 0.1 as a single float will still be there, since that
>> is
>>> the value you put in to the program. Converting it to bigfloat afterward
>>> means that the conversion from 1/10 to a binary number has been done to
>>> machine precision, and in binary. Thus inexactly. Compare to
>> bfloat(1/10)
>>> or 0.1b0 which may have the accuracy you expect. Not all functions have
>>> bfloat versions so they have to convert to something they know, like
>> double
>>> precision, and then do the calculation.
>>> Feel free to contribute bfloat versions of numerical functions :)
>>>
>>> RJF
>>>
>>>
>>>
>>>> -----Original Message-----
>>>> From: maxima-admin at math.utexas.edu [mailto:maxima-
>> admin at math.utexas.edu]
>>>> On Behalf Of sen1 at math.msu.edu
>>>> Sent: Tuesday, August 01, 2006 7:49 AM
>>>> To: maxima at math.utexas.edu
>>>> Subject: High precision
>>>>
>>>> Hello,
>>>> I would like to run certain entire maxima sessions in high precision
>>>> arithmetic.
>>>>
>>>> I have tried setting fpprec: 32.
>>>>
>>>> The numbers get listed as having that precision. But, it seems that
>>>> floating point errors I expect from functions with standard double
>>>> precision are still there. Does every single variable in an
>>>> expression have to be converted?
>>>>
>>>> Is it expected that, once one sets fpprec: 32, all further
>>>> computations, even with previously defined functions, will be at that
>>>> precision?
>>>>
>>>> Thanks for any info.
>>>>
>>>> -sen
>>>>
>>>> --
>>>> ---------------------------------------------------------------------
>> ---
>>>> ---
>>>> | Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu
>>>> |
>>>> | Mathematics Department |
> |
>>>> | Michigan State University | telephone: 517-355-9684
>>>> |
>>>> | E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562
>>>> |
>>>> ---------------------------------------------------------------------
>> ---
>>>> ---
>>>>
>>>> _______________________________________________
>>>> Maxima mailing list
>>>> Maxima at math.utexas.edu
>>>> http://www.math.utexas.edu/mailman/listinfo/maxima
>>>
>>
>> --
>> ------------------------------------------------------------------------
>> ---
>> | Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu
>> |
>> | Mathematics Department | |
>> | Michigan State University | telephone: 517-355-9684
>> |
>> | E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562
>> |
>> ------------------------------------------------------------------------
>> ---
>>
>> _______________________________________________
>> 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
>
--
---------------------------------------------------------------------------
| Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu |
| Mathematics Department | |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------