ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 20 Jun 2019 11:23:23 +0200SageManifolds: Equations of motion for scalar fieldhttps://ask.sagemath.org/question/46948/sagemanifolds-equations-of-motion-for-scalar-field/The following code illustrates the problem I'm having:
phi = M.scalar_field(function('phi')(*coord), name='phi')
print(phi)
V = function('V')(phi)
Scalar field phi on the 4-dimensional differentiable manifold R^4
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-61-7de84076176e> in <module>()
1 phi = M.scalar_field(function('phi')(*coord), name='phi')
2 print(phi)
----> 3 V = function('V')(phi)
/home/cduston/Programs/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6664)()
473 if callable(method):
474 return method()
--> 475 raise TypeError("cannot coerce arguments: %s" % (err))
476
477 else: # coerce == False
TypeError: cannot coerce arguments: no canonical coercion from Algebra of differentiable scalar fields on the 4-dimensional differentiable manifold R^4 to Symbolic Ring
I want to determine the equations of motion for a scalar field $\phi$ on a 4-manifold with potential $V(\phi)$. However, Sage can't seem to associate an algebra with those objects. This is a pretty standard thing to do in field theory / GR - study the inflaton field, or dark energy, for example.
Is there a correct way to write to get the behavior we expect?
EDIT: Eventually, this function needs to be added to other scalar quantities, constructed from tensors:
dphi=nab(phi)
T1=dphi['_a']*dphi['_b']
T2=g.inverse()['^ab']*T1['_ab']
T3=dphi*dphi + 1/2*g*(T2 - V)Wed, 19 Jun 2019 22:37:17 +0200https://ask.sagemath.org/question/46948/sagemanifolds-equations-of-motion-for-scalar-field/Answer by eric_g for <p>The following code illustrates the problem I'm having:</p>
<pre><code>phi = M.scalar_field(function('phi')(*coord), name='phi')
print(phi)
V = function('V')(phi)
Scalar field phi on the 4-dimensional differentiable manifold R^4
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-61-7de84076176e> in <module>()
1 phi = M.scalar_field(function('phi')(*coord), name='phi')
2 print(phi)
----> 3 V = function('V')(phi)
/home/cduston/Programs/SageMath/local/lib/python2.7/site-packages/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:6664)()
473 if callable(method):
474 return method()
--> 475 raise TypeError("cannot coerce arguments: %s" % (err))
476
477 else: # coerce == False
TypeError: cannot coerce arguments: no canonical coercion from Algebra of differentiable scalar fields on the 4-dimensional differentiable manifold R^4 to Symbolic Ring
</code></pre>
<p>I want to determine the equations of motion for a scalar field $\phi$ on a 4-manifold with potential $V(\phi)$. However, Sage can't seem to associate an algebra with those objects. This is a pretty standard thing to do in field theory / GR - study the inflaton field, or dark energy, for example.</p>
<p>Is there a correct way to write to get the behavior we expect?</p>
<p>EDIT: Eventually, this function needs to be added to other scalar quantities, constructed from tensors:</p>
<pre><code>dphi=nab(phi)
T1=dphi['_a']*dphi['_b']
T2=g.inverse()['^ab']*T1['_ab']
T3=dphi*dphi + 1/2*g*(T2 - V)
</code></pre>
https://ask.sagemath.org/question/46948/sagemanifolds-equations-of-motion-for-scalar-field/?answer=46952#post-id-46952Symbolic functions, as created via `function('V')(phi)`, accept only symbolic expressions (i.e. elements of the Symbolic Ring) for their arguments. Hence the error message that you get. To derive the equations of motion, I would advise to introduce, in addition to the scalar field `phi`, a symbolic expression, `phi0` say, that will represent the scalar field as the argument of the potential `V`:
phi0 = var('phi0', latex_name=r'\phi')
V_phi = function('V')(phi0)
Thu, 20 Jun 2019 11:23:23 +0200https://ask.sagemath.org/question/46948/sagemanifolds-equations-of-motion-for-scalar-field/?answer=46952#post-id-46952