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

Implement imaginary literals #194

Merged
merged 1 commit into from
Mar 26, 2024
Merged

Conversation

jlapeyre
Copy link
Collaborator

OQ3 has no imaginary type, only complex type (I don't know of any general purpose language that differs in this respect). But it is convenient to implement and use imaginary literals in order to handle expressions like 10 im, 10im, 12.3 im, 12.3im, etc.

We already have implemented all the machinery for timing literals. Lexing and maniuplating imaginary literal is structurally identical, so we can use the machinery for timing literals at (almost) no extra cost in coding or complexity. A disadvantage is that imaginary and timing literals don't belong in the same category. IDK, we could rename everything to `timing_or_imaginary.

An imaginary float literal can be stored and manipulated in exactly the same way, with the same semantics as a real float literal. The exception is the last step of specifying the type. For this reason we break with the precedent of all other variants of enums in asg.rs by reusing a the struct field for real literals. That is, we have:

Float(FloatLiteral),
ImaginaryFloat(FloatLiteral),

The type (float or complex float) is stored at a higher level as it is for all expressions.

Closes #190

OQ3 has no imaginary type, only complex type (I don't know of any general
purpose language that differs in this respect). But it is convenient to
implement and use imaginary literals in order to handle expressions like
`10 im`, `10im`, `12.3 im`, `12.3im`, etc.

We already have implemented all the machinery for timing literals. Lexing and
maniuplating imaginary literal is structurally identical, so we can use the
machinery for timing literals at (almost) no extra cost in coding or complexity.
A disadvantage is that imaginary and timing literals don't belong in the same
category. IDK, we could rename everything to `timing_or_imaginary.

An imaginary float literal can be stored and manipulated in exactly the same
way, with the same semantics as a real float literal. The exception is the
last step of specifying the type. For this reason we break with the precedent
of all other variants of enums in asg.rs by reusing a the struct field for
real literals. That is, we have:

```
Float(FloatLiteral),
ImaginaryFloat(FloatLiteral),
```
The type (float or complex float) is stored at a higher level as it is for
all expressions.
@jlapeyre jlapeyre merged commit a421dff into Qiskit:main Mar 26, 2024
7 checks passed
@jlapeyre jlapeyre deleted the complex-literals branch March 26, 2024 01:59
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.

Support imaginary numbers and complex literals
1 participant