Skip to content

Conversation

@Shobhit21287
Copy link

@Shobhit21287 Shobhit21287 commented Dec 15, 2025

Closes #13966

Added a negate function for expr.Expr letting users negate expressions of type float, Uint, duration.

The following have been done

  • A new unary operator introduced
  • relevant tests have been modified and a few new ones have been added
  • Release note has been added

@Shobhit21287 Shobhit21287 requested a review from a team as a code owner December 15, 2025 16:58
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Dec 15, 2025
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

float, unsigned int and duration expressions. Incase a non-expression is passed, it is automatically
lifted to the correct type.
Examlpe usage::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Shobhit21287 , thank you so much for your contribution! there is a small typo in this line, should be Example*

Also, perhaps you should leave a new line at the end of the release note, are the docs still compiling?

Duration())
"""
operand = lift(operand)
if operand.type.kind not in (types.Uint, types.Float, types.Duration):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Uint here may be problematic and can lead to undefined or unexpected behavior, because unsigned integers cannot represent negative values (a user expecting a signed integer or an error may end up getting back a large unsigned integer (2**3) - value which is an ambiguous value, and a silent failure). While negation is unambiguous for Float and Duration, negating a Uint requires choosing a specific interpretation like 2's complement, to negate which, a specialized method may need to be defined.

So for now, perhaps Uint could be removed from the check, or specialized logic can be added? Do let me know what you think! Thank you

Copy link
Contributor

@aaryav-3 aaryav-3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Shobhit21287 , this work is a great addition to qiskit, your PR is well written and clean. I had just some clarifications before it looks good to go

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement unary negation operator for expr.Expr

3 participants