Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent definitions of bitwise not and logical not #227

Open
idavis opened this issue Aug 30, 2024 · 0 comments
Open

Inconsistent definitions of bitwise not and logical not #227

idavis opened this issue Aug 30, 2024 · 0 comments

Comments

@idavis
Copy link

idavis commented Aug 30, 2024

In the spec, bitwise negation is represented as ~ and logical not is represented as !.

In crates/oq3_syntax/src/ast/expr_ext.rs the code represents the opposite:

impl ast::PrefixExpr {
    pub fn op_kind(&self) -> Option<UnaryOp> {
        let res = match self.op_token()?.kind() {
            T![~] => UnaryOp::LogicNot,
            T![!] => UnaryOp::Not,
            T![-] => UnaryOp::Neg,
            _ => return None,
        };
        Some(res)
    }

    pub fn op_token(&self) -> Option<SyntaxToken> {
        self.syntax().first_child_or_token()?.into_token()
    }
}

as well as in crates/oq3_syntax/src/ast/operators.rs

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum UnaryOp {
    /// `~`
    LogicNot,
    /// `!`
    Not,
    /// `-`
    Neg,
}

In the Qiskit repo, qiskit/qiskit/qasm3/ast.py defines Unary expr as:

class Unary(Expression):
    class Op(enum.Enum):
        LOGIC_NOT = "!"
        BIT_NOT = "~"

    def __init__(self, op: Op, operand: Expression):
        self.op = op
        self.operand = operand

While the Qiskit repo is missing negation (-), I believe the parser needs to be updated to reflect the spec and Qiskit repo for logical and bitwise not.

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

No branches or pull requests

1 participant