neurolang.probabilistic.transforms module

neurolang.probabilistic.transforms.add_existentials_except(query, variables)

Existentially-quantify each free variable in query except for those in variables

Parameters:
queryLogicExpression

logic expression to add the existential quantifiers to.

variablesIterable of Symbol

variables to exclude from existential quantification.

Returns:
LogicExpression

logic expression with existentially-quantified variables added.

neurolang.probabilistic.transforms.convert_rule_to_ucq(implication)

Convert datalog rule to logic UCQ. A UCQ is defined by a logic expression in where the only quantifier is existential.

Parameters:
expressionImplication

Datalog rule.

Returns:
LogicExpression

UCQ with the same ground set as the input datalog rule.

neurolang.probabilistic.transforms.convert_to_cnf_existential_ucq(expression)

Convert logic UCQ to conjunctive normal from (CNF) with only existential quantifiers.

Parameters:
expressionLogicExpression

UCQ.

Returns:
LogicExpression

equivalent UCQ in CNF form.

neurolang.probabilistic.transforms.convert_to_dnf_existential_ucq(expression)

Convert logic UCQ to disjunctive normal from (DNF) with only existential quantifiers.

Parameters:
expressionLogicExpression

UCQ.

Returns:
LogicExpression

equivalent UCQ in DNF form.

neurolang.probabilistic.transforms.minimise_formulas_containment(components, containment_op, head_vars)
neurolang.probabilistic.transforms.minimize_component_conjunction(conjunction, head_vars=None)

Given a conjunction of queries Q1 ∧ … ∧ Qn remove each query Qi such that exists Qj and Qj → Qi.

Parameters:
conjunctionConjunction

conjunction of logical formulas to minimise.

head_vars: set

variables to be considered as constants

Returns:
Conjunction

minimised conjunction.

neurolang.probabilistic.transforms.minimize_component_disjunction(disjunction, head_vars=None)

Given a disjunction of queries Q1 ∨ … ∨ Qn remove each query Qi such that exists Qj and Qi → Qj.

Parameters:
disjunctionDisjunction

Disjunction of logical formulas to minimise.

head_vars: set

variables to be considered as constants

Returns:
Disjunction

Minimised disjunction.

neurolang.probabilistic.transforms.minimize_ucq_in_cnf(query)

Convert UCQ to CNF form and minimise.

Parameters:
queryLogicExpression.

query in UCQ semantics.

Returns:
LogicExpression

minimised query in UCQ semantics.

neurolang.probabilistic.transforms.minimize_ucq_in_dnf(query)

Convert UCQ to DNF form and minimise.

Parameters:
queryLogicExpression.

query in UCQ semantics.

Returns:
LogicExpression

minimised query in UCQ semantics.

neurolang.probabilistic.transforms.split_positive_negative_formulas(nary_logic_operation)

Split formulas of the n_ary_logic operation in those containing a negated predicate and those not.

Parameters:
nary_logic_operationNAryLogicOperation

Operation whose formulas are going to be split

Returns:
positive, negative

two Iterable[Union[LogicOperation, FunctionApplication]] objects containing the positive and negative formulas

neurolang.probabilistic.transforms.unify_existential_variables(query)

Reduce the number of existentially-quantified variables. Specifically if query is an UCQ and can be rewritten in DNF such that Q = ∃x.Q1 ∨ ∃y.Q2 and x in Q1 unifies with y in Q2, then Q is transformed to Q = ∃f.(Q1[f/x] ∨ Q2[f/y]) where f is possibly a fresh variable.

Parameters:
queryLogicExpression

UCQ expression to unify existential variables if possible.

Returns:
LogicExpression

logic expression with existential variables unifies