Class TruthTable
- Namespace
- LogicalOptimizer
- Assembly
- LogicalOptimizer.Core.dll
Class for generating and working with truth tables
public class TruthTable
- Inheritance
-
TruthTable
- Inherited Members
Constructors
TruthTable(List<string>, List<bool>)
public TruthTable(List<string> variables, List<bool> results)
Parameters
Fields
MaxVariables
Hard cap: 2^n rows are materialized, so n must stay small.
public const int MaxVariables = 20
Field Value
Properties
Results
public IReadOnlyList<bool> Results { get; }
Property Value
Rows
One assignment dictionary per row, materialized on first access.
Building these eagerly cost a Dictionary<TKey, TValue> per row - 1024 of them for a 10-variable table - on every truth table ever constructed, including the ones the optimizer and its soundness guard build internally and then read only through Results. In production only the CSV exporter reads this, so the rows are now built when they are actually asked for. The content is identical.
public IReadOnlyList<Dictionary<string, bool>> Rows { get; }
Property Value
Variables
public IReadOnlyList<string> Variables { get; }
Property Value
Methods
AreEquivalent(AstNode, AstNode)
Compare two ASTs for logical equivalence over the union of their variables. Evaluates directly, without materializing table rows.
public static bool AreEquivalent(AstNode expression1, AstNode expression2)
Parameters
Returns
AreEquivalent(TruthTable, TruthTable)
Compare two truth tables for equivalence
public static bool AreEquivalent(TruthTable table1, TruthTable table2)
Parameters
table1TruthTabletable2TruthTable
Returns
AreEquivalent(string, string)
Compare two expressions for truth table equivalence
public static bool AreEquivalent(string expression1, string expression2)
Parameters
Returns
CompareExpressions(string, string)
Generate a side-by-side comparison of two truth tables
public static string CompareExpressions(string expression1, string expression2)
Parameters
Returns
Evaluate(AstNode, Dictionary<string, bool>)
Evaluates an expression for a given set of variable values
public static bool Evaluate(AstNode node, Dictionary<string, bool> assignment)
Parameters
nodeAstNodeassignmentDictionary<string, bool>
Returns
Generate(AstNode)
Generates a truth table for an AST expression
public static TruthTable Generate(AstNode expression)
Parameters
expressionAstNode
Returns
Generate(string)
Generates a truth table for a string expression
public static TruthTable Generate(string expression)
Parameters
expressionstring
Returns
GetResultsString()
Get results as binary string (for backward compatibility)
public string GetResultsString()
Returns
IsContradiction()
Checks if the truth table represents a contradiction (always false)
public bool IsContradiction()
Returns
IsEquivalentTo(TruthTable)
Checks if this truth table is equivalent to another one
public bool IsEquivalentTo(TruthTable other)
Parameters
otherTruthTable
Returns
IsSatisfiable()
Checks if the truth table is satisfiable (at least one true result)
public bool IsSatisfiable()
Returns
IsTautology()
Checks if the truth table represents a tautology (always true)
public bool IsTautology()
Returns
ToString()
Returns a string representation of the truth table in proper tabular format
public override string ToString()