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

How to implement support for non-commutative algebra? #1731

Closed
m93a opened this issue Feb 2, 2020 · 1 comment
Closed

How to implement support for non-commutative algebra? #1731

m93a opened this issue Feb 2, 2020 · 1 comment
Labels

Comments

@m93a
Copy link
Collaborator

m93a commented Feb 2, 2020

I'm thinking about implementing a simple module for quantum mechanics similar to that of Sympy. The most important features would be:

  1. kets – abstract vectors, they aren't arrays of numbers but instead symbols with specific multiplication rules
  2. operators – abstraction of matrices, again instead of multi-dimensional arrays, they are just symbols, multiplying A * B * ket(n) is equivalent to applying operator B to the ket n and then applying operator A to the result
  3. bras – duals of kets, multiplying bra(m) * ket(n) is equivalent to dot product of vectors

These three types of objects have to obey specific multiplication rules, and multiplication isn't commutative for them.

In Sympy these are implemented this way: each new object is defined by a class that extends the core Expression class. The classes redefine the base class's multiply method. This way they can define custom multiplication rules without modifying the core library.

If I understand it correctly, math.js doesn't have multiply method on expressions, but instead I can define a new non-commutative multiplication that extends the core Operator class and mark it as non-commutative. Is that right?

Or is there a better way to approach this?


This is what the workflow could look like:

import { Operator } from "math/quantum"

let H = new Operator('H', { hermitian: true });
let E3 = H.eigenket(3);
let scope = { H, E3 }

math.evaluate('dagger(H * E3) * H * E3', scope)
// <E3| H⁺ H |E3> = 3 * 3 <E3|E3> = 9

EDIT: Maybe somewhat related to #467.
EDIT 2: Obviously I'll need symbols first #1732.

@josdejong
Copy link
Owner

The symbolic computation that mathjs has so far uses nodes like SymbolNode and OperatorNode, the same as generated by the parser when parsing an expression (math.parse('...')).

See code: https://github.com/josdejong/mathjs/tree/develop/src/expression/node
See docs: https://mathjs.org/docs/expressions/expression_trees.html

Is that what you mean?

@m93a m93a added the question label May 19, 2021
@m93a m93a closed this as completed May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants