cana.function_outputs.ast module

Boolean expression AST: parse, invert, and leaf walks.

Structural & / | / ! trees only — no read-once assumption. Callers that need syntactic ROF (single occurrence) should use cana.function_properties.rof.

class cana.function_outputs.ast.LogicNode(op, children)[source]

Bases: object

Node in a boolean expression AST.

op is one of AND, OR, LITERAL, NEGATED_LITERAL. For leaves, children is the variable name (str); for gates it is a list of child LogicNode instances.

Parameters:
  • op (str)

  • children (Union[str, List['LogicNode']])

op
children
cana.function_outputs.ast.expression_to_ast(expr_str)[source]

Parse a boolean expression into a LogicNode AST.

Accepts python (and/or/not) or symbolic (&/|/!) operators. Splits on top-level | then &, unwraps outer parentheses, and treats ! as a prefix pushed via invert_ast() (NNF; stacked !!a cancels).

Parameters:

expr_str (str)

Return type:

LogicNode | None

cana.function_outputs.ast.invert_ast(node)[source]

Apply De Morgan dualization (swap AND/OR, flip literals).

Parameters:

node (LogicNode)

Return type:

LogicNode

cana.function_outputs.ast.ast_variable_names(node)[source]

Collect leaf variable names in node (preorder, with multiplicity).

Parameters:

node (LogicNode | None)

Return type:

List[str]

cana.function_outputs.ast.ast_leaf_polarities(node)[source]

Collect (name, polarity) for each leaf (preorder, with multiplicity).

LITERAL → (name, "pos"); NEGATED_LITERAL → (name, "neg").

Parameters:

node (LogicNode | None)

Return type:

List[Tuple[str, Literal[‘pos’, ‘neg’]]]