Thank you so much I am goig to foloow your suggestion

El viernes, 6 de abril de 2018, 1:02:31 (UTC-5), Moises Zeleny escribió:
>
> Hi, everyone
>
> I am a new sympy user and usually I work with Jupyter notebook. I would 
> like construct a new symbolic class named FV (Four vector), I have made this
>
> from sympy import *
> init_printing()
>
> class FV:
>     
>     def __init__(self,p0,p1,p2,p3):
>         self.p0 = p0
>         self.p1 = p1
>         self.p2 = p2
>         self.p3 = p3
>     
>     def __str__(self):
>         return '({a},{b},{c},{d})'.format(a=self.p0, b=self.p1, c=self.p2, 
> d=self.p3)
>     
>     def __repr__(self):
>         return self.__str__()
>     
>     def __add__(self,other):
>         p0,p1,p2,p3 = self.p0,self.p1,self.p2,self.p3
>         k0,k1,k2,k3 = other.p0,other.p1,other.p2,other.p3
>         return FV(p0+k0, p1+k1, p2+k2, p3+k3)
>     
>     def __mul__(self,other):
>         p0,p1,p2,p3 = self.p0,self.p1,self.p2,self.p3
>         k0,k1,k2,k3 = other.p0,other.p1,other.p2,other.p3
>         return FV(p0*k0,-p1*k1,-p2*k2,-p3*k3)
>     
>     def __abs__(self):
>         from sympy import sqrt
>         p0,p1,p2,p3 = self.p0,self.p1,self.p2,self.p3
>         return sqrt(p0**2 - p1**2 - p2**2 - p3**2)
>     
>     def __eq__(self,other):
>         return self.p0 == other.p0 and self.p1 == other.p1 and self.p2 == 
> other.p2 and self.p3 == other.p3
>     
>     def __neq__(self,other):
>         return not self.__eq__(other)
>
> but this works while I use float or int python objects for the components 
> in FV, when I use symbols I obtained
>
> p = {i:symbols('{{p^{a}}}'.format(a=i)) for i in range(4)}
> pmu = FV(p[0],p[1],p[2],p[3])
> pmu
>
> ({p^0},{p^1},{p^2},{p^3})
>
>
> this output do not used a init_printing(). Can someone help me please?
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/a147c755-98fc-4734-9b4d-f7c974f53f52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to