improve usage of ``substitutions`` in ``continuum``
note: description edited to include larger scope
type of substitutions:
So far substitutions
accept dictionary in form key: sympy expression
. One could also expect it to accept strings
, i.e
following works:
>>> kwant.continuum.sympify('k_x**2 + V', substitutions=dict(V=kwant.continuum.sympify('V_0 + V')))
V + V_0 + k_x**2
once following fails
>>> kwant.continuum.sympify('k_x**2 + V', substitutions=dict(V='V_0 + V'))
[traceback skipped]
TypeError: unsupported operand type(s) for +: 'Symbol' and 'str'
Also currently subsitutions that contains momentum or position operators are ignored, i.e
>>> kwant.continuum.sympify('k_x**2 + k_y**2', substitutions=dict(k_y=0))
k_x**2 + k_y**2
applying substitutions also when input is sympy object:
Currently substitutions
are used only when input type is a string. This was overlooked because initially they were playing role of locals
passed to sympy.sympify
when input was string. It makes sense though to apply them according to their name on already sympified input. For example following to piece of code should do the same:
hamiltonian = 'k_x**2 + V'
substitutions = {'V': kwant.continuum.sympify('V + V_0')}
h = kwant.continuum.lambdify(hamiltonian, substitutions=substitutions)
hamiltonian = kwant.continuum.sympify('k_x**2 + V')
substitutions = {'V': kwant.continuum.sympify('V + V_0')}
h = kwant.continuum.lambdify(hamiltonian, substitutions=substitutions)
this should address every public function that uses substitutions
.