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

qm.simplify() breaks for some input #12

Open
LarryBattle opened this issue Feb 19, 2014 · 6 comments
Open

qm.simplify() breaks for some input #12

LarryBattle opened this issue Feb 19, 2014 · 6 comments
Labels

Comments

@LarryBattle
Copy link
Owner

In Version 0.9.5, some expressions don't return anything for the simplified form.

Example of Bug:

qm.simplify("A,B".split(","), "A*") === ""
qm.simplify("A,B".split(","), "B*") === "B*"
@LarryBattle
Copy link
Owner Author

The problem is that the binary length of the prime implicants are set by the minterms and not by the inputs length.
Example:

var x = qm.func.getPrimeImplicantsFromMinterms("0,1".split(",")); 
x.value === "-" 

The above example works for f(A) but not for f(A,B).
As you can see x.value will always return "-" irregardless of the inputs.

Solutions:

  • The methods for multiple functions needs to be redone to take the input length into account.
  • Add a patch that adds padding to the prime implicants.

@LarryBattle
Copy link
Owner Author

Fixed in Version 0.9.6 beta. The constructor for the BinaryGroupTable class now requires a binary length for the second argument. An error is thrown if not supplied.
BinaryGroupTable.prototype.numbersToSortedChartElements() will use that value to ensure that all the binary strings have a fixed length. The code doesn't check if the binary length is too short though.

@LarryBattle
Copy link
Owner Author

This is still an issue.
If the value is 1, then an empty string is returned.

qm.simplify("A,B".split(","), "B*+B") === ""

@LarryBattle LarryBattle reopened this Feb 24, 2014
@LarryBattle
Copy link
Owner Author

Updated fix for that bug.
However, there's a failing test where if the user includes two of the same literals in a term then an error should be thrown.

@LarryBattle
Copy link
Owner Author

Why don't these work?

Error:

Error: Invalid index(-1) to prime implicant.

Code:

qm.simplify("A,B,C".split(","),"A*B*C*+A*BC*+A*BC+AB*C*+AB*C+ABC");
qm.simplify("A,B,C".split(","),"A*B*C+A*BC*+A*BC+AB*C*+AB*C+ABC*");
qm.simplify("A,B,C".split(","),"A*B*C*+A*B*C+A*BC*+AB*C+ABC*+ABC");
qm.simplify("A,B,C,D".split(","),"A*B*CD*+A*BC*D+A*BCD*+A*BCD+AB*C*D*+AB*CD*+AB*CD+ABC*D*+ABC*D+ABCD*");
qm.simplify("A,B,C,D".split(","),"A*B*C*D*+A*B*C*D+A*B*CD+A*BCD+AB*C*D*+AB*CD*+AB*CD+ABC*D+ABCD*+ABCD");
qm.simplify("A,B,C,D".split(","),"A*B*CD*+A*B*CD+A*BC*D*+A*BC*D+A*BCD+AB*C*D*+AB*C*D+AB*CD*");

@LarryBattle
Copy link
Owner Author

The cause is that CoverageTable.prototype.getBestPrimeImpForMinterm() is the pIndex isn't getting set, so the method is returning -1. -1 isn't a valid array index.

This can be fixed by replacing this with the petrick method, once completed.

From CoverageTable.prototype.solve()

} else {
    var m = this.getNextMinterm();
    var pIndex = this.getBestPrimeImpForMinterm(m);
    this.usePrimeImp(pIndex);
}

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

No branches or pull requests

1 participant