private string GetSimplest(int input) { LogicRecord logicRecord = logicRecords.Find(obj => obj._output == input); if (logicRecord == null) { return(input.ToString()); } else { if (logicRecord._operator == Operators.BUF || logicRecord._operator == Operators.INV) { string part1 = GetSimplest(logicRecord._inputs.ElementAt(0)); string operatorPart = logicRecord._operator.ToString(); return("(" + operatorPart + " " + part1 + ")"); } else { string part1 = GetSimplest(logicRecord._inputs.ElementAt(0)); string operatorPart = logicRecord._operator.ToString(); string part2 = GetSimplest(logicRecord._inputs.ElementAt(1)); return("(" + part1 + " " + operatorPart + " " + part2 + ")"); } } }
private void ConstructFormula(int output) { LogicRecord logicRecord = logicRecords.Find(obj => obj._output == output); string formula; if (logicRecord._operator == Operators.BUF || logicRecord._operator == Operators.INV) { formula = "(" + logicRecord._operator + " " + logicRecord._inputs.ElementAt(0) + ")"; } else { formula = GetSimplest(logicRecord._inputs.ElementAt(0)) + " " + logicRecord._operator.ToString() + " " + GetSimplest(logicRecord._inputs.ElementAt(1)); } outputFormula.Add(formula); outputFormulaTextBox.AppendText(output + " = " + formula + "\n\n"); }
private int GetSimplExp(int output) { LogicRecord logicRecord = logicRecords.Find(obj => obj._output == output); int outputValue = -1; if (logicRecord == null) { bool success = inputSignalsDict.TryGetValue(output, out outputValue); return(outputValue); } else { switch (logicRecord._operator) { case Operators.INV: return((GetSimplExp(logicRecord._inputs.ElementAt(0)) == 1) ? 0 : 1); case Operators.BUF: return(GetSimplExp(logicRecord._inputs.ElementAt(0))); case Operators.AND: return(GetSimplExp(logicRecord._inputs.ElementAt(0)) & GetSimplExp(logicRecord._inputs.ElementAt(1))); case Operators.OR: return(GetSimplExp(logicRecord._inputs.ElementAt(0)) | GetSimplExp(logicRecord._inputs.ElementAt(1))); case Operators.NAND: return(((GetSimplExp(logicRecord._inputs.ElementAt(0)) & GetSimplExp(logicRecord._inputs.ElementAt(1))) == 1) ? 0 : 1); case Operators.NOR: return(((GetSimplExp(logicRecord._inputs.ElementAt(0)) | GetSimplExp(logicRecord._inputs.ElementAt(1))) == 1) ? 0 : 1); default: return(-1); } } }