Cadabra Q&A - Recent questions and answers
http://cadabra.science/qa/qa
Powered by Question2AnswerAnswered: unexpected crash
http://cadabra.science/qa/390/unexpected-crash?show=1133#a1133
<p>In case anyone is still following this thread, this is now fixed on github master (version 2.2.7 or later).</p>
Bug reportshttp://cadabra.science/qa/390/unexpected-crash?show=1133#a1133Thu, 18 Apr 2019 11:56:11 +0000Answered: Inconsistencies in factor_out and factor_in
http://cadabra.science/qa/1126/inconsistencies-in-factor_out-and-factor_in?show=1130#a1130
<p>Let me first address the case which does work with the current version (at least for me):</p>
<pre><code>ex2:= (a + b - c) d + (-a -b + c) d
factor_out(_,$d$);
</code></pre>
<p>correctly factors out $d$. Factoring out composite expressions (like the $a+b-c$) is currently not supported, unfortunately.</p>
<p>All the other cases have to do with factoring out tensors. In general, for that to work, you need to have the indices on the expression you want to factor out be the same on all terms (so sort the expression and <code>rename_dummies</code> first), and it needs to be un-ambiguous (your last example isn't, because the <code>factor_out(_, $g_{a b}$)</code> means 'factor out the g-tensor with two indices', not 'factor out the g-tensor with one index 'a' and one 'b'').</p>
<p>Fixing this has been on the TODO list for some time, but there are only 25 hours in each day unfortunately.</p>
Bug reportshttp://cadabra.science/qa/1126/inconsistencies-in-factor_out-and-factor_in?show=1130#a1130Thu, 18 Apr 2019 09:53:06 +0000Answered: Cadabra crashes on non-ASCII input
http://cadabra.science/qa/1127/cadabra-crashes-on-non-ascii-input?show=1129#a1129
<p>This should now be fixed with the current version on github. There are still a few issues with actually using non-ascii symbols in Cadabra expressions, but the crashes are gone.</p>
Bug reportshttp://cadabra.science/qa/1127/cadabra-crashes-on-non-ascii-input?show=1129#a1129Thu, 18 Apr 2019 09:37:54 +0000Answered: How define a general tensor symmetry
http://cadabra.science/qa/1098/how-define-a-general-tensor-symmetry?show=1125#a1125
<p>With the provided information, you cannot determine an irrep under which your tensor transform. That's why you cannot use <code>TableauSymmetry</code></p>
<p>Notice however that, your tensor could lie on the <code>{2,2,2}</code> Young tableau. Perhaps that can help!</p>
<p>Cheers.</p>
General questionshttp://cadabra.science/qa/1098/how-define-a-general-tensor-symmetry?show=1125#a1125Tue, 16 Apr 2019 15:45:47 +0000Answered: Symmetrise pairs of indices
http://cadabra.science/qa/1111/symmetrise-pairs-of-indices?show=1124#a1124
<p>As shown in the manual, <a rel="nofollow" href="https://cadabra.science/manual/TableauSymmetry.html,">https://cadabra.science/manual/TableauSymmetry.html,</a> you could use the property <code>TableauSymmetry</code></p>
<pre><code>A_{a b c d}::TableauSymmetry( shape={2,2}, indices={0,2,1,3} );
</code></pre>
<p>Cheers.</p>
General questionshttp://cadabra.science/qa/1111/symmetrise-pairs-of-indices?show=1124#a1124Tue, 16 Apr 2019 15:32:38 +0000Answered: what is the use of question mark postindices, how it changes contractions and symmetry properties of indices?
http://cadabra.science/qa/1117/question-postindices-changes-contractions-symmetry-properties?show=1118#a1118
<p>A single question mark indicates a pattern (or wildcard), so that should only be used in e.g. <code>substitute</code>. Under most circumstances you don't need them for normal indices. Two question marks indicate an <code>object wildcard</code>, that is, a wildcard which matches an entire tensor. Have a look at</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_patterns.html">https://cadabra.science/notebooks/ref_patterns.html</a></p>
<p>in the reference guide, and then reply to this answer in case it is still not clear.</p>
General questionshttp://cadabra.science/qa/1117/question-postindices-changes-contractions-symmetry-properties?show=1118#a1118Mon, 08 Apr 2019 08:15:50 +0000Answered: nested zoom/unzoom
http://cadabra.science/qa/1112/nested-zoom-unzoom?show=1115#a1115
<p>The easter bunny is early this year: the version now on github does <code>unzoom</code> step by step, except when you give it the <code>repeat=True</code> parameter, in which it unzooms all the way to the original expression. Let me know if you run into any issues.</p>
General questionshttp://cadabra.science/qa/1112/nested-zoom-unzoom?show=1115#a1115Sat, 06 Apr 2019 13:16:19 +0000Answered: glob pattern in rules
http://cadabra.science/qa/1105/glob-pattern-in-rules?show=1106#a1106
<p>Try</p>
<pre><code>foo := t0 A + t2 B + t13 C;
substitute(foo, $t? | \regex{t?}{"t[0-9]*"} -> 1$);
</code></pre>
<p>The structure of this replacement rule is described in the reference guide chapter on <a rel="nofollow" href="https://cadabra.science/notebooks/ref_patterns.html">patterns</a>.</p>
General questionshttp://cadabra.science/qa/1105/glob-pattern-in-rules?show=1106#a1106Sun, 31 Mar 2019 11:28:21 +0000Answered: to_lhs produces Python syntax error
http://cadabra.science/qa/1101/to_lhs-produces-python-syntax-error?show=1102#a1102
<p>Thanks for reporting this, you are number 2 today ;-) It's now fixed on github, or if you want to patch it locally: just replace that line with <code>to_rhs(ex, *parts)</code>.</p>
Bug reportshttp://cadabra.science/qa/1101/to_lhs-produces-python-syntax-error?show=1102#a1102Wed, 27 Mar 2019 12:09:34 +0000Answered: Is it possible to use "+/-" as indices?&How to define a commutator?
http://cadabra.science/qa/1093/is-it-possible-to-use-as-indices-%26how-to-define-a-commutator?show=1094#a1094
<p>Use <code>fm</code> and <code>fp</code> and define</p>
<pre><code>fm{#}::LaTeXForm("{f_{-}}").
fp{#}::LaTeXForm("{f_{+}}").
</code></pre>
<p>To expand, use</p>
<pre><code>substitute(_, $\commutator{A??}{B??} -> A?? B?? - B?? A??$);
</code></pre>
<p>Does that help?</p>
General questionshttp://cadabra.science/qa/1093/is-it-possible-to-use-as-indices-%26how-to-define-a-commutator?show=1094#a1094Sun, 24 Mar 2019 08:10:36 +0000Answered: Can I use any Greek alphabet as a spinor?
http://cadabra.science/qa/1088/can-i-use-any-greek-alphabet-as-a-spinor?show=1089#a1089
<p>If you declare <code>\xi</code> to be a <code>Spinor</code> too, it should work.</p>
General questionshttp://cadabra.science/qa/1088/can-i-use-any-greek-alphabet-as-a-spinor?show=1089#a1089Thu, 21 Mar 2019 11:14:54 +0000some things about "substitute"
http://cadabra.science/qa/1084/some-things-about-substitute
<p>I want to achieve following rule</p>
<pre><code>...a b c d...->c d... ...a b
</code></pre>
<p>I have tried function <code>substitute</code>, but I have no idea how to achieve it. My recent work need this operation. Are there any suggestions about it?</p>
<p>For example, everything is <code>NonCommuting</code> and <code>depends \partial{#}</code> in following formula<br>
$$ <br>
a b \partial_{\mu} c d <br>
$$</p>
<p>I must exchange $a b$ with $ \partial_{\mu} c d $ to get</p>
<p>$$ <br>
\partial_{\mu} {c} d a b<br>
$$</p>
<p>then use <code>substitute</code> or <code>integrate_by_parts</code> to get </p>
<p>$$<br>
- c \partial_{\mu}(d a b)<br>
$$</p>
<p>I am trapped in this point now. </p>
General questionshttp://cadabra.science/qa/1084/some-things-about-substituteTue, 19 Mar 2019 14:41:35 +0000Some suggestions for the next version
http://cadabra.science/qa/1079/some-suggestions-for-the-next-version
<p>Hi, Kasper,<br>
There days, I try to learn cadabra to help me to do computation, it is great and I like it. BUT I find there are some things could be done better :</p>
<ol>
<li><p>If cadabra could implement substitute operation continuously like mathematica in following method</p>
<p><code>a\.a->b\.b->c\.c->d...</code><br>
, cadabra will be easier to use. After all, most people use this function frequently;</p></li>
<li><p>Add code completion;</p></li>
<li><p>Add usage of keyboard shortcuts;</p></li>
<li><p>Add functions trace(especially,for gamma matrix) and dagger( I have mentioned it at another place);</p></li>
<li><p>Perfect fucntion <code>substitute</code> or add a function can change <code>a b ... c d..</code> to <code>c d...a b...</code> ;</p></li>
<li><p>Update this paper <a rel="nofollow" href="https://cadabra.science/static/pdf/cadabra.pdf">Tutorial and reference guide</a> to 2.x;</p></li>
<li><p>Add optional parameter to make <code>function</code> keep original value unchangable after implementing(especially, function <code>substitute</code>);</p></li>
<li><p>Make notebook supports Chinese language when writing in latex mode.</p></li>
</ol>
<p>I just wish cadabra would be more perfect.Thanks for your so great work again.</p>
Feature requestshttp://cadabra.science/qa/1079/some-suggestions-for-the-next-versionTue, 19 Mar 2019 05:27:04 +0000Answered: How to use \dagger ?
http://cadabra.science/qa/1071/how-to-use-dagger?show=1072#a1072
<p>We are in the process of making this properly supported, but in the meantime, give this function a shot (you need to build Cadabra from source for this, the functionality is not yet in any of the binary packages):</p>
<pre><code>def expand_conjugate(ex):
tst:= (A??)^{\dagger};
for node in ex:
if tst.matches( node ):
rep=$P$
lst=[]
for prod in node["\\prod"]:
for factor in prod.factors():
lst.append($ @(factor) $)
for factor in list(reversed(lst)):
rep.top().append_child($ @(factor)^{\dagger} $)
rep.top().name=r"\prod"
node.replace(rep)
return ex
</code></pre>
<p>If you stick the above in a cell and evaluate it, you can then do</p>
<pre><code>\dagger::Symbol;
ex:= (A B C)^{\dagger} + Q + (D E)^{\dagger};
expand_conjugate(ex);
</code></pre>
<p>to produce</p>
<p>$$C^{\dagger} B^{\dagger} A^{\dagger} + Q + E^{\dagger} D^{\dagger}$$</p>
<p>There will be better support for generic conjugation operations in Cadabra soon.</p>
<p>For the other two lines, try simple substitution with a rule of the type</p>
<pre><code>rl:= { (A?^{\dagger})^{\dagger} = A?,
( (A??)^{\dagger} )^{\dagger} = A??,
A?^{\dagger} A? = 1,
A? A^{\dagger} = 1,
(A??)^{\dagger} A?? = 1,
A?? (A??)^{\dagger} = 1 };
</code></pre>
<p>You can then do e.g.</p>
<pre><code>\dagger::Symbol;
{A,B,U}::NonCommuting;
ex:= ( U^{\dagger} )^{\dagger} + U^{\dagger} U
+ (A B)^{\dagger} + ( (A B)^{\dagger} )^{\dagger};
substitute(ex, rl);
</code></pre>
<p>Hope this helps.</p>
General questionshttp://cadabra.science/qa/1071/how-to-use-dagger?show=1072#a1072Sun, 17 Mar 2019 15:19:13 +0000Answered: NameError: name 'dsolve' is not defined At: <string>(7)
http://cadabra.science/qa/1067/nameerror-name-dsolve-is-not-defined-at-string-7?show=1069#a1069
<p>You need to </p>
<pre><code>from cdb.sympy.solvers import *
</code></pre>
<p>before this works. Requires a fairly recent pull from git, this functionality is not yet in any of the binary distributions. You do not need <code>import sympy</code>, that's already done for you by Cadabra.</p>
General questionshttp://cadabra.science/qa/1067/nameerror-name-dsolve-is-not-defined-at-string-7?show=1069#a1069Sat, 16 Mar 2019 09:22:56 +0000Sort product with symbols
http://cadabra.science/qa/1064/sort-product-with-symbols
<p>Hey, I have been working for a few hours now with substitute and it behaves perfectly so far! <br>
However, now that symbols which were initially indices appear in the main expression, there seems to be a problem with sort product. I am attaching below a sample piece of code:</p>
<pre><code>{\dagger}::Symbol.
{a,b,c,\alpha,\beta,\gamma}::Symbol;
{P^{\dagger}_{a? \alpha?}, K_{a? b?}}::NonCommuting.
{a?, x_{a?},P^{\dagger}_{a? \alpha?}, K_{a? b?}}::SortOrder;
ex:=K_{a b} a x_{a} P^{\dagger}_{b \alpha};
sort_product(_);
</code></pre>
<p>In this case the expression remains unchanged, although the c-numbers a and x_a should be taken to the left. Am I missing something?</p>
<p>Thank you!</p>
General questionshttp://cadabra.science/qa/1064/sort-product-with-symbolsWed, 13 Mar 2019 10:44:30 +0000Answered: How to bypass triple index error for symbols?
http://cadabra.science/qa/1037/how-to-bypass-triple-index-error-for-symbols?show=1062#a1062
<p>I have pushed a fix for this to github master just now. It took a little while longer than planned as this was probably the first time such expressions got tested properly, and in that process I ran into a subtle other <code>substitute</code> bug which I wanted to fix as well. </p>
<p>Let me know if this does what you need (or not, in which case I'll be happy to make more changes/fixes).</p>
General questionshttp://cadabra.science/qa/1037/how-to-bypass-triple-index-error-for-symbols?show=1062#a1062Tue, 12 Mar 2019 19:49:38 +0000Answered: Bug in split index cadabra 2.2.6 (build 2031.aa34dcb4e3 dated 2019-03-04)
http://cadabra.science/qa/1044/bug-split-index-cadabra-build-2031-aa34dcb4e3-dated-2019-04?show=1052#a1052
<p>I have pushed a fix for this to github master. Are you able to build from source?</p>
Bug reportshttp://cadabra.science/qa/1044/bug-split-index-cadabra-build-2031-aa34dcb4e3-dated-2019-04?show=1052#a1052Tue, 05 Mar 2019 15:04:28 +0000Answered: update Cadabra: reference guide and tutorial to 2.x
http://cadabra.science/qa/1039/update-cadabra-reference-guide-and-tutorial-to-2-x?show=1040#a1040
<p>See <a rel="nofollow" href="https://cadabra.science/help.html">https://cadabra.science/help.html</a> (not entirely complete but better than nothing).</p>
Feature requestshttp://cadabra.science/qa/1039/update-cadabra-reference-guide-and-tutorial-to-2-x?show=1040#a1040Sat, 02 Mar 2019 11:02:16 +0000Matrix exponential
http://cadabra.science/qa/1035/matrix-exponential
<p>It would be nicer if the future Cadabra would be able to deal with calculating the exponentials of (Gamma) matrices. </p>
Feature requestshttp://cadabra.science/qa/1035/matrix-exponentialSun, 17 Feb 2019 14:18:29 +0000Examles of using Cadabra for superspace calculations.
http://cadabra.science/qa/1033/examles-of-using-cadabra-for-superspace-calculations
<p>I am trying to use a program for computation in superspace. Unfortunately, this raises many questions. I am sure that many people have already done such calculations. Can someone send examples of such calculations? For example, how the action of covariant derivatives is realized and the chiral superfield is described.</p>
General questionshttp://cadabra.science/qa/1033/examles-of-using-cadabra-for-superspace-calculationsFri, 01 Feb 2019 13:47:09 +0000Answered: Curved and Flat Indices
http://cadabra.science/qa/1031/curved-and-flat-indices?show=1032#a1032
<p>Those are just names; the full form of that first property is</p>
<pre><code> {\mu,\nu,\rho}::Indices(name=curved, position=fixed).
</code></pre>
General questionshttp://cadabra.science/qa/1031/curved-and-flat-indices?show=1032#a1032Thu, 31 Jan 2019 14:36:20 +0000Answered: Please show a simple example showing difference b/w Indices(curved) and Indices(flat).
http://cadabra.science/qa/1029/simple-example-showing-difference-indices-curved-indices?show=1030#a1030
<p>Read the chapter on indices in the reference manual,</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_indices.html">https://cadabra.science/notebooks/ref_indices.html</a></p>
<p>Hope that helps; if it doesn't, reply to this and I'll make another attempt.</p>
General questionshttp://cadabra.science/qa/1029/simple-example-showing-difference-indices-curved-indices?show=1030#a1030Tue, 29 Jan 2019 10:00:19 +0000Answered: Substitute Christoffel2nd into Dual Riemann tensor
http://cadabra.science/qa/1027/substitute-christoffel2nd-into-dual-riemann-tensor?show=1028#a1028
<p>The steps should be</p>
<pre><code>substitute(uDualRiemann, lRieman);
substitute(uDualRiemann, Riemann);
substitute(uDualRiemann,Christoffel2nd);
</code></pre>
<p>The 1st line rewrites the Riemann with all lower indices in terms of one with the first index raised. The 2nd line substitutes the definition of the Riemann in terms of Christoffel symbols. And then the 3rd line rewrites the Christoffel symbols in terms of derivatives of the metric.</p>
General questionshttp://cadabra.science/qa/1027/substitute-christoffel2nd-into-dual-riemann-tensor?show=1028#a1028Sun, 27 Jan 2019 11:41:46 +0000Answered: Fedora 29 rpm cpack error
http://cadabra.science/qa/1020/fedora-29-rpm-cpack-error?show=1023#a1023
<p>I have made a few changes to detect Fedora 29 and build the package appropriately (using normal cmake, not cmake3). The resulting package is now available from the download page.</p>
Installation troublehttp://cadabra.science/qa/1020/fedora-29-rpm-cpack-error?show=1023#a1023Mon, 14 Jan 2019 19:06:53 +0000Answered: Correlation functions, Wick theorem and summation
http://cadabra.science/qa/1012/correlation-functions-wick-theorem-and-summation?show=1018#a1018
<p>I am not sure exactly which summation problem you are trying to solve; maybe you can give a bit more detail?</p>
<p>For the Wick story, here's a bit of code I put together a while ago which may help you get things implemented. It basically gives you a <code>contract</code> function which takes a product of fields and replaces all pairs with propagators. You'll need to expand this of course to do real world problems but the gist of the solution is in here.</p>
<p>First, you need something that takes a list of numbers and returns all possible ways in <br>
which you can pair numbers:</p>
<pre><code>def all_pairs(lst):
if len(lst) < 2:
yield []
return
else:
a = lst[0]
for i in range(1,len(lst)):
pair = (a,lst[i])
for rest in all_pairs(lst[1:i]+lst[i+1:]):
yield [pair] + rest
</code></pre>
<p>That's just a bit of standard Python, nothing Cadabra-specific. Then you need something that takes a cadabra expression and does the contractions in there:</p>
<pre><code>def contract(ex):
amp:=0.
L=list(range(len(ex)))
for c in all_pairs(L):
diag:=1;
for p in c:
a1=ex[p[0]][0]
a2=ex[p[1]][0]
diag *= $G( @(a1) - @(a2) )$
amp += diag
return amp
</code></pre>
<p>Hopefully this makes it clear how to take Cadabra expressions apart and build new ones from the pieces. Then the following works:</p>
<pre><code>ex:=\phi(x_1) \phi(x_2) \phi(x_3) \phi(x_4);
contract(ex);
</code></pre>
<p>gives</p>
<p>$$G\left(x_{1}-x_{2}\right) G\left(x_{3}-x_{4}\right)+G\left(x_{1}-x_{3}\right) G\left(x_{2}-x_{4}\right)+G\left(x_{1}-x_{4}\right) G\left(x_{2}-x_{3}\right)$$</p>
<p>For any serious work you'll probably have to rewrite the <code>all_pairs</code> function so that it is not recursive.</p>
General questionshttp://cadabra.science/qa/1012/correlation-functions-wick-theorem-and-summation?show=1018#a1018Sat, 12 Jan 2019 14:13:48 +0000Answered: Fedora 29 rpm is missing
http://cadabra.science/qa/1016/fedora-29-rpm-is-missing?show=1017#a1017
<p>I didn't yet get around to building it, will do so the next few days.</p>
Installation troublehttp://cadabra.science/qa/1016/fedora-29-rpm-is-missing?show=1017#a1017Sat, 12 Jan 2019 12:53:23 +0000Answered: whenever make Cadabra do lengthy calculations, I always get error on output
http://cadabra.science/qa/1009/whenever-cadabra-lengthy-calculations-always-error-output?show=1010#a1010
<p>You'll have to make this a bit more specific. Can you email me (info@cadabra.science) a notebook that fails in this way (preferably as short as possible)? </p>
General questionshttp://cadabra.science/qa/1009/whenever-cadabra-lengthy-calculations-always-error-output?show=1010#a1010Wed, 02 Jan 2019 17:42:33 +0000Answered: Homebrew install problem
http://cadabra.science/qa/1005/homebrew-install-problem?show=1007#a1007
<p>There is now the option to install directly using homebrew. First install MacTeX, either directly from its website, or using homebrew,</p>
<pre><code>brew tap caskroom/cask
brew cask install mactex
</code></pre>
<p>Then install cadabra using</p>
<pre><code>brew tap kpeeters/repo
brew install cadabra2
</code></pre>
<p>These instructions are now also on the download page. Please let me know if you run into any trouble; this has not yet received a lot of testing!</p>
Installation troublehttp://cadabra.science/qa/1005/homebrew-install-problem?show=1007#a1007Mon, 17 Dec 2018 20:26:02 +0000Answered: Grouping substitution rules makes the kernel unresponsive
http://cadabra.science/qa/1001/grouping-substitution-rules-makes-the-kernel-unresponsive?show=1002#a1002
<p>Those output lines suggest that you used a version which wasn't really meant for production. I am assuming you compiled from source? Can you try pulling the latest version from github, building that and then trying again?</p>
<p>If that does not solve the problem, please email your notebook to info@cadabra.science and I'll have a look. If it worked before it is probably something small.</p>
Bug reportshttp://cadabra.science/qa/1001/grouping-substitution-rules-makes-the-kernel-unresponsive?show=1002#a1002Fri, 14 Dec 2018 11:14:08 +0000Answered: collect_factors(_) for Symbol indices
http://cadabra.science/qa/998/collect_factors-_-for-symbol-indices?show=999#a999
<p>It should, it's a bug introduced with tidying up some pattern matching functions. I have just pushed a fix for this to github. Thanks for reporting.</p>
General questionshttp://cadabra.science/qa/998/collect_factors-_-for-symbol-indices?show=999#a999Mon, 03 Dec 2018 15:02:11 +0000Answered: Calculating determinants and traces
http://cadabra.science/qa/951/calculating-determinants-and-traces?show=991#a991
<p>There's a <code>Determinant</code> property now which you can use together with <code>complete</code> to compute determinants, as in <a rel="nofollow" href="https://cadabra.science/manual/Determinant.html">https://cadabra.science/manual/Determinant.html</a> .</p>
General questionshttp://cadabra.science/qa/951/calculating-determinants-and-traces?show=991#a991Fri, 23 Nov 2018 21:47:11 +0000Answered: Simple example showing differences between position=free, fixed and independent
http://cadabra.science/qa/937/example-showing-differences-between-position-independent?show=990#a990
<p>See the updated chapter 1.4 of the reference guide, <a rel="nofollow" href="https://cadabra.science/notebooks/ref_indices.html">https://cadabra.science/notebooks/ref_indices.html</a> .</p>
General questionshttp://cadabra.science/qa/937/example-showing-differences-between-position-independent?show=990#a990Fri, 23 Nov 2018 16:14:47 +0000Answered: Multiplying \sqrt{2} by 1/\sqrt{2} crashes the kernel unexpectedly
http://cadabra.science/qa/983/multiplying-sqrt-by-sqrt-2-crashes-the-kernel-unexpectedly?show=984#a984
<p>No, this is a bug. You'd be surprised how many computations can be done without ever encountering this one... Will fix, thanks.</p>
General questionshttp://cadabra.science/qa/983/multiplying-sqrt-by-sqrt-2-crashes-the-kernel-unexpectedly?show=984#a984Mon, 19 Nov 2018 21:17:52 +0000Answered: AntiCommuting/SelfAntiCommuting only for different indices
http://cadabra.science/qa/977/anticommuting-selfanticommuting-only-different-indices?show=979#a979
<p>You would first declare the $a$ and $a^\dagger$ operators to be anti-commuting among themselves, so</p>
<pre><code>{n,m,p,q}::Indices(position=free);
a_{n}::SelfAntiCommuting;
ad_{n}::SelfAntiCommuting;
ad_{n}::LaTeXForm("a^\dagger").
</code></pre>
<p>where the last line is just to make the <code>ad_{n}</code> print nicely. Then ensure that the default is for daggered and non-daggered operators to be non-commuting,</p>
<pre><code>{a_{n}, ad_{m}}::NonCommuting;
</code></pre>
<p>Now the only thing you need to do is to decide what you want to do with expressions which involve $a$ and $a^\dagger$. In many cases, the logic is to 'move' all $a$ to the far right of an expression (so they can annihilate a vacuum state on which they act). You can do that with the rule</p>
<pre><code>\delta_{m n}::KroneckerDelta;
rl:= a_{m} ad_{n} -> - ad_{n} a_{m} + \delta_{n m};
</code></pre>
<p>You then apply this rule repeatedly to an expression, distributing products at every step and eliminating Kronecker deltas. If you want you can do this automatically at every step of a calculation, by sticking that logic into the <code>post_process</code> function. Example:</p>
<pre><code>def post_process(ex):
# move all a operators to the right
converge(ex):
substitute(ex, rl)
distribute(ex)
eliminate_kronecker(ex)
sort_product(ex)
collect_terms(ex)
</code></pre>
<p>If you now enter e.g. the expression</p>
<pre><code>ex:= a_{n} ad_{p} a_{m} ad_{m} a_{n};
</code></pre>
<p>you get the answer</p>
<p>$$ -a^\dagger_m a_m a_p + \delta_{m m} a_p .$$</p>
<p>Hope this helps.</p>
General questionshttp://cadabra.science/qa/977/anticommuting-selfanticommuting-only-different-indices?show=979#a979Mon, 12 Nov 2018 20:54:18 +0000Answered: Windows 10 version doesn't work
http://cadabra.science/qa/971/windows-10-version-doesnt-work?show=972#a972
<p>This is a known issue and we're investigating the origin of it; will post here if there's something new to try. </p>
Installation troublehttp://cadabra.science/qa/971/windows-10-version-doesnt-work?show=972#a972Sun, 28 Oct 2018 20:22:24 +0000Answered: IPython notebooks example not working
http://cadabra.science/qa/963/ipython-notebooks-example-not-working?show=964#a964
<p>The <code>param</code> argument should have been optional, but at some point we stripped out the default value for that argument, and since the Cadabra preparser fills it in automatically, no-one noticed. </p>
<p>Until this is fixed, you can use</p>
<pre><code>Symmetric(ex, Ex(''))
</code></pre>
<p>in place of your last line (that is, set <code>param</code> equal to an empty expression).</p>
Bug reportshttp://cadabra.science/qa/963/ipython-notebooks-example-not-working?show=964#a964Thu, 25 Oct 2018 20:36:42 +0000Answered: drop_weight before distribute
http://cadabra.science/qa/954/drop_weight-before-distribute?show=955#a955
<p>The logic here is intentional: <code>drop_weight</code> only acts on terms with a well-defined weight, and the $\epsilon (\epsilon^3 + 5)$ term is not of that type. So at the moment the answer is 'no'.</p>
<p>However, if your problem is that doing <code>distribute</code> is going to mess up too many other terms, you can try zooming into the expression and only distributing terms which match a certain pattern. E.g.</p>
<pre><code>\epsilon::Weight(label=field, value=1);
Exp:=(A+B)*\epsilon**2+\epsilon*(\epsilon**3+5);
zoom(_, $\epsilon Q??$);
distribute(_);
unzoom(_);
drop_weight(_, $field=4$);
</code></pre>
<p>would produce $(A+B)\epsilon^2 + 5\epsilon$, with the brackets in the first term intact.</p>
General questionshttp://cadabra.science/qa/954/drop_weight-before-distribute?show=955#a955Mon, 15 Oct 2018 10:09:53 +0000Issue with combine algorithm
http://cadabra.science/qa/953/issue-with-combine-algorithm
<p>I am using cadabra 2.2.1 </p>
<p>ex:=A^\alpha B<em>{\alpha};<br>
combine(</em>);</p>
<p>produces the output (BA) which is clearly unexpected while, </p>
<p>ex:=A<em>\alpha B</em>{\alpha};<br>
combine(_);</p>
<p>produces the output (AB) which is expected. I require the combine to work for contractions like Einstein summation. Please help</p>
Bug reportshttp://cadabra.science/qa/953/issue-with-combine-algorithmSat, 13 Oct 2018 13:11:03 +0000Require two calls to canonicalise?
http://cadabra.science/qa/938/require-two-calls-to-canonicalise
<p>Hi Folks,</p>
<p>The following code requires two calls to <code>canonicalise</code> to get the expected output (zero).<br>
Is this expected behaviour? </p>
<pre><code>W^{a}_{b c}::TableauSymmetry(shape={2}, indices={1,2});
{a,b,c,d,e,f,g,h#}::Indices(position=fixed).
foo := v_{a} W^{a}_{b c} - v^{a} W_{a c b};
sort_product (foo);
canonicalise (foo);
canonicalise (foo);
</code></pre>
<p>Cheers,<br>
Leo</p>
Bug reportshttp://cadabra.science/qa/938/require-two-calls-to-canonicaliseFri, 28 Sep 2018 09:51:08 +0000Answered: Generic typesetting LaTex error on Windows 10, Cadabra2.2.1d
http://cadabra.science/qa/930/generic-typesetting-latex-error-on-windows-10-cadabra2-2-1d?show=932#a932
<p>Once that happens, can you open a command line window, navigate to the TMPDIR path, and do</p>
<pre><code>pdflatex [filename]
</code></pre>
<p>where <code>filename</code> is, in the example above, <code>sglw.2.tex</code>. Then send me the resulting error message (if any).</p>
<p>It is possible that MikTeX is installed to not download missing packages, or perhaps the <code>pdflatex</code> command is not in your path, but I can't see that from the error message you quoted.</p>
Bug reportshttp://cadabra.science/qa/930/generic-typesetting-latex-error-on-windows-10-cadabra2-2-1d?show=932#a932Thu, 20 Sep 2018 08:24:30 +0000Answered: Derivatives not inheriting SelfAntiCommuting with canonicalise
http://cadabra.science/qa/908/derivatives-inheriting-selfanticommuting-canonicalise?show=909#a909
<p>This is a bug, thanks for reporting it. The code path for <code>sort_product</code> is different from the one for <code>canonicalise</code>; the latter is more complicated and contains a bug somewhere. <br>
I have opened an issue at <a rel="nofollow" href="https://github.com/kpeeters/cadabra2/issues/113">https://github.com/kpeeters/cadabra2/issues/113</a> .</p>
Bug reportshttp://cadabra.science/qa/908/derivatives-inheriting-selfanticommuting-canonicalise?show=909#a909Fri, 24 Aug 2018 18:01:10 +0000Answered: Windows 10 64-bit install not working yet
http://cadabra.science/qa/755/windows-10-64-bit-install-not-working-yet?show=902#a902
<p>Please try the 2.2.1d installer which is now available, and let me know if that's any better.</p>
Installation troublehttp://cadabra.science/qa/755/windows-10-64-bit-install-not-working-yet?show=902#a902Mon, 20 Aug 2018 16:09:24 +0000Answered: Bug: Generic TeX error
http://cadabra.science/qa/728/bug-generic-tex-error?show=901#a901
<p>There is now a 2.2.1d installer on the download page; can anyone with issues on Windows please try that one? I think this one should finally do the trick...</p>
<p>It is probably advisable to first remove the installation directory of any previous installs.</p>
Bug reportshttp://cadabra.science/qa/728/bug-generic-tex-error?show=901#a901Mon, 20 Aug 2018 16:08:02 +0000Answered: Defining the Rarita-Schwinger action: Action outputs 0
http://cadabra.science/qa/898/defining-the-rarita-schwinger-action-action-outputs-0?show=899#a899
<p>It's mostly an issue with not putting brackets at the right places. While Cadabra uses TeX notation, you sometimes have to be a little more explicit than strictly necessary in TeX, in order to avoid ambiguity. So you have to write e.g.</p>
<pre><code>\bar{\psi_{\mu}}
</code></pre>
<p>so that it is clear to Cadabra that the <code>\psi_{\mu}</code> is an 'argument' of <code>\bar</code>. Ditto for <code>\partial</code>, which you need to write as</p>
<pre><code>\partial_{\nu}{ \psi_{\rho} }
</code></pre>
<p>so that the <code>\psi_{\rho}</code> explicitly becomes an 'argument' of <code>\partial</code>. In your example, the <code>\partial_{\nu}\psi_{\rho}</code> was interpreted as a derivative acting on nothing, multiplied with <code>\psi_{\rho}</code>, giving nothing.</p>
<p>Here's a tidied-up version which works:</p>
<pre><code>#Rarita-Scwhinger Action
def post_process(ex):
sort_product(ex)
eliminate_kronecker(ex)
canonicalise(ex)
collect_terms(ex)
{\mu,\nu,\rho}::Indices(position=independent);
x::Coordinate;
\Gamma{#}::GammaMatrix(metric=\eta);
\eta_{\mu\nu}::Metric;
\partial{#}::Derivative;
\psi_{\mu}::Spinor;
\bar{#}::DiracBar;
\psi_{\mu}::Depends(x);
S:=\int{\bar{\psi_{\mu}} \Gamma^{\mu\nu\rho} \partial_{\nu}{\psi_{\rho}} }{x};
</code></pre>
<p>I have fixed a few typos and also changed the index type to 'independent' to prevent Cadabra from raising/lowering index pairs (usually better for susy computations, as you can then keep all indices on the Gamma's upstairs and more easily convert them using vielbeine).</p>
General questionshttp://cadabra.science/qa/898/defining-the-rarita-schwinger-action-action-outputs-0?show=899#a899Mon, 20 Aug 2018 10:03:08 +0000Answered: Partial derivative of exp()
http://cadabra.science/qa/895/partial-derivative-of-exp?show=896#a896
<p>This is something somewhere in the middle between an abstract and a component computation, and I haven't yet settled completely on what is the best way to handle this. For the time being I would suggest you use a simple substitution rule, e.g.</p>
<pre><code>\partial{#}::PartialDerivative;
test:=\partial_{\mu}{\exp(i*x^{\lambda}*k_{\lambda})};
rl:= \partial_{\mu}{ \exp( A?? ) } -> \exp( A?? ) \partial_{\mu}{ A?? };
substitute(test, rl);
product_rule(test);
substitute(test, $\partial_{\mu}{x^{\lambda}} -> \delta_{\mu}^{\lambda}$ );
unwrap(test);
</code></pre>
<p>That gets you almost there, but <code>eliminate_kronecker</code> which you would now want to use cannot handle the duplicate dummy index pair. So you'll need another substitution to get rid of the Kronecker delta.</p>
<p>Good example though, will see if we can make this work more easily.</p>
General questionshttp://cadabra.science/qa/895/partial-derivative-of-exp?show=896#a896Fri, 17 Aug 2018 09:22:45 +0000Answered: Is number_of_terms deprecated?
http://cadabra.science/qa/892/is-number_of_terms-deprecated?show=893#a893
<p>Yes, use standard Python <code>len</code>:</p>
<pre><code>ex:=A+B+C;
len(ex);
</code></pre>
<p>shows '3'.</p>
General questionshttp://cadabra.science/qa/892/is-number_of_terms-deprecated?show=893#a893Thu, 16 Aug 2018 07:03:49 +0000Answered: How to evaluate components of covariant derivative
http://cadabra.science/qa/885/how-to-evaluate-components-of-covariant-derivative?show=887#a887
<p>Yes you will need to determine the components of the metric and Christoffel symbols first, following e.g. the Schwarzschild tutorial notebook. You then need to expand your covariant derivatives into partial derivatives and Christoffels. You can do that with a simple substitution rule if you only have vectors and co-vectors, or you can use a more generic routine to do arbitrary tensors; see the example at the bottom of</p>
<p><a rel="nofollow" href="https://cadabra.science/notebooks/ref_programming.html">https://cadabra.science/notebooks/ref_programming.html</a></p>
<p>for more on that. This is something that will become available in the form of a package in 2.2.2 or 2.2.4.</p>
General questionshttp://cadabra.science/qa/885/how-to-evaluate-components-of-covariant-derivative?show=887#a887Sun, 12 Aug 2018 09:00:34 +0000Answered: Operator acting on tensors
http://cadabra.science/qa/879/operator-acting-on-tensors?show=880#a880
<p>Adding indices to object wildcards is not supported because there are very few cases where that actually makes much sense. The problem is that, if your rule had worked, it would also match</p>
<pre><code> met{ A_{b} }{ B_{b} }
met{ A_{b c d} }{ B_{c} }
</code></pre>
<p>and so on. You then almost always want to have control over where the extra $a$ index would need to be added (at the beginning of the set? at the end? in the middle?) and the notation which you wanted to use does not leave any way to specify that location. </p>
<p>So instead, you will need to make a rule which does not take an arbitrary object, but something which has the index structure spelled out. If you had in mind just to act on symbols $V$ and $W$, the rule</p>
<pre><code>Expmet:= met{X?}{Y?} -> X?_{a} Y?_{a};
</code></pre>
<p>would work. This will apply to your <code>met{V}{W}</code> case, but will not apply to any of the cases at the top of this reply. You could, however, write e.g.</p>
<pre><code>Expmet2:= met{ X?_{b} }{ Y?_{b} } -> X?_{b a} Y?_{a b};
</code></pre>
<p>or similar. That rule would allow you to do</p>
<pre><code>{a,b,c,d}::Indices;
ex:= met{ A_{c} }{ B_{c} };
exmet:= met{ X?_{b} }{ Y?_{b} } -> X?_{b a} Y?_{a b} ;
substitute(ex, exmet);
</code></pre>
<p>Hope the logic is clear.</p>
<p>So <strong>TL;DR</strong>: object patterns (patterns with '<code>??</code>' attached) are very brute force hammers, not always suitable when name patterns (patterns with just '<code>?</code>') will do.</p>
<p>(In addition, your example triggered a parsing bug that led to the indices being put on the product, not on the individual tensors, but that's a different story).</p>
General questionshttp://cadabra.science/qa/879/operator-acting-on-tensors?show=880#a880Sat, 11 Aug 2018 10:15:16 +0000Answered: How to evaluate the tensor of energy momentum for provided metric anzatz and 4-velocity
http://cadabra.science/qa/873/evaluate-energy-momentum-provided-metric-anzatz-velocity?show=874#a874
<p>Combine the rules for <code>u</code> and <code>g</code> into one call to <code>evaluate</code>, as in</p>
<pre><code>evaluate(T, u+g, rhsonly=True);
</code></pre>
General questionshttp://cadabra.science/qa/873/evaluate-energy-momentum-provided-metric-anzatz-velocity?show=874#a874Thu, 09 Aug 2018 16:34:53 +0000