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

Specify Logic Resource. #266

Merged
merged 4 commits into from
Jul 13, 2023
Merged

Specify Logic Resource. #266

merged 4 commits into from
Jul 13, 2023

Conversation

cqc-alec
Copy link
Collaborator

No description provided.

@cqc-alec cqc-alec requested a review from ss2165 July 12, 2023 15:10
| `not` | `bool` | `bool` | logical "not" |
| `and` | `bool`, `bool` | `bool` | logical "and" |
| `or` | `bool`, `bool` | `bool` | logical "or" |
| `xor` | `bool`, `bool` | `bool` | logical "xor" |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In two minds about including this. It's rarely used as a logical operation and can be constructed from the others if needed ... then again why not ... then again again why not include nand as well... Any thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Couple of changes I'd like to make here on reflection:

  • remove xor;
  • allow and and or to take any number of inputs.
    (Then true is just and with 0 inputs and false is just or with 0 inputs and we just have three basic op types.)

Copy link
Member

Choose a reason for hiding this comment

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

why is not not N-ary?

Copy link
Member

Choose a reason for hiding this comment

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

also where do you see operations like xor being defined? It's too primitive to be defined as a library function no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Presumably that would mean applying N nots in parallel -- so N inputs and N outputs? Yes we could define this, but it seems less useful. N-ary and and or save us from chaining a bunch of them together in a tree, taking advantage of associativity and commutativity, but I don't think there's a particularly compelling reason to combine parallel nots into one.

Copy link
Collaborator Author

@cqc-alec cqc-alec Jul 13, 2023

Choose a reason for hiding this comment

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

also where do you see operations like xor being defined? It's too primitive to be defined as a library function no?

Well, I wonder about this. As far as I can see xor is very rarely used as a logical operation (I can't think of any examples in tket), and on occasions when it is it can be implemented as something like "(A or B) and not (A and B)". It is much more often used in bit-twiddling or as addition mod 2; in both these cases I imagine one would use int<1> from the arithmetic resource (where addition is xor).

But I will add it if you think it's useful here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think any of C, C++ or Python have a logical xor operation (analogous to && or ||, or and and or) (though they all have bitwise xor).

Copy link
Member

Choose a reason for hiding this comment

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

that makes sense - happy with current state

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

Comments already added as single comments

@cqc-alec cqc-alec merged commit f9d52b7 into main Jul 13, 2023
6 checks passed
@cqc-alec cqc-alec deleted the logic branch July 13, 2023 12:38
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.

2 participants