Closed redeboer closed 4 years ago
@spflueger What about implementing a Partilce.__neg__
operator? Then one could just write for instance:
assert pi_minus == -pi_plus
Not sure thought how much sense this syntax makes from a physics point of view. And I'm also not sure how much overhead the construction of a new Particle
instance (which __neg__
would do) causes. But maybe dataclasses.replace
optimizes that. Nonetheless, a method like is_antiparticle_of
or something along those lines would still have to flip several properties, see:
https://github.com/ComPWA/expertsystem/blob/61c339457e906b90baa4031539bb103ab7b55d74/expertsystem/data.py#L520-L551
Sounds quite nice. I think you have to create a new particle anyways, so I would not worry about the overhead. If we want to have a faster comparison check we can always implement that in addition
There's one problem though:
https://github.com/ComPWA/expertsystem/blob/a81dda95e569afa7323cd91578624318d338aba5/expertsystem/data.py#L524-L526
With a __neg__
operator, one cannot set the name of the output particle.
The implementation in
create_anti_particle
can be used to check whether one instance of aParticle
is the anti-particle of the other. This allows for a more reliable implementation of, say, the C-parity conservation check inconservation_rules
(which currently uses PID).