Skip to content

Fix op_dag subtraction operators evaluating as addition - #147

Merged
ajaypanyala merged 2 commits into
NWChemEx:mainfrom
guillaume-michel:fix/op-dag-subtraction
Sep 23, 2026
Merged

ajaypanyala merged 2 commits into
NWChemEx:mainfrom
guillaume-michel:fix/op-dag-subtraction

Conversation

@guillaume-michel

Copy link
Copy Markdown
Contributor

Fixes #146

Problem

The operator- overloads in src/tamm/op_dag.hpp that build op trees had the same body as the matching operator+ overloads. The right-hand operand was never negated, so A - B built the same AddOp as A + B.

Change

Negate the right-hand operand in each of the three subtraction overloads:

  • lhs - rhs -> {lhs, -1.0 * rhs}
  • lhs - value -> {lhs, Scalar{-value}}
  • value - rhs -> {Scalar{value}, -1.0 * rhs}

Testing

Not built or tested locally. This PR adds no regression test.

🤖 Generated with Claude Code

The operator- overloads building op trees had the same body as operator+,
so the right-hand operand was never negated. Negate it: rhs becomes
-1.0 * rhs and a scalar value becomes -value.

Fixes NWChemEx#146

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Sep 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ajaypanyala
❌ qb-gmichel
You have signed the CLA already but the status is still pending? Let us recheck it.

@ajaypanyala
ajaypanyala merged commit fa8c892 into NWChemEx:main Sep 23, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

op_dag: operator- overloads are identical to operator+ (subtraction is evaluated as addition)

4 participants