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

operator== on truth tables? #88

Open
mfernan2 opened this issue Feb 26, 2020 · 4 comments
Open

operator== on truth tables? #88

mfernan2 opened this issue Feb 26, 2020 · 4 comments

Comments

@mfernan2
Copy link

static_truth_table and dynamic_truth_table do not implement operator== and operator!=, so code like tt1 == tt2 does not work. It seems you still can compare truth tables with something like the following (untested) code:

bool eq = true;
for (auto it = tt1.begin(), it2 = tt2.begin(); ; ++it, ++it2) {
  if (it == tt1.end()) {
    eq &= it2 == tt2.end();
    break;
  } else if (it2 == tt2.end()) {
    eq = false;
    break;
  }
  eq &= *it == *it2;
}

Is it possible to implement operator== and operator!= on these classes to avoid having to do this? It should be possible to do some template-based specialization to optimize these too.

OTOH perhaps I've misunderstood something and equality comparison makes no sense on these classes. In which case, I would be interested to learn of this too.

@msoeken
Copy link
Owner

msoeken commented Mar 3, 2020

These functions are implemented in the header kitty/operators.hpp.

@msoeken msoeken closed this as completed Mar 3, 2020
@mfernan2
Copy link
Author

mfernan2 commented Mar 3, 2020

Ah thanks! I did not even notice these. FWIW I ended up implementing something pretty similar but using SFINAE to ensure the functions are only callable with truth tables:

template<typename T1, typename T2,
  // make this only compile for Kitty’s truth table types
  typename std::enable_if<kitty::is_truth_table<T1>::value && kitty::is_truth_table<T2>::value>::type* = nullptr>
static bool equal(const T1 &x, const T2 &y) {
...

@mfernan2
Copy link
Author

mfernan2 commented Mar 3, 2020

Actually I just realized why I ran into this issue in the first place. Kitty does not implement operator== for a dynamic truth table compared to a static truth table. I.e.:

template<int NumVars>
bool operator==( const static_truth_table<NumVars>& first, const dynamic_truth_table& second );

Would it be possible to implement a comparator that handles this case as well? I do not seem to have the ability to re-open this issue.

@msoeken msoeken reopened this Mar 3, 2020
@msoeken
Copy link
Owner

msoeken commented Mar 3, 2020

That's a good point.

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

No branches or pull requests

3 participants