Skip to content

Instantly share code, notes, and snippets.

@Krastanov
Created May 5, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krastanov/2601322 to your computer and use it in GitHub Desktop.
Save Krastanov/2601322 to your computer and use it in GitHub Desktop.
why is there a diamond subclassing here?
At the moment we have:
======================
<~~~ is for metaclasses
| \ or / is for subclasses
Basic <~~~~~~~~ WithAssumptions
blah / \ |
\ / \ |
Expr Application <~~~ FunctionClass
\ /
\ /
Function
But changing it to:
===================
Basic <~~~~~~~~ WithAssumptions
blah | |
\ | |
Expr |
| |
| |
Application <~~~ FunctionClass
|
Function
is a two line change in functions.py and does not cause any test failures
at least for
[./bin/test ./bin/doctest] [core function logic util]
Is there any drawback in the second approach?
I consider its simplicity an advantage.
@Krastanov
Copy link
Author

Maybe it is because the EvalfMixing that is part of Expr. But I consider it appropriate for Application as well (say the Application is a linear application - it is appropriate to demand evaluation of the coefficients of that application).

@Krastanov
Copy link
Author

On a similar note:

Max is defined as Max(MinMaxBase, Application, Basic). Removing Basic does not trigger any test failures. The same goes for Min.

@Krastanov
Copy link
Author

On a similar note: BasicType and BasicMeta can be merged (BasicType does absolutely nothing).

@Krastanov
Copy link
Author

On a similar note: Atom and AtomicExpr can be merged (Atom is used only by AtomicExpr).

@asmeurer
Copy link

asmeurer commented May 5, 2012

But in theory there could be a class that should derive from Atom but not AtomicExpr.

@Krastanov
Copy link
Author

@asmeurer, I believe that your comment is based in the idea that Expr represents only a complex number and Basic represent general mathematical object. But I think (as mentioned on the mailing list) that Expr and Basic are awfully mixed in practice throughout the code base.

Disclaimer: I am really unsure about the correctness of my comment.

@asmeurer
Copy link

asmeurer commented May 5, 2012

Do you have any specific examples where they are mixed? The only one I can think of off the top of my head is Symbol, which derives from both Boolean and Expr.

As an example for my case, I can't find where Sean's old implementation of http://code.google.com/p/sympy/issues/detail?id=2531 is, but my guess is that those classes were Atom but not AtomicExpr.

@Krastanov
Copy link
Author

@asmeurer, I mentioned them on the mailing list, but I am unsure where is the best place to have this discussion so I am posting them also here:

Most of these are operator on Hilbert spaces, Hilbert space vectors or some kind of containers like matrices:

sympy/core/relational.py:class Relational(Expr, EvalfMixin):
sympy/core/function.py:class Lambda(Expr):
sympy/core/function.py:class Subs(Expr):
sympy/matrices/expressions/matexpr.py:class MatrixExpr(Expr):
sympy/physics/quantum/spin.py:class WignerD(Expr):
sympy/physics/quantum/qexpr.py:class QExpr(Expr):
sympy/physics/quantum/innerproduct.py:class InnerProduct(Expr):
sympy/physics/quantum/anticommutator.py:class AntiCommutator(Expr):
sympy/physics/quantum/tensorproduct.py:class TensorProduct(Expr):
sympy/physics/quantum/commutator.py:class Commutator(Expr):
sympy/physics/quantum/dagger.py:class Dagger(Expr):
sympy/physics/quantum/cg.py:class Wigner3j(Expr):
sympy/physics/quantum/cg.py:class Wigner6j(Expr):
sympy/physics/quantum/cg.py:class Wigner9j(Expr):
sympy/physics/gaussopt.py:class BeamParameter(Expr):
sympy/physics/secondquant.py:class Dagger(Expr):
sympy/physics/secondquant.py:class TensorSymbol(Expr):
sympy/physics/secondquant.py:class SqOperator(Expr):
sympy/physics/secondquant.py:class FockState(Expr):
sympy/physics/secondquant.py:class PermutationOperator(Expr):
sympy/series/order.py:class Order(Expr):
sympy/tensor/indexed.py:class Indexed(Expr):
sympy/tensor/indexed.py:class IndexedBase(Expr):
sympy/tensor/indexed.py:class Idx(Expr):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment