lie.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #Copyright (c) 2008, Riccardo De Maria
  2. #All rights reserved.
  3. from .polmap import *
  4. from .pol import *
  5. def Jmat(vars):
  6. """ Simplectic matrix or order 2 n
  7. >>> from lie import *
  8. >>> print Jmat('x px y py z pz'.split())
  9. pz=- 1.0*z
  10. px=- 1.0*x
  11. py=- 1.0*y
  12. y=py
  13. x=px
  14. z=pz
  15. """
  16. d=polmap()
  17. vars=list(vars)
  18. while vars:
  19. q,p=vars.pop(0),vars.pop(0)
  20. d[q]=pol(p)
  21. d[p]=-pol(q)
  22. return d
  23. def parder(p,vars):
  24. """ Return derivative of the pol p given a vector of var
  25. >>> from lie import *
  26. >>> f=pol('l*(p**2+q**2)/2.')
  27. >>> print parder(f,'qp')
  28. q=q*l
  29. p=p*l
  30. """
  31. d=polmap()
  32. for i in vars:
  33. d[i]=p.der(i)
  34. return d
  35. def lieop(f,vars):
  36. """ Return the lie operator for f
  37. >>> from lie import *
  38. >>> f=pol('l*(p**2+q**2)/2.')
  39. >>> Lf=lieop(f,'qp')
  40. >>> print Lf
  41. q=p*l
  42. p=- 1.0*q*l
  43. >>> print Jmat('qp')*parder(f,'qp')
  44. q=p*l
  45. p=- 1.0*q*l
  46. >>> print Lf*polmap(q='q',p=0)
  47. q=0
  48. p=- 1.0*q*l
  49. >>> print Lf*polmap(p='p',q=0)
  50. q=p*l
  51. p=0
  52. """
  53. d=polmap()
  54. vars=list(vars)
  55. while vars:
  56. q,p=vars.pop(0),vars.pop(0)
  57. d[q]=f.der(p)
  58. d[p]=-f.der(q)
  59. return d
  60. def pbracket(f,g,vars):
  61. out=0
  62. vars=list(vars)
  63. while vars:
  64. q,p=vars.pop(0),vars.pop(0)
  65. out+=f.der(q)*g.der(p) - f.der(p)*g.der(q)
  66. return out
  67. def pmbracket(f,g,vars):
  68. out=polmap()
  69. for i in g:
  70. out[i]=pbracket(f,g[i],vars)
  71. return out
  72. def idmap(vars):
  73. vars=list(vars)
  74. g=polmap()
  75. for i in vars:
  76. g[i]=pol(i)
  77. return g
  78. def liexp(f,vars):
  79. vars=list(vars)
  80. g=idmap(vars)
  81. out=polmap(g)
  82. out+=pmbracket(f,g,vars)
  83. out+=pmbracket(f,pmbracket(f,g,vars),vars)