<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Cadabra Q&amp;A - Recent questions in General questions</title>
<link>https://cadabra.science/qa/questions/general-questions</link>
<description>Powered by Question2Answer</description>
<item>
<title>Tutorial on Differential Forms: I would expect A1 ^ A2 + A2 ^ A1 = 0</title>
<link>https://cadabra.science/qa/3091/tutorial-on-differential-forms-i-would-expect-a1-a2-a2-a1-0</link>
<description>&lt;p&gt;Hi, I am just beginning. Looking at the tutorial I am confused by the answer cadabra gives: A1 ^ A2 + A2 ^ A1 = 2 A1 ^ A2. I would have expected 0 as result.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3091/tutorial-on-differential-forms-i-would-expect-a1-a2-a2-a1-0</guid>
<pubDate>Sat, 02 May 2026 18:01:24 +0000</pubDate>
</item>
<item>
<title>Problem with SympyBridge</title>
<link>https://cadabra.science/qa/3088/problem-with-sympybridge</link>
<description>&lt;p&gt;I am attempting to use SympyBridge to simplify a somewhat involved algebraic expression and it appears to be throwing a python error. Here is the notebook&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://drive.google.com/file/d/16jcPyMk7OkSsiShWLiYIw_7ng7-MUdFG/view?usp=sharing&quot;&gt;https://drive.google.com/file/d/16jcPyMk7OkSsiShWLiYIw_7ng7-MUdFG/view?usp=sharing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The error message  after the call to SympyBridge is&lt;/p&gt;
&lt;p&gt;\begin{verbatim}TokenError: ('unexpected character after line continuation character', (1, 82))&lt;/p&gt;
&lt;p&gt;At:
  /usr/lib/python3.12/tokenize.py(582): _generate_tokens_from_c_tokenizer
  /usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py(891): stringify_expr
  /usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py(1072): parse_expr
  Notebook Cell (Line 1): ex_sympy = sbb.to_sympy()
\end{verbatim}&lt;/p&gt;
&lt;p&gt;I have used SympyBridge on simpler expressions like those in the Cadabra Book and it works fine....&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3088/problem-with-sympybridge</guid>
<pubDate>Mon, 13 Apr 2026 14:22:18 +0000</pubDate>
</item>
<item>
<title>Trouble running standard cnb file</title>
<link>https://cadabra.science/qa/3079/trouble-running-standard-cnb-file</link>
<description>&lt;p&gt;I have installed cadabra2 on a Ubuntu 24.04 system using the deb file provided. I imported the sample notebook called einstein_equations.cnb which derives Einstein's equation using an action variation. The last  cell to be executed using python gives the following error:&lt;/p&gt;
&lt;p&gt;substitute: Index error in replacement rule. substitute: No numerical pre-factors allowed on lhs of replacement rule.&lt;/p&gt;
&lt;p&gt;The offending cell is &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;t1 = action[1][0][0][2]
eom:= 2\kappa @(t1) = 0;
distribute(_)
collect_factors(_)
manip.to_rhs(_, $- \kappa T_{\mu\nu}$);
substitute(_, manip.swap_sides(einsteinTensor));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and the last substitute command appears to give the error. &lt;code&gt;manip.swap_sides&lt;/code&gt; command is coming from the imported &lt;code&gt;cdb.core.manip&lt;/code&gt; package.&lt;/p&gt;
&lt;p&gt;Any ideas what is going wrong?&lt;/p&gt;
&lt;p&gt;Also could anyone enlighten me on the syntactical meaning of the first two lines of this cell. I couldn't find any references to it in the manual...&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3079/trouble-running-standard-cnb-file</guid>
<pubDate>Wed, 01 Apr 2026 16:10:51 +0000</pubDate>
</item>
<item>
<title>declare a mapping with previous expression</title>
<link>https://cadabra.science/qa/3077/declare-a-mapping-with-previous-expression</link>
<description>&lt;p&gt;I have some expression reached after a long list of manipulations with some free indices, and I want to create a mapping (I think documentation prefers calling them &quot;substitution rules&quot;) like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;M_{\mu} -&amp;gt; &amp;lt;previous expression with only \mu as free indice&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I tried doing:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;M_mapping := M_{\mu} -&amp;gt; $(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but this gives:&lt;br&gt;
`\begin{verbatim}RuntimeError: Python object '' does not exist.&lt;/p&gt;
&lt;p&gt;At:
Notebook Cell (Line 1): M&lt;em&gt;mapping = Ex(' M&lt;/em&gt;{\mu} -&amp;gt; @(_)')
\end{verbatim}`&lt;/p&gt;
&lt;p&gt;I tried doing:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;M_expr = _;   &amp;lt;--- this succeeds
M_mapping := M_{\mu} -&amp;gt; @(M_expr); &amp;lt;--- this gives an error:&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`\begin{verbatim}RuntimeError: Python object '\prod' does not exist.&lt;/p&gt;
&lt;p&gt;At:
Notebook Cell (Line 1): M&lt;em&gt;mapping = Ex(' M&lt;/em&gt;{\mu} -&amp;gt; @(M_expr)')
\end{verbatim}`&lt;/p&gt;
&lt;p&gt;What's the correct syntax to create a mapping with the previous expression?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3077/declare-a-mapping-with-previous-expression</guid>
<pubDate>Fri, 23 Jan 2026 16:12:30 +0000</pubDate>
</item>
<item>
<title>canonicalise gets stuck on swapped indices</title>
<link>https://cadabra.science/qa/3069/canonicalise-gets-stuck-on-swapped-indices</link>
<description>&lt;p&gt;The following snippet shows the issue I'm having right now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;expr_test := \nabla_{\mu}{ A_{\alpha } } * \nabla^{\mu}{ A_{\beta} } + \nabla^{\mu}{ A_{\alpha } } * \nabla_{\mu}{ A_{\beta} };
sort_product(_);
sort_sum(_);
canonicalise(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At the end I still get:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\nabla_{\mu}{A_{\alpha}} \nabla^{\mu}{A_{\beta}}\discretionary{}{}{}
+
\nabla_{\mu}{A_{\beta}} \nabla^{\mu}{A_{\alpha}}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;all indices are &lt;code&gt;position=independent&lt;/code&gt;, but I tried switching to &lt;code&gt;fixed&lt;/code&gt; and didn't help this particular issue.&lt;/p&gt;
&lt;p&gt;Also, nabla is declared as:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\nabla{#}::Derivative.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;But AFAIU the non-commutativity of &lt;code&gt;Derivative&lt;/code&gt; should only affect order of indices, not the resulting object.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3069/canonicalise-gets-stuck-on-swapped-indices</guid>
<pubDate>Wed, 21 Jan 2026 19:22:39 +0000</pubDate>
</item>
<item>
<title>Rename specific dummy indices in expressions</title>
<link>https://cadabra.science/qa/3063/rename-specific-dummy-indices-in-expressions</link>
<description>&lt;p&gt;In some cases, it would be useful to rename a specific subset of indices (dummy or not). In my particular case I am doing Hilbert metric variations of a matter Lagrangian and trying to reach a final expression that factors out a single metric variation coefficient.&lt;/p&gt;
&lt;p&gt;What is happening is that I have many terms with metric variation factors, but each having different dummy indices. Even &lt;code&gt;rename_dummies&lt;/code&gt; doesn't really help as it's a global action and I don't see a way to rename only the dummies of the \delta{g} terms.&lt;/p&gt;
&lt;p&gt;What other strategy could be useful here? I'm thinking into a pseudo-code doing this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;for each \delta{g}^{?a ?b} term matching with a \delta{g} factor:&lt;/li&gt;
&lt;li&gt;rename indices ?a to something unused or reserved in entire term&lt;/li&gt;
&lt;li&gt;rename indices ?b to something unused or reserved in entire term&lt;/li&gt;
&lt;/ul&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3063/rename-specific-dummy-indices-in-expressions</guid>
<pubDate>Mon, 19 Jan 2026 19:20:52 +0000</pubDate>
</item>
<item>
<title>Issue with split_index and dummy index</title>
<link>https://cadabra.science/qa/3062/issue-with-split_index-and-dummy-index</link>
<description>&lt;p&gt;I am new to Cadabra and have a couple of beginner questions that I haven’t been able to resolve on my own. I would greatly appreciate any help or clarification you can offer. I have the following Cadabra Code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{M,N,P,Q,R#}::Indices(full, position=fixed).
{a,b,c,d,e#}::Indices(space1, position=fixed).
{a,b,c,d,e}::Integer(1..2).
{m,n,p,q,r#}::Indices(space2, position=fixed).&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;\partial{#}::PartialDerivative.
g_{M N}::Metric.
g^{M N}::InverseMetric.
g_{M?N?}::Symmetric.
g^{M?N?}::Symmetric.&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;Gtog:=\Gamma^{P?}_{M? N?}-&amp;gt;(1/2)*g^{P? Q}(\partial_{N?}{g_{Q M?}}
+\partial_{M?}{g_{Q N?}}-\partial_{Q}{g_{M? N?}});&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;ex:=\Gamma^{2}_{1 2};
substitute(_, Gtog);
split_index(_, $M, a, m$);&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;todo:=\Gamma^{R}_{q m}\Gamma^{p}_{n R};
substitute(_, Gtog);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Question1: I tried using split index to split an index in my expression, but it doesn’t seem to do anything -- it simply returns the answer without performing the split. What might be the issue?&lt;/p&gt;
&lt;p&gt;Question2: For the expression \Gamma^{R}&lt;em&gt;{q m}\Gamma^{p}&lt;/em&gt;{n R} I am getting the same index Q repeated four times in the output. How can I prevent this and get the correct index contractions without the same dummy index appearing too many times?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3062/issue-with-split_index-and-dummy-index</guid>
<pubDate>Tue, 13 Jan 2026 11:06:33 +0000</pubDate>
</item>
<item>
<title>absolute value in Cadabra expression</title>
<link>https://cadabra.science/qa/3058/absolute-value-in-cadabra-expression</link>
<description>&lt;p&gt;Hi,
Sorry for the simplistic question, but what is the proper way to generate a Cadabra expression with absolute value?&lt;/p&gt;
&lt;p&gt;I tried&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ex := \sqrt{g} -&amp;gt; \abs(Z) \sqrt{h}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but I get an error, also using sympy.Abs doesn't seem to generate an output with 
|Z|&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3058/absolute-value-in-cadabra-expression</guid>
<pubDate>Fri, 19 Dec 2025 12:15:46 +0000</pubDate>
</item>
<item>
<title>How to remove/unset properties</title>
<link>https://cadabra.science/qa/3034/how-to-remove-unset-properties</link>
<description>&lt;p&gt;I'm reading The Cadabra Book and try every example in the same cadabra session. I tried command line and Jupyter kernel and same result.&lt;/p&gt;
&lt;p&gt;I got the following error because in the same session the first two lines interfere with the others :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt; {m#, n#}::Indices(vector);
Property Indices(position=free) attached to {m#, n#}.
&amp;gt; {n, m, p, q}::Integer(1..d);
Property Integer attached to {n, m, p, q}.
&amp;gt; A_{m n p}::TableauSymmetry(shape={1,1}, indices={1,2});
Property TableauSymmetry attached to A_{m n p}.
&amp;gt; p = TableauSymmetry.get($A_{m n p}$)
&amp;gt; p.attach($B_{m n p}$)
&amp;gt; ex:= B_{m n p} - B_{m p n};
B_{m n p}-B_{m p n}
&amp;gt; canonicalise(_);
Traceback (most recent call last):
  File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;
RuntimeError: Indicex has integer property, but explicit range needed.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there a way to remove properties ?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/3034/how-to-remove-unset-properties</guid>
<pubDate>Sat, 12 Jul 2025 17:26:32 +0000</pubDate>
</item>
<item>
<title>Evaluate does not respect NonCommuting</title>
<link>https://cadabra.science/qa/2996/evaluate-does-not-respect-noncommuting</link>
<description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;Thanks for Cadabra! I just started playing around. I'm using the Fedora 40 package of Version 2.5.10 (build private dated 2024-12-24).&lt;/p&gt;
&lt;p&gt;I'm trying the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\partial{#}::PartialDerivative;
t::Coordinate;
O::Depends(t);
{H,O_0}::NonCommuting;

ex := O = \exp(i*H*t) O_0 \exp(-i*H*t);
ex2 := \partial_t{O};

substitute(ex2, ex);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So far so good. However&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;evaluate(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;yiels 0 which should not be because &lt;code&gt;H&lt;/code&gt; and &lt;code&gt;O_0&lt;/code&gt; are not commuting.&lt;/p&gt;
&lt;p&gt;I've read that &lt;code&gt;simplify&lt;/code&gt; should not be used (&lt;a rel=&quot;nofollow&quot; href=&quot;https://cadabra.science/qa/798/simple-commutator-in-quantum-mechanics?show=798#q798&quot;&gt;https://cadabra.science/qa/798/simple-commutator-in-quantum-mechanics?show=798#q798&lt;/a&gt;) but is this true for &lt;code&gt;evaluate&lt;/code&gt; as well?&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Sebastian&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2996/evaluate-does-not-respect-noncommuting</guid>
<pubDate>Fri, 14 Mar 2025 07:08:52 +0000</pubDate>
</item>
<item>
<title>How to manage two projects in their own folders which import .cnb's with the same names</title>
<link>https://cadabra.science/qa/2994/manage-projects-their-folders-which-import-cnbs-with-names</link>
<description>&lt;p&gt;I have two separate folders for different projects with some notebook (.cnb) files. In both folders I use the names methods.cnb, latex_macros.cnb, properties.cnb to split up the code, then import them into a main file to do work.&lt;/p&gt;
&lt;p&gt;I noticed that, when importing from a .cnb, cadabra will convert it to a .py file and store it in the /home/user/cadabra_packages folder (on Ubuntu).&lt;/p&gt;
&lt;p&gt;At the moment, I need to manually delete these cached files in cadabra_packages before I can swap between my projects.&lt;/p&gt;
&lt;p&gt;I was wondering if there are any suggestions on how to make this better? I am very amateurish, but would appreciate a pointer in the right direction so that I can manage my files better. The only thing I would like is for it to be operating system agnostic, so I can also do it on mac.&lt;/p&gt;
&lt;p&gt;Some ideas I thought of:&lt;/p&gt;
&lt;p&gt;(1) Directly use .py files in the project folders so no .cnbs need to be cached.&lt;/p&gt;
&lt;p&gt;(2) Rename the files e.g. methods1.cnb in the first folder, methods2.cnb in the second.&lt;/p&gt;
&lt;p&gt;I am not keen on (2) because it would be nice to have the same layout in folders for different projects. I could compromise with (1), but I do enjoy editing the files using the notebook interface.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2994/manage-projects-their-folders-which-import-cnbs-with-names</guid>
<pubDate>Mon, 17 Feb 2025 07:24:51 +0000</pubDate>
</item>
<item>
<title>derivatives are not evaluated in evaluation of components</title>
<link>https://cadabra.science/qa/2978/derivatives-are-not-evaluated-in-evaluation-of-components</link>
<description>&lt;p&gt;Hi,
I wanted to compute the metric of AdS&lt;em&gt;{d+1} through its embedding in \mathbb{R}^{d+2}.
When evaluating the components of the induced metric as below, it ends up with components that still contain derivatives, i.e. things like \partial&lt;/em&gt;{\phi}{\cos{\phi}}, whereas if I compute the derivative directly, e.g.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ll :=\partial_{\phi}{\cos{\phi}}
evaluate(ll);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it evaluates it correctly. So how do I evaluate these derivative if I have all the component together in an expression?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{t,\rho,\phi}::Coordinate;
{A,B}::Indices(higher,values={0,1,2,3}, position=fixed);
{\mu, \nu, \sigma, \kappa,\alpha,\beta,\gamma}::Indices(lower,values={t,\rho,\phi}, position=fixed);
X^{A}::Depends(t,\rho,\phi);

\partial{#}::PartialDerivative;

X^{A}::Depends(t,\rho,\phi,\partial_{\nu}{#});
g_{A B}::Metric(higher).
g^{A B}::InverseMetric(higher).

G_{\mu \nu}::Metric(lower).
G^{\mu \nu}::InverseMetric(lower).


metricRdp2 := [
g_{0 2} = 0, g_{0 3} = 0, g_{0 4} = 0,
g_{0 1} = 0, g_{1 2} = 0, g_{1 3} = 0,g_{1 4} = 0,
g_{2 3} = 0,g_{2 4} = 0,g_{3 4}= 0,  g_{4 4} = -1, g_{0 0} = -1, 
g_{1 1} = 1, g_{2 2} = 1, g_{3 3} = -1];

global2 := [ X^{0} = R \cosh{\rho} \cos{t}, 
X^{3} = R \cosh{\rho} \sin{t}, 
X^{1} = R \sinh{\rho} \sin{\phi},
X^{2} = R \sinh{\rho} \cos{\phi}];

cc := G_{\mu \nu} = \partial_{\mu}{X^{A}}\partial_{\nu}{X^{B}}g_{A B};

ex2 := G_{\mu \nu}:
substitute(ex2,cc);

evaluate(ex2)
canonicalise(ex2)
substitute(ex2,metricRdp2)
substitute(ex2,global2)
unwrap(ex2)
collect_factors(ex2);&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2978/derivatives-are-not-evaluated-in-evaluation-of-components</guid>
<pubDate>Fri, 20 Dec 2024 13:12:42 +0000</pubDate>
</item>
<item>
<title>How to handle metric on submanifold?</title>
<link>https://cadabra.science/qa/2963/how-to-handle-metric-on-submanifold</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was trying to play with cadabra to study Einsteins equations at future null infinity.
I have the coordinates $u,r,\phi,\theta$, for which I use lowercase greek indices ($\mu,\nu,...$) and I want to use the coordinate $\phi, \theta$ just to label points on the sphere, which I would like to label with uppercase latin indices (A,B,C,..)&lt;/p&gt;
&lt;p&gt;Now I would like to define a metric just on the sphere, so I used in its definition only the indices A,B, hoping that it makes it an object only of those indices. Apparently this is not the case, since if I just evaluate the metric, I still get components written out for the u and r directions and if I try to complete the rule ssid, I get the error that the metric has zero determinant. Is there a way to make \gamma_{A B} an object only of the intrinsic coordinates \phi \theta such that e.g. complete works?&lt;/p&gt;
&lt;p&gt;Here my minimal example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{u,r,\phi,\theta}::Coordinate;

{\mu,\nu,\rho,\sigma}::Indices(higher,values={u,r,\phi,\theta}, position=fixed);
{A,B}::Indices(lower,values={\phi,\theta}, position=fixed,parent=higher);

\gamma_{A B}::Metric(lower, signature = 2);
\gamma^{A B}::InverseMetric(lower, signature = 2);
#\gamma_{A B}::Depends(r,\phi,\theta);

ssid:= {\gamma_{\phi \phi} = r**2*\sin(\theta)**2,   
       \gamma_{\theta \theta} = r**2
       };

ex1 := \gamma_{B A};
evaluate(ex1);
complete(ssid, $\gamma^{A B}$);&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2963/how-to-handle-metric-on-submanifold</guid>
<pubDate>Sat, 07 Dec 2024 10:52:01 +0000</pubDate>
</item>
<item>
<title>Cadabra in Jupyter notebook - how to store?</title>
<link>https://cadabra.science/qa/2956/cadabra-in-jupyter-notebook-how-to-store</link>
<description>&lt;p&gt;Hello,
I'm working with Cadabra on Jupyter notebooks, specifically via JupyterHub running on a linux system.
I save my work and shuts down the computer until my next session, but then when I open the notbook again I see that the results are fonw, only the code is saved.
I think only once I managed to somehow save a notebook with all of the results still showing when I re-open it. I don't know how I did it.&lt;/p&gt;
&lt;p&gt;So my questio nis how to save a Cadabra-notebook (on a jupyterhub) with all the data still in the cache, and saved even after the computer is shut down?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2956/cadabra-in-jupyter-notebook-how-to-store</guid>
<pubDate>Sun, 20 Oct 2024 12:59:00 +0000</pubDate>
</item>
<item>
<title>Custom display symbols for variables?</title>
<link>https://cadabra.science/qa/2940/custom-display-symbols-for-variables</link>
<description>&lt;p&gt;As well as the usual spherical polar coordinates r,\theta,\phi, I also want to use their velocites as coordinates, which I'm currently representing as vr, vtheta, vphi. 
I'd prefer to display the latter as (latex) \dot r, \dot\theta, \dot\phi.&lt;/p&gt;
&lt;p&gt;I vaguely recall cadabra1 had a way of doing this. Can I do it somehow in cadabra2?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2940/custom-display-symbols-for-variables</guid>
<pubDate>Mon, 30 Sep 2024 02:37:00 +0000</pubDate>
</item>
<item>
<title>Simple derivative evaluation not working for me.</title>
<link>https://cadabra.science/qa/2939/simple-derivative-evaluation-not-working-for-me</link>
<description>&lt;p&gt;So I copied and modified that start of schwarzschild.cnb to my own notebook which I'll call Laplacian.cnb&lt;/p&gt;
&lt;p&gt;I modified the first code block to add some more coordinates vr, vtheta, vphi (intended to represent velocities -- I'm working in velocity phase space).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{t,r,\theta,\phi, vt, vr, vtheta, vphi}::Coordinate;
{\mu,\nu,\rho,\sigma,\lambda,\kappa,\chi,\gamma}::Indices(values={t,r,\phi,\theta}, position=fixed);
\partial{#}::PartialDerivative;
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now I try to define a simple (scalar) function
f, which is just &lt;code&gt;f() = r + vtheta**2&lt;/code&gt;  and try to evaluate &lt;code&gt;\partial_r f&lt;/code&gt;. My code block is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;f::Depends(r,\theta,\phi, vr, vtheta, vphi);
exf:= { f = r + vtheta**2 } ;
exfr:= { fr = \partial_r{f} };
evaluate(exfr,exf);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final line of output is just &lt;code&gt;\partial_r f&lt;/code&gt;.
I.e., it didn't perform the partial derivative.
(The answer should have been 1.)&lt;/p&gt;
&lt;p&gt;What am I doing wrong?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2939/simple-derivative-evaluation-not-working-for-me</guid>
<pubDate>Mon, 30 Sep 2024 02:27:19 +0000</pubDate>
</item>
<item>
<title>Expanding sum into time and purely space components.</title>
<link>https://cadabra.science/qa/2927/expanding-sum-into-time-and-purely-space-components</link>
<description>&lt;p&gt;Greetings.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ricci tensor perturbations involve sum over spacetime components (in FLRW -&amp;gt;{t, r, \theta \varphi} ). How to expand spacetime sum (greek indices) into time and purely space components (latin indices)?&lt;/li&gt;
&lt;li&gt;For each Gamma and \delta{\Gamma} there are subrules (see related image):
&lt;em&gt;Gamma^{t}_{t t}= ...
&lt;/em&gt;Gamma^{t}_ {t i}=...
How to setup and substitute this relations in master equations? &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The core of programm is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import cdb.core.manip as mp
import cdb.core.component as cmp
{t,r, \theta, \varphi}::Coordinate.
a::Depends(t).
{\mu, \nu, \rho, \sigma, \alpha, \beta, \gamma, \lambda, \tau, \chi, \iota, \upsilon, \omega}::Indices(curved,position=fixed,values={t,r, \theta, \varphi}).
{a,b,c,d,e,f,g,i,j,k,l,m,n,p,s}::Indices(position=fixed,values={r, \theta, \varphi})
gb{#}::LaTeXForm(&quot;\bar{g}&quot;).
gb_{\mu \nu}::Symmetric.
gb::Diagonal;
{gb^{\mu}_{\nu}, gb_{\mu}^{\nu}}::KroneckerDelta.
back := gb\_\{t t\}=\-1\, gb\_\{r r\}=a**2/(1-k*r**2), gb_{\theta \theta}=a**2*r**2, gb_{\varphi \varphi}=a**2*r**2*\sin{\theta}**2, gb^{t t}=-1, gb^{r r}=(1-k*r**2)/(a**2), gb^{\theta \theta}=1/(r**2_a**2), gb^{\varphi \varphi}=1/(a**2_r\*\*2\*\sin\{\theta\}\*\*2\)\, gb\_\{t r\}=0\, gb\_\{t \theta\}=0\, gb\_\{t \varphi\}=0\, gb\_\{r \theta\}=0\, gb\_\{r \varphi\}=0\, gb\_\{\theta \varphi\}=0\, gb\_\{r t\}=0\, gb\_\{\theta t\}=0\, gb\_\{\varphi t\}=0\, gb\_\{\theta r\}=0\, gb\_\{\varphi r\}=0\, gb\_\{ \varphi \theta\}=0;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the part we define components of ricci perturbations:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gs{#}::LaTeXForm(&quot;\overline{\gamma}&quot;)
dGamma{#}::LaTeXForm(&quot;\delta\Gamma&quot;);

dRic{#}::LaTeXForm(&quot;\delta R&quot;).
perric := \delta{R_{\mu \nu}} = \partial_{\sigma}{dGamma^{\sigma}_{\mu \nu}} - \partial_{\nu}{dGamma^{\sigma}_{\mu \sigma}} + dGamma^{\rho}_{\mu \nu} \Gamma^{\sigma}_{\rho \sigma} + \Gamma^{\rho}_{\mu \nu} dGamma^{\sigma}_{\rho \sigma} - dGamma^{\rho}_{\mu \sigma} \Gamma^{\sigma}_{\nu \rho} - \Gamma^{\rho}_{\mu \sigma} dGamma^{\sigma}_{\nu \rho};

dr1 = cmp.get_component(perric, $t,t$);
dr2 = cmp.get_component(perric, $t,i$);
dr3 = cmp.get_component(perric, $j,k$);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How to expand sum?&lt;/p&gt;
&lt;p&gt;We try to define relation for non perturbed Gamma!:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;eq1 := {\Gamma}^{t}_{i j}=(a \partial_{t}{a} {gs}_{i j});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But error appear:
&lt;code&gt;RuntimeError: Free indices on lhs and rhs do not match.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Thank you in advance for your help.
&lt;img src=&quot;https://files.catbox.moe/lmxthe.png&quot; alt=&quot;Relations from Weinberg&amp;#39;s &amp;quot;Cosmology&amp;quot;&quot;&gt;&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2927/expanding-sum-into-time-and-purely-space-components</guid>
<pubDate>Sat, 10 Aug 2024 12:23:25 +0000</pubDate>
</item>
<item>
<title>question about eliminate_metric</title>
<link>https://cadabra.science/qa/2920/question-about-eliminate_metric</link>
<description>&lt;p&gt;For example,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{\mu,\nu,\rho}::Indices(vector).
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.
g_\mu^\nu::KroneckerDelta.
g^\mu_\nu::KroneckerDelta.
\delta{#}::Accent.

ex:=\delta{g_{\mu\nu}} g^{\nu\rho};
eliminate_metric(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I get an odd result.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2920/question-about-eliminate_metric</guid>
<pubDate>Fri, 02 Aug 2024 14:27:21 +0000</pubDate>
</item>
<item>
<title>I'm trying to reproduce equation 4.6 from 4.5 in Carrolls Spacettime ;and Geometry</title>
<link>https://cadabra.science/qa/2901/trying-reproduce-equation-from-carrolls-spacettime-geometry</link>
<description>&lt;p&gt;The following is my code.  The last line has a partial with respect to nu and I want to use the chain rule to convert to d/dlamda.  &lt;/p&gt;
&lt;p&gt;I'm an newbie here so I may be doing something reallty dumb.  I did convert the partial declaration to have the Derivative property so I don't end up with a double partial derivative of \nu and \lambda.  Any suggestions would be appreciated.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
{t,x,y,z,\lambda}::Coordinate.
{t,x,y,z,}::Depends(\lambda);
{\mu,\nu,\sigma,\rho,\alpha}::Indices(values={t,x,y,z},position=independent);
\nabla{#}::Derivative.
#\partial{#}::PartialDerivative;
\partial{#}::Derivative;

#deriv := \nabla_{\mu}{v?^{\nu}} -&amp;gt; \partial_{\mu}{v?^{\nu}} + \Gamma^{\nu}_{\sigma \mu} v?^{\sigma};

deriv := \nabla_{\nu}{\partial_{\lambda}{x^{\mu}}} -&amp;gt; \partial_{\nu}{\partial_{\lambda}{x^{\mu}}} 
    + \Gamma^{\mu}_{\sigma \nu} \partial_{\lambda}{x^{\sigma}};

expr := \partial_{\lambda}{x^{\nu}} * \nabla_{\nu}{\partial_{\lambda}{x^{\mu}}};

substitute(expr,deriv);

distribute(expr);
sort_product(expr);
&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2901/trying-reproduce-equation-from-carrolls-spacettime-geometry</guid>
<pubDate>Thu, 27 Jun 2024 22:01:26 +0000</pubDate>
</item>
<item>
<title>Factor out of numerical coefficient</title>
<link>https://cadabra.science/qa/2899/factor-out-of-numerical-coefficient</link>
<description>&lt;p&gt;Hi everyone! I'm using cadabra for a several years, but still can't understand how to factor out numerical coefficients, for example &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;factor_out($6 A B + 6 A C$, $A$);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;factor_out($6 A B + 6 A C$, $A,6$);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It would be much prettier if you could factor out the numerical coefficient too. it doesn't affect the functionality, but when exporting formulas to latex, a lot of time is spent on manual editing.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2899/factor-out-of-numerical-coefficient</guid>
<pubDate>Mon, 24 Jun 2024 13:41:15 +0000</pubDate>
</item>
<item>
<title>how to deal with lovelock gravity?</title>
<link>https://cadabra.science/qa/2898/how-to-deal-with-lovelock-gravity</link>
<description>&lt;p&gt;For Lovelock gravity,&lt;/p&gt;
&lt;p&gt;$$
L=R_{a_{2}b_{2}}^{c_{2}d_{2}}\cdots R_{a_{m}b_{m}}^{c_{m}d_{m}}\delta_{c_{2}d_{2}\cdots c_{m}d_{m}}^{a_{2}b_{2}\cdots a_{m}b_{m}}
$$&lt;/p&gt;
&lt;p&gt;where&lt;/p&gt;
&lt;p&gt;$$
\delta_{{jc_{1}d_{1}...c_{m}d_{m}}}^{{ia_{1}b_{1}...a_{m}b_{m}}}=\det\left[\begin{array}{c|ccc}\delta_{j}^{i} &amp;amp; \delta_{{c_{1}}}^{i} &amp;amp; \cdots &amp;amp; \delta_{{d_{m}}}^{i}\\hline \\delta_{j}^{{a&lt;em&gt;{1}}}\\vdots &amp;amp;  &amp;amp; \delta_{{c_{1}d_{1}...c_{m}d_{m}}}^{{a_{1}b_{1}...a_{m}b_{m}}}\\delta_{j}^{{b\&lt;/em&gt;{m}}}\end{array}\right]
$$&lt;/p&gt;
&lt;p&gt;when $m=2$, we get Einstein gravity; when $m=3$, we get Gauss-Bonnet gravity. But how to deal with it more generally? More concretely, I don't know how to do it use &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2898/how-to-deal-with-lovelock-gravity</guid>
<pubDate>Sun, 23 Jun 2024 03:15:45 +0000</pubDate>
</item>
<item>
<title>How to copy output as tex format in jupyter notebook?</title>
<link>https://cadabra.science/qa/2871/how-to-copy-output-as-tex-format-in-jupyter-notebook</link>
<description>&lt;p&gt;Today, I try cadabra2 in jupyter, and it's very nice, but I don't know how to do copy output as tex format. &lt;/p&gt;
&lt;p&gt;Update: When I right-click the mouse, I can see &lt;code&gt;mathjax copy latex&lt;/code&gt;, but this just works when I run cell, and it just can copy the final result.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2871/how-to-copy-output-as-tex-format-in-jupyter-notebook</guid>
<pubDate>Mon, 27 May 2024 16:38:47 +0000</pubDate>
</item>
<item>
<title>Why does evaluate of metric eating vector shows only non-zero components.</title>
<link>https://cadabra.science/qa/2855/does-evaluate-metric-eating-vector-shows-only-zero-components</link>
<description>&lt;p&gt;I do not understand why g(.,v) only shows non-zero components after evaluation.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{m,n,a,b,c,r,s}::Indices(values={0,1,2,3}).
#
g_{a b}::Metric.
g^{a b}::InverseMetric.
#
g:=[g_{0 0}=-1, g_{0 1}=0, g_{0 2}=1, g_{0 3}=0, g_{1 0}=0,  g_{1 1}=1, g_{1 2}=0, g_{1 3}=0, g_{2 0}=1, g_{2 1}=0, g_{2 2}=1, g_{2 3}=0, g_{3 0}=0, g_{3 1}=0, g_{3 2}=0, g_{3 3}=1].
v:=[v^{0}=1, v^{1}=1, v^{2}=1, v^{3}=1];
display(v)
ex:=g_{a b} v^{a};
evaluate(ex,join(g,v), rhsonly=True);&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;OUTPUT gives
□_{b}
    {1} = 1
    {2} = 2
    {3} = 1&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Setting g00=1 (tather than -1 above) gives &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;□_{b}
    {0} = 2
    {1} = 1
    {2} = 2
    {3} = 1&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2855/does-evaluate-metric-eating-vector-shows-only-zero-components</guid>
<pubDate>Tue, 14 May 2024 20:17:56 +0000</pubDate>
</item>
<item>
<title>How can I store the result of evaluating g(.,v) as a co-vector?</title>
<link>https://cadabra.science/qa/2852/how-can-i-store-the-result-of-evaluating-g-v-as-a-co-vector</link>
<description>&lt;p&gt;Mathematically I expect &lt;code&gt;g(.,v)&lt;/code&gt; to be a co-vector. Now, given: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import cdb.core.component as comp
{m,n,a,b,c,d,q,r,s}::Indices(values={0,1}).
g_{a b}::Metric.
g^{a b}::InverseMetric.
g:=[g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1];
v:=[v^{0}=12, v^{1}=-11];
ex:=g_{a b} v^{a};
gv:=evaluate(ex,join(g,v), rhsonly=True)
w:=w_{a};&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I would like to loop through components of &lt;code&gt;gv&lt;/code&gt; and assign component values produce the desired co-vector &lt;code&gt;w&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;w_{b}=comp.get_component(w, b);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have tried many approaches which fail.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2852/how-can-i-store-the-result-of-evaluating-g-v-as-a-co-vector</guid>
<pubDate>Tue, 14 May 2024 15:40:59 +0000</pubDate>
</item>
<item>
<title>Christoffel symbols computation in $d$ dimensions with split indices</title>
<link>https://cadabra.science/qa/2851/christoffel-symbols-computation-dimensions-split-indices</link>
<description>&lt;p&gt;I have a metric of the form,
g_{\mu \nu} =&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;0&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;b_{ij}&lt;/td&gt;
&lt;td&gt;u&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;u^T&lt;/td&gt;
&lt;td&gt;f&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;where $u$ and $b_{i j }$ do not depend on the first coordinate $s$.
The inverse metric is
g^{\mu \nu} =&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;b^{i j} u_i u_j - f&lt;/th&gt;
&lt;th&gt;- u_i b^{i j}&lt;/th&gt;
&lt;th&gt;1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-b^{i j}u_j&lt;/td&gt;
&lt;td&gt;b^{i j}&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I would like to compute the Christoffel symbols I first try to followed section 2.5 in the paper,
&lt;a rel=&quot;nofollow&quot; href=&quot;https://arxiv.org/pdf/hep-th/0701238&quot;&gt;https://arxiv.org/pdf/hep-th/0701238&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After the comments I have updated my code, here is the edited code and an explanation. &lt;/p&gt;
&lt;p&gt;I wanted to split the Greek indices (${ \mu, \nu ...}$) into three parts: first: a capital Latin index that runs from 2 to $d$, second: small latin letters that  run from 2 to $d-1$ and the last index $s1, s2,s3$ to the last coordinate $d$. To simplify the problem I tried first $d=4$ so for example, $\mu=1,2,3,4$, $A=2,3,4$, $i,j = 2, 3$ and $s1=4$. 
To do this splitting I used, &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{\mu,\nu,\rho,\sigma,\kappa,\lambda,\eta,\chi#}::Indices(full, position=fixed, values={1,2,3,4}).
{A,B,C,D}::Indices(subspace, position=fixed, parent=full, values={2,3,4}).
{i,j, m,n,p,q,r,v#}::Indices(subspace2, position=fixed, parent=subspace, values={2,3}).
{s1,s2,s3}::Indices(subspace1, position=fixed, parent=subspace, values={4}).&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the updated code following the sugestions in the comments is,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\partial{#}::PartialDerivative.
g_{\mu\nu}::Metric.
g^{\mu\nu}::InverseMetric.
g_{\mu? \nu?}::Symmetric.
g^{\mu? \nu?}::Symmetric.

b_{i j}::Metric.
b^{i j}::InverseMetric.
\delta^{\mu?}_{\nu?}::KroneckerDelta.
\delta_{\mu?}^{\nu?}::KroneckerDelta.

Gtog:= \Gamma^{\lambda}_{\mu \nu} -&amp;gt; (1/2) * g^{\lambda \kappa} (\partial_{\nu}{ g_{\kappa\mu}} + \partial_{\mu}{g_{\kappa \nu}} + \partial_{\kappa}{g_{\mu\nu} } );

Gamma4ij := \Gamma^{4}_{i j};

substitute(Gamma4ij, Gtog);

split_index(Gamma4ij, $\mu, 1, A$, repeat=True);

split_index(Gamma4ij, $A, i, 4$, repeat=True);&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-substitute(_, $g_{1 1} -&amp;gt; 0$ )&quot;&gt;substitute(_, $g_{1 m} -&amp;gt; 0$ )
substitute(_, $g_{1 4} -&amp;gt; 1$ )
substitute(_, $g_{m 1} -&amp;gt; 0$ )
substitute(_, $g_{m n} -&amp;gt; b_{m n}$ )
substitute(_, $g_{m 4} -&amp;gt; U_{m}$ )
substitute(_, $g^{4 1} -&amp;gt; 1$ )
substitute(_, $g_{4 m} -&amp;gt; U_{m}$ )
substitute(_, $g_{4 4} -&amp;gt; f$ )&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;substitute(_, $g^{1 1} -&amp;gt; U_{m} b^{m n} U_{n} - f$ )
substitute(_, $g^{1 m} -&amp;gt; - U_{n} b^{n m}$ )
substitute(_, $g^{1 4} -&amp;gt; 1$ )
substitute(_, $g^{m 1} -&amp;gt; - U_{n} b^{n m}$ )
substitute(_, $g^{m n} -&amp;gt; b^{n m}$ )
substitute(_, $g^{m 4} -&amp;gt; 0$ )
substitute(_, $g^{4 1} -&amp;gt; 1$ )
substitute(_, $g^{4 m} -&amp;gt; 0$ )
substitute(_, $g^{4 4} -&amp;gt; 0$ )&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;substitute(_, $\partial_{1}{U??} -&amp;gt; 0$, repeat=True)
substitute(_, $\partial_{1 \mu?}{U??} -&amp;gt; 0$, repeat=True)
substitute(_, $\partial_{\mu? 1}{U??} -&amp;gt; 0$, repeat=True)
substitute(_, $\partial_{\mu? 1}{b???} -&amp;gt; 0$, repeat=True)

canonicalise(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I obtained the output $\Gamma^{4}_{i j} $, while if I change the definition of the Christoffel symbols and include ?, &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Gtog:= \Gamma^{\lambda?}_{\mu?\nu?} -&amp;gt;
 (1/2) * g^{\lambda?\kappa} (
 \partial_{\nu?}{ g_{\kappa\mu?} } + \partial_{\mu?}{g_{\kappa\nu?} }
- \partial_{\kappa}{ g_{\mu?\nu?} } ); &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I obtain 0, but I know $\Gamma^{4}$ is not 0 so I don't know where my code is wrong.
I would like to ask, how can I improve it and how can I generalise it to $d$ dimensions.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2851/christoffel-symbols-computation-dimensions-split-indices</guid>
<pubDate>Tue, 14 May 2024 14:17:33 +0000</pubDate>
</item>
<item>
<title>why can't cadabra find cdb.sympy.calculus?</title>
<link>https://cadabra.science/qa/2845/why-cant-cadabra-find-cdb-sympy-calculus</link>
<description>&lt;p&gt;Running only the below produces no result
ex := x+y;
diff( ex, $y$ );&lt;/p&gt;
&lt;p&gt;try to import&lt;/p&gt;
&lt;p&gt;from cdb.sympy.calculus import diff
ex := x+y;
diff( ex, $y$ );&lt;/p&gt;
&lt;p&gt;produces...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;from cdb.sympy.calculus import diff&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ModuleNotFoundError: No module named 'cdb.sympy.calculus'&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2845/why-cant-cadabra-find-cdb-sympy-calculus</guid>
<pubDate>Tue, 07 May 2024 20:19:25 +0000</pubDate>
</item>
<item>
<title>how to compute metric(vector,vector) or g(v,w) where g,v,w already defined without haqving to repeat the definitions.</title>
<link>https://cadabra.science/qa/2839/compute-metric-already-defined-without-haqving-definitions</link>
<description>&lt;p&gt;I am able to compute g(v,v) but have to repeat the definition of the component definitions (values or functions). Below is the is the code that &quot;works&quot; but it is strange that I have to repeat the definition of g and v in the line&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, 
    v^{0}=12, v^{1}=-11 , v^{0}=12, v^{1}=-11$, rhsonly=True)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I want to write something like &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;evaluate(ex, [g, v])&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or prefereably&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;evaluate(g(v,v))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt; ############################ 
 #CODE

{m,n,a,b,c,d,q,r,s}::Indices(values={0,1}).
g_{a b}::Metric.
g^{a b}::InverseMetric.
g:={g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1}.
display(g)
display(&quot;......................0&quot;)
v:={v^{0}=12, v^{1}=-11}.
display(v)
display(&quot;......................1&quot;)
ex:=g_{a b} v^{b}.
display(ex)
display(&quot;......................2&quot;)
evaluate(ex, $v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display(&quot;......................3&quot;)
ex:=g_{a b} v^{b}.
evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display(&quot;......................4&quot;)
ex:=g_{a b} v^{a} v^{b}.
display(ex)
display(&quot;......................5&quot;)
evaluate(ex, $g_{0 0}=28, g_{0 1}=2, g_{1 0}=3, g_{1 1}=-1, v^{0}=12, v^{1}=-11 , v^{0}=12, v^{1}=-11$, rhsonly=True)
display(ex)
display(&quot;......................6&quot;)&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2839/compute-metric-already-defined-without-haqving-definitions</guid>
<pubDate>Tue, 07 May 2024 14:31:01 +0000</pubDate>
</item>
<item>
<title>convert other format to cadabra2 format</title>
<link>https://cadabra.science/qa/2833/convert-other-format-to-cadabra2-format</link>
<description>&lt;p&gt;From &lt;a rel=&quot;nofollow&quot; href=&quot;https://cadabra.science/notebooks/scalar_manipulations.html&quot;&gt;Using Cadabra and Sympy together&lt;/a&gt;, I learn how to convert cadabra2 format to sympy format, but how to do the reverse operation? I.e. How to convert other formals, e.g. sympy format, to cadabra2 format?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2833/convert-other-format-to-cadabra2-format</guid>
<pubDate>Wed, 24 Apr 2024 13:31:05 +0000</pubDate>
</item>
<item>
<title>question about keep_weight</title>
<link>https://cadabra.science/qa/2814/question-about-keep_weight</link>
<description>&lt;p&gt;In the following code,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{u,v,x}::Coordinate.
f::Coordinate.
{a,b,c,d,e,g,h,p,r#}::Indices(full,values={u,v,x},position=independent).
\partial{#}::PartialDerivative.
\nabla{#}::Derivative.
g_{a b}::Metric.
g^{a b}::InverseMetric.
g_a^b::KroneckerDelta.
g^a_b::KroneckerDelta.
g^{a b}::Symmetric.
g_{a b}::Symmetric.
{n_u,n_v,\gamma,w,\alpha,\lambda,A,B,C}::Depends({u,v,f,x}).

{u,v}::Weight(label=field,value=1);
{f}::Weight(label=field,value=2);

metric:={g_{u v}=1,
         g_{v u}=1,g_{v v}=-u**2\alpha,g_{v x}=u w,
         g_{x v}=u w,g_{x x}=\gamma};   
complete(_,$g^{a b}$);

from cdb.sympy.calculus import *

lamb:=(g^{a b}\partial_a{u v}\partial_b{u v})**{-1/2} ;
evaluate(_,metric,rhsonly=True);
substitute(_,$v-&amp;gt;f/u$)
simplify(_);
substitute(_,$\alpha-&amp;gt;a,w**2\gamma**{-1}-&amp;gt;b$);
series(_,$f$,0,5/2);
substitute(_,$\bigO(A??)-&amp;gt;0$)
keep_weight(_,$field=1$);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final result is not right. There seems to be something wrong here.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2814/question-about-keep_weight</guid>
<pubDate>Fri, 19 Apr 2024 03:46:06 +0000</pubDate>
</item>
<item>
<title>function expand_power not work for fractional power</title>
<link>https://cadabra.science/qa/2804/function-expand_power-not-work-for-fractional-power</link>
<description>&lt;p&gt;For example, &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ex:=(a b)**{1/2};
expand_power(_);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Maybe some function like &lt;code&gt;Assumption&lt;/code&gt; in &lt;code&gt;Mathematica&lt;/code&gt; can be added.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2804/function-expand_power-not-work-for-fractional-power</guid>
<pubDate>Thu, 18 Apr 2024 13:20:11 +0000</pubDate>
</item>
<item>
<title>How to calculate Christoffel symbols with metric defined by abstract matrices?</title>
<link>https://cadabra.science/qa/2780/calculate-christoffel-symbols-defined-abstract-matrices</link>
<description>&lt;p&gt;For example, when looking at ADM formalism, I have $ds^2 = -N^2dt^2+g_{ij}(dx^{i}+N^{i}dt)(dx^{j}+N^{j}dt)$ in which the specific function relation between $g_{\mu \nu}$ and coordinates is not that clear so is abstract. Then how to do calculation on this kind of metric to get, say, the Christoffel symbols or other quantities after that? Below is what I've tried, but it didn't work with a result that all the Christoffel symbols are 0.&lt;/p&gt;
&lt;p&gt;By the way, as a very beginner in ADM formalism, is it the case that I have some misunderstanding in the calculation of it?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{t,x,y,z}::Coordinate;
{\mu,\nu,\rho,\sigma,\lambda,\kappa,\chi,\gamma,i,j,k}::Indices(values={t,x,y,z},position=fixed);
\partial{#}::PartialDerivative;
g_{\mu\nu}::Metric;
g^{\mu\nu}::InverseMetric;
h_{i j}::Metric;
h^{i j}::InverseMetric;
ss:={ g_{t t}=0,
    g_{0 i}=N_i,
    g_{i j}=h_{i j}
};
complete(ss, $g^{\mu\nu}$);
ch:= \Gamma^{\mu}_{\nu\rho} = 1/2 g^{\mu\sigma} ( 
                                   \partial_{\rho}{g_{\nu\sigma}} 
                                  +\partial_{\nu}{g_{\rho\sigma}}
                                  -\partial_{\sigma}{g_{\nu\rho}} );
                                  evaluate(ch, ss, rhsonly=True);&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2780/calculate-christoffel-symbols-defined-abstract-matrices</guid>
<pubDate>Tue, 16 Apr 2024 13:33:31 +0000</pubDate>
</item>
<item>
<title>Error printing as mma format</title>
<link>https://cadabra.science/qa/2776/error-printing-as-mma-format</link>
<description>&lt;p&gt;When I print the following expression as mma format
$$
v {\left(\sqrt{f \left(f \alpha \gamma_{x x} \gamma_{y y}-f \alpha {\gamma_{x y}}^{2}+f \gamma_{x x} {w_{y}}^{2}-2f \gamma_{x y} w_{x} w_{y}+f \gamma_{y y} {w_{x}}^{2}-2\gamma\right) {\gamma}^{-1}}\right)}^{-1}
$$
using code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;print(_.mma_form())&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I got the following error message:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LaTeX error, probably a missing style file. See the output below.

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./fileKtiEnn.tex
LaTeX2e &amp;lt;2021-11-15&amp;gt; patch level 1
L3 programming layer &amp;lt;2022-01-21&amp;gt;
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/iftex/ifvtex.sty
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty))

Package geometry Warning: `lmargin' and `rmargin' result in NEGATIVE (-266.7303
6pt).
    `width' should be shortened in length.


Package geometry Warning: `tmargin' and `bmargin' result in NEGATIVE (-7740.856
78pt).
    `height' should be shortened in length.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How can I solve this problem?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2776/error-printing-as-mma-format</guid>
<pubDate>Fri, 12 Apr 2024 23:19:59 +0000</pubDate>
</item>
<item>
<title>Question about Gaussian normal coordinate</title>
<link>https://cadabra.science/qa/2774/question-about-gaussian-normal-coordinate</link>
<description>&lt;p&gt;When I do calculation under Gaussian normal coordinate:&lt;/p&gt;
&lt;p&gt;$$
d s^2=-2 d u d v-u^2\alpha(x) d v^2-2u w_i(x) dv dx^i+\gamma_{ij}(x) d x^i d x^j\,\quad x=(uv\,,x^i)
$$&lt;/p&gt;
&lt;p&gt;How to get inverse metric and others directly? I don't know how to deal with $w_i$ and $\gamma_{ij}$.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2774/question-about-gaussian-normal-coordinate</guid>
<pubDate>Thu, 11 Apr 2024 07:20:30 +0000</pubDate>
</item>
<item>
<title>Formula rendering in jupyter notebook 7 and jupyter lab</title>
<link>https://cadabra.science/qa/2773/formula-rendering-in-jupyter-notebook-7-and-jupyter-lab</link>
<description>&lt;p&gt;Hi!
I recently updated jupyter notebook and jupyter lab, and found out that the latest versions use mathjax3 instead of mathjax2 to render formulas. Their developer promises 80% faster rendering and it's really cool, except that the formulas are now rendered as one line, one very long line. Maybe someone has already dealt with that and managed to fix it? &lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2773/formula-rendering-in-jupyter-notebook-7-and-jupyter-lab</guid>
<pubDate>Thu, 04 Apr 2024 13:24:21 +0000</pubDate>
</item>
<item>
<title>how to swap indices for partial derivatives</title>
<link>https://cadabra.science/qa/2750/how-to-swap-indices-for-partial-derivatives</link>
<description>&lt;p&gt;I need Cadabra to understand that the indices of derivatives can be swapped. For example, part of my expression looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{a c d}{z} v_{b} v_{c} v_{d} - 
2 \chi w**(3) M**(\xi+1) \delta{z} 
    \partial_{a b}{z} \partial_{c d a}{z} v_{b} v_{c} v_{d}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In theory, these 2 terms should contract, but they do not.&lt;/p&gt;
&lt;p&gt;The indices are given as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{a,b,c,d,f,i,j,h,k,l,m,n,p,r,s,t,u,v,w,z}::Indices(&quot;flat&quot;,position = free).
{a,b,c,d,f,i,j,h,k,l,m,o,p,r,s,t,u,v,w,z}::Integer(1..N) .&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Partial derivative as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\partial{#}::PartialDerivative.&lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2750/how-to-swap-indices-for-partial-derivatives</guid>
<pubDate>Tue, 19 Mar 2024 09:51:53 +0000</pubDate>
</item>
<item>
<title>Hello i am a beginner in using Cadabra 2</title>
<link>https://cadabra.science/qa/2747/hello-i-am-a-beginner-in-using-cadabra-2</link>
<description>&lt;p&gt;iam facing a repeated question , &quot;index error in replacement rule&quot;, i want to know the reasons  for this error?&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2747/hello-i-am-a-beginner-in-using-cadabra-2</guid>
<pubDate>Sat, 16 Mar 2024 19:44:04 +0000</pubDate>
</item>
<item>
<title>How to create derivatives of coordinates with indices?</title>
<link>https://cadabra.science/qa/2738/how-to-create-derivatives-of-coordinates-with-indices</link>
<description>&lt;p&gt;I have two sets of coordinates, and two partial derivatives which can act on these coordinates. These should work in a way such that:&lt;/p&gt;
&lt;p&gt;$$ 
\partial_{x^{\mu}} x^{\nu} = \delta_{\mu}^{\nu} = \partial_{a&lt;em&gt;{\nu}} a\&lt;/em&gt;{\mu}. 
$$&lt;/p&gt;
&lt;p&gt;How would I go about implementing this in Cadabra? I've tried defining partial derivatives of corresponding coordinates directly, I've tried using notation like DX and DA to differentiate between the two and then using LaTeXform to make it more tidy but I inadvertently run into a stop of some sort. &lt;/p&gt;
&lt;p&gt;Any and all help will be greatly appreciated!&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2738/how-to-create-derivatives-of-coordinates-with-indices</guid>
<pubDate>Thu, 15 Feb 2024 17:28:42 +0000</pubDate>
</item>
<item>
<title>derivatives with two indices</title>
<link>https://cadabra.science/qa/2729/derivatives-with-two-indices</link>
<description>&lt;p&gt;Hello, &lt;/p&gt;
&lt;p&gt;I need to use derivatives with two indices. However, when I use product_rule or integrate_by_parts, Cadabra splits the derivatives into two derivatives with one index each. Is there any way to circumvent this ? &lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2729/derivatives-with-two-indices</guid>
<pubDate>Thu, 18 Jan 2024 10:13:42 +0000</pubDate>
</item>
<item>
<title>How do I use object properties in a python executable?</title>
<link>https://cadabra.science/qa/2711/how-do-i-use-object-properties-in-a-python-executable</link>
<description>&lt;p&gt;Hello, I am trying to declare properties to Cadabra objects inside a python file. Could someone help me with finding the right input syntax, for instance for the property Indices?&lt;/p&gt;
&lt;p&gt;Consider the following cadabra notebook contents:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{ a, b, c, d }::Indices(spacetime, independent=True)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This assigns the Indices property to the a,b,c,d objects in a cadabra notebook. I would like to do this inside a python notebook. Here is my attempt:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import cadabra2 as cad
example_index = ['a', 'b', 'c', 'd']
cad.Indices(example_index_set, space=spacetime, independent=True)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This returns the error that example_index is not a Cadabra object, so I'm not understanding the syntax for cad.Indices. &lt;/p&gt;
&lt;p&gt;Thanks in advance!&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2711/how-do-i-use-object-properties-in-a-python-executable</guid>
<pubDate>Sat, 06 Jan 2024 11:28:02 +0000</pubDate>
</item>
<item>
<title>evaluate() returns RuntimeError when using the explicit value of an index</title>
<link>https://cadabra.science/qa/2710/evaluate-returns-runtimeerror-using-explicit-value-index</link>
<description>&lt;p&gt;Hi cdb experts and a happy new year (hopefully).&lt;/p&gt;
&lt;p&gt;Please consider the following code snippet:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;d = 3
{k,l,m,n}::Indices(rotation, values={1..3}).
\epsilon{#}::EpsilonTensor.

ex := (K_{1})_{m n} e_{1}_{n} = \epsilon_{1 m n} e_{1}_{n};
evaluate(ex, $e_{1}_{1} = 1, e_{1}_{2} = 0, e_{1}_{3} = 0$, rhsonly=True);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am trying to evaluate the simple matrix multiplication &lt;code&gt;K_1 e_1&lt;/code&gt; where &lt;code&gt;K_1&lt;/code&gt; is the antisymmetric matrix &lt;code&gt;\epsilon_{1 m n}&lt;/code&gt; and &lt;code&gt;e_1&lt;/code&gt; is the unit vector &lt;code&gt;[1,0,0]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I get the error &lt;code&gt;RuntimeError: No Indices property known for indices in EpsilonTensor&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On the other hand, if instead of the explicit index &lt;code&gt;_{1}&lt;/code&gt; I use a general index &lt;code&gt;_{l}&lt;/code&gt; then the calculation works (but it's not what I wanted to calculate):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;d = 3
{k,l,m,n}::Indices(rotation, values={1..3}).
\epsilon{#}::EpsilonTensor.

ex := (K_{l})_{m n} e_{l}_{n} = \epsilon_{l m n} e_{l}_{n};
evaluate(ex, $e_{1}_{1} = 1, e_{1}_{2} = 0, e_{1}_{3} = 0$, rhsonly=True);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any advice? Thank you!&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2710/evaluate-returns-runtimeerror-using-explicit-value-index</guid>
<pubDate>Thu, 04 Jan 2024 16:16:00 +0000</pubDate>
</item>
<item>
<title>Simplification of sum of terms r a^m + s a^m to (r+s)a^m</title>
<link>https://cadabra.science/qa/2707/simplification-of-sum-of-terms-r-a-m-s-a-m-to-r-s-a-m</link>
<description>&lt;p&gt;I'm trying to solve simple operator algebra problems invovling the harmonic oscillator creation and annihilation operators. So I want to do things like
a b^n -&amp;gt; n b^(n-1) + b^n a
where [a,b] = 1&lt;/p&gt;
&lt;p&gt;I've defined a set of rules that almost get me there, but the final result does not fully simplify and I don't know why. For example if I try to reduce a b^5 it produces
2 b^4 + 3 b^4 + b^5 a&lt;/p&gt;
&lt;p&gt;I'm not sure what I'm doing wrong here. If there is a better way to go about doing this kind of simplification please let me know.&lt;/p&gt;
&lt;p&gt;My code is as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a::Symbol;
b::Symbol;

{a,b}::NonCommuting;
{m,n,r,s}::Integer.

r1 := {
a^0 -&amp;gt; 1,
b^0 -&amp;gt; 1,
b^1 -&amp;gt; b,
a b^m  -&amp;gt; (1+b a) b^{m-1},
a b -&amp;gt; 1 + b a,
b^m  b -&amp;gt; b^{m+1},
b  b^m -&amp;gt; b^{1+m}
};

def act(ex):
    converge(ex):
        distribute(ex)
        expand(ex)
        substitute(ex,r1)
        sort_sum(ex)
        collect_factors(ex)
        collect_terms(ex)
        simplify(ex)
    return ex

act($a b^5$);    &lt;/code&gt;&lt;/pre&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2707/simplification-of-sum-of-terms-r-a-m-s-a-m-to-r-s-a-m</guid>
<pubDate>Mon, 01 Jan 2024 16:12:07 +0000</pubDate>
</item>
<item>
<title>Display &quot;hand-made&quot; latex</title>
<link>https://cadabra.science/qa/2702/display-hand-made-latex</link>
<description>&lt;p&gt;Hi experts.&lt;/p&gt;
&lt;p&gt;In a Jupyter notebook with Cadabra2 kernel:&lt;/p&gt;
&lt;p&gt;Is there any way to display &quot;hand made&quot; Latex, such as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;s = Latex(
    '\\begin{array}{l} \n'
    ' 0 &amp;amp;  0 &amp;amp;  0 \\   \n'
    ' 0 &amp;amp;  0 &amp;amp;  1 \\   \n'
    ' 0 &amp;amp; -1 &amp;amp;  0      \n'
    '\\end{array}      \n'
)._repr_latex_()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Trying to display the above with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;s;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;prints it out as a string not as a properly formated array.&lt;/p&gt;
&lt;p&gt;I am working in&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Jupyter notebook&lt;/li&gt;
&lt;li&gt;Cadabra2 kernel&lt;/li&gt;
&lt;li&gt;ipynb file&lt;/li&gt;
&lt;li&gt;Cadabra 2.4.5&lt;/li&gt;
&lt;li&gt;Ubuntu 22.04&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2702/display-hand-made-latex</guid>
<pubDate>Fri, 29 Dec 2023 13:01:02 +0000</pubDate>
</item>
<item>
<title>Replacing expressions in a matrix</title>
<link>https://cadabra.science/qa/2700/replacing-expressions-in-a-matrix</link>
<description>&lt;p&gt;Seasons greetings cdb experts, and many thanks in advance!&lt;/p&gt;
&lt;p&gt;In the code below I first create the set of matrices &lt;code&gt;Kl&lt;/code&gt;, then try to pick out the components of one of the matrices (&lt;code&gt;K1&lt;/code&gt; in the example) and display them.&lt;/p&gt;
&lt;p&gt;My actual goal is to display a matrix with the right values in a nice LaTeX format.&lt;/p&gt;
&lt;p&gt;If you run the code below, you will notice that I try to change the &lt;code&gt;i,j&lt;/code&gt; element of a matrix but despite the &lt;code&gt;element.replace()&lt;/code&gt;, the final &lt;code&gt;TheK1Matrix&lt;/code&gt; has values {12, 21} and not values {1, -1}. My questions are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;How to set the &lt;code&gt;i,j&lt;/code&gt; element of the matrix below?&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;from cdb.core.component import *
from  cdb.utils.node import *

{k,l,m,n}::Indices(rotation, values={1,2,3}).
\epsilon{#}::EpsilonTensor.
Kl := (K_{l})_{m n} = \epsilon_{l m n};
evaluate(Kl, rhsonly=True);

TheK1Matrix := [[0,0,0],[0,0,12],[0,21,0],].
for ex in Kl[r'\equals']:
    lhs = get_lhs(ex.ex())
    rhs = get_rhs(ex.ex())
    if ${a?,b?,c?}$.matches(lhs):
        n = int(str(nth_arg(lhs,0)))
        if n == 1:
            i = int(str(nth_arg(lhs,1)))
            j = int(str(nth_arg(lhs,2)))
            for element in TheK1Matrix[i-1][j-1]:
                element;
                rhs;
                element.replace(rhs);
TheK1Matrix;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Ultimately, my goal is to display that matrix using &quot;nice&quot; LaTeX formatting, of the general form&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;\begin{array}
    0 &amp;amp; 0 &amp;amp; 0 \\
    0 &amp;amp; 0 &amp;amp; 1 \\
    0 &amp;amp; -1 &amp;amp; 0
\end{array}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How to achieve that?&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2700/replacing-expressions-in-a-matrix</guid>
<pubDate>Wed, 27 Dec 2023 12:25:35 +0000</pubDate>
</item>
<item>
<title>Displaying a matrix with matplotlib error &quot;non-GUI backend&quot;</title>
<link>https://cadabra.science/qa/2698/displaying-a-matrix-with-matplotlib-error-non-gui-backend</link>
<description>&lt;p&gt;Hi cdb experts.&lt;/p&gt;
&lt;p&gt;I am in the&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Jupyter notebook with Cadabra2 kernel&lt;/li&gt;
&lt;li&gt;Ubuntu 22.04&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When trying to use matplotlib, I get the error&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and when I specifically set the backend to TkAgg I get&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UserWarning: Matplotlib is currently using TkAgg, which is a non-GUI backend, so cannot show the figure&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;even though Tk is a GUI backend.&lt;/p&gt;
&lt;p&gt;I &lt;em&gt;have&lt;/em&gt; set the pythonpath to &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;PYTHONPATH=/usr/lib/python3.10/:/usr/lib/python3.10/dist-packages:/usr/lib/python3.10/tkinter/&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and I &lt;em&gt;do&lt;/em&gt; have both matplotlib and tkinter (&quot;python3-tk&quot;) installed. What am I doing wrong, please?&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
&lt;p&gt;P.S. As an example, the following code produces said error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import matplotlib.pyplot as plt
from cdb.core.component import *

{i,j,k,l,m,n}::Indices(rotation, values={1,2,3}).
\epsilon{#}::EpsilonTensor.
Ki := (K_{i})_{m n} = \epsilon_{i m n}.
evaluate(Ki, rhsonly=True);

fig = plt.figure()

with plt.rc_context({'backend':'tkagg'}):
    for i in range(3):
        for j in range(3):
            val = get_component(Ki, $1, 0, 0$)
            plt.text(i,j,str(val), va='center',ha='center')

    plt.show()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Many thanks!&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2698/displaying-a-matrix-with-matplotlib-error-non-gui-backend</guid>
<pubDate>Mon, 25 Dec 2023 11:07:25 +0000</pubDate>
</item>
<item>
<title>Displaying components of the epsilon matrix</title>
<link>https://cadabra.science/qa/2696/displaying-components-of-the-epsilon-matrix</link>
<description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;Two questions please.&lt;/p&gt;
&lt;p&gt;Please consider the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;from cdb.core.component import *

{i,j,k,l,m,n}::Indices(topological,)
\epsilon::EpsilonTensor.
Ki := (K_{i})_{m n} = \epsilon_{i m n}.
get_component(Ki, $0, 0, 0$);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The answer it provides is entirely correct (&lt;code&gt;\epsilon_{0 0 0}&lt;/code&gt;) but&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I would like it to go the next step and display the actual value &lt;code&gt;1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Is there any way to obtain all the components of the complete matrix &lt;code&gt;Ki&lt;/code&gt; for a given &lt;code&gt;i&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Of course, if I have the answer to Q1, I can do a for-loop and get the answer to Q2. Ideally, I would like some function that provides a &lt;code&gt;list&lt;/code&gt; or &lt;code&gt;dict&lt;/code&gt; which I can then further format.&lt;/p&gt;
&lt;p&gt;Many thanks as always!&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2696/displaying-components-of-the-epsilon-matrix</guid>
<pubDate>Sun, 24 Dec 2023 11:56:20 +0000</pubDate>
</item>
<item>
<title>LaTeXForm expansion fails with &quot;free indices do not match&quot;</title>
<link>https://cadabra.science/qa/2692/latexform-expansion-fails-with-free-indices-do-not-match</link>
<description>&lt;p&gt;Hi and thanks as always for cdb.&lt;/p&gt;
&lt;p&gt;Please consider the following definition of an &quot;inner product&quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{α, β}::Indices(spacetime).
σ::LaTeXForm(&quot;\mathbf{σ}&quot;).
σ::DifferentialForm(degree=1).

e_{idx?}::LaTeXForm(&quot;\mathbf{e}&quot;, &quot;_{&quot;, idx?, &quot;}&quot;).

inner{a?? b??}::LaTeXForm(&quot;\langle&quot;,a??,&quot;, &quot;,b??,&quot;\rangle&quot;).&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works nicely when I write&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;σβ := inner{σ e_{β}} ;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but it fails when I write&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;σβ := σ_{β} = inner{σ e_{β}} ;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The error is&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;RuntimeError: Free indices on lhs and rhs do not match&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What am I doing wrong please?&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2692/latexform-expansion-fails-with-free-indices-do-not-match</guid>
<pubDate>Fri, 22 Dec 2023 11:23:54 +0000</pubDate>
</item>
<item>
<title>How to collect terms containing derivatives</title>
<link>https://cadabra.science/qa/2680/how-to-collect-terms-containing-derivatives</link>
<description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;I'm running the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{a#,b#}::Indices.
\delta{#}::KroneckerDelta.
{a#,b#}::Integer(0..3)
\partial{#}::PartialDerivative.
\epsilon{#}::EpsilonTensor(delta=-\delta).
h_{a1 b1}::Symmetric.
toh := {h_{a1 a1} = h, h_{a1}^{a1} = h}.
def LLmanip(ex):
    product_rule(ex) 
    distribute(ex)
    product_rule(ex)
    distribute(ex)
    epsilon_to_delta(ex)
    expand_delta(ex)
    distribute(ex)
    eliminate_kronecker(ex)
    canonicalise(ex)
    rename_dummies(ex)
    distribute(ex) 
    sort_product(ex)
    sort_sum(ex)
    substitute(ex, toh)
    lower_free_indices(ex)
    canonicalise(ex)
    rename_dummies(ex)
    collect_factors(ex)
    return(ex)

LL := \delta^{a1 b1 a2 b2 a3 b3 a4 b4} \partial_{a1}{h_{a2 b2}} \partial_{b1}{h_{a3 b3}} h_{a4 b4};
LLmanip(LL);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result i get has these two terms:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\partial_{a1}{h_{a1 a2}} \partial_{a2}{h} h&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;\partial_{a1}{h} \partial_{a2}{h_{a1 a2}} h&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which are the same but are not collected into one.&lt;/p&gt;
&lt;p&gt;Is there some way to combine the terms?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2680/how-to-collect-terms-containing-derivatives</guid>
<pubDate>Fri, 15 Dec 2023 14:55:16 +0000</pubDate>
</item>
<item>
<title>Partial derivative of a vector</title>
<link>https://cadabra.science/qa/2669/partial-derivative-of-a-vector</link>
<description>&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;I am very a new Cadabra user and I am trying to expand partial derivative of a vector field A i.e. $\partial_{\mu} { A^{\mu} }$ with the following snippet of code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{A^t,A^x, A^y, A^z}::Depends(\partial{#});
A := {A^{t}=A^t,A^{x}=A^x, A^{y}=A^y, A^{z}=A^z};
dA:=\partial_{\mu}{ A^{\mu} };
evaluate(dA,A);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which returns an error:
&lt;code&gt;RuntimeError: Dependencies on derivatives are not yet handled in the SymPy bridge&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I ideally want it to give me the componenet expansion like: $ \partial_{\mu} { A^{\mu} } = - \partial_t  A^t + \partial_x  A^x + \partial_y  A^y + \partial_z  A^z  $.&lt;/p&gt;
&lt;p&gt;Also I want it to return a 2x2 matrix when I try to evaulate $ \partial_{\mu} { A^{\nu} } $.&lt;/p&gt;
&lt;p&gt;Thanks in advance!&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2669/partial-derivative-of-a-vector</guid>
<pubDate>Wed, 06 Dec 2023 14:04:22 +0000</pubDate>
</item>
<item>
<title>A vector-field basis of derivatives?</title>
<link>https://cadabra.science/qa/2665/a-vector-field-basis-of-derivatives</link>
<description>&lt;p&gt;Hi Cdb experts. Thanks as always for your help.&lt;/p&gt;
&lt;p&gt;I am trying to write down a vector field as is common in differential geometry, with a basis of derivatives. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;u := u^{\mu} \partial_{\mu};&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My difficulty is that any serious calculation I try to do comes out all zeros. For example,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;from cdb.relativity.abstract import *
u := u^{\mu} \partial_{\mu};
v := v^{\mu} \partial_{\mu};
ex := @(u)@(v) - @(v)@(u);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there any way to make cdb aware that should be considered on operator &quot;waiting&quot; for something to operate upon?&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
&lt;p&gt;GPN&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2665/a-vector-field-basis-of-derivatives</guid>
<pubDate>Mon, 04 Dec 2023 22:23:50 +0000</pubDate>
</item>
<item>
<title>Avoiding index classes when handling ExNodes</title>
<link>https://cadabra.science/qa/2653/avoiding-index-classes-when-handling-exnodes</link>
<description>&lt;p&gt;I'm curious if other people have good strategies for avoiding index clashes when handling ExNodes directly.&lt;/p&gt;
&lt;p&gt;I have in mind the example of the covariant derivative in &lt;a rel=&quot;nofollow&quot; href=&quot;https://cadabra.science/notebooks/ref_programming.html&quot;&gt;https://cadabra.science/notebooks/ref_programming.html&lt;/a&gt;, which works fine so long as the index p on the connection doesn't appear in the original expression. (If it does, it breaks.) As far as I can tell, introducing indices when hacking ExNodes directly can easily lead to this.&lt;/p&gt;
&lt;p&gt;Presumably the only solution is to work hard to avoid index clashes? This is what substitute does behind the scenes when it's running, I gather.&lt;/p&gt;</description>
<category>General questions</category>
<guid isPermaLink="true">https://cadabra.science/qa/2653/avoiding-index-classes-when-handling-exnodes</guid>
<pubDate>Sat, 02 Dec 2023 03:58:14 +0000</pubDate>
</item>
</channel>
</rss>