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

variables List<string>
results List<bool>

Fields

MaxVariables

Hard cap: 2^n rows are materialized, so n must stay small.

public const int MaxVariables = 20

Field Value

int

Properties

Results

public IReadOnlyList<bool> Results { get; }

Property Value

IReadOnlyList<bool>

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

IReadOnlyList<Dictionary<string, bool>>

Variables

public IReadOnlyList<string> Variables { get; }

Property Value

IReadOnlyList<string>

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

expression1 AstNode
expression2 AstNode

Returns

bool

AreEquivalent(TruthTable, TruthTable)

Compare two truth tables for equivalence

public static bool AreEquivalent(TruthTable table1, TruthTable table2)

Parameters

table1 TruthTable
table2 TruthTable

Returns

bool

AreEquivalent(string, string)

Compare two expressions for truth table equivalence

public static bool AreEquivalent(string expression1, string expression2)

Parameters

expression1 string
expression2 string

Returns

bool

CompareExpressions(string, string)

Generate a side-by-side comparison of two truth tables

public static string CompareExpressions(string expression1, string expression2)

Parameters

expression1 string
expression2 string

Returns

string

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

node AstNode
assignment Dictionary<string, bool>

Returns

bool

Generate(AstNode)

Generates a truth table for an AST expression

public static TruthTable Generate(AstNode expression)

Parameters

expression AstNode

Returns

TruthTable

Generate(string)

Generates a truth table for a string expression

public static TruthTable Generate(string expression)

Parameters

expression string

Returns

TruthTable

GetResultsString()

Get results as binary string (for backward compatibility)

public string GetResultsString()

Returns

string

IsContradiction()

Checks if the truth table represents a contradiction (always false)

public bool IsContradiction()

Returns

bool

IsEquivalentTo(TruthTable)

Checks if this truth table is equivalent to another one

public bool IsEquivalentTo(TruthTable other)

Parameters

other TruthTable

Returns

bool

IsSatisfiable()

Checks if the truth table is satisfiable (at least one true result)

public bool IsSatisfiable()

Returns

bool

IsTautology()

Checks if the truth table represents a tautology (always true)

public bool IsTautology()

Returns

bool

ToString()

Returns a string representation of the truth table in proper tabular format

public override string ToString()

Returns

string