Exemple #1
0
    public string simplify(string formula)
    {
        expression1 = new BoolExpr(formula);
        GenBtn();


        string functionOutput = "";

        Simplifier simplifier       = new Simplifier();
        string     functionSimplify = "";

        int[] arrMinTerms   = getSubArray(theTruthTable, 1);
        int[] arrIgnorances = getSubArray(theTruthTable, 2);

        //Debug.Log("Print:" + arrMinTerms.Length);
        //for (int a = 0; a < arrMinTerms.Length; a++)
        //{
        //    Debug.Log("Printed => s" + arrMinTerms[a]);
        //}

        //Debug.Log("Minterms Here:");
        printArray(arrMinTerms);
        //Debug.Log("Ignorances Here:");
        printArray(arrIgnorances);

        //Debug.Log(arrMinTerms.Length + " " + arrIgnorances.Length);
        functionSimplify = simplifier.getSimplifier(arrMinTerms, arrIgnorances, VARIABLE);
        functionOutput  += functionSimplify;

        //Debug.Log(functionOutput);
        return(functionOutput);
    }
Exemple #2
0
    private string simplify(string[] aValueTruthTable, string[] theTruthTable, string[][] aValueKMapTable, string[][] theKMapTable)
    {
        string functionOutput = "";
        int    i;
        bool   isAllZeros = true, isAllOnes = true, isAllIgnorances = true;

        functionOutput = "F(" + VARIABLE_NAME[0] + ", " + VARIABLE_NAME[1] + ", " + VARIABLE_NAME[2] + ", " + VARIABLE_NAME[3] + ") = ";

        // check if all 0s or all 1s
        for (i = 0; i < theTruthTable.Length; i++)
        {
            if (theTruthTable[i].Equals("1"))
            {
                isAllZeros = false;
            }
            if (theTruthTable[i].Equals("0"))
            {
                isAllOnes = false;
            }
            if (!theTruthTable[i].Equals("x"))
            {
                isAllIgnorances = false;
            }
        }

        if (isAllZeros || isAllIgnorances)
        {
            functionOutput += "0";
        }
        else if (isAllOnes || isAllIgnorances)
        {
            functionOutput += "1";
        }
        // do the simplification here
        else
        {
            Simplifier simplifier       = new Simplifier();
            String     functionSimplify = "";

            int[] arrMinTerms   = getSubArray(theTruthTable, 1);
            int[] arrIgnorances = getSubArray(theTruthTable, 2);

            printArray(arrMinTerms);
            printArray(arrIgnorances);

            //functionOutput += getFunctionOutput(aValueKMapTable, theKMapTable);

            functionSimplify = simplifier.getSimplifier(arrMinTerms, arrIgnorances, VARIABLE);
            functionOutput  += functionSimplify;
        }

        return(functionOutput);
    }