Cadabra Q&A - Recent questions and answers
https://cadabra.science/qa/qa
Powered by Question2AnswerAnswered: Display currently running function
https://cadabra.science/qa/2447/display-currently-running-function?show=2448#a2448
<p>There is some internal functionality for algorithms to send out-of-band progress information to the user interface in v2, but it has mostly been to experiment with it and see what we need. Only the <code>meld</code> algorithm really uses it at the moment. I am not sure we have converged on the right mechanism yet, hence it hasn't been included in other algorithms. </p>
<p>The problem is, as always with logging, that you do not want to log too little, but you also do not want to log too much. However, this distinction is very much a function of the problem you are solving: sometimes you want to see an update for all terms <code>canonicalise</code> acts on, but sometimes that's a very fast part of some inner loop and you are not interested in that. Some nested progress indicator is probably best.</p>
<p>If you have any good ideas, please post.</p>Feature requestshttps://cadabra.science/qa/2447/display-currently-running-function?show=2448#a2448Thu, 02 Feb 2023 19:26:52 +0000Answered: Incorrect behaviour of meld?
https://cadabra.science/qa/2442/incorrect-behaviour-of-meld?show=2446#a2446
<p><code>Meld</code> does at present not work with anticommuting objects. Use <code>canonicalise</code> for now.</p>Bug reportshttps://cadabra.science/qa/2442/incorrect-behaviour-of-meld?show=2446#a2446Sat, 28 Jan 2023 20:56:25 +0000Incorrect Derivative Free Index Behaviour For User-Defined Symbols
https://cadabra.science/qa/2445/incorrect-derivative-free-index-behaviour-defined-symbols
<p>Consider the following example:</p>
<pre><code>\m::LaTeXForm("\mu").
\n::LaTeXForm("\nu").
D{#}::Derivative;
{\m,\n}::Indices(s,position=fixed);
{\mu,\nu}::Indices(p,position=fixed);
{x_\mu}::Coordinate;
ex:=D_{x_\mu}{\theta_\mu};
for i in ex.top().free_indices():
display(i);
{x_\m}::Coordinate;
ex:=D_{x_\m}{\theta_\m};
for i in ex.top().free_indices():
display(i);</code></pre>
<p>One would expect no free indices in both expressions. Indeed, for D<em>{x</em>\mu}{\theta_\mu}, there are no free indices. However, for the expression involving the user-defined LaTeXForm symbols \m, there are free indices.</p>
<p>This creates issues when trying to add two expressions like this together.</p>Bug reportshttps://cadabra.science/qa/2445/incorrect-derivative-free-index-behaviour-defined-symbolsFri, 27 Jan 2023 05:35:51 +0000How to get the `weight` value of an object?
https://cadabra.science/qa/2440/how-to-get-the-weight-value-of-an-object
<p>According to the (source) documentation, the <code>weight</code> property:</p>
<blockquote>
<p>Attach a labelled weight to an object, which can subsequently be used in the algorithms <code>keep_weight</code> and <code>drop_weight</code>. See the documentation of those algorithms for examples.</p>
</blockquote>
<p>Examples of it use can be found on the manual pages of the algorithms <a rel="nofollow" href="https://cadabra.science/manual/keep_weight.html">keep_weight</a> and <a rel="nofollow" href="https://cadabra.science/manual/drop_weight.html">drop_weight</a></p>
<h2>Question</h2>
<p>Is it possible to get the <code>weight</code> of an object?</p>
<p>My question is inspire in the uses of algorithms like <code>n_args</code> or <code>n_indices</code> (See <a rel="nofollow" href="https://cadabra.science/manual/cdb/utils/node.html">util.node</a>).</p>General questionshttps://cadabra.science/qa/2440/how-to-get-the-weight-value-of-an-objectSun, 22 Jan 2023 09:26:01 +0000Broken link in manual: `Weight`
https://cadabra.science/qa/2439/broken-link-in-manual-weight
<p>While the algorithms <a rel="nofollow" href="https://cadabra.science/manual/keep_weight.html">keep_weight</a> and <a rel="nofollow" href="https://cadabra.science/manual/drop_weight.html">drop_weight</a> are documented and both make use of (and called explicitly to) the <code>Weight</code> property, the manual page of this last function does not exist.</p>Bug reportshttps://cadabra.science/qa/2439/broken-link-in-manual-weightSun, 22 Jan 2023 08:07:11 +0000Answered: Index replacement problem
https://cadabra.science/qa/2435/index-replacement-problem?show=2438#a2438
<p>This is bug in <code>eliminate_kronecker</code>, which does not respect the grouping introduced by the inverse power. I have opened an issue at <a rel="nofollow" href="https://github.com/kpeeters/cadabra2/issues/271">https://github.com/kpeeters/cadabra2/issues/271</a> ; will try to fix it but it may take a few days.</p>Bug reportshttps://cadabra.science/qa/2435/index-replacement-problem?show=2438#a2438Wed, 11 Jan 2023 22:30:13 +0000Answered: Can not set the correct Cadabra kernel path for jupyter.
https://cadabra.science/qa/2432/can-not-set-the-correct-cadabra-kernel-path-for-jupyter?show=2433#a2433
<p>see link <a rel="nofollow" href="https://cadabra.science/faq.html#q_01_01">https://cadabra.science/faq.html#q_01_01</a></p>Installation troublehttps://cadabra.science/qa/2432/can-not-set-the-correct-cadabra-kernel-path-for-jupyter?show=2433#a2433Thu, 05 Jan 2023 20:12:51 +0000Answered: Missing directory when running Cadabra for the first time
https://cadabra.science/qa/2428/missing-directory-when-running-cadabra-for-the-first-time?show=2429#a2429
<p>The <code>cadabra2</code> package in Debian/Ubuntu is currently broken, and this leads to the error you showed. Please install a package from the download page at <a rel="nofollow" href="https://cadabra.science/download.html">https://cadabra.science/download.html</a> instead for now.</p>Installation troublehttps://cadabra.science/qa/2428/missing-directory-when-running-cadabra-for-the-first-time?show=2429#a2429Wed, 04 Jan 2023 21:31:50 +0000Answered: Cadabra with Wolfram Engine
https://cadabra.science/qa/2426/cadabra-with-wolfram-engine?show=2427#a2427
<p>I haven't tried with Wolfram Engine, but if what they write is true, then it should work. Be aware that I haven't built against Mathematica for a long time, so things like the CMake support to figure out where the Wolfram software is located on disk may not work. Also, the code that bridges between Cadabra and Mathematica notation is not as tested as that to SymPy.</p>
<p>You do need the Wolfram software installed locally as Cadabra will need the headers of the WRSTP library <a rel="nofollow" href="https://www.wolfram.com/wstp/">https://www.wolfram.com/wstp/</a> to build. I cannot distribute those along with Cadabra as that violates Wolfram's terms. </p>
<p>If you do give it a try, please post here to let us know how it went.</p>General questionshttps://cadabra.science/qa/2426/cadabra-with-wolfram-engine?show=2427#a2427Wed, 04 Jan 2023 17:28:06 +0000Answered: commuting variations and partial derivatives
https://cadabra.science/qa/2424/commuting-variations-and-partial-derivatives?show=2425#a2425
<p>The first <code>substitute</code> does nothing, as there is no explicit <code>A</code> in your expression. If you write, instead of <code>A</code>, a proper object wildcard <code>A??</code> (on both sides of the arrow) then it will work, and then your second substitute will do its job too.</p>General questionshttps://cadabra.science/qa/2424/commuting-variations-and-partial-derivatives?show=2425#a2425Fri, 30 Dec 2022 22:57:31 +0000Answered: Broken link on the webpage documentation
https://cadabra.science/qa/2406/broken-link-on-the-webpage-documentation?show=2421#a2421
<p>Now fixed, thanks.</p>Bug reportshttps://cadabra.science/qa/2406/broken-link-on-the-webpage-documentation?show=2421#a2421Mon, 19 Dec 2022 22:42:44 +0000Answered: Strange triple index error
https://cadabra.science/qa/2405/strange-triple-index-error?show=2420#a2420
<p>This is now fixed in 2.4.3.3, which is currently the head of the github master branch.</p>Bug reportshttps://cadabra.science/qa/2405/strange-triple-index-error?show=2420#a2420Mon, 19 Dec 2022 22:34:23 +0000Answered: Import notebook from subdirectory
https://cadabra.science/qa/2417/import-notebook-from-subdirectory?show=2418#a2418
<p>Do this as you do with any Python module which is stored in a subdirectory: use a "dot" as path separator. So</p>
<pre><code>from directory.notebook_name import *</code></pre>General questionshttps://cadabra.science/qa/2417/import-notebook-from-subdirectory?show=2418#a2418Fri, 16 Dec 2022 22:34:16 +0000Answered: Power with free indices not allowed
https://cadabra.science/qa/2414/power-with-free-indices-not-allowed?show=2415#a2415
<p>You wrote $r^2$ as <code>r^2</code> (in the definition of $g_{u u}$), which means "$r$ with superscript index 2". Write it as <code>r**2</code>. Ditto for $l^2$.</p>General questionshttps://cadabra.science/qa/2414/power-with-free-indices-not-allowed?show=2415#a2415Thu, 15 Dec 2022 21:48:39 +0000Answered: Simplify products of scalar functions
https://cadabra.science/qa/2407/simplify-products-of-scalar-functions?show=2412#a2412
<p>This is what <code>collect_factors</code> is for. In general the <code>simplify</code> function is a sledge-hammer which should be avoided, as it calls through to SymPy to do the work, which is slow and prone to issues when the expression contains concepts which SymPy does not know about (like that implicit dependence).</p>General questionshttps://cadabra.science/qa/2407/simplify-products-of-scalar-functions?show=2412#a2412Thu, 15 Dec 2022 08:37:05 +0000Answered: Installing with apt-get on Linux Mint 21
https://cadabra.science/qa/2398/installing-with-apt-get-on-linux-mint-21?show=2399#a2399
<p>You installed the old 1.x series. The package for the new series (since about 2016) is called cadabra2. You'll need a fairly recent Mint for that though. The alternative is to download a package from the downloads page at <a rel="nofollow" href="https://cadabra.science/download.html">https://cadabra.science/download.html</a> .</p>Installation troublehttps://cadabra.science/qa/2398/installing-with-apt-get-on-linux-mint-21?show=2399#a2399Fri, 09 Dec 2022 07:04:04 +0000Answered: How can I invert the product rule nicely [where there are extra numerical factors]?
https://cadabra.science/qa/2383/invert-product-nicely-where-there-extra-numerical-factors?show=2384#a2384
<p>I could <em>factor</em> the terms as you wanted.</p>
<p>The behaviour of your session might be due to the <code>properties</code> of your objects.</p>
<p>I took your (incomplete) example, and re-ensembled it like this:</p>
<pre><code>{a,b}::Indices.
\partial{#}::PartialDerivative.
{A,B,C,D}::Depends(\partial{#}).
ex := \partial_{a}{A} B + A \partial_{a}{B};
rule := \partial_{b?}{C??} D?? + C?? \partial_{b?}{D??}
-> \partial_{b?}{C?? D??};
substitute(ex, rule);</code></pre>
<hr>
<p><strong>Update</strong></p>
<p><code>Physics Cat</code> thank you for highlighting that the extra factor of <code>2</code> was not a typo.</p>
<p>In your case, I'd follow Kasper's (usual) advise, and use the substitution the other way around,</p>
<pre><code>rule2 := \partial_{b?}{C??} D?? -> - C?? \partial_{b?}{D??}
+ \partial_{b?}{C?? D??};</code></pre>
<p>The whole notebook (MWE) would be:</p>
<pre><code>{a,b}::Indices.
\partial{#}::PartialDerivative.
{A,B,C,D}::NonCommuting.
{A,B,C,D}::Depends(\partial{#}).
ex1 := \partial_{a}{A} B + A \partial_{a}{B};
rule := \partial_{b?}{C??} D?? + C?? \partial_{b?}{D??}
-> \partial_{b?}{C?? D??};
substitute(ex1, rule);
ex2 := \partial_{a}{A} B + 2 A \partial_{a}{B};
rule2 := \partial_{b?}{C??} D?? -> - C?? \partial_{b?}{D??}
+ \partial_{b?}{C?? D??};
substitute(ex2, rule2);</code></pre>
<p>Hope this could be of use!</p>General questionshttps://cadabra.science/qa/2383/invert-product-nicely-where-there-extra-numerical-factors?show=2384#a2384Thu, 08 Dec 2022 09:05:05 +0000Answered: Expansion of covariant derivative
https://cadabra.science/qa/2041/expansion-of-covariant-derivative?show=2382#a2382
<p>There's a very simple workaround for this.</p>
<pre><code>{\mu, \nu, \lambda, \kappa, \rho, \sigma#}::Indices(space, position=independent).
\partial{#}::PartialDerivative.
\nabla{#}::Derivative.
A{#}::Depends(\partial{#}, \nabla{#}).
ex1:= A_\mu.
ex2:= B_{\mu \nu} = \nabla_{\mu}{ A_\nu }.
expand_nabla(ex2)
rename_dummies(ex2);
ex3:= C_{\mu \nu \rho} = \nabla_{\mu}{B_{\nu \rho }}.
substitute(ex3, ex2)
expand_nabla(ex3);</code></pre>
<p>You essentially have to rename dummy indices after each use of expand_nabla.</p>General questionshttps://cadabra.science/qa/2041/expansion-of-covariant-derivative?show=2382#a2382Wed, 07 Dec 2022 09:06:36 +0000Answered: Scope of Depends()
https://cadabra.science/qa/2380/scope-of-depends?show=2381#a2381
<p>Two issues here. Firstly, make sure you do not write a space between the nabla and the thing on which it acts, so write</p>
<pre><code>\nabla_{a}{ A_{b c} }</code></pre>
<p>not</p>
<pre><code>\nabla_{a} { A_{b c} }</code></pre>
<p>If you do that, the double-nabla stays.</p>
<p>Secondly, you need to merge all the <code>Depends</code> properties into one, otherwise the 2nd one overwrites the first. So make that</p>
<pre><code>A{#}::Depends(\partial{#}, \nabla{#}).</code></pre>
<p>Then <code>unwrap</code> works as expected.</p>General questionshttps://cadabra.science/qa/2380/scope-of-depends?show=2381#a2381Tue, 06 Dec 2022 20:13:58 +0000Answered: Weird behavior where kernel crashes when substituting expression, depending on how the expression is written
https://cadabra.science/qa/2378/behavior-crashes-substituting-expression-depending-expression?show=2379#a2379
<p>This was due to an issue when simplifying powers of rationals, in particular things of the form $(-a)^{-1}$, which left unsimplified rationals in the expression tree. </p>
<p>This is now fixed in 2.4.3.2 available on the github master branch.</p>Bug reportshttps://cadabra.science/qa/2378/behavior-crashes-substituting-expression-depending-expression?show=2379#a2379Tue, 06 Dec 2022 12:22:08 +0000Answered: substitute() is buggy?
https://cadabra.science/qa/2376/substitute-is-buggy?show=2377#a2377
<p>That term which did not get substituted has an index <code>\alpha</code> on <code>covd2</code>. But you did not declare <code>\alpha</code> to be part of the index set <code>total</code>. Hence that object does not match the rule in <code>ex1</code>.</p>
<p>Just add <code>\alpha</code> to the index set and it works.</p>Bug reportshttps://cadabra.science/qa/2376/substitute-is-buggy?show=2377#a2377Sat, 03 Dec 2022 20:41:50 +0000Answered: How to access the value of an object?
https://cadabra.science/qa/2370/how-to-access-the-value-of-an-object?show=2373#a2373
<p>Your own answer works, but makes it impossible to use that same expression with a different free index. A more Cadabra-like way of doing this is to declare</p>
<pre><code>{\mu,\nu,\rho,\lambda,\phi,\chi}::Indices.
ex1:= T^{\mu\lambda} = A^{\mu \nu} B_{\nu \rho} C^{\rho \lambda};
ex2 := D_{\kappa \mu\nu} T^{\mu\nu};</code></pre>
<p>and then substitute <code>expr</code> with</p>
<pre><code> substitute(ex2, ex1);</code></pre>
<p>In Cadabra, equations have names, but those names are not themselves tensors. Those equation names (<code>ex1</code> and <code>ex2</code> above) do not carry indices.</p>General questionshttps://cadabra.science/qa/2370/how-to-access-the-value-of-an-object?show=2373#a2373Sat, 03 Dec 2022 19:11:28 +0000Answered: How to "factor out" derivatives?
https://cadabra.science/qa/2366/how-to-factor-out-derivatives?show=2367#a2367
<p>There's nothing built-in, but some variation of </p>
<pre><code>substitute(ex, $\partial_{a}{A??} + \partial_{a}{B??} -> \partial_{a}{A??+B??}$);</code></pre>
<p>will probably do the trick.</p>General questionshttps://cadabra.science/qa/2366/how-to-factor-out-derivatives?show=2367#a2367Fri, 02 Dec 2022 08:41:12 +0000Answered: Collect factors with negative power
https://cadabra.science/qa/2361/collect-factors-with-negative-power?show=2365#a2365
<p>Now fixed in 2.4.3.</p>General questionshttps://cadabra.science/qa/2361/collect-factors-with-negative-power?show=2365#a2365Thu, 01 Dec 2022 21:40:05 +0000Answered: Select/pattern matching for noncommuting expressions (gamma matrices) with free indices
https://cadabra.science/qa/2362/pattern-matching-noncommuting-expressions-matrices-indices?show=2364#a2364
<p>The problem with referring to explicit index names is always that computations tend to break quickly when you change things slightly. My usual approach is to replace each product by "half the symmetric product plus half the anti-symmetric product", and then replace the symmetric product by the metric. </p>
<p>But I admit that sometimes that's making things more complicated. I think the right way to go is to add this functionality to substitute's conditionals, so that you can write</p>
<pre><code>substitute(ex, $\gamma^{a?} \gamma^{b?} | a? < b? -> \gamma^{b?}\gamma^{a?} + 2\eta^{a? b?}$);</code></pre>
<p>That does not work yet, but I have added an issue on the github tracker: <a rel="nofollow" href="https://github.com/kpeeters/cadabra2/issues/265">https://github.com/kpeeters/cadabra2/issues/265</a></p>General questionshttps://cadabra.science/qa/2362/pattern-matching-noncommuting-expressions-matrices-indices?show=2364#a2364Thu, 01 Dec 2022 16:03:13 +0000Answered: Pattern matching based on free index?
https://cadabra.science/qa/2359/pattern-matching-based-on-free-index?show=2360#a2360
<p>There isn't a pattern for that, but you can simulate it by first contracting your expression with a dummy vector and then substituting in there. So e.g.</p>
<pre><code>{a,b,c}::Indices.
ex:= x^a + x^b x_b y^a;
ex := @(ex) f_a:
distribute(_);
substitute(_, $x^a f_a -> z^a f_a$);
factor_out(_, $f_a$);</code></pre>General questionshttps://cadabra.science/qa/2359/pattern-matching-based-on-free-index?show=2360#a2360Thu, 01 Dec 2022 13:51:21 +0000Answered: Import from notebook library not working
https://cadabra.science/qa/2356/import-from-notebook-library-not-working?show=2358#a2358
<p>The problem was that the <code>library.cnb</code> file was just a plain text file with Cadabra input, not a notebook file. When saving those, use the <code>.cdb</code> extension; <code>.cnb</code> is reserved for notebooks.</p>General questionshttps://cadabra.science/qa/2356/import-from-notebook-library-not-working?show=2358#a2358Wed, 30 Nov 2022 18:39:39 +0000Answered: Summation of the substitution rules
https://cadabra.science/qa/2353/summation-of-the-substitution-rules?show=2354#a2354
<p>This was changed in 2.4.0 to match more closely what other computer algebra systems do. You now need to call <code>join</code>, so e.g.</p>
<pre><code>lst1:= [a,b,c];
lst2:= [e,f,g];
lst3 = join(lst1, lst2);</code></pre>
<p>When you write lists inside a Cadabra expression, you can use the tie operator "~" (tilde),</p>
<pre><code>lst := [a,b,c] ~ [e,f,g];</code></pre>
<p>Hope this helps.</p>General questionshttps://cadabra.science/qa/2353/summation-of-the-substitution-rules?show=2354#a2354Wed, 30 Nov 2022 17:40:29 +0000Answered: Problems installing with brew on MacOS
https://cadabra.science/qa/2345/problems-installing-with-brew-on-macos?show=2352#a2352
<p>This turned out to be a compatibility issue with the recently released Python 3.11. I have updated Cadabra to 2.4.2.4 which contains a fix for this, and have also updated the Homebrew tap so that <code>brew install cadabra2</code> uses this latest version. This now works on my mac, please let me know if there are any remaining issues.</p>Installation troublehttps://cadabra.science/qa/2345/problems-installing-with-brew-on-macos?show=2352#a2352Mon, 28 Nov 2022 17:39:48 +0000Answered: Raising and lowering indices with an anti-symmetric tensor
https://cadabra.science/qa/2347/raising-and-lowering-indices-with-an-anti-symmetric-tensor?show=2348#a2348
<p>Add the <code>AntiCommuting</code> property to the indices, so e.g.</p>
<pre><code>{A,B}::Indices(position=fixed);
{A,B}::AntiCommuting;
ex:= v^A v_A - v_A v^A;
canonicalise(_);</code></pre>
<p>which produces $2 v^A v_A$. </p>Feature requestshttps://cadabra.science/qa/2347/raising-and-lowering-indices-with-an-anti-symmetric-tensor?show=2348#a2348Wed, 16 Nov 2022 18:30:51 +0000Answered: New properties: "Normal" and "Orthogonal"
https://cadabra.science/qa/2336/new-properties-normal-and-orthogonal?show=2337#a2337
<p>I am not in principle against adding some functionality to make these kind of manipulations easier. However, most of what you want to do can be achieved with some simple substitution rules. I think that the main thing you are looking for is some way to "put vectors or tensors in a labelled set", so that you can apply a rule whenever such an object appears. That makes things more useful in a wider context; your solution is very much tuned to a particular class of problems, and does not generalise well to situations where you may have multiple vector bundles or multiple surfaces to which something can be "orthogonal" or "normal".</p>
<p>Let's think this through a bit. Feel free to continue the discussion here so we get a better idea of what your requirements are.</p>Feature requestshttps://cadabra.science/qa/2336/new-properties-normal-and-orthogonal?show=2337#a2337Tue, 11 Oct 2022 21:18:03 +0000Answered: The sign of the Tides tensor is incorrect
https://cadabra.science/qa/2330/the-sign-of-the-tides-tensor-is-incorrect?show=2333#a2333
<p>Just to be clear, I got the correct result. The problem was solved when I changed the indices that where summed over by the vierbeins, i.e</p>
<p><code>K^{a}_{b}=R^{\mu}_{\rho\nu\beta}ei^{a}_{\mu}i^{\rho}_{t}i^{\nu}_{b}i^{\beta}_{t} -> K^{a}_{b}=R^{\mu}_{\rho\nu\beta}ei^{a}_{\mu}i^{\rho}_{t}i^{\beta}_{b}i^{\nu}_{t}</code></p>General questionshttps://cadabra.science/qa/2330/the-sign-of-the-tides-tensor-is-incorrect?show=2333#a2333Wed, 28 Sep 2022 14:51:12 +0000How to add new properties: "Normal" and "Othogonal"
https://cadabra.science/qa/2327/how-to-add-new-properties-normal-and-othogonal
<p>Hi, I want to know how to code properly for Cadabra. I read the section on programming in "The Cadabra Book" pdf but I need a little more explanation on programming new properties (like "::Coordinate")</p>
<p>I want to generate two new properties</p>
<ul>
<li>"Normal" can be applied to a 1D tensor (vector or covector)</li>
<li>"Orthogonal" can be applied to any tensor (that is not a scalar)</li>
</ul>
<p>Then if I have an expression with contraction of two tensors then I will write a function such that</p>
<ol>
<li>if the two tensors are normal vectors then their contraction is -1</li>
<li>if one tensor is orthogonal and the other is a normal (co)vector then their contraction is 0</li>
</ol>General questionshttps://cadabra.science/qa/2327/how-to-add-new-properties-normal-and-othogonalFri, 23 Sep 2022 09:51:43 +0000Questions about KroneckerDelta
https://cadabra.science/qa/2326/questions-about-kroneckerdelta
<p>The following codes </p>
<p><code>{t,x,y,z,r}::Coordinate; \delta{#}::KroneckerDelta. {i,j,k,l,m,n,o,p,q,s#}::Indices(fourD,values={t,x,y,z},position=independent); {i,j,k,l,m,n,o,p,q,s#}::Integer(range=0..3) xx:=\delta^1_1^2_2; evaluate(_); </code></p>
<p>give me the ouput :
<code>0</code></p>
<p>But, in my opinion I should get the value <code>1/2</code>.</p>
<p>Further, I run </p>
<p><code>xx2:=\delta^1_1^2_2; expand_delta(_); eliminate_kronecker(_); evaluate(_); </code>
at last, I get</p>
<p><code>RuntimeError: evaluate: Index 1 does not have an Indices property. At: Notebook Cell (Line 1): _ = evaluate(_); display(_) </code></p>General questionshttps://cadabra.science/qa/2326/questions-about-kroneckerdeltaTue, 13 Sep 2022 06:31:33 +0000Issue in sort_product() with AntiCommuting indices.
https://cadabra.science/qa/2325/issue-in-sort_product-with-anticommuting-indices
<p>I have the need for anti-commuting derivatives and objects so am trying to use anti-commuting indices instead of making the objects/derivatives themselves anti-commuting. product_rule() works as expected\, but I've found issues in sort_product() with this approach.</p>
<p>For example see the following code where I try sorting with various combinations of anti-commuting spinor indices and commuting vector indices.</p>
<pre><code>{\alpha, \beta, \rho, \lambda}::Indices(spinor, position=independent).
{\alpha, \beta, \rho, \lambda}::AntiCommuting.
{a, b, c}::Indices(vector, position=free).
\nabla{#}::Derivative.
{X{#}}::Depends(\nabla{#}).
zeroDer := X^{\alpha} X^{\beta} + X^{\beta} X^{\alpha};
sort_product(_);
oneDerSpinor := \nabla_{\alpha}(X^{\beta}) X^{\rho} + X^{\rho}\nabla_{\alpha}(X^{\beta});
sort_product(_);
oneDerVector := \nabla_{a}(X^{\beta}) X^{\rho} + X^{\rho}\nabla_{a}(X^{\beta});
sort_product(_);
twoDerSpinor := \nabla_{\lambda}(\nabla_{\alpha}(X^{\beta})) X^{\rho} + X^{\rho}\nabla_{\lambda}(\nabla_{\alpha}(X^{\beta}));
sort_product(_);
twoDerVector:= \nabla_{a}(\nabla_{b}(X^{\beta})) X^{\rho} + X^{\rho}\nabla_{a}(\nabla_{b}(X^{\beta}));
sort_product(_);</code></pre>
<p>You'll find that some of these combine correctly while some do not. If I attach AntiCommuting to X, it fixes some while breaking others. If my approach is incorrect, I'd greatly appreciate any other suggestions on how to handle AntiCommuting derivatives. I'm on macOs using Cadabra 2.3.8.</p>
<p>Thank you!
Greg</p>Bug reportshttps://cadabra.science/qa/2325/issue-in-sort_product-with-anticommuting-indicesFri, 19 Aug 2022 08:16:23 +0000Answered: Adjoint Spinor subscript Labels
https://cadabra.science/qa/2305/adjoint-spinor-subscript-labels?show=2316#a2316
<p>This is now fixed in 2.3.9.5 available on github.</p>
<p>Just for the record, you don't have to give <code>LaTeXForm</code> properties for symbols with numbers at the end. The <code>\psi1</code> symbol will automatically typeset as $$\psi_{1}$$.</p>General questionshttps://cadabra.science/qa/2305/adjoint-spinor-subscript-labels?show=2316#a2316Tue, 09 Aug 2022 16:28:26 +0000Answered: Problem with changed behaviour of '+' for lists.
https://cadabra.science/qa/2296/problem-with-changed-behaviour-of-for-lists?show=2302#a2302
<p>Apart from the 'tie' operator, there is now also the 'join' function. So you can do either</p>
<pre><code>ex1:={A,B};
ex2:={C,D};
ex3:= @(ex1) ~ @(ex2);</code></pre>
<p>to get <code>{A,B,C,D}</code>, or you can do</p>
<pre><code>ex1:={A,B};
ex2:={C,D};
ex3 = join(ex1, ex2)</code></pre>
<p>Join on a single element and a list will just add that element to the list, and join on two single elements will create a two-element list.</p>
<p>This was a quick hack not really thought through very deeply, so please report issues with this if you find any.</p>
<p><strong>Added</strong>: Just to explain why this was all necessary: I am working on fast numerical evaluation of symbolic expressions. This frequently involves component-wise addition of lists or nested lists. Since both Numpy and Mathematica use '+' for component-wise list addition, I decided to follow that.</p>Bug reportshttps://cadabra.science/qa/2296/problem-with-changed-behaviour-of-for-lists?show=2302#a2302Fri, 05 Aug 2022 14:14:39 +0000Answered: Variable can be handled like values?
https://cadabra.science/qa/813/variable-can-be-handled-like-values?show=2299#a2299
<p>I'd like to provide the full answer using Kasper's suggestion (and adding a few changes of my own)</p>
<pre><code>z::Coordinate;
{a,b,c,d}::Indices(values={0,1,2, 3, z},position=fixed);
\Gamma{#}::GammaMatrix(metric=\eta);
\eta{a b}::KroneckerDelta;
C_{a b c}::AntiSymmetric;
D^{a b c}::AntiSymmetric;
ex1:= C_{a b c} \Gamma^{a b c};
ex2:= C_{a b c} D^{a b c};
rl:= { C_{0 1 2} = \alpha, C_{1 2 3} = \beta, C_{1 2 z} = \gamma, D^{1 2 3} = \theta, D^{1 2 z} = \tau};
evaluate(ex1, rl);
evaluate(ex2, rl);</code></pre>
<p>The result of the code is <a rel="nofollow" href="https://ibb.co/5kwmQ2K">here</a></p>General questionshttps://cadabra.science/qa/813/variable-can-be-handled-like-values?show=2299#a2299Fri, 05 Aug 2022 09:37:56 +0000Answered: Substitution $A \mapsto A + \delta_A$
https://cadabra.science/qa/2297/substitution-%24a-mapsto-a-delta_a%24?show=2298#a2298
<p>Hi <code>novice0516</code>.</p>
<p>I'm not sure what is your aim with your notebook, but I know that the capabilities of <code>cadabra2</code> with differential forms is far from optimal... you might note that not even all the properties and algorithms are documented! (btw, it would be great to help developing those missing capabilities).</p>
<p>From my ignorance, I'd suggest to follow a different approach.</p>
<h2>Some critics to your workflow:</h2>
<ul>
<li>Your are defining differential forms but you are not using the wedge product.</li>
<li>If you substitute an object with a derivative, What is the <em>scope</em> of the derivative?</li>
<li>I would argue that your substitution is changing the degree of the expression.</li>
</ul>
<h2>Suggestions</h2>
<p>Please take into account that my suggestions come from the ignorance of your purpose.</p>
<ul>
<li>I'd define my objects as non-commutative (if necessary). Your operetors <code>A</code>, <code>B</code>, <code>C</code> and <code>D</code> should commute but in the example below I defined as non-commuting just for fun!</li>
<li>If you define the variations as derivative, general derivatives do not commute! (I've included a commented line with the explicit declaration anyway).</li>
<li>Define the scope of the derivative operators</li>
</ul>
<h2>Code</h2>
<pre><code>{A,B,C,D}::NonCommuting;
{da{#},db{#}}::Derivative;
# {da{#},db{#}}::NonCommuting;
ex:= da{ B C D};
converge(ex):
distribute(_)
product_rule(_)
;</code></pre>
<p>I tried the second derivative</p>
<pre><code>ex:= db{da{ B C D }};
converge(ex):
distribute(_)
product_rule(_)
;</code></pre>
<p>And the commutator of derivatives</p>
<pre><code>ex:= db{da{ B C D }} - da{db{ B C D }};
converge(ex):
distribute(_)
product_rule(_)
;</code></pre>
<p>Let me know if my suggestions were useful, but remember that my intention is to give you a different way to try your programme.</p>
<p>Cheers.</p>General questionshttps://cadabra.science/qa/2297/substitution-%24a-mapsto-a-delta_a%24?show=2298#a2298Mon, 01 Aug 2022 10:17:16 +0000Answered: Similar terms are not collected
https://cadabra.science/qa/2292/similar-terms-are-not-collected?show=2294#a2294
<p>This issue is now hopefully fixed, in version 2.3.9.3 which is the current head of the github master branch. Please let me know.</p>Bug reportshttps://cadabra.science/qa/2292/similar-terms-are-not-collected?show=2294#a2294Wed, 22 Jun 2022 18:20:34 +0000Answered: sort_product bug with position=independent and identical variables
https://cadabra.science/qa/2291/sort_product-with-position-independent-identical-variables?show=2293#a2293
<p>Thanks for creating a minimal example! This issue should be fixed in 2.3.9.3, which is on the current github master branch.</p>Bug reportshttps://cadabra.science/qa/2291/sort_product-with-position-independent-identical-variables?show=2293#a2293Wed, 22 Jun 2022 18:18:33 +0000Answered: Using spherical harmonics in cadabra.
https://cadabra.science/qa/2289/using-spherical-harmonics-in-cadabra?show=2290#a2290
<p>Cadabra currently does not have any functionality for spherical harmonics. There is some support for that in sympy though, which may help. As long as you go from a Cadabra expression to a sympy expression all is fine; getting expressions from sympy back into Cadabra for further computations is not very well supported at the moment. </p>Feature requestshttps://cadabra.science/qa/2289/using-spherical-harmonics-in-cadabra?show=2290#a2290Thu, 02 Jun 2022 18:03:52 +0000Cadabra 2 notebooks and REPL more responsive than script interpreter
https://cadabra.science/qa/2288/cadabra-notebooks-repl-more-responsive-script-interpreter
<p>I am having some trouble using the <code>diff</code> command. If run Cadabra2 REPL with <code>cadabra2</code> it works just fine:</p>
<pre><code>> ex:= A*A + B + C;
A A + B + C
> diff(ex, $A$);
2*A</code></pre>
<p>Same with the GTK GUI. I would expect it to do the same if I put my commands into a <code>.cdb</code> file and ran <code>cadabra2 file.cdb</code>. File contents are</p>
<pre><code>ex:= A*A + B + C;
diff(ex, $A$);</code></pre>
<p>so exactly the same thing, but <code>diff</code> just spits the original expression back at me instead:</p>
<pre><code>$ cadabra2 file.cdb
A A + B + C
A A + B + C</code></pre>
<p>It seems to just echo the last expression before the diff command; if I put some other expression in between the two,</p>
<pre><code>ex:= A*A + B + C;
foo:= B;
diff(ex, $A$);</code></pre>
<p>the output is</p>
<pre><code>$ cadabra2 file.cdb
A A + B + C
B
B</code></pre>
<p>Surely this is not intentional?</p>Bug reportshttps://cadabra.science/qa/2288/cadabra-notebooks-repl-more-responsive-script-interpreterSun, 22 May 2022 21:11:05 +0000Answered: doubt about how to make assumptions in multiple files
https://cadabra.science/qa/2286/doubt-about-how-to-make-assumptions-in-multiple-files?show=2287#a2287
<p>Put these lines in a separate notebook, let's say <code>defs.cnb</code>. Then import that notebook into another one by doing <code>import defs</code>. </p>General questionshttps://cadabra.science/qa/2286/doubt-about-how-to-make-assumptions-in-multiple-files?show=2287#a2287Sat, 21 May 2022 10:29:43 +0000Answered: Generic TeX error bug
https://cadabra.science/qa/2184/generic-tex-error-bug?show=2185#a2185
<p>There are a few things going on here. Let me start with the right way to do this:</p>
<pre><code>test := e_{\mu}{}^{a};
for n in test:
display(n.ex())</code></pre>
<p>In order to display Cadabra expressions, it's almost always best to use <code>display</code>, as <code>print</code> lacks the logic to make the notebook display LaTeX expressions. The <code>display</code> function ensures that many things (mathematical expressions, plots, ...) show up in the best way in the notebook.</p>
<p>You also need <code>n.ex()</code>, not just <code>n</code>, because <code>display</code> does not (yet) understand the <code>ExNode</code> object (which <code>n</code> is). For everything it does not understand, it calls <code>str</code> on it, and then you are effectively back to what you wrote. By calling <code>n.ex()</code> you convert the <code>ExNode</code> object <code>n</code> to an <code>Ex</code> object, which <code>display</code> knows how to handle.</p>
<p>Finally: I agree it would have been useful if <code>str(n)</code> produced something printable in the notebook (so that your original code would display the three expressions in non-typeset LaTeX form). Unfortunately, by default <code>str</code> turns <code>\mu</code> into the Unicode symbol for that character, and LaTeX doesn't understand that. This is a bug, we should turn off Unicode printing in the notebook.</p>Bug reportshttps://cadabra.science/qa/2184/generic-tex-error-bug?show=2185#a2185Thu, 31 Mar 2022 08:09:30 +0000Answered: Substitution employing double overline accent?
https://cadabra.science/qa/2180/substitution-employing-double-overline-accent?show=2181#a2181
<p>That's because your first term contains</p>
<pre><code>\overline{ \overline{u_{i}} \overline{u_{j}} }</code></pre>
<p><em>not</em></p>
<pre><code>\overline{ \overline{ u_{i} u_{j} } }</code></pre>
<p>So your pattern in <code>rl2</code> does not match.</p>
<p>It's difficult to see in the LaTeX output as the two overlines merge, but if you print the tree-form
with <code>print(tree(conv))</code> you can see it.</p>General questionshttps://cadabra.science/qa/2180/substitution-employing-double-overline-accent?show=2181#a2181Thu, 03 Mar 2022 20:00:26 +0000Answered: Issue with eliminate metric
https://cadabra.science/qa/2176/issue-with-eliminate-metric?show=2177#a2177
<p>If you want to use metrics to raise/lower your indices, then you <em>cannot</em> declare them as <code>position=free</code>. The latter means that the position of indices (subscript/superscript) has no meaning and can be changed arbitrarily, without factors of the metric. But worse, it means that all your patterns collapse to a single one, because upper indices will match lower indices and vice versa.</p>
<p>If you change your first line to contain <code>position=fixed</code> then things work as expected. The <code>eliminate_metric</code> will then not do anything (since there is no metric in your expression), but <code>eliminate_kronecker</code> will replace the $g_{\mu}{}^{\mu}$ with $d$. A further <code>canonicalise</code> will remove the $\Gamma^{\mu}{}_{\mu}$.</p>Bug reportshttps://cadabra.science/qa/2176/issue-with-eliminate-metric?show=2177#a2177Sun, 27 Feb 2022 18:21:39 +0000issue installing on mac
https://cadabra.science/qa/2174/issue-installing-on-mac
<p>Hi,</p>
<p>I'm trying to install cadabra2 on my mac and I keep getting error that I copied below upon doing the cmake. I tried every step a couple of times and all installed well on my operator. I just wonder if you have an idea what the problem can be from?</p>
<p>thank you</p>
<p>build % cmake -DENABLE_MATHEMATICA=OFF ..</p>
<p>-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Git found: /usr/bin/git</p>
<hr>
<h2>Building Cadabra version 2.3.9.1 (64-bit)</h2>
<p>-- Build id '2803.ce5bc98ee9' dated 2022-02-18
-- Build mode is set to ''
-- Install directory set to /usr/local
-- Building tweak version
-- Building in user mode
-- Building tests</p>
<hr>
<h2>Configuring Python</h2>
<p>-- Building for use with Python 3 (good!)
-- pybind11 v2.9.0 dev1
-- Found PythonInterp: /usr/local/bin/python3.9 (found version "3.9.10")
-- Found PythonLibs: /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Performing Test HAS_FLTO_THIN
-- Performing Test HAS_FLTO_THIN - Success
-- Found python /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib
-- Python version is 3.9.
-- Installing Python module in /usr/local/lib/python3.9/site-packages
-- Python abi name cpython-39-darwin</p>
<hr>
<h2>Configuring Jupyter kernel</h2>
<p>-- Building the default Jupyter kernel</p>
<hr>
<h2>Configuring client-server</h2>
<p>-- Found PkgConfig: /opt/local/bin/pkg-config (found version "0.29.2")
Warning: Use glibmm@2.66 instead of deprecated glibmm@2.64
Warning: Use glibmm@2.66 instead of deprecated glibmm@2.64
Warning: Use pangomm@2.46 instead of deprecated pangomm@2.42
Warning: Use pangomm@2.46 instead of deprecated pangomm@2.42
-- Using PKG_CONFIG_PATH = /usr/local/opt/glibmm@2.66/lib/pkgconfig:/usr/local/opt/cairomm@1.14/lib/pkgconfig:/usr/local/opt/pangomm@2.46/lib/pkgconfig:/usr/local/opt/atkmm@2.28/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig:
-- Checking for module 'glibmm-2.4'
-- Package 'sigc++-2.0', required by 'glibmm-2.4', not found
CMake Error at /opt/local/share/cmake-3.18/Modules/FindPkgConfig.cmake:545 (message):
A required package was not found
Call Stack (most recent call first):
/opt/local/share/cmake-3.18/Modules/FindPkgConfig.cmake:733 (_pkg_check_modules_internal)
cmake/modules/FindGLIBMM.cmake:16 (pkg_check_modules)
client_server/CMakeLists.txt:18 (find_package)</p>
<p>-- Configuring incomplete, errors occurred!
See also "/Users/amirrrezahashemi/Documents/Eonum/cadabra2/build/CMakeFiles/CMakeOutput.log".
See also "/Users/amirrrezahashemi/Documents/Eonum/cadabra2/build/CMakeFiles/CMakeError.log".</p>General questionshttps://cadabra.science/qa/2174/issue-installing-on-macMon, 21 Feb 2022 09:15:08 +0000question regarding a rule involving partial derivative
https://cadabra.science/qa/2169/question-regarding-a-rule-involving-partial-derivative
<p>Hi,</p>
<p>I was looking for a rule involving partial derivative action on a tensor. Suppose I have an expression like </p>
<p>\begin{align}
\partial_{a} A^{a}+ A_{a}B^{a} + (\partial_{a b}A_{a}) B^{b} + \partial_{b}A_{a} \partial^{b}B^{a}
\end{align} </p>
<p>I wish to define a rule such that I need to set the quadratic terms that involves the derivatives to vanish , i.e, I need to set $\partial_{a b}{A_{a}} B^{b} \rightarrow 0, \partial_{b}A_{a} \partial^{b}B^{a} \rightarrow 0$, I am not abe to get a proper rule to do this.</p>
<p>Also is there any way in which I can also set a partial derivative that involves any no f derivatives to zero, like I need to set
\begin{align}
\partial_{a} A^{c} =0;
\partial_{a b} A^{c}=0;
\end{align}</p>
<p>etc</p>
<p>I was thinking of something like</p>
<pre><code>ex:= \partial{#}{A{#}} -> 0;</code></pre>
<p>But didnt seem to work. can you please help me out</p>Feature requestshttps://cadabra.science/qa/2169/question-regarding-a-rule-involving-partial-derivativeMon, 14 Feb 2022 07:48:40 +0000converting partial derivative to covariant derivative
https://cadabra.science/qa/2167/converting-partial-derivative-to-covariant-derivative
<p>Hi,</p>
<p>After a computation I ended up in expression that involves partial derivatives. I want to simplofy that to covariant derivative expression . I am expressing a prototype of the problem here</p>
<p>Suppose after a computation i ended up in a expression like</p>
<p>\begin{align}
\partial_{a}A^{b} + \frac{1}{2}A^{c} q^{b d}\partial_{a} q_{d c} + \frac{1}{2} A^{c} q^{b d}\partial_{c}q_{a d} - \frac{1}{2} A^{c} q^{b d}\partial_{d}q_{a c}
\end{align}</p>
<p>I want to simplify this to $\nabla_{a}A^{b}$. For this I used the following code</p>
<pre><code>{u, r, z1 , z2}::Coordinate;
{a , b , c , d , e , f , g , h , i , j , k , l , m , n#}::Indices(values={(z1),(z2)}, position=fixed);
\partial{#}::PartialDerivative;
\nabla{#}::Derivative;
q_{a b}::Metric;
q^{a b}::InverseMetric;
q^{a}_{b}::KroneckerDelta;
q_{a}^{b}::KroneckerDelta;
q{#}::Depends(u , a , b , c , d , e , f , g , h , i , j , k , l , m , n# ,\partial{#});
\delta{#}::KroneckerDelta;
\Gamma^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2});
A_{a}::Depends(u, r , a , b , c , d , e , f , g , h , i , j , k , l , m , n#);
rule:={\partial_{a}{A^{b}} -> \nabla_{a}{A^{b}} - \Gamma^{b}_{a c} A^{c} , \partial_{a}{q_{b c}} -> \Gamma^{d}_{a b} q_{d c} + \Gamma^{d}_{a c} q_{b d}} };
test:=\partial_{a}{A^{b}} + (1/2)*A^{c} q^{b d}\partial_{a}{q_{d c}} + (1/2)*A^{c} q^{b d}\partial_{c}{q_{a d}} - (1/2)*A^{c} q^{b d}\partial_{d}{q_{a c}};
substitute(test, rule);
distribute(test);
canonicalise(_);</code></pre>
<p>But i ended up in a completely different expression . I think the issue might be that CHristoffel symbols are raised and lowered w.r.t metric. Can you please help me out to simplify such expressions.</p>General questionshttps://cadabra.science/qa/2167/converting-partial-derivative-to-covariant-derivativeFri, 11 Feb 2022 10:30:24 +0000