I just found a bug in code generation with Boolean operators. For
example, the sympy expression x&y ought to generate the C++ code x&&y
but it actually generates And(x,y). I have a fix for this to add to
sympy.printing.ccode.CCodePrinter, the extra methods:
def _print_And(self, expr):
PREC = precedence(expr)
return '&&'.join(self.parenthesize(a, PREC) for a in
expr.args)
def _print_Or(self, expr):
PREC = precedence(expr)
return '||'.join(self.parenthesize(a, PREC) for a in
expr.args)
def _print_Not(self, expr):
PREC = precedence(expr)
return '!'+self.parenthesize(expr.args[0], PREC)
I don't mess around with sympy internals much, so I might be using
self.parenthesize and precedence wrong here (it certainly seems to
create too many parentheses like this), but it does at least seem to
work.
Dan Goodman
Thanks for the fix. If possible, could you please send it as a git
patch? We'll review it and push it in.
Ondrej
Thanks,
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
Unfortunately I don't have the time for the git patch/test writing at
the moment. Indeed, I've never even used git! :) This was more like a
slightly-more-helpful-than-usual bug report than a proper patch. It's
probably not even 100% correct (for example x&y generates (x)&&(y)
rather than x&&y and I have no idea why or what I should have
written). Sorry, hope it was of some use anyway!
Dan
By the way, Ondrej has some good git patch tutorials here if you are ever interested:
http://code.google.com/p/sympy/wiki/GitTutorials
Aaron Meurer
cd somedir
git clone git://git.sympy.org/sympy.git
cd sympy
(download the patches in this directory)
git apply 0001-Precedence-for-boolean-operators-And-Or-and-Not.patch
git apply 0002-Fix-boolean-operatures-in-ccode.patch
(run python, from sympy import *, and try it out)
cheers,
Toon
--
Dr. ir. Toon Verstraelen
Center for Molecular Modeling
Ghent University
Technologiepark 903,
B9052 Zwijnaarde
Belgium
Tel: +32 9 264 65 56
E-mail: Toon.Ver...@UGent.be
http://molmod.UGent.be/
http://molmod.UGent.be/code/
Aaron - yeah, I really should learn to use git some time soon, it
seems to be what all the cool kids are using these days. Not now
though, 3 papers to write by the end of March! :/
Thanks everyone for this fantastic package by the way!
Dan
Write your papers in git then --- that's what I do. :)
>
> Thanks everyone for this fantastic package by the way!
Thanks and thanks for your report!
Ondrej