Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Angular Momentum builtins... #496

Merged
merged 7 commits into from
Aug 15, 2022
Merged

Add Angular Momentum builtins... #496

merged 7 commits into from
Aug 15, 2022

Conversation

rocky
Copy link
Member

@rocky rocky commented Aug 7, 2022

which starts a Quantum Mechanics section.

TODO:

  • Unit tests for errors.
  • Ensure function attributes are correct
  • Ensure we error on what we are supposed to and not on what we do not

@rocky rocky marked this pull request as draft August 7, 2022 16:59
@rocky rocky force-pushed the add-angular-momentum branch 5 times, most recently from 61a71c6 to e30dff9 Compare August 7, 2022 22:10

<dl>
<dt>'ClebschGordan[{$j1$, $m1$}, {$j2$, $m2$}, {$j$ $m$}]'
<dd>returns the Clebsch-Gordan coefficient for the decomposition of in terms of |$j$, $m$|$j2$, $m2$>.
Copy link
Contributor

@mmatera mmatera Aug 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be precise, * ... in terms of |$j_1, m_1$>|j_2 m_2$>.*

Maybe $\rangle$ instead of $&gt;$.

Copy link
Member Author

@rocky rocky Aug 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The persistent problem we have is that we the homegrown doc system really can't handle symbols reliably. We have seen this time and time again with things like Phi.

Do we use the bra or ket symbols anywhere else? If you know that when we go to print this it will work, then we can use.

Copy link
Contributor

@mmatera mmatera Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's keep ">", but then the description should say
returns the Clebsch-Gordan coefficient for the decomposition of in terms of $|j_1, m_1>|j_2, m_2>$.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the mistake. I think it is fixed now in bb73c51

Copy link
Member Author

@rocky rocky Aug 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of >, the ket symbol and our homegrown docsystem fragility: when I was working on the guide section for the process of adding Curl as an example, I wanted to write:

$$ ( \partial f_3 / \partial x_2 - \partial f_2 / \partial x_3, \ \ % \partial f_1 / \partial x_3 - \partial f_3 / \partial x_1, \ \ % \partial f_2 / \partial x_1 - \partial f_1 / \partial x_2 ) $$

in the Sphinx document. and I was pleasantly surprised that I could do this without fuss, and that there was a world of flexibility available rather that this kind of constrained system where we are working around things and getting less-good results in the end.

So there is hope if we can get over the mountain of moving this to sphinx.

sympy_jms += [p.to_sympy() for p in pair.elements]
return from_sympy(CG(*sympy_jms).doit())


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some place, it would be good to implement also KroneckerProduct (https://reference.wolfram.com/language/ref/KroneckerProduct.html)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been going by reference guide section. That seems to belong to Matrix or Tensor things even though everything is related. Feel free to add it, but I am not sure where we would add it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure where we would add it.

It looks like it goes under "Vector Space Operations" which we already have. See https://reference.wolfram.com/language/guide/OperationsOnVectors.html

Copy link
Member Author

@rocky rocky Aug 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was doing these, it occurred to me that there was a set not intuitive process I used that makes doing this kind of thing more automatic.

  • Find a Builtin that hasn't been implemented. This PR comes from the bottom this this issue. See also TODO's at the bottom of newer sections/modules for missing functions.
  • Decide where in the code/doc to put it. As noted, I first noticed it as a missing Combinatorial Function. However on more recent reflection, those last three are more specifically isolated as Angular Momentum functions (and in Combinatorial Functions it is not split out or noted as such). If this is a new section, then things are harder. If not a new section, then please add class in alphabetic order.
  • See if it is a SymPy function. And the rest will assume yes. But if not try to SciPy and mpmath. I suppose numpy might be tried too.
  • Copy one of the newer existing Sympy functions and adapt. Newer existing Sympy functions have Wiki, SyPy, and WMA links. Probably in the WMA link, all you will have to do is change the copied WMA name into the new name.
  • Use WMA link to adapt the docstring. It might be consulted to get the summary text too.
  • Go into mathics and see that you can get "info" or "?" on the changed doc.
  • Adapt the pattern match rule and parameters. This is probably the hardest part. Cases in mathics can help here. If you have put the code with related functions, often that class will be similar to some other class and that can make adapting the pattern match and body of the code easier. Also, similar classes do not follow the most recent conventions, consider updating nearby related builtins so that do follow new conventions.
  • Adapt the eval method parameters and body.
  • Make sure the function attributes are correct.
  • Adapt some doctests and test. Examples from WMA and SymPy are a good source, but try to make the examples meaningful.
  • Run the tests using python mathics/docpipeline -s <builtin name>
  • Go over error conditions and error messages
  • Write unit tests for all of these edge cases and uninteresting cases to try. test using python -m pytest -s test/builtin/.../test-.py`
  • Run all tests.
  • Add new builtin entry to CHANGES.rst
  • Create PR.

The above even though long is still kind of sketchy. So I will go through this process on KroneckerProdect as a detailed example and put this in the developer guide.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably,this is something that should go into the developer guide.

Copy link
Member Author

@rocky rocky Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started down this path. See https://github.com/Mathics3/mathics-development-guide/tree/adding-KroneckerProduct and https://mathics-development-guide.readthedocs.io/en/adding-kroneckerproduct/extending/developing-code/extending/adding-new-mathics-function.html.

I stopped however when I see that there is this is not going to make for a simple example, because of the matrix checking, and conversion to Matrix in SymPy that we probably need to do. And this is just for the matrix case, not the vector case.

I will pick a simpler example. As for the KroneckerProduct branch , I don't intend on going further there in case you are interested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I would say that this is almost ready.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I never was my intention to add it here - these are the angular momentum functions.)

Possibly over the weekend I may add pytests.. However redoing how Part works and changes ListExpression is more important.

@mmatera
Copy link
Contributor

mmatera commented Aug 7, 2022

Something that I am not sure about this is whether these functions belong to a quantum mechanics section, or to other modules (PauliMatrix to linear algebra, ClebschGordan, ThreeJSymbol and SixJSymbol to "Combinatorial Functions" (https://reference.wolfram.com/language/guide/CombinatorialFunctions.html) , etc. Otherwise, we should put the special polynomials also under this category.

@rocky
Copy link
Member Author

rocky commented Aug 7, 2022

Something that I am not sure about this is whether these functions belong to a quantum mechanics section, or to other modules (PauliMatrix to linear algebra, ClebschGordan, ThreeJSymbol and SixJSymbol to "Combinatorial Functions" (https://reference.wolfram.com/language/guide/CombinatorialFunctions.html) , etc. Otherwise, we should put the special polynomials also under this category.

I am following https://reference.wolfram.com/language/guide/FunctionsUsedInQuantumMechanics.html

We will also have to deal with the duplication somehow. But that is yet another battle with autodoc for some other time.

Otherwise, we should put the special polynomials also under this category.

Again I am following the organization cited above and we'll have to figure out how to deal with duplication under sections.

@rocky rocky force-pushed the add-angular-momentum branch 3 times, most recently from c71ec83 to f862984 Compare August 8, 2022 06:29
@rocky rocky marked this pull request as ready for review August 13, 2022 17:00
@rocky rocky force-pushed the add-angular-momentum branch 3 times, most recently from 94a053e to e888eea Compare August 13, 2022 19:32
rocky added 7 commits August 13, 2022 15:36
which starts a Quantum Mechanics section.

TODO:

* Unit tests for errors.
* Ensure function attributes are correct
* Ensure we error on what we are supposed to and not on what we do not
Show symmetry in doc and add some error handling
@rocky rocky force-pushed the add-angular-momentum branch from e888eea to 881a11b Compare August 13, 2022 19:36
@rocky rocky merged commit 432e80b into master Aug 15, 2022
@rocky rocky deleted the add-angular-momentum branch August 15, 2022 10:21
@rocky
Copy link
Member Author

rocky commented Aug 15, 2022

This weekday's activity will probably be finish the development guide for Curl, and I might also add KroneckerProduct since I now see what is up with sympy Matrices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants