-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add extract_expression_from_wavefunction
to sympy.physics.quantum.state.Wavefunction
#26520
base: master
Are you sure you want to change the base?
Changes from 12 commits
11e3ac5
4a14428
e0f7acd
b47a450
e7b1b6a
8fd73db
2376679
da5986b
cfc856e
5782b53
4d9f8d3
ea41cd9
e2851d3
657a885
db01ff6
77e27a7
baba985
5f3fa7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Dirac notation for states.""" | ||
|
||
from sympy import KroneckerDelta | ||
from sympy.core.cache import cacheit | ||
from sympy.core.containers import Tuple | ||
from sympy.core.expr import Expr | ||
|
@@ -643,7 +644,7 @@ class OrthogonalKet(OrthogonalState, KetBase): | |
>>> (OrthogonalBra(n)*OrthogonalKet(n+1)).doit() | ||
0 | ||
>>> (OrthogonalBra(n)*OrthogonalKet(m)).doit() | ||
<n|m> | ||
KroneckerDelta(m, n) | ||
""" | ||
|
||
@classmethod | ||
|
@@ -665,7 +666,7 @@ def _eval_innerproduct(self, bra, **hints): | |
return S.Zero # i.e. Integer(0) | ||
|
||
if is_zero is None: | ||
return None | ||
return KroneckerDelta(arg, bra_arg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of this is that |
||
|
||
return S.One # i.e. Integer(1) | ||
|
||
|
@@ -909,6 +910,50 @@ def expr(self): | |
""" | ||
return self._args[0] | ||
|
||
@staticmethod | ||
def extract_expression_from_wavefunction(input_expression): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function does not seem to be used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this as a handicap to extract the expression from the wavefunction objects. In the current state, simply doing |
||
""" | ||
This function recursively traverses the given expression, replacing any instances of Wavefunction with their | ||
internal expressions. | ||
|
||
Parameters | ||
========== | ||
|
||
input_expression : sympy.Expr | ||
The expression that needs to be simplified. | ||
|
||
Example | ||
======= | ||
|
||
import sympy as sp | ||
from sympy.physics.quantum.state import Wavefunction | ||
|
||
R = sp.Function('R') | ||
Z = sp.Function('Z') | ||
x,y = sp.symbols('x y', real=True) | ||
|
||
ϕ = Wavefunction(R(x)*Z(y), x, y) | ||
|
||
extract_expression_from_wavefunction(ϕ + ϕ) | ||
|
||
Returns | ||
======= | ||
|
||
sympy.Expr | ||
The simplified expression with Wavefunction instances replaced by their internal expressions. | ||
""" | ||
def replace_wavefunctions(expression): | ||
simplified_expression = expression | ||
for argument in expression.args: | ||
if argument.func == Wavefunction: | ||
simplified_expression = simplified_expression.subs(argument, argument.expr) | ||
else: | ||
new_term = replace_wavefunctions(argument) | ||
simplified_expression = simplified_expression.subs(argument, new_term) | ||
return simplified_expression | ||
|
||
return replace_wavefunctions(input_expression) | ||
|
||
@property | ||
def is_normalized(self): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AUTHORS file should not be edited.