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

Prime implicant finding uses an unnecessarily slow algorithm #2

Open
TheLoneWolfling opened this issue Jan 2, 2017 · 0 comments
Open

Comments

@TheLoneWolfling
Copy link

Current prime implicant finding uses an algorithm that works out to be O(|nonzero miniterms|^2) time.

However, it's possible to get prime implicants in O(|nonzero miniterms|) time using a set instead of explicit comparisons:

current = {"0000", "1001", ...}
primImps = set()
while current:
  nxt = set()
  for c in current:
    added = False
    for i, old in enumerate(c):
      for new in "01x":
        if old == new:
          continue
        d = c[:i] + new + c[i+1:]
        if d in current:
          n = "".join(x if x == y else 'x' for x,y in zip(c,d))
          nxt.add(n)
          added = True
    if not added:
      primImps.add(c)
  current = nxt

(Well, technically there's a O(|miniterm|) factor in there - but that's present regardless.)
This (drastically) speeds up larger problems.

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