How can I simplify boolean Algebra Expressions without using outside Java addons? -
i trying take boolean algebra expression generated part of project , simplify before output it. boolean expression include or statements due nature of rest of program.
an example starting expression ac + bc + bc + ab + ac + ac + ab , ending + c. lower case letters indicate not e.g. means not a.
i have struggled hours trying figure out, every time solve 1 case ruin another. imagine there recursive function problem struggled find elsewhere.
edit: clear, understand how simplify expression on paper, unable simplify using java.
thanks in advance.
public static void mutate (arraylist<string> final, arraylist<string> factored, string a){ int multiples = 0; string holder = ""; (int = 0; < final.size(); i++){ if (final.get(i).contains(a)){ multiples++; if (multiples == 1) holder = final.get(i); if (multiples >=2) factored.add(final.get(i)); } } if (multiples > 1) factored.add(holder); } public static void simplify (arraylist<string> factored, char a, arraylist<string> main){ string temp = ""; int size = factored.size(); int cnt = 0; int cnt2 = 0; int holder = 0; system.out.println(factored); int menial = 0; if (factored.size() == 0) menial = 1; else{ (int = 0; < size; i++){ //gets rid of leading letters if(factored.get(i).charat(0) == a){ temp = factored.get(i).substring(1); factored.add(temp); } } (int = 0; < size; i++){ //gets rid of leading letters if(factored.get(i).charat(1) == a){ temp = factored.get(i).substring(1); factored.add(temp); } } (int j = 0; j < size; j++){ factored.remove(j - cnt); cnt++; } (int = 0; < factored.size(); i++){ //gets rid of duplicates if exist (int j = + 1; j < factored.size();j++) if (factored.get(i).equals(factored.get(j))){ cnt2++; if (cnt2 == 1) holder = i; } } if (cnt2 >= 1) factored.remove(holder); string temp1 = ""; int size1 = factored.size(); (int = 0; < size1; i++){ //makes uppercase temp1 = factored.get(i).touppercase(); factored.add(temp1); } int cnt3 = 0; (int = 0; <size1; i++){ factored.remove(i-cnt3); cnt3++; } int sizeover2 = factored.size()/2; int holder1 = 0; int holder2 = 0; (int q = 0; q < sizeover2; q++){ int cnt4 = 0; (int = 0; < factored.size(); i++){ //gets rid of duplicates if exist there caps (int j = + 1; j < factored.size();j++) if (factored.get(i).equals(factored.get(j))){ cnt4++; if (cnt4 == 1) holder1 = i; holder2 = j; } if (cnt4 >= 1){ factored.remove(holder1); factored.remove(holder2 - 1); } } } if (factored.size() == 0) main.add(character.tostring(a)); else if (factored.size() > 1) menial = 5; else (int = 0; < factored.size(); i++) main.add(factored.get(i)); }} }
edit2: have added code above. apologize slopiness in advance, got pretty messy towards end. factored arraylist has of elements of boolean expression separated e.g. first element ac, , second bc, etc. plan find duplicates , try factor them out, after coding of realized egregious logic error. has more complicated , @ point i'm lost in own code.
Comments
Post a Comment