ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 01 Oct 2020 13:56:23 +0200Defining 4jm Wigner symbolshttps://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/Hi everyone,
I am a neophyte and I can't understand my error in spite of the many tutorials I have watched. I want to define the 4jm Wigner symbols, which should basically be defined as:
var('m')
wigner_4j(j1,j2,j3,j4,j,m1,m2,m3,m4) = sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4),m,-j,j)
I get plenty of errors that I can't fix. It is weird to me because the overall logic seemed good, as it works for instance when I define in a similar manner:
var('n')
b(p,q) = sum(binomial(p,n)*binomial(q,n),n,0,min(p,q))
Thanks for your help!Wed, 30 Sep 2020 22:04:35 +0200https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/Comment by slelievre for <p>Hi everyone,</p>
<p>I am a neophyte and I can't understand my error in spite of the many tutorials I have watched. I want to define the 4jm Wigner symbols, which should basically be defined as:</p>
<pre><code>var('m')
wigner_4j(j1,j2,j3,j4,j,m1,m2,m3,m4) = sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4),m,-j,j)
</code></pre>
<p>I get plenty of errors that I can't fix. It is weird to me because the overall logic seemed good, as it works for instance when I define in a similar manner:</p>
<pre><code>var('n')
b(p,q) = sum(binomial(p,n)*binomial(q,n),n,0,min(p,q))
</code></pre>
<p>Thanks for your help!</p>
https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?comment=53673#post-id-53673Welcome to Ask Sage! Thank you for your question!Wed, 30 Sep 2020 23:24:16 +0200https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?comment=53673#post-id-53673Answer by rburing for <p>Hi everyone,</p>
<p>I am a neophyte and I can't understand my error in spite of the many tutorials I have watched. I want to define the 4jm Wigner symbols, which should basically be defined as:</p>
<pre><code>var('m')
wigner_4j(j1,j2,j3,j4,j,m1,m2,m3,m4) = sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4),m,-j,j)
</code></pre>
<p>I get plenty of errors that I can't fix. It is weird to me because the overall logic seemed good, as it works for instance when I define in a similar manner:</p>
<pre><code>var('n')
b(p,q) = sum(binomial(p,n)*binomial(q,n),n,0,min(p,q))
</code></pre>
<p>Thanks for your help!</p>
https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?answer=53669#post-id-53669With this syntax you are trying to create a [callable symbolic expression](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/callable.html). It doesn't work because the [symbolic `sum`](https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html#sage.calculus.calculus.symbolic_sum) that you are using requires a symbolic expression (depending on the symbolic summation index `m` here) as the first argument, and [`wigner_3j`](https://doc.sagemath.org/html/en/reference/functions/sage/functions/wigner.html#sage.functions.wigner.wigner_3j) in Sage does not accept symbolic arguments, only numeric arguments (more precisely, only integers or half-integers). This explains the errors. (By contrast, Sage does support symbolic binomial coefficients and sums, and hence callable symbolic expressions involving them.)
In this case you have no need for symbolics at all; you can just define a plain Python function, using the plain (non-symbolic) `sum`:
wigner_4j = lambda j1,j2,j3,j4,j,m1,m2,m3,m4: sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4) for m in range(-j,j+1))
Or, without `lambda`:
def wigner_4j(j1,j2,j3,j4,j,m1,m2,m3,m4):
return sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4) for m in range(-j,j+1))
Wed, 30 Sep 2020 23:00:54 +0200https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?answer=53669#post-id-53669Comment by pmd for <p>With this syntax you are trying to create a <a href="https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/callable.html">callable symbolic expression</a>. It doesn't work because the <a href="https://doc.sagemath.org/html/en/reference/calculus/sage/calculus/calculus.html#sage.calculus.calculus.symbolic_sum">symbolic <code>sum</code></a> that you are using requires a symbolic expression (depending on the symbolic summation index <code>m</code> here) as the first argument, and <a href="https://doc.sagemath.org/html/en/reference/functions/sage/functions/wigner.html#sage.functions.wigner.wigner_3j"><code>wigner_3j</code></a> in Sage does not accept symbolic arguments, only numeric arguments (more precisely, only integers or half-integers). This explains the errors. (By contrast, Sage does support symbolic binomial coefficients and sums, and hence callable symbolic expressions involving them.)</p>
<p>In this case you have no need for symbolics at all; you can just define a plain Python function, using the plain (non-symbolic) <code>sum</code>:</p>
<pre><code>wigner_4j = lambda j1,j2,j3,j4,j,m1,m2,m3,m4: sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4) for m in range(-j,j+1))
</code></pre>
<p>Or, without <code>lambda</code>:</p>
<pre><code>def wigner_4j(j1,j2,j3,j4,j,m1,m2,m3,m4):
return sum(wigner_3j(j1,j2,j,m1,m2,m)*wigner_3j(j,j3,j4,-m,m3,m4) for m in range(-j,j+1))
</code></pre>
https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?comment=53687#post-id-53687Perfect, thanks for your help!Thu, 01 Oct 2020 13:56:23 +0200https://ask.sagemath.org/question/53667/defining-4jm-wigner-symbols/?comment=53687#post-id-53687