a, b, x, y = symbols('a b x y')
Enter code here...a, b, x, y = symbols('a b x y')
Eq(Mul(*[eq.lhs for eq in (<your_equations>)]), Mul(*[eq.rhs for eq in (<your_equations)])
The above is a general method and can be modified for commutative operatprs, like Mul, Add, etc.
Hi Gary,
I wonder if we are overcomplicating things here. Does this do what you want?
x, y = symbols('x, y')
a = x + y
b = x * y
print(a * b)
--
Oscar
On Tue, 9 Jul 2019 at 03:11, Gary Pajer <gary...@gmail.com> wrote:
>
> I'm sure I'm not the first person having trouble getting started. If there is a good tutorial, more detailed than the sympy docs tutorial, please point me to it!
>
> I want to display the product of two expressions. Suppose I have
>
> a, b, x, y = symbols('a b x y')
> ex1 = Eq(a, x + y)
> ex2 = Eq(b, x * y)
>
> How do I display a * b in terms of x and y?
>
> Thainks.
>
> --
> 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 sy...@googlegroups.com.
Generally it is a lot easier to understand SymPy if you are experienced with Python. A lot of our users are new to both Python and SymPy and I think that makes it hard to explain what's going on. Some things would be cleaner for users if SymPy was not embedded within Python and can be confusing unless you already know Python well and can see why things are the way they are. -- Oscar
I am also fairly new to Python and sympy, but I think I have pushed through this pain barrier.
As far as I can see, you really need to use symbols() or var() to set up variables which are going to be used as symbols in bits of algebra or calculus, but you do not need to make a variable symbolic if it is just going to be used to hold expressions or for some other pythonic purpose, such as a counter. However, no harm is done (someone correct me if I am wrong) if you create a lot of symbols, which you can do with :
from sympy.abc import *
because if, say, you subsequently assign X=42 that will harmlessly destroy the sympy symbol attached to x which will become pythonic again, but you obviously want to use it as a constant so that is fine.
I think a good strategy is to either save some letters for use as pythonic variables, or only use variables with more than one character as pythonic variables (they don't look nice in expressions, anyway)
If you want to use x in expressions, then it is probably best not
to assign it to 42 (as above) but to leave it symbolic, and use
subs to replace it in an expression by 42.
David