Reorganize algorithm definition
Our algorithm (the core of _block_diagonalize
) does several things:
- Implements the algebraic expressions for evaluating all the series,
- Implements series initialization,
- Keeps track of (anti-)hermiticity of the series,
- Implements the implicit version by wrapping proper terms with linear operators,
- Implements pruning the data that is guaranteed to only be accessed once.
While the code is relatively clean and compact, modifying and optimizing this has proven hard in e.g. !86 (merged). We also know that we will modify the core of the algorithm in the future, at the very least when dealing with #23 and likely also #45 (closed).
Another possibility that streamlining the algorithm would enable is a possibility to implement several algorithms within the same codebase. For example we could implement the minimal old general
algorithm and use it for testing.
I think a useful approach to reorganize the code is to identify repeated patterns and factor these out into functions. I already started some of that work in !85 (closed), although it's buggy now. There I have defined functions for generating sums of series, (anti-)hermitizing them, or taking diagonal or offdiagonal terms. Once the code contains no hand-made eval
definitions, we will be able to make the entire function body automatically generated.