AngouriMath

Navigation

← Back to list of members

SolveBooleanTable​(AngouriMath.​Entity,​AngouriMath.​Entity.​Variable[])

 Method (no overloads)

Summary

Solves a boolean expression. That is, finds all values for
variables such that the expression turns into True when evaluated
Uses a simple table of truth
Use SolveBoolean(AngouriMath.Entity.Variable) for smart solving

Example

Entity expr = "(a xor b or c) implies (a or c)";
var sols = MathS.SolveBooleanTable(expr, "a", "b", "c");

if (sols is null)
    Console.WriteLine("No solution found");
else
{
    Console.WriteLine(sols.ToString(multilineFormat: true));
    Console.WriteLine();
    for (int i = 0; i < sols.RowCount; i++)
    {
        var a = (bool)sols[i, 0].EvalBoolean();
        var b = (bool)sols[i, 1].EvalBoolean();
        var c = (bool)sols[i, 2].EvalBoolean();
        Console.WriteLine($"Solution #{i}: {a}, {b}, {c}");
    }
}

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 1534 pages online