--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.
Ondrej
Ondrej
> I would be interested in CSymPy with working "integrate", for example.
It would be cool. Though unfortunately integrate() happens to be the
most difficult part,
as it depends on many modules, so it will take some time. However, if
we choose to implement another version of
integrate based on pattern matching, then that might be possible sooner.
Sophisticated algorithms for pattern matching against a large collection of potentially associative-commutative terms can be both very involved/challenging and also be vastly more efficient than naive algorithms.Optimization on this problem over algorithms is more effective than optimization over language-implementations and as such the performance advantages of C++ over Python are negligible.
--
"Or maybe even try to define a standard to write Python code in order to make it easy to translate it to C++ through code generators?"Doesn't Cython already do this?
@is_cpp_translatable
class SomeClass(Basic):
@staticvars({'a': 'int', 'b': 'int', 'c': 'double'})
def simple_method(a, b):
c = a // 2 + b // 3
return cclass SomeClass : public Basic {
public:
double simple_method(int a, int b) {
double c = ((double)a)/2 + ((double)b)/2;
return c;
}
}@is_cpp_translatable
class SomeClass(Basic):
@staticvars({'a': 'int', 'b': 'int', 'c': 'double'})
def simple_method(a, b):
c = a // 2 + b // 3
return c
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscribe@googlegroups.com.
The main problem of Python is that.
Translation could occur only once in the future, as soon as the Python code is deemed mature and stable. After that development would continue in C++.
Otherwise an alternative could be to write the sympy core entirely in cython, so there is an option to use both Python expressions and statically typed variables.
That's a good thing, though they'd still have to upgrade the system with
each new Python version, so it's not buying the project THAT much.
But yes it makes sure that no deviations creep into the parsing, which
is good.
The main question, then, is: Is Nuitka viable?
I.e. is it going to stay around as long as Sympy will? How fast do they
fix showstopper bugs? Are type decorators and (hopefully) something
smart for the data representation going to be implemented within our
lifetimes?
Alternatively, we could do our own Python-to-C++ translator. This would
be easier than a full-fledged translator because we'd have to cover only
those constructs that are actually used in Sympy, so we could take
considerable shortcuts (at the cost of needing a list of coding
restrictions, so this option would still come with attached strings).
--
Anyone ever heard of Nuitka? I discovered this project today, and it looks very promising.
@Franz, while I do not have an opinion on what is discussed here, I would like to correct an error that was repeated a few times: The Pypy interpreter for Python2.7 does *not* restrict what you can do - it is a *fully* compliant python interpreter.
You are probably thinking about the RPython language, which indeed is a part of the Pypy project and it is a very restricted subset of Python2. But RPython is *not* meant for use outside of writing the interpreter itself.
I've played around with Cython, Nuitka, shedskin etc. I would not recommend Nuitka (see Stefan Behnels blog post on the topic) - furthermore: it produces huge binaries.
Based on what I've read lately mypy might be the silver bullet but it's quite new and I haven't found
the time to play around with it yet.
On the note of de dynamizing the code base it might be worth looking into param:
https://github.com/ioam/param
http://pyvideo.org/video/1230/param-declarative-programming-using-parameters
I've also played around automatic (cython) code generation of decorated classes
https://gist.github.com/bjodah/6790854
(requires Py3, cython & mako) but it got cumbersome so I didn't go any further.
I think once we stop supporting Python 2.7, we can start using static typing
quite easily and I think it helps.
Though I think one of the most useful algorithms in SymPy that are
candidates for C++ rewrite
are polynomials, and those as far as I know don't use much duck typing, so
it should be fairly easy to rewrite using fast native C++ datastructures.
For example, here is my implementation of sparse polynomial multiplication
in C++:
https://github.com/certik/csympy/blob/master/src/rings.cpp#L63
https://github.com/certik/csympy/blob/master/src/monomials.cpp#L7
and I think it might be possible to speed it up further by playing
with the hashtable
and hashes and similar things. I tried to optimize a hash function for
this case already,
see here:
https://github.com/certik/csympy/blob/master/src/dict.h#L48
the idea is that the hash function needs to be fast to compute for the
tuple of ints and
also as unique as possible.
Btw, I don't want to discourage you from trying things. I only wanted
to share my own
(hard-earned) experience, as I tried various approaches. For example,
one great project
would be to implement similar symbolic core in Julia. It might get
competitive or even
faster than my Cython version above. Whether it could match my C++ version,
that I don't know.
... that's giving me a thought though: Maybe it's a good idea to make a
Sympy-to-whatever-language translation. On Jython, a C++ library just
doesn't make sense, but it would allow experimentation with different
languages.
Am 07.10.2013 20:07, schrieb F. B.:
> I just had a look at the Julia project http://julialang.org/
>
> Have a look at how they manage operator overloading:
I just did and shuddered.
Unrestrained multple dispatch runs into modularity issues. It's one of
those mistakes that language designers make over and over again, because
the base idea seems to simple and the use cases one can think of are so
straightforward, but they almost never consider the case what happens
when two independent developers have their work merged by a third.
> That is a great idea, it would keep code clear and readable, and avoid the
> need of all those *if isinstance( ) ... elif isinstance( )*
There are better and more general ways to avoid that.
Unfortunately, neither Julia's approach nor the ones typically employed
in FPLs are available in Python.
> By the way, the aim of Julia is to be both an interpreted language and a
> fast compiled language, with speed of execution near to those of C. At the
> same time they want to keep perfect interaction with both Python and C...
Sounds like they're too ambitious to succeed.
> and at the
> same time allow perfect interaction with both Python and C, and reach the
> performance of C.
I doubt that you can have both easy interaction with dynamic languages
and raw performance. To the very least, you'll have to keep the number
of inter-language calls down, and that would impose design restrictions
on Sympy's code. Sympy already has a lot of restrictions to observe, I
doubt that that's going to be easy.
Just for the record. With the help of Rubi I just solved an integral for which both Mathematica and Maxima gave a rather ugly answer. Rubi provided the same result that appears in a book. Based on this experience I definitely recommend, and if I can find the time I will collaborate, to work on implenting the Rubi rules for Sympy.