I don't think there is an option in sympify() at this point to do
that. You could probably handle most cases by doing a search and
replace of )( for )*(. Or rather, do a grep search and replace for )
*( with )\*(.
I can't think of any instances where the former is part of a legal
SymPy expression right now. Note that something like x(x + y) will be
converted to Function('x')(x + y).
Another idea would be to hack Expr.__call__ to return a
multiplication. In other words, try something like:
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index e1b942d..da74fae 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -95,6 +95,10 @@ def __abs__(self):
return C.Abs(self)
@_sympifyit('other', NotImplemented)
+ def __call__(self, other):
+ return Mul(self, other)
+
+ @_sympifyit('other', NotImplemented)
@call_highest_priority('__radd__')
def __add__(self, other):
return Add(self, other)
Which lets you do:
In [1]: (x + y)(x + y)
Out[1]:
2
(x + y)
I did this and ran the tests, and surprisingly, there weren't many
failures. The only ones were some in the mechanics module, and some
tests that specifically tested that that behavior was not allowed.
Note that with this, x(stuff) would still create Function('s')(stuff).
If you disable that, I can guarantee you that a bunch of tests will
fail.
Finally, you might look at the very rudimentary mathematica parser in
sympy/parsing/mathematica.py, which handles some of this stuff.
Aaron Meurer
On Fri, Nov 4, 2011 at 8:34 AM, gsagrawal <[email protected]> wrote:
> Hi ,
> I am trying to parse some mathematical expressions using sympify from string
> format to sympy format.
> But if my expression is like "(x+y)(x-y)" ,i am getting TypeError exception
> (Add is not a callable ). I know i am missing one * symbol in between these
> brackets (correct expression is (x+y)*(x-y) ) . but As i am taking this
> expression input from User , so is there any way to handle this exception
> and any way to get specific section where i missed
> this multiplication symbol ?
> Thanks,
>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.