Logical Kernels

jlnn.core.logic.implies_kleene_dienes(int_a: Array, int_b: Array) Array[source]

Implements Kleene-Dienes implication (standard max-min logic).

This method of computing the implication (A -> B) is defined as max(1 - A, B). In the context of interval logic JLNN, this is a “pessimistic” approach, since the resulting truth depends only on the most significant extreme (either the antecedent is false or the consequent is true).

Unlike Łukasiewicz logic, there is no linear addition of truths, which can be useful for robust systems resistant to the accumulation of small errors.

Parameters:
  • int_a (jnp.ndarray) – Input interval for antecedent (assumption) of the form (…, 2).

  • int_b (jnp.ndarray) – Input interval for the consequent of the form (…, 2).

Returns:

The resulting truth interval [L, U] of the form (…, 2).
The calculation is as follows:

L_res = max(1 - U_a, L_b) U_res = max(1 - L_a, U_b)

Return type:

jnp.ndarray

jlnn.core.logic.implies_lukasiewicz(int_a: Array, int_b: Array, weights: Array, beta: float) Array[source]

Logical implication A -> B (S-implication) based on Łukasiewicz logic.

In JLNN, implication is implemented using logical equivalence: (A -> B) ≡ (¬A ∨ B).

This implementation uses interval arithmetic, where negation (NOT) inverts the interval boundaries: NOT [L, U] = [1 - U, 1 - L]. The result is then processed by a weighted OR operator, allowing the model to learn the relevance of a given rule.

Parameters:
  • int_a (jnp.ndarray) – Tensor for the antecedent (presupposition A) of the form (…, 2). The last dimension contains [Lower Bound, Upper Bound].

  • int_b (jnp.ndarray) – Tensor for the consequent (consequent B) of the form (…, 2). The last dimension contains [Lower Bound, Upper Bound].

  • weights (jnp.ndarray) – Tensor of weights for an OR gate of the form (2,). The first weight is applied to ¬A, the second to B. Typically initialized to [1, 1].

  • beta (float) – Threshold (bias) determining the stringency of the implication activation.

Returns:

The resulting truth interval of the implication [L, U] of the form (…, 2).

Return type:

jnp.ndarray

jlnn.core.logic.implies_reichenbach(int_a: Array, int_b: Array) Array[source]

Implements Reichenbach implication (product logic).

This method of computing the implication (A -> B) is defined by the relation 1 - A + (A * B). In the context of interval logic, JLNN represents a “compromise” approach that, unlike Łukasiewicz or Kleene-Dienes, does not contain sharp breaks caused by min/max operations.

The main advantage of this implication is that it is fully differentiable over the entire range [0, 1], which ensures stable and non-zero gradients for both arguments (A and B) simultaneously.

Parameters:
  • int_a (jnp.ndarray) – Input interval for antecedent (assumption) of the form (…, 2).

  • int_b (jnp.ndarray) – Input interval for the consequent of the form (…, 2).

Returns:

The resulting truth interval [L, U] of the form (…, 2).
The calculation is performed with respect to interval arithmetic:

L_res = 1 - U_a + (L_a * L_b) U_res = 1 - L_a + (U_a * U_b) The result is treated with the clip function to keep the values ​​in the range [0, 1].

Return type:

jnp.ndarray

jlnn.core.logic.weighted_and_lukasiewicz(x: Array, weights: Array, beta: Array) Array[source]

Calculates a weighted Łukasiewicz conjunction (AND) over truth intervals.

In LNN logic, conjunction is defined through “negative evidence”. The closer the inputs are to falsehood (1 - x) and the higher their weight, the more they reduce the overall truth of the result. The parameter beta determines the threshold below which the result is considered absolutely false (0.0).

Interval semantics: Because negation inverts limits, to calculate the upper limit of the result (U) we use the negation of the lower limits of the inputs (L), and to calculate the lower limit of the result (L) we use the negation of the upper limits of the inputs (U).

Parameters:
  • x (jnp.ndarray) – Input interval tensor of the form (…, num_inputs, 2).

  • weights (jnp.ndarray) – A tensor of weights of the form (num_inputs,).

  • beta (jnp.ndarray) – Scalar threshold parameter (bias).

Returns:

The resulting truth interval [L, U].

Return type:

jnp.ndarray

jlnn.core.logic.weighted_or_lukasiewicz(x: Array, weights: Array, beta: Array) Array[source]

Calculates the weighted Łukasiewicz disjunction (OR) over truth intervals.

Disjunction in LNN acts as an accumulator of “positive evidence”. Each true input increases the overall truth of the result depending on its weight. The beta parameter determines how much “evidence” is needed to reach absolute truth (1.0).

Interval semantics: The OR operation preserves the orientation of the limits: the lower limits of the inputs determine the lower limit of the result, and the upper limits of the inputs determine the upper limit of the result.

Parameters:
  • x (jnp.ndarray) – Input interval tensor of the form (…, num_inputs, 2).

  • weights (jnp.ndarray) – A tensor of weights of the form (num_inputs,).

  • beta (jnp.ndarray) – Scalar threshold parameter (bias).

Returns:

The resulting truth interval [L, U].

Return type:

jnp.ndarray

This module implements low-level mathematical definitions of logical operators. It focuses primarily on Łukasiewicz logic, which is the basis for LNN.

Supported semantics

  • Łukasiewicz (Linear/Optimistic): Standard for JLNN. Provides stable gradients and is highly interpretable.

  • Interval reasoning: Computations are designed to correctly propagate uncertainty through the entire network. For example, in an AND gate, the lower bound of the result is derived from the most pessimistic combination of inputs.

Note

All functions in this module are designed as “pure functions” (pure functions) for maximum compatibility with jax.jit.