jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
517 stars 82 forks source link

Tensor product support? #554

Closed yasuhito closed 4 years ago

yasuhito commented 4 years ago

Hi, I am currently trying to implement a quantum computer simulator in a browser using Nerdamer. To simulate quantum bits, it needs a lot of tensor products of matrices, so I am thinking of extending Nerdamer to do this.

Screen Shot 2020-07-16 at 14 51 06

https://en.wikipedia.org/wiki/Tensor_product

So my question is if I want to add a custom operator like tensorProduct ("A @ B"), can I refer to the "Extending the core" for the right way to do it?

  1. create a function called tensorProduct that uses internal CAS API
  2. register the function with nerdamer.register()

In this case, to create a tensor product, we need to multiply the matrices by x and then create a new bigger one by lining them up. Is there such an API already available?

If not, I need to extract i,j elements of the matrix one by one, multiply, and set the result into a new matrix. Can you tell me where to look in the source code for an internal API for such a matrix operation?

Finally, thank you for developing such an excellent library.

jiggzson commented 4 years ago

Hi, I am currently trying to implement a quantum computer simulator in a browser using Nerdamer. To simulate quantum bits, it needs a lot of tensor products of matrices, so I am thinking of extending Nerdamer to do this.

That's pretty cool to hear. Hopefully nerdamer can meet your needs. If there's anything missing please bring it to my attention so it can be considered for future additions. I've been away from my computer for a few days hence my late reply.

So my question is if I want to add a custom operator like tensorProduct ("A @ B"), can I refer to the "Extending the core" for the right way to do it?

Yes. Additonally take a look at #154. That issue deals with custom operators. The custom operator section on the site needs to be updated.

The main classes that you'd be looking for are the Matrix and maybe the Vector class. The API is pretty much that of Sylvester JS since those classes are pretty much a verbatim port. The internal documentation of the library is somewhat sparse. The primary reason for this is due to the fact that there are quite a few functions that I'm not ready to commit to. If you run into any issues feel free to send me an email. My email can be found on the website. I'm all over the place these days but promise to do my best to respond as quickly as possible.

Finally, thank you for developing such an excellent library.

Thank you and glad to help.