Cadabra Q&A  Recent questions and answers
http://cadabra.science/qa/qa
Powered by Question2Answer

Answered: Can not define Kronecker delta using Jupyter notebook
http://cadabra.science/qa/1667/cannotdefinekroneckerdeltausingjupyternotebook?show=1668#a1668
<p>Are you sure you are using a Cadabra kernel, not a standard Python kernel? What does</p>
<pre><code>print(__cdbkernel__.version)
</code></pre>
<p>show when you evaluate it in a cell?</p>
Bug reports
http://cadabra.science/qa/1667/cannotdefinekroneckerdeltausingjupyternotebook?show=1668#a1668
Wed, 17 Jun 2020 17:06:42 +0000

Answered: EpsilonTensor product not showing negative sign?
http://cadabra.science/qa/1665/epsilontensorproductnotshowingnegativesign?show=1666#a1666
<p>Cadabra's epsilon product will always produce a plus sign, irrespective of the signature of the metric. So you'll need to stick in that '1' by hand if your convention is different.</p>
General questions
http://cadabra.science/qa/1665/epsilontensorproductnotshowingnegativesign?show=1666#a1666
Tue, 16 Jun 2020 07:46:39 +0000

Defining a vector field.
http://cadabra.science/qa/1664/definingavectorfield
<p>Hello,</p>
<p>I am trying to define a vector fields $X=X^{\mu} \partial{x^{\mu}}$, $Y=Y^{\nu}\partial{x^{\nu}}$ and a one form $\omega=\omega_{\mu}dx^{\mu}$. I want to evaluate expressions such as $X[\omega(Y)]$. Need help/direction on how to do this.</p>
General questions
http://cadabra.science/qa/1664/definingavectorfield
Mon, 15 Jun 2020 18:01:09 +0000

Answered: Issue with brew link
http://cadabra.science/qa/1658/issuewithbrewlink?show=1659#a1659
<p>You can try that suggestion, but if that also fails, try <code>brew doctor</code> before you do anything else. That usually comes up with useful suggestions on broken installations.</p>
Installation trouble
http://cadabra.science/qa/1658/issuewithbrewlink?show=1659#a1659
Fri, 12 Jun 2020 15:33:11 +0000

Answered: bugs with sort_product&meld
http://cadabra.science/qa/1647/bugswithsort_product%26meld?show=1656#a1656
<p>The <code>meld</code> algorithm does not work with noncommuting/anticommuting objects yet, please wait a little longer.</p>
Bug reports
http://cadabra.science/qa/1647/bugswithsort_product%26meld?show=1656#a1656
Thu, 11 Jun 2020 08:13:12 +0000

Problem with rename_dummies and sort_product
http://cadabra.science/qa/1649/problemwithrename_dummiesandsort_product
<p>Hello,</p>
<p>With the input</p>
<pre><code>{a,b,c#}::Indices("a");
ex:=1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a};
vary(ex,$X_{a}>A_{a}$);
sort_product(ex);
rename_dummies(ex);
{\delta{#},Z{#},X{#},B{#},K{#}}::SortOrder;
ex:=1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a};
vary(ex,$X_{a}>Z_{a}$);
sort_product(ex);
rename_dummies(ex);
\delta{#}::Accent;
ex:=1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a};
vary(ex,$X_{a}>\delta{X_{a}}$);
sort_product(ex);
rename_dummies(ex);
</code></pre>
<p>The output I get is</p>
<pre><code>Attached property Indices(position=free) to {a, b, c#}.
1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a}
1/2 A_{a} B^{a b} X_{b} + 1/2 X_{a} B^{a b} A_{b} + K^{a} A_{a}
1/2 A_{a} B^{a b} X_{b} + 1/2 A_{b} B^{a b} X_{a} + A_{a} K^{a}
1/2 A_{a} B^{a b} X_{b} + 1/2 A_{a} B^{b a} X_{b} + A_{a} K^{a}
Attached property SortOrder to {\delta(#), Z(#), X(#), B(#), K(#)}.
1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a}
1/2 Z_{a} B^{a b} X_{b} + 1/2 X_{a} B^{a b} Z_{b} + K^{a} Z_{a}
1/2 Z_{a} X_{b} B^{a b} + 1/2 Z_{b} X_{a} B^{a b} + Z_{a} K^{a}
1/2 Z_{a} X_{b} B^{a b} + 1/2 Z_{b} X_{a} B^{a b} + Z_{a} K^{a}
Attached property Accent to \delta{#}.
1/2 X_{a} B^{a b} X_{b} + K^{a} X_{a}
1/2 \delta{X_{a}} B^{a b} X_{b} + 1/2 X_{a} B^{a b} \delta{X_{b}} + K^{a} \delta{X_{a}}
1/2 \delta{X_{a}} X_{b} B^{a b} + 1/2 \delta{X_{b}} X_{a} B^{a b} + \delta{X_{a}} K^{a}
1/2 \delta{X_{a}} X_{b} B^{a b} + 1/2 \delta{X_{b}} X_{a} B^{a b} + \delta{X_{a}} K^{a}
</code></pre>
<p>Is this behaviour expected? If yes, is there a way to obtain</p>
<pre><code> 1/2 Z_{a} X_{b} B^{a b} + 1/2 Z_{a} X_{b} B^{b a} + Z_{a} K^{a}
</code></pre>
<p>and</p>
<pre><code> 1/2 \delta{X_{a}} X_{b} B^{a b} + 1/2 \delta{X_{a}} X_{b} B^{b a} + \delta{X_{a}} K^{a}
</code></pre>
<p>instead?</p>
<p>In case it is really a bug, I run Cadabra 2.2.9 (built on April 7) on macOS High Sierra.</p>
Bug reports
http://cadabra.science/qa/1649/problemwithrename_dummiesandsort_product
Mon, 25 May 2020 11:02:13 +0000

Answered: Using function within expression
http://cadabra.science/qa/1644/usingfunctionwithinexpression?show=1645#a1645
<p>Not possible at the moment. The <code>@</code> operator which pulls a Python expression into a maths expression does not do any evaluation. It would be nice to be able to write</p>
<pre><code>Rule := {
x > @{ anything python that produces an Ex }
};
</code></pre>
<p>but at the moment that does not exist. </p>
General questions
http://cadabra.science/qa/1644/usingfunctionwithinexpression?show=1645#a1645
Thu, 21 May 2020 09:41:18 +0000

Answered: Problem with installation from github repository (Debian bullseye)
http://cadabra.science/qa/1638/probleminstallationfromgithubrepositorydebianbullseye?show=1642#a1642
<p>Can you please pull from github once more and try on Debian again? I have updated pybind11, which seems to have fixed the issue with attempting to link to the wrong python library. It builds here fine on a clean Debian bullseye installation.</p>
Installation trouble
http://cadabra.science/qa/1638/probleminstallationfromgithubrepositorydebianbullseye?show=1642#a1642
Tue, 19 May 2020 11:03:08 +0000

Answered: About data structure in Cadabra
http://cadabra.science/qa/1434/aboutdatastructureincadabra?show=1640#a1640
<p>This is now handled cleanly by Dom's new <code>meld</code> algorithm, which is now on github. Instead of <code>sort_product</code>, just use <code>meld(_)</code>. Documentation on this will be in a forthcoming paper.</p>
General questions
http://cadabra.science/qa/1434/aboutdatastructureincadabra?show=1640#a1640
Mon, 18 May 2020 20:35:57 +0000

Answered: Q: extending coordinate computation from configuration space to phase space
http://cadabra.science/qa/1632/extendingcoordinatecomputationconfigurationspacespace?show=1635#a1635
<p>Because the <code>a</code> index is not in the index set of which <code>h</code> forms part, the pattern in <code>h_flow</code> will not match when you try to substitute <code>h_flow</code> into <code>D1</code>. You can do</p>
<pre><code>D1 := \nabla{q_{h}};
</code></pre>
<p>and then the substitutes work. To make <code>evaluate</code> work, you need to declare that <code>q_{h}</code> depends on <code>x</code> and <code>y</code>,</p>
<pre><code>q_{h}::Depends(x,y);
</code></pre>
<p>After that things seem to work as intended (have not verified the result).</p>
General questions
http://cadabra.science/qa/1632/extendingcoordinatecomputationconfigurationspacespace?show=1635#a1635
Sat, 09 May 2020 16:57:19 +0000

Answered: all_contractions( ) is not defined?
http://cadabra.science/qa/1629/all_contractionsisnotdefined?show=1630#a1630
<p>This doesn't exist at the moment, as people had the wrong ideas about what this would do, and solving the problem properly is more complicated than you might think. In particular, it is quite nontrivial to take into account dimensiondependent identities between tensor monomials. There is ongoing work to get more general purpose algorithms in cadabra which handle this, but <code>all_contractions</code> does not have the highest priority at the moment.</p>
General questions
http://cadabra.science/qa/1629/all_contractionsisnotdefined?show=1630#a1630
Tue, 05 May 2020 20:18:15 +0000

Answered: Weird output when running through terminal.
http://cadabra.science/qa/1623/weirdoutputwhenrunningthroughterminal?show=1624#a1624
<p>What does the first line of output read when you start <code>cadabra2</code>, e.g.</p>
<pre><code> Cadabra 2.2.9 (build 2387.f0a2a51a62 dated 20200502)
</code></pre>
<p>?</p>
General questions
http://cadabra.science/qa/1623/weirdoutputwhenrunningthroughterminal?show=1624#a1624
Sun, 03 May 2020 09:54:40 +0000

Answered: Q: simple Cadabra coordinate computation
http://cadabra.science/qa/1618/qsimplecadabracoordinatecomputation?show=1621#a1621
<p>So as you already discovered, the following gives the form with $V$ unevaluated:</p>
<pre><code>{x, y}::Coordinate;
{i, j, k, l, m, n, h#}::Indices(values={x, y}, position=fixed);
\partial{#}::PartialDerivative;
g_{i j}::Metric.
g^{i j}::InverseMetric.
# HÃ©nonHeiles potential
V::Depends(x,y);
V := (x**2 + y**2)/2 + (x**2)*y  (y**3)/3;
# Ho is a constant: conservation of energy
metric := { g_{x x} = 2*(Ho  V), g_{y y} = 2*(Ho  V) };
complete(metric, $g^{i j}$);
Christoffel := \Gamma^{i}_{j k} = (1/2)*g^{i l}*( \partial_{k}{g_{l j}}
+ \partial_{j}{g_{l k}}
 \partial_{l}{g_{j k}} );
</code></pre>
<p>followed by</p>
<pre><code>evaluate(Christoffel, metric, rhsonly=True);
</code></pre>
<p>This produces e.g. $\Gamma^{x}{}_{x x}=2\partial_{y}V (2Ho  2V)^{1}$.</p>
<p>If you want that written out in terms of $x$ and $y$, you <em>probably</em> want that only for the derivative part. I would then do something like</p>
<pre><code>substitute(Christoffel, $\partial_{a?}{V} = \partial_{a?}{@(V)}$ )
map_sympy(Christoffel, 'simplify');
</code></pre>
<p>which produces precisely the result you quoted, $\Gamma^{x}{}_{x x} = x(2y+1) (2Ho2V)^{1}$. In the first line above, note how we 'pull in' the value of the expression <code>V</code> using <code>@(V)</code>. In Cadabra, there is a difference between 'python objects' and 'maths objects'. The things on the lefthand side of a <code>:=</code> symbol are python objects, and everything appearing on the righthand side is built from maths objects. You have to tell Cadabra when to make such substitutions, it won't automatically do that for you (with the advantage that you can keep $V$ in the overall factor $(2Ho2V)^{1}$ while writing out the derivative).</p>
<p>The last line above just uses 'sympy' to simplify the expression (cadabra does not have a lot of scalar computer algebra logic built in, but instead passes that on to 'sympy' or 'mathematica'). </p>
<p>Last comment: if you wanted to eliminate $V$ immediately, you can of course substitute</p>
<pre><code>substitute(metric, $V = @(V)$);
</code></pre>
<p>just before you <code>evaluate</code>.</p>
<p>Hope this helps; if not, please ask again.</p>
General questions
http://cadabra.science/qa/1618/qsimplecadabracoordinatecomputation?show=1621#a1621
Wed, 29 Apr 2020 21:16:56 +0000

Answered: Why am I getting "Free indices in different terms in a sum do not match" when I integrate by parts?
http://cadabra.science/qa/1613/gettingindicesdifferenttermsmatchwhenintegrateparts?show=1614#a1614
<p>The reason for that error message is that, as it stands in your code, the object <br>
$\delta(A_{\mu})$ does not have any free indices. That is because Cadabra by default 'absorbs' indices when you apply a function to a tensor. So $\delta(...)$ is seen as a function applied to $A_{\mu}$ and that has no indices.</p>
<p>To make $\delta(...)$ show these indices, you need to give it a property <code>IndexInherit</code> (or if you want to inherit other properties, like dependence on coordinates, you may want to use the catchall <code>Accent</code> property instead).</p>
<p>With that, your example becomes</p>
<pre><code>{\mu,\nu,\rho,\sigma}::Indices(position=free).
\partial{#}::Derivative.
\delta{#}::Accent.
FieldStrength := F_{\mu\nu} > \partial_{\mu}{A_\nu}  \partial_{\nu}{A_\mu};
Lagrangian := L > (1/4)F_{\mu\nu}F^{\mu\nu};
S := \int{L}{x}:
substitute(S,Lagrangian);
substitute(S,FieldStrength);
distribute(S);
vary(S, $A_{\mu} > \delta{A_{\mu}}$);
integrate_by_parts(S, $\delta{A_{\mu}}$);
sort_product(_);
canonicalise(_);
factor_out(S, $\delta{A^{\mu}}$);
</code></pre>
<p>to produce</p>
<p>$$ \frac{1}{4}\int \delta\left(A^{\mu}\right) \left(4\partial^{\nu}\left(\partial_{\nu}{A_{\mu}}\right)+4\partial^{\nu}\left(\partial_{\mu}{A_{\nu}}\right)\right) {\rm d}x$$</p>
General questions
http://cadabra.science/qa/1613/gettingindicesdifferenttermsmatchwhenintegrateparts?show=1614#a1614
Tue, 21 Apr 2020 18:10:50 +0000

Answered: No output  Running Cadabra 2 on WSL 2 [Ubuntu 18.04] using VS Code
http://cadabra.science/qa/1608/nooutputrunningcadabra2onwsl2ubuntu1804usingvscode?show=1610#a1610
<p>"Have you tried whether running it using Jupyter's own notebook server works?"</p>
<p>No, I had not done so.</p>
<p>While WSL 2 is a fully functional Linux OS, not an emulator, it is commandline only  there is no GUI desktop and no browser. With a addition of an Xserver on the Windows 10 side, such as VcXsrv, one can display matplotlib output, in a separate window, generated in VS Code running on WSL side.Which is more than sufficient for scientific computing using numpy/sympy/numba/etc.</p>
<p>[update in following comment]</p>
Installation trouble
http://cadabra.science/qa/1608/nooutputrunningcadabra2onwsl2ubuntu1804usingvscode?show=1610#a1610
Sun, 19 Apr 2020 23:24:49 +0000

Answered: Can indices be moved?
http://cadabra.science/qa/1605/canindicesbemoved?show=1606#a1606
<p>Declare your index positions <code>free</code> and use <code>lower_free_indices</code>:</p>
<pre><code>{m,n,p}::Indices(position=free);
ex:=A_{m p} B^{p n};
lower_free_indices(ex);
</code></pre>
<p>The word 'free' here refers to the index type <code>position=free</code>, not to the fact that they are uncontracted.</p>
General questions
http://cadabra.science/qa/1605/canindicesbemoved?show=1606#a1606
Thu, 09 Apr 2020 08:25:15 +0000

Answered: Bug in @unwrap for Cadabra 1.42
http://cadabra.science/qa/761/bugin%40unwrapforcadabra142?show=1601#a1601
<p>Fixed on github master now (finally...).</p>
Bug reports
http://cadabra.science/qa/761/bugin%40unwrapforcadabra142?show=1601#a1601
Tue, 07 Apr 2020 19:34:02 +0000

Answered: "unwrap" returns 0 if pushing anticommuting constant past a mixed object
http://cadabra.science/qa/1598/unwrapreturnspushingcommutingconstantpastmixedobject?show=1599#a1599
<p>Good one. Internally, when Cadabra cannot figure out how to commute two objects, an internal function somewhere returns '0', instead of '+1' or '1'. That zero should have made <code>unwrap</code> stop, but instead it just went ahead and then multiplied the resulting unwrapped expression with '0'. </p>
<p>Now fixed in github, can you give it a shot? It will leave that first expression untouched, because it cannot move <code>C</code> through <code>A F + G</code> without flipping that 2nd factor to <code>A F  G</code>, and it will not do that kind of thing. Hope that's ok for now.</p>
Bug reports
http://cadabra.science/qa/1598/unwrapreturnspushingcommutingconstantpastmixedobject?show=1599#a1599
Tue, 07 Apr 2020 19:16:24 +0000

Answered: Export file to pdf
http://cadabra.science/qa/1595/exportfiletopdf?show=1596#a1596
<p>From the notebook you can pick 'Export to standalone LaTeX', after which you can latex the resulting file just like any other. Images will be exported as <code>.png</code> files and included at the appropriate places (if you use any).</p>
General questions
http://cadabra.science/qa/1595/exportfiletopdf?show=1596#a1596
Sun, 05 Apr 2020 21:48:02 +0000

Answered: Installing CADABRA2
http://cadabra.science/qa/1588/installingcadabra2?show=1590#a1590
<p>You are building against python3.7 which you installed yourself, right? (since it fetches <code>libpython3.7m.a</code> from <code>/usr/local/lib</code>). </p>
<p>Moreover, you are lacking the shared libraries, since it tries to link to the <code>.a</code>, not the <code>.so</code>. That by itself won't work; you need to link against shared libraries in order to produce the Python <code>cadabra2.so</code> module.</p>
<p>Any chance you can just build against stock python3.6 which comes with Ubuntu 18.04? I just tried that on a clean 18.04 install and it works fine. If that's not an option for you, you'll need to figure out why your python 3.7 installation does not have the shared libraries.</p>
Installation trouble
http://cadabra.science/qa/1588/installingcadabra2?show=1590#a1590
Mon, 30 Mar 2020 10:59:00 +0000

Bugs with 'sort_product'
http://cadabra.science/qa/1587/bugswithsort_product
<p>When I use 'sort_product' in the following code</p>
<pre><code>{\mu,\nu,\rho,sigma}::Indices(vector).
a^{\mu}::SelfNonCommuting.
{a^{\mu},b^{\mu}}::NonCommuting.
\nabla{#}::Derivative.
tr{#}::Trace.
ex:=tr{a^{\mu}\nabla^{\nu}{a^{\mu}}b^{\nu}\nabla^{\rho}{a^{\rho}}};
sort_product(_);
sort_product(_);
</code></pre>
<p>I find that cadabra don't know where to stop. This bug is similar to <a rel="nofollow" href="https://cadabra.science/qa/1434/aboutdatastructureincadabra">this</a> and <a rel="nofollow" href="https://cadabra.science/qa/729/howcaniimplementcyclicityoftrace">this</a>.</p>
Bug reports
http://cadabra.science/qa/1587/bugswithsort_product
Fri, 27 Mar 2020 15:49:16 +0000

Answered: Issues with 'canonicalise'
http://cadabra.science/qa/1576/issueswithcanonicalise?show=1577#a1577
<p>Well spotted, thanks for reporting this. I have just pushed a fix to github that handles part of the problem (when the content of the trace is a simple tensor, not a sum or product). The problem was (and to some extent still is) that the symmetries did not make it 'out of' the trace. Will post here when a full solution is available.</p>
Bug reports
http://cadabra.science/qa/1576/issueswithcanonicalise?show=1577#a1577
Sat, 21 Mar 2020 21:08:23 +0000

Issues with 'integrate_by_parts'
http://cadabra.science/qa/1573/issueswithintegrate_by_parts
<p>I want to implement the following integration by parts</p>
<pre><code>\nabla{#}::Derivative.
{A,B,C}::Depends(\nabla{#}).
tr{#}::Trace.
ex:=\int{\tr{A}\tr{B\nabla{C}}};
integrate_by_parts(_,$C$);
</code></pre>
<p>I have a try</p>
<pre><code>substitute(_,$\tr{A??}\tr{B?? \nabla{C??}}>\tr{\nabla{A??}}\tr{B?? C??}\tr{A??}\tr{\nabla{B??} C??}$);
</code></pre>
<p>Is there is any simpler way to implement it?</p>
General questions
http://cadabra.science/qa/1573/issueswithintegrate_by_parts
Thu, 12 Mar 2020 15:35:28 +0000

Answered: How to know the properties of an object?
http://cadabra.science/qa/1564/howtoknowthepropertiesofanobject?show=1569#a1569
<p>You can query a property to see whether a pattern has been registered with it; in your example</p>
<pre><code>p = RiemannTensor.get($R_{a1 a2 a3 a4}$)
</code></pre>
<p>will set <code>p</code> to the corresponding <code>RiemannTensor</code> object (which, since it derives from <code>TableauSymmetry</code>, has methods such as <code>get_tab</code>, <code>is_simple_symmetry</code> etc...). If there is no associated property then <code>None</code> is returned.</p>
General questions
http://cadabra.science/qa/1564/howtoknowthepropertiesofanobject?show=1569#a1569
Mon, 24 Feb 2020 17:49:29 +0000

Answered: Installation problem on macOSMojave
http://cadabra.science/qa/1565/installationproblemonmacosmojave?show=1566#a1566
<p>What happens if you try to run <code>cadabraserver</code> ? It should produce some output and then sit there until you kill it, but it probably produces an error instead.</p>
Installation trouble
http://cadabra.science/qa/1565/installationproblemonmacosmojave?show=1566#a1566
Mon, 24 Feb 2020 06:55:42 +0000

Answered: How to sort by upper and lower indices?
http://cadabra.science/qa/1558/howtosortbyupperandlowerindices?show=1561#a1561
<p>Never mind, I solved it with</p>
<pre><code>{\gamma_{p? q?},\gamma^{p? q?}}::SortOrder()
</code></pre>
<p>But anyway, thanks for the quick response!</p>
General questions
http://cadabra.science/qa/1558/howtosortbyupperandlowerindices?show=1561#a1561
Fri, 21 Feb 2020 12:44:28 +0000

Answered: How to make integrands their own expressions?
http://cadabra.science/qa/1556/howtomakeintegrandstheirownexpressions?show=1557#a1557
<p>You are on the right track. If you do</p>
<pre><code>G := \int{ g(x) }{x};
H := \int{ h(x) }{x};
iG = G[0];
iH = H[0];
P := \int{ @(iG) @(iH) }{x};
</code></pre>
<p>it works as expected. The key is to <em>first</em> assign the integrand to a separate expression (and give it a new python name, like the <code>iG</code> above), and <em>then</em> pull that expression into the expression for <code>P</code>. It would be nice if you could skip line 3 & 4 and write instead</p>
<pre><code>G := \int{ g(x) }{x};
H := \int{ h(x) }{x};
P := \int{ @(G[0]) @(H[0]) }{x};
</code></pre>
<p>but the '@' operator only accepts simple python variable names at the moment, so this will not work.</p>
<p>If you are confused by this all, note that when you write</p>
<pre><code>\int{G[0] H[0]}{x}
</code></pre>
<p>then <code>G[0]</code> and <code>H[0]</code> are viewed as maths, not python. If you want to pull an expression, which you have previously given a python name (like the 'G' and 'H' above) into a maths expression, you need to use the <code>@(...)</code> operator.</p>
<p>Please ask again if it is still confusing. Cadabra makes a distinction between 'maths expressions' and 'python expressions', and that can be a bit daunting in the beginning.</p>
General questions
http://cadabra.science/qa/1556/howtomakeintegrandstheirownexpressions?show=1557#a1557
Wed, 12 Feb 2020 20:39:00 +0000

Answered: Issues with Trace
http://cadabra.science/qa/1554/issueswithtrace?show=1555#a1555
<p>Now fixed on github. The problem was that <code>collect_factors</code> would try to collect the trace expressions because it didn't correctly scan for free indices on those factors. </p>
General questions
http://cadabra.science/qa/1554/issueswithtrace?show=1555#a1555
Sun, 09 Feb 2020 20:52:26 +0000

Can I do Finsler geometry with Cadabra?
http://cadabra.science/qa/1553/canidofinslergeometrywithcadabra
<p>I'm working on an extension to General Relativity that uses Finsler geometry. The main difference is that a Finsler metric can depend not just on position, (denoted by $x^a$, say), but also on the tangent vector $y^a$ of a worldline passing through x. (Think of the generic $y^a$ as all possible velocities $dx^a(s)/ds$ of all worldlines that pass through $x$.)</p>
<p>In short, whereas the usual Riemannian metric is just positiondependent, i.e., $g_{ab}(x)$, the Finsler metric is something like $g_{ab}(x,y)$.</p>
<p>The Finsler metric is obtained from a scalar "fundamental function" $F = F(x,y)$, which is 1homogeneous in y, as follows:</p>
<p>$$g_{ab}(x,y) = 1/2 \partial^2 F^2 / \partial y^a \partial y^b$$</p>
<p>Later, to compute a generalized connections and curvatures, the $\partial y^a$ need to be used in expressions that also have ordinary derivatives $\partial x^a$. (The 2 kinds of derivative commute, so that's ok.)</p>
<p>So I need to be able to write derivatives wrt the $y^a$ variables, (and evaluate concrete expressions in these accordingly through SymPy), but then be able to match the a,b indices on the $y$'s onto the "$g$" on the LHS.</p>
<p>So,... can Cadabra2 handle this somehow?</p>
<p>Cheers.</p>
General questions
http://cadabra.science/qa/1553/canidofinslergeometrywithcadabra
Fri, 31 Jan 2020 09:02:13 +0000

Highlighted text almost invisible.
http://cadabra.science/qa/1552/highlightedtextalmostinvisible
<p>Hi Kasper. (Remember me? :)</p>
<p>I just installed Cadabra2 on openSUSE LEAP 15.1 but immediately encountered the following bug (or is it a feature?).</p>
<p>When attempting to highlight some text (intending to copy or delete it, or whatever), the text seemed to just disappear instead of being highlighted. After a while I realized it's because the highlighted text is actually white on a pale grey background, making it almost invisible.</p>
<p>I tried playing with the "highlight syntax" options, but failed to find anything applicable.<br>
Is there some other preferences setting elsewhere that would fix this? If not, then... how?</p>
<p>Kind regards.</p>
Bug reports
http://cadabra.science/qa/1552/highlightedtextalmostinvisible
Fri, 31 Jan 2020 09:01:21 +0000

Cadabra2gtk command not found on mac os x
http://cadabra.science/qa/1550/cadabra2gtkcommandnotfoundonmacosx
<p>I installed cadabra according to instructions and it says command not found.</p>
Installation trouble
http://cadabra.science/qa/1550/cadabra2gtkcommandnotfoundonmacosx
Thu, 23 Jan 2020 08:58:39 +0000

Answered: Import of commands from txt file to cnb
http://cadabra.science/qa/1544/importofcommandsfromtxtfiletocnb?show=1549#a1549
<p>Finally, I have sorted out things by generating the txt files with a list of commands appended by the line:</p>
<pre><code> #!/usr/local/bin/cadabra2
</code></pre>
<p>(therefore what would be a result of using in terminal "cadabra2cadabra example.cnb example.txt").</p>
<p>The last step for me was just running in a terminal:</p>
<pre><code>cadabra2 file.txt
</code></pre>
General questions
http://cadabra.science/qa/1544/importofcommandsfromtxtfiletocnb?show=1549#a1549
Thu, 16 Jan 2020 22:52:07 +0000

Importing a file with definitions
http://cadabra.science/qa/1541/importingafilewithdefinitions
<p>Happy new year, dear community.</p>
<p>I bother you so early this 2020 with a kind of silly question.</p>
<h2><strong>Question:</strong> How to import a file with definitions properly?</h2>
<h3>Explanation:</h3>
<p>I have on a folder two files, say <code>header.cnb</code> and <code>calculation.cnb</code>. In the <code>header</code> file I keep a lot of definition of expressions and functions, which will be used in <code>calculation</code>.</p>
<p>I try to import the <code>header</code> as (i.e. in the first lines of <code>calculation</code>)</p>
<pre><code>from header import *
</code></pre>
<p>And <em>worked!</em> (hurray), but not always. It seems to depend on whether I open <code>cadabra</code> from the application panel or the CLI... or even worst, it depends on the <code>pwd</code>!</p>
<p>Then I try</p>
<pre><code>import sys
sys.path.insert(0,r'/global/path/to/folder')
from header import *
</code></pre>
<p>and <em>worked!</em>... but again, it stop working on a next session.</p>
<p>Even try:</p>
<pre><code>import os
os.system("cadabra2 /home/oscar/Documents/LatexFiles/UTFSM/Papers/cadabragravity/tutorials/header.cnb")
</code></pre>
<p>and</p>
<pre><code>import os
os.system("cadabra2 header.cnb")
</code></pre>
<p>and</p>
<pre><code>import os,sys
scriptpath = "../folder/"
sys.path.append(os.path.abspath(scriptpath))
import header
</code></pre>
General questions
http://cadabra.science/qa/1541/importingafilewithdefinitions
Thu, 02 Jan 2020 08:37:19 +0000

Answered: Simplify code
http://cadabra.science/qa/1534/simplifycode?show=1537#a1537
<p>Follow the example in <a rel="nofollow" href="https://cadabra.science/qa/1274/replacealistofstatementswithacycle">a previous post</a></p>
<hr>
<p>It was a simple application of the same philosophy:</p>
<pre><code>for i in range(101):
LaTeXForm(Ex(r'z'+str(i)+r'{#}'), Ex(r'"z_{'+str(i)+r'}"') )
Weight(Ex(r'z'+str(i)+r'{#}'), Ex(r'label=field, value=1') )
ex := z1 z2 + z63;
keep_weight(ex, $field=2$);
</code></pre>
General questions
http://cadabra.science/qa/1534/simplifycode?show=1537#a1537
Mon, 30 Dec 2019 08:22:46 +0000

About untrace
http://cadabra.science/qa/1533/aboutuntrace
<p>using</p>
<pre><code>tr{#}::Trace.
\nabla{#}::Derivative.
{A,B}::Depends(\nabla{#}).
A::ImplicitIndex.
ex:=tr{\nabla{A} B};
untrace(_);
</code></pre>
<p>I want to get $B tr{\nabla{A}}$, but it's invalid. When I rewrite it to</p>
<pre><code>tr{#}::Trace.
\nabla{#}::Derivative.
{A,B}::Depends(\nabla{#}).
{\nabla{#},A}::ImplicitIndex.
ex:=tr{\nabla{A B}};
product_rule(_);
untrace(_);
</code></pre>
<p>'product_rule' become invalid. How to get the right result? i.e. $B tr{\nabla{A}}+\nabla{B} tr{A}$</p>
General questions
http://cadabra.science/qa/1533/aboutuntrace
Sun, 29 Dec 2019 01:55:46 +0000

Answered: question about untrace&ImaginaryI
http://cadabra.science/qa/1529/questionaboutuntrace%26imaginaryi?show=1531#a1531
<p>Now fixed in master on github.</p>
Bug reports
http://cadabra.science/qa/1529/questionaboutuntrace%26imaginaryi?show=1531#a1531
Sat, 28 Dec 2019 12:23:23 +0000

Parallelisable calculations  Possible?
http://cadabra.science/qa/1528/parallelisablecalculationspossible
<p>Hi community. Simple question (perhaps with nontrivial answer):</p>
<p>Is it possible to calculate in parallel with <code>cadabra</code>? Is there something like a magic operator?</p>
General questions
http://cadabra.science/qa/1528/parallelisablecalculationspossible
Fri, 27 Dec 2019 11:53:44 +0000

Answered: Evaluation from the CLI
http://cadabra.science/qa/1522/evaluationfromthecli?show=1523#a1523
<p>Set the <code>CADABRA_NO_UNICODE</code> environment variable (to anything nonempty).</p>
General questions
http://cadabra.science/qa/1522/evaluationfromthecli?show=1523#a1523
Thu, 26 Dec 2019 09:27:08 +0000

Answered: expand dummy indices
http://cadabra.science/qa/1508/expanddummyindices?show=1509#a1509
<p>You need to declare the <code>\mu</code> index to run over the range that you want, e.g.</p>
<pre><code>{\mu,\nu}::Indices(values={1,2,3,4}, position=fixed);
</code></pre>
<p>The <code>fixed</code> is there to tell cadabra that there is a distinction between upper and lower indices; for your problem that's not relevant. Then you can do</p>
<pre><code>ex:=A^{\mu} A_{\mu};
evaluate(ex);
</code></pre>
<p>to get what you want. </p>
<p>The <code>evaluate</code> algorithm can do much more, all having to do with evaluating tensor expressions in components, but if you do not tell it what the components are, it will just keep them as <code>A_{1}</code>, <code>A_{2}</code> and so on. If instead of the above you do e.g.</p>
<pre><code>ex:= A^{\mu} A_{\mu};
evaluate(ex, $A_{1} > x, A_{2} > x+y, A_{4}>c$);
</code></pre>
<p>you would get $x A^{1} + (x+y) A^{2} + c A^{4}$. And so on. </p>
General questions
http://cadabra.science/qa/1508/expanddummyindices?show=1509#a1509
Sat, 21 Dec 2019 16:11:09 +0000

Issues with vary
http://cadabra.science/qa/1503/issueswithvary
<p>Why will following code produce odd result?</p>
<pre><code>{\mu,\nu}::Indices(vector).
\Vt{#}::LaTeXForm("{\tilde{V}}").
ex:=\int{\Vt_{\mu}\Vt^{\mu}};
vary(_,$\Vt_{\mu}>\delta{\Vt_{\mu}}$);
</code></pre>
General questions
http://cadabra.science/qa/1503/issueswithvary
Sat, 21 Dec 2019 09:56:44 +0000

Answered: Difference between `:=` and `=`
http://cadabra.science/qa/1496/differencebetweenand?show=1497#a1497
<p>'<code>:=</code>' wants a mathematical expression on the righthand side, and then converts that to an <code>Ex</code> object, before it assigns it to the python symbol on the lefthand side.</p>
<p>'<code>=</code>' wants a python object on the righthand side.</p>
<p>So you can do</p>
<pre><code>ex := A_{m n};
</code></pre>
<p>but you cannot do</p>
<pre><code>ex = A_{m n};
</code></pre>
<p>because the righthand side of the latter expression is not python.</p>
<p>To suppress output, use a '<code>:</code>' to terminate the line when you use the '<code>:=</code>' form, or simply nothing if you use the '<code>=</code>' construction.</p>
General questions
http://cadabra.science/qa/1496/differencebetweenand?show=1497#a1497
Tue, 17 Dec 2019 14:52:11 +0000

Answered: Problems with linsolve
http://cadabra.science/qa/1494/problemswithlinsolve?show=1495#a1495
<p>Your <code>sympy</code> does not have <code>linsolve</code>, better upgrade it to something more recent.</p>
General questions
http://cadabra.science/qa/1494/problemswithlinsolve?show=1495#a1495
Tue, 17 Dec 2019 06:58:09 +0000

Answered: Issues with explicit_indices
http://cadabra.science/qa/1481/issueswithexplicit_indices?show=1482#a1482
<p>This happens because <code>explicit_indices</code> does not quite work the way you thought it would work. If you have</p>
<pre><code>{a,b,c,d}::Indices(vector);
A::ImplicitIndex(A^{a}_{b});
ex:= A A;
</code></pre>
<p>and then do</p>
<pre><code>explicit_indices(_);
</code></pre>
<p>you do <em>not</em> get $A^{a}{}_{b} A^{b}{}_{a}$, but rather $A^{a}{}_{b} A^{b}{}_{c}$. So it will <em>not</em> assume that an object which had no indices before the operation should have no free indices after the operation. The proper 'index free' notation of that would be using a trace, so something like</p>
<pre><code>tr{#}::Trace(indices=vector);
ex:= tr( A A );
explicit_indices(_);
</code></pre>
<p>in which case you do get $A^{a}{}_{b} A^{b}{}_{a}$.</p>
<p>Note also that <code>explicit_indices</code> does not automatically raise or lower indices; when you write</p>
<pre><code>F::ImplicitIndex(F_{\mu\nu});
</code></pre>
<p>you really literally mean that the symbol <code>F</code> in index free notation can be replaced with the symbol <code>F_{\mu\nu}</code> in indexfull notation. Making <code>explicit_indices</code> 'guess' about what to do with index raising/lowering is a definite nono for many of its applications using spinor variables, in which raising one index and lowering another can mean a sign flip (e.g. $\chi^{a}\lambda_{a} =  \chi_{a}\lambda^{a}$).</p>
General questions
http://cadabra.science/qa/1481/issueswithexplicit_indices?show=1482#a1482
Sat, 14 Dec 2019 11:48:28 +0000

Answered: How to collect similar terms?
http://cadabra.science/qa/1476/howtocollectsimilarterms?show=1477#a1477
<p>Use <code>sort_product</code> to bring the factors in the same order.</p>
<p>Cadabra2 does not support TeXmacs anymore; I don't use it myself and noone else asked for it, but supporting it would still require a nontrivial time commitment on my end.</p>
<p>There is no autocompletion as of yet, but it is on the todo list.</p>
General questions
http://cadabra.science/qa/1476/howtocollectsimilarterms?show=1477#a1477
Wed, 11 Dec 2019 09:52:37 +0000

Answered: Issues with exponentiation
http://cadabra.science/qa/1472/issueswithexponentiation?show=1474#a1474
<p>In addition, please note that a lot of the 'standard' simplification stuff in computer algebra (so the things that have nothing to do with tensor algebra) are offloaded to sympy; you can run its simplifier by simply using <code>simplify</code>:</p>
<pre><code>ex:= A**3 A**2;
simplify(_);
</code></pre>
<p>also gives what you wanted. </p>
General questions
http://cadabra.science/qa/1472/issueswithexponentiation?show=1474#a1474
Wed, 11 Dec 2019 09:17:30 +0000

Answered: fierz identity for chiral spinors
http://cadabra.science/qa/159/fierzidentityforchiralspinors?show=1471#a1471
<p>Do we have any updates on these chiral Fierz identities?</p>
General questions
http://cadabra.science/qa/159/fierzidentityforchiralspinors?show=1471#a1471
Tue, 10 Dec 2019 20:14:21 +0000

Answered: Trace of Gamma Matrices?
http://cadabra.science/qa/170/traceofgammamatrices?show=1466#a1466
<p>You can do it with recent versions of Cadabra but it's a little awkward. For example,</p>
<pre><code>{\mu,\nu,\rho,\sigma}::Indices(vector);
{\mu,\nu,\rho,\sigma}::Integer(0..3);
{a,b,c,d}::Indices(spinor);
Tr{#}::Trace(indices=spinor);
\delta_{\mu \nu}::KroneckerDelta;
\Gamma^{#}::GammaMatrix(metric=\delta);
\Gamma^{\mu}::ImplicitIndex(\Gamma^{\mu}_{a b});
\Gamma^{\mu \nu}::ImplicitIndex(\Gamma^{\mu \nu}_{a b});
\Gamma^{\mu \nu \rho \sigma}::ImplicitIndex(\Gamma^{\mu \nu \rho \sigma}_{a b});
ex:=Tr(\Gamma^{\mu} \Gamma^{\nu \rho} \Gamma^{\sigma});
</code></pre>
<p>Then call "join_gamma", "distribute", "untrace" until you only see traces of single gamma matrices. Finally "canonicalise" will kill all of them except Tr(1).</p>
Feature requests
http://cadabra.science/qa/170/traceofgammamatrices?show=1466#a1466
Wed, 04 Dec 2019 01:34:04 +0000

Answered: How can I implement cyclicity of trace?
http://cadabra.science/qa/729/howcaniimplementcyclicityoftrace?show=1458#a1458
<p>The current version on github handles this:</p>
<pre><code>{\phi,\psi}::ImplicitIndex;
tr{#}::Trace;
ex:= tr( (\phi\psi  \psi\phi)**2 );
expand_power(_)
distribute(_)
sort_product(_);
</code></pre>
<p>produces your answer. Thanks to Connor Behan for providing the patch that makes this work.</p>
General questions
http://cadabra.science/qa/729/howcaniimplementcyclicityoftrace?show=1458#a1458
Tue, 03 Dec 2019 11:06:10 +0000

Answered: Simplify LaTeX input
http://cadabra.science/qa/1431/simplifylatexinput?show=1432#a1432
<p>See the answer to this <a rel="nofollow" href="https://cadabra.science/qa/1274/replacealistofstatementswithacycle">post</a></p>
General questions
http://cadabra.science/qa/1431/simplifylatexinput?show=1432#a1432
Mon, 25 Nov 2019 11:46:54 +0000

Normal ordering
http://cadabra.science/qa/1395/normalordering
<p>I wonder how to normal order a weighted sum of creation and annihilation operators raised to power k?</p>
General questions
http://cadabra.science/qa/1395/normalordering
Thu, 21 Nov 2019 20:33:07 +0000