How do i print running python code so that it can be evaluated without sympy? + shift operator issue

0 views
Skip to first unread message

Tarjan

unread,
Sep 1, 2009, 3:44:27 AM9/1/09
to sympy
for example:

x = Symbol('x')
y = Symbol('y')
print x & y

>> prints: "And(x, y)"

but i want "x & y" because & is the And operator!

AND!

why is the shift operator "<<" and ">>" overriden by Implies or how
can i symbolicaly shift a number?

Thank you in advance...

Tarjan



Ondrej Certik

unread,
Sep 1, 2009, 3:53:46 AM9/1/09
to sy...@googlegroups.com
On Tue, Sep 1, 2009 at 12:44 AM, Tarjan<t4r...@googlemail.com> wrote:
>
> for example:
>
> x = Symbol('x')
> y = Symbol('y')
> print x & y
>
>>> prints: "And(x, y)"
>
> but i want "x & y" because & is the And operator!

Create a new printer, or apply this patch:

diff --git a/sympy/printing/str.py b/sympy/printing/str.py
index 398c3cb..0f4391e 100644
--- a/sympy/printing/str.py
+++ b/sympy/printing/str.py
@@ -46,6 +46,9 @@ def emptyPrinter(self, expr):
else:
return str(expr)

+ def _print_And(self, expr):
+ return "%s & %s" % (expr.args[0], expr.args[1])
+
def _print_Add(self, expr):
args = list(expr.args)

>
> AND!
>
> why is the shift operator "<<" and ">>" overriden by Implies or how
> can i symbolicaly shift a number?

I didn't know that >> is overriden as Implies. I think it's not such a
good idea, I think we should stick to python interpretation of things
whenever possible. As to symbolically shifting a number, I think it's
not yet implemented.

All, what do you think?

Ondrej

Tarjan

unread,
Sep 2, 2009, 12:16:08 PM9/2/09
to sympy
Hallo,

i investigated a bit and it seems that only bool operations are
supported but no bitwise arithmetic.

in the evaluation methods is a check for >>> if isinstance(arg, bool):

so ints are not accounted for...

Is there a plan to change that?
Or what is needed to extend sympy in that way?

Greetings

Tarjan
Reply all
Reply to author
Forward
0 new messages