[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Nils Bruin
On Nov 24, 10:53 pm, Dima Pasechnik dimp...@gmail.com wrote:
 It's a good question how to make this capability used in Sage.

This capability is already perfectly usable in Sage:

sage: M=sage.calculus.calculus.maxima
sage: M.eval(g(x):=block([s:0],for i thru x do s:s+i^2,s);)
'g(x):=block([s:0],forithruxdos:s+i^2,s)'
sage: g=M(g)
sage: %time g(1);
CPU times: user 0.25 s, sys: 0.00 s, total: 0.25 s
Wall time: 0.26 s
sage: M.eval(compile(g);)
'[g]'
sage: %time g(1)
CPU times: user 0.05 s, sys: 0.00 s, total: 0.05 s
Wall time: 0.05 s
83335000

This runs maxima as a lisp-library inside ecl, with ecl running as a
dynamically linked library inside sage. I'm sure there are already CL
ffi bindings for the Python C-API so that you would also be able to
call back into python [is re-entrancy an issue for python?] from lisp
if you want to.

You can strip away the maxima layer if you so desire:

sage: g_lisp=g.ecl()
sage: %time g_lisp(1)
CPU times: user 0.02 s, sys: 0.00 s, total: 0.02 s
Wall time: 0.02 s
ECL: 83335000
sage: g_lisp
ECL: $G

[the variation in the timing here is use, so don't trust these times!]

On the ECL level, most conversions are done relatively efficiently,
via binary translations (of course, because Python and ECL have their
own ideas about memory management, there is no sharing -- objects are
copied over between the two worlds. This is the usual price for using
libraries that are not particularly made to cooperate with each other.
GMP bigints are still done stupidly because I couldn't figure out how
to copy over the internally identical bitstrings [both sage and ECL
use the same GMP/MPIR library].

The maxima interface is still largely based on string communication
(and the eval statements necessarily so!) because that code was
inherited from the original pexpect interface, but there is already
infrastructure to translate more efficiently. It's just a matter of
using it more widely.

So yes, if you have a piece of code that is most conveniently written
in maxima or lisp, go ahead and compile it! Most data structures will
be translated automatically between Python and ECL.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Robert Bradshaw
On Wed, Nov 23, 2011 at 2:16 PM, rjf fate...@gmail.com wrote:

 Maxima compiles code to binary, and has done so, oh for a couple of
 decades.

  Since Maxima is part of Sage, one might hope that William would be
 aware of this feature.

In the spirit of being mutually informative, here's how it's done in Sage

  Example.

 g(x):=block([s:0],for i thru x do s:s+i^2,s);

%python
def g(x):
s = 0
for i in range(x):
s += i**2
return s

 g(1);  takes 0.15 seconds.

sage: timeit(g(1))
625 loops, best of 3: 1.45 ms per loop

 compile(g);   converts g to lisp and compiles it with an optimizing
 compiler.

%cython
def g(x):
s = 0
for i in range(x):
s += i**2
return s

 g is now about 5X faster.

sage: timeit(g(1))
625 loops, best of 3: 833 µs per loop

g is now about 2X faster (though unless your computer is *way* slower
than mine, there was less room for improvement here).

 if one inserts declarations, e.g.  mode_declare(i,fixnum, x, fixnum,
 s, fixnum),
 the code goes about 10X faster.   I think that one can improve the
 speed

%cython
def g_fast(x):
cdef long i, s = 0
for i in range(x):
s += i**2
return s

sage: timeit(g(1))
625 loops, best of 3: 10.9 µs per loop

Well over a 100-fold increase in speed.

Still, if one is dealing with the few parts of Sage that use Maxima,
it could be useful to know about this compile command.

Note that another selling point of Cython is not just writing new
(fast) code, but interfacing with existing low-level libraries in a
clean way.

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Volker Braun
On Friday, November 25, 2011 10:33:24 AM UTC, Robert Bradshaw wrote:

 Note that another selling point of Cython is not just writing new
 (fast) code, but interfacing with existing low-level libraries in a
 clean way.

 
I think thats the actual advantage of Cython. Every interpreter can dload a 
library somehow. But try to mix a shared library, some custom C++ code, and 
the interpreter of your choice. In any commercial Ma* or Java JNI you'll 
invariably end up writing lots of C stubs that you can then plumb to your 
interpreter. In Cython it can be done much cleaner.

Maxima is at least potentially in a better situation since they (similar to 
Sage) don't provide an external code interface. You get whatever the 
underlying common lisp has, which almost certainly got more attention than 
an interpreter that is specific to mathematical research. CFFI seems to be 
the emerging standard here, but ECL only just got CFFI support and don't 
even think about C++ yet.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread rjf

re: writing stubs to access C (etc) libraries from Lisp.

There are several lisp programs which will take your *.h files and
attempt to
automatically write all the stubs.  This cannot be entirely automated
but
my limited experience with this suggests it can be quite successful.
I've linked to libraries (GMP, I think) that were in some python
format, years ago.

My own timings are on a different lisp, different compiler
optimizations,
different computer.  The range of speed-ups in compiling Maxima could
conceivably from 0 (i.e. not faster at all... maybe even slower...) to
huge - 1000X .

Based on absolutely no statistical evidence, my guess is that the vast
majority of
users of Sage use it as a front end to Maxima, or things which could
easily be done
in Maxima but might also be done in the Pythonish Sage front end
language/ system itself.

I further guess there is not really a competition between Sage and the
commercial Ma*.
 Rather, competition for mind-space between (A) users who simply
download Maxima from
sourceforge and use it, possibly contributing to it,
 and (B) users who download Sage, are told how great python is, and
then end up using Sage as a front-end to Maxima, but through an
apparently poor pexpect
interface. I think it is less likely that such  B) users will
understand or make use
of the tools that might be available in Maxima, and much less likely
that these users will
contribute to the tools in Maxima, which can most easily be
accomplished by writing in the Maxima language
or in Common Lisp.  Not Python.

It would be simple for William to say, occasionally, that Maxima is
written in Common Lisp and it is possible to incrementally improve the
Maxima component efficiently by writing in Lisp.  People do it all the
time.

Instead we see the occasional proposal which looks like Let's
encourage some high school student to rewrite the X facility of Maxima
in Python this summer.  It's bound to be much faster and better,
especially since we can compile parts of it via Cython. And since
Python is so easy to learn.

The idea that what is difficult about (say) the symbolic definite
integration program in Maxima is that it was written in Lisp rather
than Python is, to me, a symptom of very shallow analysis of the
situation.

But we have wandered off the track of the subject line.

RJF




-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Alfredo Portes
On Fri, Nov 25, 2011 at 7:29 AM, Volker Braun vbraun.n...@gmail.com wrote:

 I think thats the actual advantage of Cython. Every interpreter can dload a
 library somehow. But try to mix a shared library, some custom C++ code, and
 the interpreter of your choice. In any commercial Ma* or Java JNI you'll
 invariably end up writing lots of C stubs that you can then plumb to your
 interpreter. In Cython it can be done much cleaner.

https://github.com/twall/jna

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Tom Boothby
On Thu, Nov 24, 2011 at 9:25 PM, rjf fate...@gmail.com wrote:

 William seems to prefer to tout the Sage-Cython link.

That's because we use Cython, and it's easy to use in Sage, and
provides a fully-functional language-native interface between Cython
and Sage.  Not a single part of that is true about the Maxima
compiler.

It'd be dishonest to go on at length about how awesome and fast and
useful this Maxima feature is, if we didn't use it and didn't have its
functionality well-exposed in Sage.  We're not all Maxima experts
(whoda thinkit?), so why don't you show us how to do it, or better
yet, improve the Sage-Maxima interface so that we can use it?

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread William Stein
Sage-devel was so nice for the last few months with out Richard Fateman
FUD...
On Nov 25, 2011 8:13 AM, rjf fate...@gmail.com wrote:


 re: writing stubs to access C (etc) libraries from Lisp.

 There are several lisp programs which will take your *.h files and
 attempt to
 automatically write all the stubs.  This cannot be entirely automated
 but
 my limited experience with this suggests it can be quite successful.
 I've linked to libraries (GMP, I think) that were in some python
 format, years ago.

 My own timings are on a different lisp, different compiler
 optimizations,
 different computer.  The range of speed-ups in compiling Maxima could
 conceivably from 0 (i.e. not faster at all... maybe even slower...) to
 huge - 1000X .

 Based on absolutely no statistical evidence, my guess is that the vast
 majority of
 users of Sage use it as a front end to Maxima, or things which could
 easily be done
 in Maxima but might also be done in the Pythonish Sage front end
 language/ system itself.

 I further guess there is not really a competition between Sage and the
 commercial Ma*.
  Rather, competition for mind-space between (A) users who simply
 download Maxima from
 sourceforge and use it, possibly contributing to it,
  and (B) users who download Sage, are told how great python is, and
 then end up using Sage as a front-end to Maxima, but through an
 apparently poor pexpect
 interface. I think it is less likely that such  B) users will
 understand or make use
 of the tools that might be available in Maxima, and much less likely
 that these users will
 contribute to the tools in Maxima, which can most easily be
 accomplished by writing in the Maxima language
 or in Common Lisp.  Not Python.

 It would be simple for William to say, occasionally, that Maxima is
 written in Common Lisp and it is possible to incrementally improve the
 Maxima component efficiently by writing in Lisp.  People do it all the
 time.

 Instead we see the occasional proposal which looks like Let's
 encourage some high school student to rewrite the X facility of Maxima
 in Python this summer.  It's bound to be much faster and better,
 especially since we can compile parts of it via Cython. And since
 Python is so easy to learn.

 The idea that what is difficult about (say) the symbolic definite
 integration program in Maxima is that it was written in Lisp rather
 than Python is, to me, a symptom of very shallow analysis of the
 situation.

 But we have wandered off the track of the subject line.

 RJF




 --
 To post to this group, send an email to sage-devel@googlegroups.com
 To unsubscribe from this group, send an email to
 sage-devel+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/sage-devel
 URL: http://www.sagemath.org


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Volker Braun
Thanks for your well-thought out contribution. I'm sure you are aware that 
JNA, although it sucks slightly less than JNI, doesn't support C++. So its 
back to writing C stubs to use instances from one object-oriented language 
in another object-oriented language. WTF!

On Friday, November 25, 2011 4:17:21 PM UTC, doyen...@gmail.com wrote:

 https://github.com/twall/jna



-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Alfredo Portes
I was not trying to make any claims. My link was only for those that
are not aware of
JNA and usually make the claim that JNI is the only way.

But I appreciate your message as it reminds me of how welcoming this list is.
No WTFs needed, ignore me, and like Ted Kosan I am out of here.

On Fri, Nov 25, 2011 at 12:12 PM, Volker Braun vbraun.n...@gmail.com wrote:
 Thanks for your well-thought out contribution. I'm sure you are aware that
 JNA, although it sucks slightly less than JNI, doesn't support C++. So its
 back to writing C stubs to use instances from one object-oriented language
 in another object-oriented language. WTF!

 On Friday, November 25, 2011 4:17:21 PM UTC, doyen...@gmail.com wrote:

 https://github.com/twall/jna

 --
 To post to this group, send an email to sage-devel@googlegroups.com
 To unsubscribe from this group, send an email to
 sage-devel+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/sage-devel
 URL: http://www.sagemath.org


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread rjf
We could always continue this discussion on sage-flame.

I think that persons who wish to use this functionality in Maxima
could
consider that maybe they should just use Maxima.

 Exposing this functionality better from the Sage top
level may be possible, but not something that I am interested in
doing.

I think the examples are pretty evident.

You can take any Maxima program   f
and compile it by issuing the command  compile(f).

If you wish to impose assumptions on the types of variables, you can
read about mode_declare. This is optional.

Perhaps I should point out that I am not opposed to linking together
software written originally for different purposes, maybe in different
languages.
Maxima uses quadpack, linpack, gplot, ...  Some of the earliest
projects for VAX Macsyma (circa 1979) at Berkeley were to use
Macsyma as a front end to MINPACK, and also allow it to exchange
 data and send commands to MATLAB.
(In 1979 Matlab was (a) free. (b) written in Fortran).

I have personally
written, or supervised students writing, code linking Lisp/Maxima with
Excel, .NET, GMP, MPFR, net servers etc. Even within Macsyma/Maxima
there
is a proliferation of special packages for achieving higher levels of
efficiency for subclasses (e.g. polynomials over the integers, Taylor
series,
Poisson series).


I am also not opposed to free software. (Though I do not whole-
heartedly
endorse GPL as a way to achieve that).

I am also not opposed to people learning Python.

To the extent that Sage does symbolic mathematical computation in
the tradition
of (say) the ACM SIGSAM special interest group,
it should be possible to be more accurate and complete in portraying
what it
does and how it does it.

Maybe I'm old-fashioned.
I find statements like Mathematica is the world's ultimate
application for computations...
http://www.wolfram.com/products/ to be excusable only because it is
written by a marketeer.


Claims for Sage are more modest, but not so much. I am leery of using
the word ideal [except in
abstract algebra] to describe a program I wrote, but as I said, maybe
I'm old-fashioned.

Many aspects of Sage make it an ideal tool for teaching mathematics,

For many mathematicians and students, Sage is today the mature,
open source, and free foundation on which they can build their
research
program.

both quotes from focm11.pdf

RJF


RJF





On Nov 25, 8:27 am, William Stein wst...@gmail.com wrote:
 Sage-devel was so nice for the last few months with out Richard Fateman
 FUD...
 On Nov 25, 2011 8:13 AM, rjf fate...@gmail.com wrote:









  re: writing stubs to access C (etc) libraries from Lisp.

  There are several lisp programs which will take your *.h files and
  attempt to
  automatically write all the stubs.  This cannot be entirely automated
  but
  my limited experience with this suggests it can be quite successful.
  I've linked to libraries (GMP, I think) that were in some python
  format, years ago.

  My own timings are on a different lisp, different compiler
  optimizations,
  different computer.  The range of speed-ups in compiling Maxima could
  conceivably from 0 (i.e. not faster at all... maybe even slower...) to
  huge - 1000X .

  Based on absolutely no statistical evidence, my guess is that the vast
  majority of
  users of Sage use it as a front end to Maxima, or things which could
  easily be done
  in Maxima but might also be done in the Pythonish Sage front end
  language/ system itself.

  I further guess there is not really a competition between Sage and the
  commercial Ma*.
   Rather, competition for mind-space between (A) users who simply
  download Maxima from
  sourceforge and use it, possibly contributing to it,
   and (B) users who download Sage, are told how great python is, and
  then end up using Sage as a front-end to Maxima, but through an
  apparently poor pexpect
  interface. I think it is less likely that such  B) users will
  understand or make use
  of the tools that might be available in Maxima, and much less likely
  that these users will
  contribute to the tools in Maxima, which can most easily be
  accomplished by writing in the Maxima language
  or in Common Lisp.  Not Python.

  It would be simple for William to say, occasionally, that Maxima is
  written in Common Lisp and it is possible to incrementally improve the
  Maxima component efficiently by writing in Lisp.  People do it all the
  time.

  Instead we see the occasional proposal which looks like Let's
  encourage some high school student to rewrite the X facility of Maxima
  in Python this summer.  It's bound to be much faster and better,
  especially since we can compile parts of it via Cython. And since
  Python is so easy to learn.

  The idea that what is difficult about (say) the symbolic definite
  integration program in Maxima is that it was written in Lisp rather
  than Python is, to me, a symptom of very shallow analysis of the
  situation.

  But we have wandered off the track of the subject line.

  RJF

 

Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread William Stein
On Nov 25, 2011 9:30 AM, Alfredo Portes doyenatc...@gmail.com wrote:

 I was not trying to make any claims. My link was only for those that
 are not aware of
 JNA and usually make the claim that JNI is the only way.

 But I appreciate your message as it reminds me of how welcoming this list
is.
 No WTFs needed, ignore me, and like Ted Kosan I am out of here.

Please do not leave!   I am mostly unhappy about how this thread has
gone... it is not friendly or helpful (except Nils post).  I would rather
ask people being mean (or spreading FUD) to please apologize and make this
list welcoming.

William

 On Fri, Nov 25, 2011 at 12:12 PM, Volker Braun vbraun.n...@gmail.com
wrote:
  Thanks for your well-thought out contribution. I'm sure you are aware
that
  JNA, although it sucks slightly less than JNI, doesn't support C++. So
its
  back to writing C stubs to use instances from one object-oriented
language
  in another object-oriented language. WTF!
 
  On Friday, November 25, 2011 4:17:21 PM UTC, doyen...@gmail.com wrote:
 
  https://github.com/twall/jna
 
  --
  To post to this group, send an email to sage-devel@googlegroups.com
  To unsubscribe from this group, send an email to
  sage-devel+unsubscr...@googlegroups.com
  For more options, visit this group at
  http://groups.google.com/group/sage-devel
  URL: http://www.sagemath.org
 

 --
 To post to this group, send an email to sage-devel@googlegroups.com
 To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
 For more options, visit this group at
http://groups.google.com/group/sage-devel
 URL: http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread William Stein
On Nov 25, 2011 10:18 AM, rjf fate...@gmail.com wrote:

 We could always continue this discussion on sage-flame.

Please do.   This thread should be about Mathematica and the extent to
which their claim to have a compiler for arbitrary Mathematica programs is
actually true.

William

 I think that persons who wish to use this functionality in Maxima
 could
 consider that maybe they should just use Maxima.

  Exposing this functionality better from the Sage top
 level may be possible, but not something that I am interested in
 doing.

 I think the examples are pretty evident.

 You can take any Maxima program   f
 and compile it by issuing the command  compile(f).

 If you wish to impose assumptions on the types of variables, you can
 read about mode_declare. This is optional.

 Perhaps I should point out that I am not opposed to linking together
 software written originally for different purposes, maybe in different
 languages.
 Maxima uses quadpack, linpack, gplot, ...  Some of the earliest
 projects for VAX Macsyma (circa 1979) at Berkeley were to use
 Macsyma as a front end to MINPACK, and also allow it to exchange
  data and send commands to MATLAB.
 (In 1979 Matlab was (a) free. (b) written in Fortran).

 I have personally
 written, or supervised students writing, code linking Lisp/Maxima with
 Excel, .NET, GMP, MPFR, net servers etc. Even within Macsyma/Maxima
 there
 is a proliferation of special packages for achieving higher levels of
 efficiency for subclasses (e.g. polynomials over the integers, Taylor
 series,
 Poisson series).


 I am also not opposed to free software. (Though I do not whole-
 heartedly
 endorse GPL as a way to achieve that).

 I am also not opposed to people learning Python.

 To the extent that Sage does symbolic mathematical computation in
 the tradition
 of (say) the ACM SIGSAM special interest group,
 it should be possible to be more accurate and complete in portraying
 what it
 does and how it does it.

 Maybe I'm old-fashioned.
 I find statements like Mathematica is the world's ultimate
 application for computations...
 http://www.wolfram.com/products/ to be excusable only because it is
 written by a marketeer.


 Claims for Sage are more modest, but not so much. I am leery of using
 the word ideal [except in
 abstract algebra] to describe a program I wrote, but as I said, maybe
 I'm old-fashioned.

 Many aspects of Sage make it an ideal tool for teaching mathematics,

 For many mathematicians and students, Sage is today the mature,
 open source, and free foundation on which they can build their
 research
 program.

Sage is AWESOME


 both quotes from focm11.pdf

 RJF


 RJF





 On Nov 25, 8:27 am, William Stein wst...@gmail.com wrote:
  Sage-devel was so nice for the last few months with out Richard Fateman
  FUD...
  On Nov 25, 2011 8:13 AM, rjf fate...@gmail.com wrote:
 
 
 
 
 
 
 
 
 
   re: writing stubs to access C (etc) libraries from Lisp.
 
   There are several lisp programs which will take your *.h files and
   attempt to
   automatically write all the stubs.  This cannot be entirely automated
   but
   my limited experience with this suggests it can be quite successful.
   I've linked to libraries (GMP, I think) that were in some python
   format, years ago.
 
   My own timings are on a different lisp, different compiler
   optimizations,
   different computer.  The range of speed-ups in compiling Maxima could
   conceivably from 0 (i.e. not faster at all... maybe even slower...) to
   huge - 1000X .
 
   Based on absolutely no statistical evidence, my guess is that the vast
   majority of
   users of Sage use it as a front end to Maxima, or things which could
   easily be done
   in Maxima but might also be done in the Pythonish Sage front end
   language/ system itself.
 
   I further guess there is not really a competition between Sage and the
   commercial Ma*.
Rather, competition for mind-space between (A) users who simply
   download Maxima from
   sourceforge and use it, possibly contributing to it,
and (B) users who download Sage, are told how great python is, and
   then end up using Sage as a front-end to Maxima, but through an
   apparently poor pexpect
   interface. I think it is less likely that such  B) users will
   understand or make use
   of the tools that might be available in Maxima, and much less likely
   that these users will
   contribute to the tools in Maxima, which can most easily be
   accomplished by writing in the Maxima language
   or in Common Lisp.  Not Python.
 
   It would be simple for William to say, occasionally, that Maxima is
   written in Common Lisp and it is possible to incrementally improve the
   Maxima component efficiently by writing in Lisp.  People do it all the
   time.
 
   Instead we see the occasional proposal which looks like Let's
   encourage some high school student to rewrite the X facility of Maxima
   in Python this summer.  It's bound to be much faster and better,
   especially since 

[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread rjf


On Nov 25, 10:28 am, William Stein wst...@gmail.com wrote:
 On Nov 25, 2011 10:18 AM, rjf fate...@gmail.com wrote:



  We could always continue this discussion on sage-flame.

 Please do.   This thread should be about Mathematica and the extent to
 which their claim to have a compiler for arbitrary Mathematica programs is
 actually true.

 William


Surprisingly, that does seem to be an issue.  As I read the document
that Andrew Moylan
pointed to, it seems to me that what is being offered is this:

You can take a Mathematica program P1,  and produce a C language
version of it P2, and
run that version P2.  Yet it does not seem to actually run P2 through
a C compiler.  I suspect
that there is simply another byte-code interpreter for the C language
that runs that P2.

  After all, Mathematica
does not demand that you have any C compiler in your local computer
system.

I very much doubt that Andrew is responsible for this part of
Mathematica; perhaps
he can clarify, or find someone else there to do so.


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Volker Braun
Poking around a bit on the wolfram web page, it seems that
  * Compiling C code requires a 3rd party compiler, otherwise it will fall 
back to mathematica byte-code
  * Mathematica will run the compiler for you, you only have to point 
Mathematica to the desired compiler.
  * this is new in Mathematica 8

See http://reference.wolfram.com/mathematica/ref/CompilationTarget.html

On Friday, November 25, 2011 7:02:38 PM UTC, rjf wrote:

 You can take a Mathematica program P1,  and produce a C language version 
 of it P2, and run that version P2.  Yet it does not seem to actually run P2 
 through a C compiler



-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread Volker Braun
On Friday, November 25, 2011 5:30:40 PM UTC, doyen...@gmail.com wrote:

 I was not trying to make any claims. My link was only for those that
 are not aware of
 JNA and usually make the claim that JNI is the only way.


I'm sorry if I offended you.

If you would have posted the above explanation instead of just a bare naked 
link then I would have found it a much more useful contribution to this 
thread.



-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-25 Thread rjf


On Nov 25, 11:30 am, Volker Braun vbraun.n...@gmail.com wrote:
 Poking around a bit on the wolfram web page, it seems that
   * Compiling C code requires a 3rd party compiler, otherwise it will fall
 back to mathematica byte-code
   * Mathematica will run the compiler for you, you only have to point
 Mathematica to the desired compiler.
   * this is new in Mathematica 8

 Seehttp://reference.wolfram.com/mathematica/ref/CompilationTarget.html



Ah yes, more specifically,
http://reference.wolfram.com/mathematica/CCompilerDriver/tutorial/SpecificCompilers.html




-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread Simon King
On 23 Nov., 23:16, rjf fate...@gmail.com wrote:
 Maxima compiles code to binary, and has done so, oh for a couple of
 decades.

Is Maxima considered to be in the class Ma*? I thought the
definition of Ma* is: Name starts with Ma and code is closed
source?

Cheers,
Simon

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread William Stein
On Nov 24, 2011 4:56 AM, Simon King simon.k...@uni-jena.de wrote:

 On 23 Nov., 23:16, rjf fate...@gmail.com wrote:
  Maxima compiles code to binary, and has done so, oh for a couple of
  decades.

 Is Maxima considered to be in the class Ma*? I thought the
 definition of Ma* is: Name starts with Ma and code is closed
 source?

I explicitly define Ma in that article as Simon states, so Maxima is not
included.


 Cheers,
 Simon

 --
 To post to this group, send an email to sage-devel@googlegroups.com
 To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
 For more options, visit this group at
http://groups.google.com/group/sage-devel
 URL: http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread rjf
I was not claiming that Maxima was part of William's Ma*
classification
(Though perhaps Macsyma would be -- if it were marketed).

My objection is that William neglects (or is ignorant of?) features
that are
in Maxima, and especially those that are superior to features he seems
to want to market,
for whatever reasons.

In fact, Maxima's compilation feature is capable of producing binary
code that

(a) mirrors entirely the WHOLE interpreted language, except is usually
somewhat faster   OR

(b) in the face of appropriate declarations of subtypes, most
typically useful for floating point,
 can generate code that is appropriately restricted and usually much
faster.

In either case Maxima automatically loads that code for immediate
execution in the same
context as interpreted code.

Is it faster/better/simpler-to-use than Python/Cython?  I am not
sufficiently informed on the Cython side.

I also thought we went through some discussion about Cython being a
compiler for Python.
I was told that it was not.

The focm11 paper seems to be missing a letter. What is a  ython-to-C/C+
+ compiler??

I have never used Cython, and have used Python very little.  My
understanding is that
the point of Cython is that it is a different language that resembles
Python + declarations.

So a more accurate statement regarding Sage would be that someone can
write a program in Cython,
a language different from the usual Sage Python.  This program can be
compiled and linked in to
Sage.

 I figure that most of the Ma*s allow you to write a program in some
other language like C and possibly Cython [since Cython produces C?]
and link it in to their system.
For Matlab, I found this
http://www.mathworks.com/help/techdoc/matlab_external/f29502.html

and apparently for Maple,
http://www.mapleprimes.com/posts/38019-Calling-Out-To-C-From-Maple

and Mathematica responded already.

These calls to external binary programs look kind of messy. It's much
nicer in
Maxima, or in the Common Lisp that is included in Maxima.

I am unmotivated to look at Magma.

There is of course the reality that some of these systems spend very
little time in their interpreters:
Ma* user programs are often the rather trivial stringing together of
calls to hugely heavy-weight binary subroutines operating on matrices
or large symbolic objects.

RJF








On Nov 24, 8:14 am, William Stein wst...@gmail.com wrote:
 On Nov 24, 2011 4:56 AM, Simon King simon.k...@uni-jena.de wrote:



  On 23 Nov., 23:16, rjf fate...@gmail.com wrote:
   Maxima compiles code to binary, and has done so, oh for a couple of
   decades.

  Is Maxima considered to be in the class Ma*? I thought the
  definition of Ma* is: Name starts with Ma and code is closed
  source?

 I explicitly define Ma in that article as Simon states, so Maxima is not
 included.



  Cheers,
  Simon

  --
  To post to this group, send an email to sage-devel@googlegroups.com
  To unsubscribe from this group, send an email to

 sage-devel+unsubscr...@googlegroups.com For more options, visit this group at

 http://groups.google.com/group/sage-devel







  URL:http://www.sagemath.org

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread Dima Pasechnik
Unless I am missing something, Maxima in Sage is compiled into C using ECL. 
How fully these capabilities are exploited in Sage, is another question.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread rjf


On Nov 24, 6:52 pm, Dima Pasechnik dimp...@gmail.com wrote:
 Unless I am missing something, Maxima in Sage is compiled into C using ECL.
 How fully these capabilities are exploited in Sage, is another question.

I think you are missing the point.  Unless the ECL system is sadly
broken, the
Maxima system has the capability of compiling programs written in its
top-level
language (an Algol-ish style language), into binary
code.

William seems to prefer to tout the Sage-Cython link.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-24 Thread Dima Pasechnik


On Friday, 25 November 2011 13:25:43 UTC+8, rjf wrote:

 On Nov 24, 6:52 pm, Dima Pasechnik dim...@gmail.com wrote:
  Unless I am missing something, Maxima in Sage is compiled into C using 
 ECL.
  How fully these capabilities are exploited in Sage, is another question.

 I think you are missing the point.  Unless the ECL system is sadly
 broken, the
 Maxima system has the capability of compiling programs written in its
 top-level
 language (an Algol-ish style language), into binary
 code.

 good to know. 
Actually, your example works just fine in Sage's maxima console:
sage: maxima_console()
;;; Loading #P/usr/local/src/sage/current/local/lib/ecl/sb-bsd-sockets.fas
;;; Loading #P/usr/local/src/sage/current/local/lib/ecl/sockets.fas
;;; Loading #P/usr/local/src/sage/current/local/lib/ecl/defsystem.fas
;;; Loading #P/usr/local/src/sage/current/local/lib/ecl/cmp.fas
Maxima 5.23.2 http://maxima.sourceforge.net
using Lisp ECL 11.1.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) g(x):=block([s:0],for i thru x do s:s+i^2,s);
 2
(%o1)g(x) := block([s : 0], for i thru x do s : i  + s, s)
(%i2) g(1);
(%o2)83335000
(%i3) compile(g);

;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; End of Pass 1.
;;; Note:
;;;   Refusing to propagate #form PSETQ 102aa68d0
;;; Note:
;;;   Constant value optimized away or not used
;;; $done
;;; Note:
;;;   Invoking external command:
;;;   gcc -I. -I/usr/local/src/sage/sage-4.7.alpha5/local/include/ 
-I/usr/local/src/sage/sage-4.7.alpha5/local/include -g -O2 -fPIC 
-fno-common -Ddarwin -O2 -w -c 
/private/var/folders/qW/qWY+4Ku1GF0WXrOsV+IDvk+++TM/-Tmp-/ecl001jfJYt0.c -o 
/private/var/folders/qW/qWY+4Ku1GF0WXrOsV+IDvk+++TM/-Tmp-/ecl001jfJYt0.o 
;;; Note:
;;;   Invoking external command:
;;;   gcc -o 
/private/var/folders/qW/qWY+4Ku1GF0WXrOsV+IDvk+++TM/-Tmp-/ecl001jfJYt0.fas 
-L/usr/local/src/sage/sage-4.7.alpha5/local/lib/ 
/private/var/folders/qW/qWY+4Ku1GF0WXrOsV+IDvk+++TM/-Tmp-/ecl001jfJYt0.o 
-bundle -L/usr/local/src/sage/sage-4.7.alpha5/local/lib 
-L/usr/local/src/sage/sage-4.7.alpha5/local/lib -lecl -lgmp -lm (%o3)   
  [g]
(%i4) g(1);
(%o4)83335000
(%i5) 

It's a good question how to make this capability used in Sage.
 

 William seems to prefer to tout the Sage-Cython link.



-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-23 Thread Jason Grout

On 11/23/11 9:36 AM, William Stein wrote:



-- Forwarded message --
From: Andrew Moylan
Date: Wednesday, November 23, 2011
Subject: C compiler in Mathematica
To: wst...@gmail.com mailto:wst...@gmail.com


Hello Prof Stein,

In your FoCM 11 article at
http://modular.math.washington.edu/papers/focm11/focm11.pdf you
mentioned None of the Ma's has an optimizing compiler that converts
programs written in their custom interpreted language to a- fast
executable binary format that is not interpreted at runtime. However
Mathematica 8's compiler does have this capability: Compile with the
setting CompilationTarget - C compiles and links to a native machine
code dynamic library
(http://reference.wolfram.com/mathematica/ref/CompilationTarget.html).




Neat!  I just tried it out in MMA 8 and the fractal example from the 
documentation above seems to work pretty well.



You might forward back to them that there is a grammar typo in the last 
sentence on that page.  Note that this is an image to interact with the 
picture you need to evaluate the commands: should have a semicolon or 
period somewhere in there.


Thanks,

Jason

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


[sage-devel] Re: Fwd: C compiler in Mathematica

2011-11-23 Thread rjf

Maxima compiles code to binary, and has done so, oh for a couple of
decades.

 Since Maxima is part of Sage, one might hope that William would be
aware of this feature.

  Example.

g(x):=block([s:0],for i thru x do s:s+i^2,s);

g(1);  takes 0.15 seconds.

compile(g);   converts g to lisp and compiles it with an optimizing
compiler.

g is now about 5X faster.

if one inserts declarations, e.g.  mode_declare(i,fixnum, x, fixnum,
s, fixnum),
the code goes about 10X faster.   I think that one can improve the
speed
substantially beyond that by setting optimization levels in the (lisp)
compiler.
I was using a GCL-based Maxima.

RJF


-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org