Cadabra Q&A - Recent questions and answers in General questions
http://cadabra.science/qa/qa/general-questions
Powered by Question2AnswerAnswered: Apply an operator to an equation
http://cadabra.science/qa/1195/apply-an-operator-to-an-equation?show=1196#a1196
<p>Cool one. There is a subtle bug in the parser which fails on these Python names with underscores. If you replace <code>lhs_scL</code> with <code>lhsscL</code> and ditto for the rhs version, things work. Will fix, hopefully the workaround above can keep you going in the meantime.</p>
General questionshttp://cadabra.science/qa/1195/apply-an-operator-to-an-equation?show=1196#a1196Wed, 26 Jun 2019 06:38:46 +0000Answered: Graded partial differential
http://cadabra.science/qa/1188/graded-partial-differential?show=1189#a1189
<p>Assign the <code>AntiCommuting</code> property to the indices, not to the derivatives. So</p>
<pre><code>{a, b, c, d, e, f, g, h, i, j, k, l, m, n ,o, r,s,t,u,v,w,x,y,z#}::Indices(T, position=free, parent=double);
D{#}::PartialDerivative;
\xi{#}::Depends(D{#});
{a, b, c, d, e, f, g, h, i, j, k, l, m, n ,o, r,s,t,u,v,w,x,y,z#}::AntiCommuting;
</code></pre>
<p>and then</p>
<pre><code>Exp:=D_{a}{D_{b}{\xi_{c}}*\xi_{d}};
product_rule(_);
</code></pre>
<p>produces</p>
<p>$$D_{a b}{\xi_{c}} \xi_{d} + D_{b}{\xi_{c}} D_{a}{\xi_{d}}$$</p>
General questionshttp://cadabra.science/qa/1188/graded-partial-differential?show=1189#a1189Thu, 20 Jun 2019 08:18:04 +0000Answered: Poincare example evaluated twice
http://cadabra.science/qa/1186/poincare-example-evaluated-twice?show=1187#a1187
<p>What happens here is that the <code>post_process</code> function converts the <code>\commutator{#}</code> argument in the line</p>
<pre><code>{J_{\mu\nu}, P_{\mu}, W_{\mu} }::Depends(\commutator{#}).
</code></pre>
<p>to a <code>0</code>, so that that line becomes</p>
<pre><code>{J_{\mu\nu}, P_{\mu}, W_{\mu} }::Depends(0).
</code></pre>
<p>This does not happen on first run, because in that case the function <code>post_process</code> is not defined yet when the above line is encountered.</p>
<p>The problem is that <code>unwrap</code> (which is used in <code>post_process</code>) should have left <code>\commutator{#}</code> untouched. </p>
<p>Thanks for reporting this; will fix in a future update.</p>
General questionshttp://cadabra.science/qa/1186/poincare-example-evaluated-twice?show=1187#a1187Wed, 12 Jun 2019 11:47:30 +0000Answered: Using multiple notebooks
http://cadabra.science/qa/1184/using-multiple-notebooks?show=1185#a1185
<p>Just stick it anywhere in your PYTHONPATH; the import works just like any regular Python import process.</p>
General questionshttp://cadabra.science/qa/1184/using-multiple-notebooks?show=1185#a1185Wed, 12 Jun 2019 08:56:06 +0000definitions in cadabra
http://cadabra.science/qa/1176/definitions-in-cadabra
<p>can you combine letters with numbers to name definitions in cadabra? Like as follows</p>
General questionshttp://cadabra.science/qa/1176/definitions-in-cadabraFri, 07 Jun 2019 06:44:48 +0000Functional dependence
http://cadabra.science/qa/1167/functional-dependence
<p>Hi friends,</p>
<p>I would like to know if is there any possibility of defining a functional dependence for an object. For example, in the below code the Cadabra throws an error</p>
<pre><code>x::Coordinate;
\partial{#}::PartialDerivative;
\bar{#}::DiracBar;
{\phi,J, j, \eta}::Depends(x, \partial{#});
S::Depends(\phi,\bar{\eta},\eta);
</code></pre>
<p>Regards</p>
General questionshttp://cadabra.science/qa/1167/functional-dependenceTue, 04 Jun 2019 23:17:50 +0000Defining a non-nilpotent `ExteriorDerivative`
http://cadabra.science/qa/1159/defining-a-non-nilpotent-exteriorderivative
<p>Hello!</p>
<p>I'm creating a Cadabra notebook showing how the Bianchi identities are obtained, using the structural equations.</p>
<p>Although I achieve the goal, it is useful to show the results introducing an exterior covariant derivative, $D$. Such derivative is not nilpotent, i.e. $D^2 \neq 0$.</p>
<p>I tried the following</p>
<pre><code>D{#}::Derivative.
D{#}::LaTeXForm("{\rm D}").
D{#}::DifferentialForm(degree=1);
</code></pre>
<p>but I think that the last declaration spoils the super-commutativity of the differential forms.</p>
<p><strong>Question</strong></p>
<p>How could I possible define a non-nilpotent exterior derivative?</p>
General questionshttp://cadabra.science/qa/1159/defining-a-non-nilpotent-exteriorderivativeTue, 07 May 2019 16:01:20 +0000Answered: A general covariant derivative
http://cadabra.science/qa/68/a-general-covariant-derivative?show=1151#a1151
<p>Have a look at the example at the bottom of <a rel="nofollow" href="https://cadabra.science/notebooks/ref_programming.html">https://cadabra.science/notebooks/ref_programming.html</a> for a way to handle operators whose expansion depends on the object they act on. </p>
General questionshttp://cadabra.science/qa/68/a-general-covariant-derivative?show=1151#a1151Fri, 26 Apr 2019 12:13:43 +0000Answered: Dimensional reduction of a three form
http://cadabra.science/qa/1143/dimensional-reduction-of-a-three-form?show=1144#a1144
<p>The line</p>
<pre><code>C_{\Sigma \Pi \Theta}::AntiSymmetric;
</code></pre>
<p>makes the tensor antisymmetric in the 'full' indices, and it would be natural for Cadabra to infer that this implies that the anti-symmetry is also present when these indices are replaced with either '4' or one of the <code>space1</code> indices, but it doesn't do that (yet). If it does not clash with other tensors, you can do</p>
<pre><code>C_{A? B? C?}::AntiSymmetric;
</code></pre>
<p>which makes the tensor antisymmetric regardless of what you stick in the index slots. Of course this will then also yield antisymmetry for a C-tensor with indices from yet another set (which you probably won't have).</p>
<p>Unfortunately there are no logical operators in conditional substitution yet; it's fairly limited at the moment.</p>
General questionshttp://cadabra.science/qa/1143/dimensional-reduction-of-a-three-form?show=1144#a1144Thu, 25 Apr 2019 16:07:32 +0000Sorting indices of tensors
http://cadabra.science/qa/1141/sorting-indices-of-tensors
<p>Hi. I've been working on a Kaluza-Klein dimensional reduction. In the reduced model there are terms like $g<em>{a 5}$ and $g</em>{5 a}$. Is the a command that sort the indices, and allows to write everything in terms of a single component? </p>
General questionshttp://cadabra.science/qa/1141/sorting-indices-of-tensorsWed, 24 Apr 2019 13:18:28 +0000Dependence on a subspace - Possible???
http://cadabra.science/qa/1139/dependence-on-a-subspace-possible
<p>Going through the Kaluza-Klein examples, I noticed that it is possible to define subspaces (e.g. <code>split_index</code>). There is also a <code>Depends</code> property.</p>
<p>I've defined</p>
<pre><code>{\Lambda,\Theta,\Sigma,\Xi,\Gamma,\Delta,\Pi,\Omega}::Indices(full,position=independent);
{\mu,\nu,\rho,\sigma,\gamma,\lambda}::Indices(space1,position=independent);
\partial{#}::PartialDerivative;
{\phi, A_{\mu?}, h_{\mu? \nu?}}::Depends(\partial{#});
</code></pre>
<p>Is it possible to restrict the dependence of the fields to the subspace <code>space1</code>?</p>
General questionshttp://cadabra.science/qa/1139/dependence-on-a-subspace-possibleTue, 23 Apr 2019 19:53:08 +0000Answered: Problem with substitution
http://cadabra.science/qa/1134/problem-with-substitution?show=1135#a1135
<p>Should probably go in a FAQ: if you write <code>e^{a}</code> this gets interpreted as a tensor <code>e</code> with one contravariant index <code>a</code>. To write exponentials, use <code>\exp{...}</code> instead, or <code>e**{...}</code> if you really want the <code>e</code>.</p>
General questionshttp://cadabra.science/qa/1134/problem-with-substitution?show=1135#a1135Tue, 23 Apr 2019 16:39:48 +0000Answered: How define a general tensor symmetry
http://cadabra.science/qa/1098/how-define-a-general-tensor-symmetry?show=1125#a1125
<p>With the provided information, you cannot determine an irrep under which your tensor transform. That's why you cannot use <code>TableauSymmetry</code></p>
<p>Notice however that, your tensor could lie on the <code>{2,2,2}</code> Young tableau. Perhaps that can help!</p>
<p>Cheers.</p>
General questionshttp://cadabra.science/qa/1098/how-define-a-general-tensor-symmetry?show=1125#a1125Tue, 16 Apr 2019 15:45:47 +0000Answered: Symmetrise pairs of indices
http://cadabra.science/qa/1111/symmetrise-pairs-of-indices?show=1124#a1124
<p>As shown in the manual, <a rel="nofollow" href="https://cadabra.science/manual/TableauSymmetry.html,">https://cadabra.science/manual/TableauSymmetry.html,</a> you could use the property <code>TableauSymmetry</code></p>
<pre><code>A_{a b c d}::TableauSymmetry( shape={2,2}, indices={0,2,1,3} );
</code></pre>
<p>Cheers.</p>
General questionshttp://cadabra.science/qa/1111/symmetrise-pairs-of-indices?show=1124#a1124Tue, 16 Apr 2019 15:32:38 +0000Answered: what is the use of question mark postindices, how it changes contractions and symmetry properties of indices?
http://cadabra.science/qa/1117/question-postindices-changes-contractions-symmetry-properties?show=1118#a1118
<p>A single question mark indicates a pattern (or wildcard), so that should only be used in e.g. <code>substitute</code>. Under most circumstances you don't need them for normal indices. Two question marks indicate an <code>object wildcard</code>, that is, a wildcard which matches an entire tensor. Have a look at</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_patterns.html">https://cadabra.science/notebooks/ref_patterns.html</a></p>
<p>in the reference guide, and then reply to this answer in case it is still not clear.</p>
General questionshttp://cadabra.science/qa/1117/question-postindices-changes-contractions-symmetry-properties?show=1118#a1118Mon, 08 Apr 2019 08:15:50 +0000Answered: nested zoom/unzoom
http://cadabra.science/qa/1112/nested-zoom-unzoom?show=1115#a1115
<p>The easter bunny is early this year: the version now on github does <code>unzoom</code> step by step, except when you give it the <code>repeat=True</code> parameter, in which it unzooms all the way to the original expression. Let me know if you run into any issues.</p>
General questionshttp://cadabra.science/qa/1112/nested-zoom-unzoom?show=1115#a1115Sat, 06 Apr 2019 13:16:19 +0000Answered: glob pattern in rules
http://cadabra.science/qa/1105/glob-pattern-in-rules?show=1106#a1106
<p>Try</p>
<pre><code>foo := t0 A + t2 B + t13 C;
substitute(foo, $t? | \regex{t?}{"t[0-9]*"} -> 1$);
</code></pre>
<p>The structure of this replacement rule is described in the reference guide chapter on <a rel="nofollow" href="https://cadabra.science/notebooks/ref_patterns.html">patterns</a>.</p>
General questionshttp://cadabra.science/qa/1105/glob-pattern-in-rules?show=1106#a1106Sun, 31 Mar 2019 11:28:21 +0000Answered: Is it possible to use "+/-" as indices?&How to define a commutator?
http://cadabra.science/qa/1093/is-it-possible-to-use-as-indices-%26how-to-define-a-commutator?show=1094#a1094
<p>Use <code>fm</code> and <code>fp</code> and define</p>
<pre><code>fm{#}::LaTeXForm("{f_{-}}").
fp{#}::LaTeXForm("{f_{+}}").
</code></pre>
<p>To expand, use</p>
<pre><code>substitute(_, $\commutator{A??}{B??} -> A?? B?? - B?? A??$);
</code></pre>
<p>Does that help?</p>
General questionshttp://cadabra.science/qa/1093/is-it-possible-to-use-as-indices-%26how-to-define-a-commutator?show=1094#a1094Sun, 24 Mar 2019 08:10:36 +0000Answered: Can I use any Greek alphabet as a spinor?
http://cadabra.science/qa/1088/can-i-use-any-greek-alphabet-as-a-spinor?show=1089#a1089
<p>If you declare <code>\xi</code> to be a <code>Spinor</code> too, it should work.</p>
General questionshttp://cadabra.science/qa/1088/can-i-use-any-greek-alphabet-as-a-spinor?show=1089#a1089Thu, 21 Mar 2019 11:14:54 +0000some things about "substitute"
http://cadabra.science/qa/1084/some-things-about-substitute
<p>I want to achieve following rule</p>
<pre><code>...a b c d...->c d... ...a b
</code></pre>
<p>I have tried function <code>substitute</code>, but I have no idea how to achieve it. My recent work need this operation. Are there any suggestions about it?</p>
<p>For example, everything is <code>NonCommuting</code> and <code>depends \partial{#}</code> in following formula<br>
$$ <br>
a b \partial_{\mu} c d <br>
$$</p>
<p>I must exchange $a b$ with $ \partial_{\mu} c d $ to get</p>
<p>$$ <br>
\partial_{\mu} {c} d a b<br>
$$</p>
<p>then use <code>substitute</code> or <code>integrate_by_parts</code> to get </p>
<p>$$<br>
- c \partial_{\mu}(d a b)<br>
$$</p>
<p>I am trapped in this point now. </p>
General questionshttp://cadabra.science/qa/1084/some-things-about-substituteTue, 19 Mar 2019 14:41:35 +0000Answered: How to use \dagger ?
http://cadabra.science/qa/1071/how-to-use-dagger?show=1072#a1072
<p>We are in the process of making this properly supported, but in the meantime, give this function a shot (you need to build Cadabra from source for this, the functionality is not yet in any of the binary packages):</p>
<pre><code>def expand_conjugate(ex):
tst:= (A??)^{\dagger};
for node in ex:
if tst.matches( node ):
rep=$P$
lst=[]
for prod in node["\\prod"]:
for factor in prod.factors():
lst.append($ @(factor) $)
for factor in list(reversed(lst)):
rep.top().append_child($ @(factor)^{\dagger} $)
rep.top().name=r"\prod"
node.replace(rep)
return ex
</code></pre>
<p>If you stick the above in a cell and evaluate it, you can then do</p>
<pre><code>\dagger::Symbol;
ex:= (A B C)^{\dagger} + Q + (D E)^{\dagger};
expand_conjugate(ex);
</code></pre>
<p>to produce</p>
<p>$$C^{\dagger} B^{\dagger} A^{\dagger} + Q + E^{\dagger} D^{\dagger}$$</p>
<p>There will be better support for generic conjugation operations in Cadabra soon.</p>
<p>For the other two lines, try simple substitution with a rule of the type</p>
<pre><code>rl:= { (A?^{\dagger})^{\dagger} = A?,
( (A??)^{\dagger} )^{\dagger} = A??,
A?^{\dagger} A? = 1,
A? A^{\dagger} = 1,
(A??)^{\dagger} A?? = 1,
A?? (A??)^{\dagger} = 1 };
</code></pre>
<p>You can then do e.g.</p>
<pre><code>\dagger::Symbol;
{A,B,U}::NonCommuting;
ex:= ( U^{\dagger} )^{\dagger} + U^{\dagger} U
+ (A B)^{\dagger} + ( (A B)^{\dagger} )^{\dagger};
substitute(ex, rl);
</code></pre>
<p>Hope this helps.</p>
General questionshttp://cadabra.science/qa/1071/how-to-use-dagger?show=1072#a1072Sun, 17 Mar 2019 15:19:13 +0000Answered: NameError: name 'dsolve' is not defined At: <string>(7)
http://cadabra.science/qa/1067/nameerror-name-dsolve-is-not-defined-at-string-7?show=1069#a1069
<p>You need to </p>
<pre><code>from cdb.sympy.solvers import *
</code></pre>
<p>before this works. Requires a fairly recent pull from git, this functionality is not yet in any of the binary distributions. You do not need <code>import sympy</code>, that's already done for you by Cadabra.</p>
General questionshttp://cadabra.science/qa/1067/nameerror-name-dsolve-is-not-defined-at-string-7?show=1069#a1069Sat, 16 Mar 2019 09:22:56 +0000Sort product with symbols
http://cadabra.science/qa/1064/sort-product-with-symbols
<p>Hey, I have been working for a few hours now with substitute and it behaves perfectly so far! <br>
However, now that symbols which were initially indices appear in the main expression, there seems to be a problem with sort product. I am attaching below a sample piece of code:</p>
<pre><code>{\dagger}::Symbol.
{a,b,c,\alpha,\beta,\gamma}::Symbol;
{P^{\dagger}_{a? \alpha?}, K_{a? b?}}::NonCommuting.
{a?, x_{a?},P^{\dagger}_{a? \alpha?}, K_{a? b?}}::SortOrder;
ex:=K_{a b} a x_{a} P^{\dagger}_{b \alpha};
sort_product(_);
</code></pre>
<p>In this case the expression remains unchanged, although the c-numbers a and x_a should be taken to the left. Am I missing something?</p>
<p>Thank you!</p>
General questionshttp://cadabra.science/qa/1064/sort-product-with-symbolsWed, 13 Mar 2019 10:44:30 +0000Answered: How to bypass triple index error for symbols?
http://cadabra.science/qa/1037/how-to-bypass-triple-index-error-for-symbols?show=1062#a1062
<p>I have pushed a fix for this to github master just now. It took a little while longer than planned as this was probably the first time such expressions got tested properly, and in that process I ran into a subtle other <code>substitute</code> bug which I wanted to fix as well. </p>
<p>Let me know if this does what you need (or not, in which case I'll be happy to make more changes/fixes).</p>
General questionshttp://cadabra.science/qa/1037/how-to-bypass-triple-index-error-for-symbols?show=1062#a1062Tue, 12 Mar 2019 19:49:38 +0000Examles of using Cadabra for superspace calculations.
http://cadabra.science/qa/1033/examles-of-using-cadabra-for-superspace-calculations
<p>I am trying to use a program for computation in superspace. Unfortunately, this raises many questions. I am sure that many people have already done such calculations. Can someone send examples of such calculations? For example, how the action of covariant derivatives is realized and the chiral superfield is described.</p>
General questionshttp://cadabra.science/qa/1033/examles-of-using-cadabra-for-superspace-calculationsFri, 01 Feb 2019 13:47:09 +0000Answered: Curved and Flat Indices
http://cadabra.science/qa/1031/curved-and-flat-indices?show=1032#a1032
<p>Those are just names; the full form of that first property is</p>
<pre><code> {\mu,\nu,\rho}::Indices(name=curved, position=fixed).
</code></pre>
General questionshttp://cadabra.science/qa/1031/curved-and-flat-indices?show=1032#a1032Thu, 31 Jan 2019 14:36:20 +0000Answered: Please show a simple example showing difference b/w Indices(curved) and Indices(flat).
http://cadabra.science/qa/1029/simple-example-showing-difference-indices-curved-indices?show=1030#a1030
<p>Read the chapter on indices in the reference manual,</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_indices.html">https://cadabra.science/notebooks/ref_indices.html</a></p>
<p>Hope that helps; if it doesn't, reply to this and I'll make another attempt.</p>
General questionshttp://cadabra.science/qa/1029/simple-example-showing-difference-indices-curved-indices?show=1030#a1030Tue, 29 Jan 2019 10:00:19 +0000Answered: Substitute Christoffel2nd into Dual Riemann tensor
http://cadabra.science/qa/1027/substitute-christoffel2nd-into-dual-riemann-tensor?show=1028#a1028
<p>The steps should be</p>
<pre><code>substitute(uDualRiemann, lRieman);
substitute(uDualRiemann, Riemann);
substitute(uDualRiemann,Christoffel2nd);
</code></pre>
<p>The 1st line rewrites the Riemann with all lower indices in terms of one with the first index raised. The 2nd line substitutes the definition of the Riemann in terms of Christoffel symbols. And then the 3rd line rewrites the Christoffel symbols in terms of derivatives of the metric.</p>
General questionshttp://cadabra.science/qa/1027/substitute-christoffel2nd-into-dual-riemann-tensor?show=1028#a1028Sun, 27 Jan 2019 11:41:46 +0000Answered: Correlation functions, Wick theorem and summation
http://cadabra.science/qa/1012/correlation-functions-wick-theorem-and-summation?show=1018#a1018
<p>I am not sure exactly which summation problem you are trying to solve; maybe you can give a bit more detail?</p>
<p>For the Wick story, here's a bit of code I put together a while ago which may help you get things implemented. It basically gives you a <code>contract</code> function which takes a product of fields and replaces all pairs with propagators. You'll need to expand this of course to do real world problems but the gist of the solution is in here.</p>
<p>First, you need something that takes a list of numbers and returns all possible ways in <br>
which you can pair numbers:</p>
<pre><code>def all_pairs(lst):
if len(lst) < 2:
yield []
return
else:
a = lst[0]
for i in range(1,len(lst)):
pair = (a,lst[i])
for rest in all_pairs(lst[1:i]+lst[i+1:]):
yield [pair] + rest
</code></pre>
<p>That's just a bit of standard Python, nothing Cadabra-specific. Then you need something that takes a cadabra expression and does the contractions in there:</p>
<pre><code>def contract(ex):
amp:=0.
L=list(range(len(ex)))
for c in all_pairs(L):
diag:=1;
for p in c:
a1=ex[p[0]][0]
a2=ex[p[1]][0]
diag *= $G( @(a1) - @(a2) )$
amp += diag
return amp
</code></pre>
<p>Hopefully this makes it clear how to take Cadabra expressions apart and build new ones from the pieces. Then the following works:</p>
<pre><code>ex:=\phi(x_1) \phi(x_2) \phi(x_3) \phi(x_4);
contract(ex);
</code></pre>
<p>gives</p>
<p>$$G\left(x_{1}-x_{2}\right) G\left(x_{3}-x_{4}\right)+G\left(x_{1}-x_{3}\right) G\left(x_{2}-x_{4}\right)+G\left(x_{1}-x_{4}\right) G\left(x_{2}-x_{3}\right)$$</p>
<p>For any serious work you'll probably have to rewrite the <code>all_pairs</code> function so that it is not recursive.</p>
General questionshttp://cadabra.science/qa/1012/correlation-functions-wick-theorem-and-summation?show=1018#a1018Sat, 12 Jan 2019 14:13:48 +0000Answered: whenever make Cadabra do lengthy calculations, I always get error on output
http://cadabra.science/qa/1009/whenever-cadabra-lengthy-calculations-always-error-output?show=1010#a1010
<p>You'll have to make this a bit more specific. Can you email me (info@cadabra.science) a notebook that fails in this way (preferably as short as possible)? </p>
General questionshttp://cadabra.science/qa/1009/whenever-cadabra-lengthy-calculations-always-error-output?show=1010#a1010Wed, 02 Jan 2019 17:42:33 +0000Answered: collect_factors(_) for Symbol indices
http://cadabra.science/qa/998/collect_factors-_-for-symbol-indices?show=999#a999
<p>It should, it's a bug introduced with tidying up some pattern matching functions. I have just pushed a fix for this to github. Thanks for reporting.</p>
General questionshttp://cadabra.science/qa/998/collect_factors-_-for-symbol-indices?show=999#a999Mon, 03 Dec 2018 15:02:11 +0000Answered: Calculating determinants and traces
http://cadabra.science/qa/951/calculating-determinants-and-traces?show=991#a991
<p>There's a <code>Determinant</code> property now which you can use together with <code>complete</code> to compute determinants, as in <a rel="nofollow" href="https://cadabra.science/manual/Determinant.html">https://cadabra.science/manual/Determinant.html</a> .</p>
General questionshttp://cadabra.science/qa/951/calculating-determinants-and-traces?show=991#a991Fri, 23 Nov 2018 21:47:11 +0000Answered: Simple example showing differences between position=free, fixed and independent
http://cadabra.science/qa/937/example-showing-differences-between-position-independent?show=990#a990
<p>See the updated chapter 1.4 of the reference guide, <a rel="nofollow" href="https://cadabra.science/notebooks/ref_indices.html">https://cadabra.science/notebooks/ref_indices.html</a> .</p>
General questionshttp://cadabra.science/qa/937/example-showing-differences-between-position-independent?show=990#a990Fri, 23 Nov 2018 16:14:47 +0000Answered: Multiplying \sqrt{2} by 1/\sqrt{2} crashes the kernel unexpectedly
http://cadabra.science/qa/983/multiplying-sqrt-by-sqrt-2-crashes-the-kernel-unexpectedly?show=984#a984
<p>No, this is a bug. You'd be surprised how many computations can be done without ever encountering this one... Will fix, thanks.</p>
General questionshttp://cadabra.science/qa/983/multiplying-sqrt-by-sqrt-2-crashes-the-kernel-unexpectedly?show=984#a984Mon, 19 Nov 2018 21:17:52 +0000Answered: AntiCommuting/SelfAntiCommuting only for different indices
http://cadabra.science/qa/977/anticommuting-selfanticommuting-only-different-indices?show=979#a979
<p>You would first declare the $a$ and $a^\dagger$ operators to be anti-commuting among themselves, so</p>
<pre><code>{n,m,p,q}::Indices(position=free);
a_{n}::SelfAntiCommuting;
ad_{n}::SelfAntiCommuting;
ad_{n}::LaTeXForm("a^\dagger").
</code></pre>
<p>where the last line is just to make the <code>ad_{n}</code> print nicely. Then ensure that the default is for daggered and non-daggered operators to be non-commuting,</p>
<pre><code>{a_{n}, ad_{m}}::NonCommuting;
</code></pre>
<p>Now the only thing you need to do is to decide what you want to do with expressions which involve $a$ and $a^\dagger$. In many cases, the logic is to 'move' all $a$ to the far right of an expression (so they can annihilate a vacuum state on which they act). You can do that with the rule</p>
<pre><code>\delta_{m n}::KroneckerDelta;
rl:= a_{m} ad_{n} -> - ad_{n} a_{m} + \delta_{n m};
</code></pre>
<p>You then apply this rule repeatedly to an expression, distributing products at every step and eliminating Kronecker deltas. If you want you can do this automatically at every step of a calculation, by sticking that logic into the <code>post_process</code> function. Example:</p>
<pre><code>def post_process(ex):
# move all a operators to the right
converge(ex):
substitute(ex, rl)
distribute(ex)
eliminate_kronecker(ex)
sort_product(ex)
collect_terms(ex)
</code></pre>
<p>If you now enter e.g. the expression</p>
<pre><code>ex:= a_{n} ad_{p} a_{m} ad_{m} a_{n};
</code></pre>
<p>you get the answer</p>
<p>$$ -a^\dagger_m a_m a_p + \delta_{m m} a_p .$$</p>
<p>Hope this helps.</p>
General questionshttp://cadabra.science/qa/977/anticommuting-selfanticommuting-only-different-indices?show=979#a979Mon, 12 Nov 2018 20:54:18 +0000Answered: drop_weight before distribute
http://cadabra.science/qa/954/drop_weight-before-distribute?show=955#a955
<p>The logic here is intentional: <code>drop_weight</code> only acts on terms with a well-defined weight, and the $\epsilon (\epsilon^3 + 5)$ term is not of that type. So at the moment the answer is 'no'.</p>
<p>However, if your problem is that doing <code>distribute</code> is going to mess up too many other terms, you can try zooming into the expression and only distributing terms which match a certain pattern. E.g.</p>
<pre><code>\epsilon::Weight(label=field, value=1);
Exp:=(A+B)*\epsilon**2+\epsilon*(\epsilon**3+5);
zoom(_, $\epsilon Q??$);
distribute(_);
unzoom(_);
drop_weight(_, $field=4$);
</code></pre>
<p>would produce $(A+B)\epsilon^2 + 5\epsilon$, with the brackets in the first term intact.</p>
General questionshttp://cadabra.science/qa/954/drop_weight-before-distribute?show=955#a955Mon, 15 Oct 2018 10:09:53 +0000Answered: Defining the Rarita-Schwinger action: Action outputs 0
http://cadabra.science/qa/898/defining-the-rarita-schwinger-action-action-outputs-0?show=899#a899
<p>It's mostly an issue with not putting brackets at the right places. While Cadabra uses TeX notation, you sometimes have to be a little more explicit than strictly necessary in TeX, in order to avoid ambiguity. So you have to write e.g.</p>
<pre><code>\bar{\psi_{\mu}}
</code></pre>
<p>so that it is clear to Cadabra that the <code>\psi_{\mu}</code> is an 'argument' of <code>\bar</code>. Ditto for <code>\partial</code>, which you need to write as</p>
<pre><code>\partial_{\nu}{ \psi_{\rho} }
</code></pre>
<p>so that the <code>\psi_{\rho}</code> explicitly becomes an 'argument' of <code>\partial</code>. In your example, the <code>\partial_{\nu}\psi_{\rho}</code> was interpreted as a derivative acting on nothing, multiplied with <code>\psi_{\rho}</code>, giving nothing.</p>
<p>Here's a tidied-up version which works:</p>
<pre><code>#Rarita-Scwhinger Action
def post_process(ex):
sort_product(ex)
eliminate_kronecker(ex)
canonicalise(ex)
collect_terms(ex)
{\mu,\nu,\rho}::Indices(position=independent);
x::Coordinate;
\Gamma{#}::GammaMatrix(metric=\eta);
\eta_{\mu\nu}::Metric;
\partial{#}::Derivative;
\psi_{\mu}::Spinor;
\bar{#}::DiracBar;
\psi_{\mu}::Depends(x);
S:=\int{\bar{\psi_{\mu}} \Gamma^{\mu\nu\rho} \partial_{\nu}{\psi_{\rho}} }{x};
</code></pre>
<p>I have fixed a few typos and also changed the index type to 'independent' to prevent Cadabra from raising/lowering index pairs (usually better for susy computations, as you can then keep all indices on the Gamma's upstairs and more easily convert them using vielbeine).</p>
General questionshttp://cadabra.science/qa/898/defining-the-rarita-schwinger-action-action-outputs-0?show=899#a899Mon, 20 Aug 2018 10:03:08 +0000Answered: Partial derivative of exp()
http://cadabra.science/qa/895/partial-derivative-of-exp?show=896#a896
<p>This is something somewhere in the middle between an abstract and a component computation, and I haven't yet settled completely on what is the best way to handle this. For the time being I would suggest you use a simple substitution rule, e.g.</p>
<pre><code>\partial{#}::PartialDerivative;
test:=\partial_{\mu}{\exp(i*x^{\lambda}*k_{\lambda})};
rl:= \partial_{\mu}{ \exp( A?? ) } -> \exp( A?? ) \partial_{\mu}{ A?? };
substitute(test, rl);
product_rule(test);
substitute(test, $\partial_{\mu}{x^{\lambda}} -> \delta_{\mu}^{\lambda}$ );
unwrap(test);
</code></pre>
<p>That gets you almost there, but <code>eliminate_kronecker</code> which you would now want to use cannot handle the duplicate dummy index pair. So you'll need another substitution to get rid of the Kronecker delta.</p>
<p>Good example though, will see if we can make this work more easily.</p>
General questionshttp://cadabra.science/qa/895/partial-derivative-of-exp?show=896#a896Fri, 17 Aug 2018 09:22:45 +0000Answered: Is number_of_terms deprecated?
http://cadabra.science/qa/892/is-number_of_terms-deprecated?show=893#a893
<p>Yes, use standard Python <code>len</code>:</p>
<pre><code>ex:=A+B+C;
len(ex);
</code></pre>
<p>shows '3'.</p>
General questionshttp://cadabra.science/qa/892/is-number_of_terms-deprecated?show=893#a893Thu, 16 Aug 2018 07:03:49 +0000Answered: How to evaluate components of covariant derivative
http://cadabra.science/qa/885/how-to-evaluate-components-of-covariant-derivative?show=887#a887
<p>Yes you will need to determine the components of the metric and Christoffel symbols first, following e.g. the Schwarzschild tutorial notebook. You then need to expand your covariant derivatives into partial derivatives and Christoffels. You can do that with a simple substitution rule if you only have vectors and co-vectors, or you can use a more generic routine to do arbitrary tensors; see the example at the bottom of</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_programming.html">https://cadabra.science/notebooks/ref_programming.html</a></p>
<p>for more on that. This is something that will become available in the form of a package in 2.2.2 or 2.2.4.</p>
General questionshttp://cadabra.science/qa/885/how-to-evaluate-components-of-covariant-derivative?show=887#a887Sun, 12 Aug 2018 09:00:34 +0000Answered: Operator acting on tensors
http://cadabra.science/qa/879/operator-acting-on-tensors?show=880#a880
<p>Adding indices to object wildcards is not supported because there are very few cases where that actually makes much sense. The problem is that, if your rule had worked, it would also match</p>
<pre><code> met{ A_{b} }{ B_{b} }
met{ A_{b c d} }{ B_{c} }
</code></pre>
<p>and so on. You then almost always want to have control over where the extra $a$ index would need to be added (at the beginning of the set? at the end? in the middle?) and the notation which you wanted to use does not leave any way to specify that location. </p>
<p>So instead, you will need to make a rule which does not take an arbitrary object, but something which has the index structure spelled out. If you had in mind just to act on symbols $V$ and $W$, the rule</p>
<pre><code>Expmet:= met{X?}{Y?} -> X?_{a} Y?_{a};
</code></pre>
<p>would work. This will apply to your <code>met{V}{W}</code> case, but will not apply to any of the cases at the top of this reply. You could, however, write e.g.</p>
<pre><code>Expmet2:= met{ X?_{b} }{ Y?_{b} } -> X?_{b a} Y?_{a b};
</code></pre>
<p>or similar. That rule would allow you to do</p>
<pre><code>{a,b,c,d}::Indices;
ex:= met{ A_{c} }{ B_{c} };
exmet:= met{ X?_{b} }{ Y?_{b} } -> X?_{b a} Y?_{a b} ;
substitute(ex, exmet);
</code></pre>
<p>Hope the logic is clear.</p>
<p>So <strong>TL;DR</strong>: object patterns (patterns with '<code>??</code>' attached) are very brute force hammers, not always suitable when name patterns (patterns with just '<code>?</code>') will do.</p>
<p>(In addition, your example triggered a parsing bug that led to the indices being put on the product, not on the individual tensors, but that's a different story).</p>
General questionshttp://cadabra.science/qa/879/operator-acting-on-tensors?show=880#a880Sat, 11 Aug 2018 10:15:16 +0000Answered: How to evaluate the tensor of energy momentum for provided metric anzatz and 4-velocity
http://cadabra.science/qa/873/evaluate-energy-momentum-provided-metric-anzatz-velocity?show=874#a874
<p>Combine the rules for <code>u</code> and <code>g</code> into one call to <code>evaluate</code>, as in</p>
<pre><code>evaluate(T, u+g, rhsonly=True);
</code></pre>
General questionshttp://cadabra.science/qa/873/evaluate-energy-momentum-provided-metric-anzatz-velocity?show=874#a874Thu, 09 Aug 2018 16:34:53 +0000Answered: Code for general Einstein field equations with diagonal metric anzatc
http://cadabra.science/qa/870/general-einstein-field-equations-with-diagonal-metric-anzatc?show=871#a871
<p>Thanks for reporting this. The main issue is a bug in computing dependencies of expressions like <code>exp(F(r))</code>, which fail to figure out that this depends on <code>r</code>. I have just pushed a fix to github which solves this (your notebook then reproduces the Ricci tensor/scalar results in that PDF file). </p>
<p>The last error (when computing the Einstein tensor) is something weird in the bridge to sympy. Will look into that.</p>
General questionshttp://cadabra.science/qa/870/general-einstein-field-equations-with-diagonal-metric-anzatc?show=871#a871Wed, 08 Aug 2018 10:25:13 +0000Answered: Unwrap applied on expresion with partial derivative and two single variable functions
http://cadabra.science/qa/854/applied-expresion-partial-derivative-variable-functions?show=855#a855
<p>It's a bug :-( That is to say, your code should have read</p>
<pre><code>{x,y}::Coordinate.
\partial{#}::PartialDerivative.
f::Depends(x).
g::Depends(y).
ex:=\partial_{x}{A*f*g};
unwrap(_);
ex:=\partial_{y}{A*f*g};
unwrap(_);
</code></pre>
<p>(changed the two <code>Depends</code> lines) but even then it would produce the wrong answer.</p>
<p>This got introduced in the 1.x -> 2.x rewrite and somehow escaped the tests. I have just pushed a fix to github now which fixes this. </p>
General questionshttp://cadabra.science/qa/854/applied-expresion-partial-derivative-variable-functions?show=855#a855Mon, 06 Aug 2018 10:40:54 +0000Answered: how can i tell cadabra that the partial derivatives commute upto linear order while calculating Riemann Tensor
http://cadabra.science/qa/850/cadabra-partial-derivatives-commute-calculating-riemann?show=851#a851
<p>That one had me puzzled for a minute... The solution is to match your brackets: both terms should have an additional <code>}</code> to close the argument of the outmost derivative. So</p>
<pre><code>\partial{#}::PartialDerivative;
c1:= \partial_{\alpha}{\partial_{\beta}{h_{\mu \nu}}} =
\partial_{\beta}{\partial_{\alpha}{h_{\mu \nu}}};
</code></pre>
<p>And to answer the question in the subject: you can then make these terms equal with a call to <code>canonicalise(c1)</code>.</p>
General questionshttp://cadabra.science/qa/850/cadabra-partial-derivatives-commute-calculating-riemann?show=851#a851Wed, 01 Aug 2018 19:32:20 +0000Answered: Exponential series (or string type to expression type)
http://cadabra.science/qa/835/exponential-series-or-string-type-to-expression-type?show=836#a836
<p>That's easy: you can create a Cadabra expression object from a string by creating an <code>Ex</code> object with the string as argument. So make your last line read</p>
<pre><code>return Ex(expOutput)
</code></pre>
<p>and the result will be a Cadabra expression. </p>
<p>Should probably go into the reference guide, thanks for reminding me ;-)</p>
General questionshttp://cadabra.science/qa/835/exponential-series-or-string-type-to-expression-type?show=836#a836Tue, 24 Jul 2018 17:22:10 +0000Answered: Edit the output
http://cadabra.science/qa/823/edit-the-output?show=824#a824
<p>No, you can't, but that's a deliberate decision, as cutting and pasting makes your<br>
notebook very unreproducible (you cannot change something at the top and have the<br>
effects of that change automatically propagate to the remainder). But there is a better<br>
(IMHO) way to do something with a similar effect. I have started writing something more about this a chapter of the new reference manual, see</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_selecting.html">https://cadabra.science/notebooks/ref_selecting.html</a></p>
General questionshttp://cadabra.science/qa/823/edit-the-output?show=824#a824Sat, 14 Jul 2018 16:22:30 +0000Answered: Variable can be handled like values?
http://cadabra.science/qa/813/variable-can-be-handled-like-values?show=814#a814
<p>Yes, just make sure that you declare <code>z</code> to be a Coordinate, so add as your first line</p>
<pre><code>z::Coordinate;
</code></pre>
<p>and then all works as you expected.</p>
General questionshttp://cadabra.science/qa/813/variable-can-be-handled-like-values?show=814#a814Tue, 10 Jul 2018 20:18:09 +0000Answered: How can I implement cyclicity of trace?
http://cadabra.science/qa/729/how-can-i-implement-cyclicity-of-trace?show=802#a802
<p>Not perfect... but helpful.</p>
<p>A time ago I was trying something related to your question. After a while of looking on the web (and asking... just like you!) I came out with the following: define a circular function.</p>
<p>Let $a$ and $b$ be noncommuting, but distributable</p>
<pre><code>{a,b}::NonCommuting.
{a,b}::Distributable.
def post_process(ex):
expand_power(ex)
distribute(ex)
</code></pre>
<p>I define the function</p>
<pre><code>def isCircular(arr1, arr2):
return arr1 in arr2+' '+arr2
</code></pre>
<p>and a expression to test</p>
<pre><code>expr := (a + b)**2;
</code></pre>
<p>The trick is now to convert this to a string, split it, and compare term by term if they are circular. <strong>NOTE:</strong> blank spaces before and after the plus sign inside the <code>split</code> method.</p>
<pre><code>list = str(expr)
list = str(expr).split(' + ')
list;
for i in range(len(list)):
for j in range(i+1,len(list)):
if isCircular( list[i], list[j]):
list[j] = list[i]
list;
</code></pre>
<p>Then, convert it back to a <em>cadabra</em> expression to finally simplify. <strong>NOTE:</strong> the <code>newexpr</code> is initalised as an empty expression, it is <em>not</em> a single double quote, but double single quotes. </p>
<pre><code>newexpr = '';
for word in list:
newexpr = newexpr + ' + ' + word
;
cab_expr = Ex(newexpr)
collect_terms(cab_expr);
</code></pre>
<p>I tried something like <code>expr := (a b + b a)**2;</code> and the result is almost there! It could be a starting point!!!</p>
<p>Cheers.</p>
General questionshttp://cadabra.science/qa/729/how-can-i-implement-cyclicity-of-trace?show=802#a802Wed, 04 Jul 2018 09:51:43 +0000Answered: Gamma_5 matrix
http://cadabra.science/qa/783/gamma_5-matrix?show=800#a800
<p>If you're working on four dimensions, $\gamma^5$ is proportional to the product of the four (elemental) gamma's. Therefore you can define something like</p>
<pre><code>{s,r,l,k,m,n,p}::Indices(vector);
{s,r,l,k,m,n,p}::Integer(0..3);
\Gamma_{#}::GammaMatrix(metric=\delta);
e_{\mu\nu\lambda\rho}::EpsilonTensor(delta=\delta);
\delta_{m n}::KroneckerDelta;
g5 := e_{l m n p} \Gamma^{l m n p};
</code></pre>
<p>You have to normalise this definition accordingly. </p>
<p>Remember that <em>Cadabra</em> has a definition for the imaginary number</p>
<pre><code>i::ImaginaryI;
</code></pre>
General questionshttp://cadabra.science/qa/783/gamma_5-matrix?show=800#a800Tue, 03 Jul 2018 15:30:11 +0000