liealg.py 413 B

12345678910111213141516171819202122
  1. from pytpsa import *
  2. d=pol('d1*px+d2*px**2+d3*px**3')
  3. k=pol('a1*x+a2*x**2+a3*x**3')
  4. vars='x px'.split()
  5. pbracket(d,k,vars)
  6. d=pol('d2*px**2+d3*px**3')
  7. k=pol('a2*x**2+a3*x**3')
  8. vars='x px'.split()
  9. pbracket(d,k,vars)
  10. def pb(lst):
  11. x=lst.pop(0)
  12. if len(lst)==0:
  13. return x
  14. else:
  15. return pbracket(x,pb(lst),vars)
  16. # return '[%s,%s]' % (x,pb(lst))
  17. d+k+1./2*pb([d,k])+1./12*pb([d,d,k])-1./12*pb([k,d,k])