Interval Arithmetic¶
- jlnn.core.intervals.check_contradiction(interval: Array) Array[source]¶
Detects a logical contradiction in the truth interval.
Within LNN (Logical Neural Networks), we work with intervals [L, U], where L (Lower Bound) is the level of evidence for truth and U (Upper Bound) is the upper limit above which there is no more evidence for falsity.
A logical contradiction occurs when L > U. This means that the sum of evidence for truth and falsehood is so high that the boundaries have been “crossed.” This condition indicates inconsistent learning or conflicting data in the knowledge base.
- Parameters:
interval (jnp.ndarray) – Input tensor of intervals of the form (…, 2). The last dimension is assumed to contain the pair [Lower Bound, Upper Bound].
- Returns:
- Boolean tensor (or float tensor 1.0/0.0 in JAX) of the form (…).
A value of True (1.0) indicates that a conflict occurred in the given interval (L > U).
- Return type:
jnp.ndarray
- jlnn.core.intervals.create_interval(lower: Array, upper: Array) Array[source]¶
Creates an interval tensor representing truth values as [Lower Bound, Upper Bound].
This function groups two separate tensors (lower and upper bounds) into one common tensor. In the JLNN architecture, this format is the standard for representing uncertainty - the greater the difference between the upper and lower bounds, the greater the system’s ignorance about the given fact.
- Parameters:
lower (jnp.ndarray) – Tensor containing lower truth bounds (0.0 to 1.0). Can have any shape.
upper (jnp.ndarray) – Tensor containing upper truth limits (0.0 to 1.0). Must have the same shape as the ‘lower’ parameter.
- Returns:
- The resulting interval tensor of the form (…, 2),
where the last dimension contains the pair [L, U]. This format is optimized for efficient use in JAX transformations such as vmap and jit.
- Return type:
jnp.ndarray
- jlnn.core.intervals.ensure_consistent(lower: Array, upper: Array) Tuple[Array, Array][source]¶
Enforces interval consistency by ensuring that the lower bound is less than or equal to the upper bound.
In neuro-symbolic and fuzzy logic operations, continuous transformations (like weighted negations) can sometimes invert interval boundaries. This function corrects such inversions using vectorized minimum and maximum operations, maintaining compatibility with JAX’s JIT compilation and auto-differentiation.
- Parameters:
lower – A JAX array representing the lower bounds (L) of the intervals.
upper – A JAX array representing the upper bounds (U) of the intervals.
- Returns:
A tuple of (new_lower, new_upper) where new_lower <= new_upper for all elements. The shapes of the returned arrays match the input shapes.
Example
>>> L, U = jnp.array(0.7), jnp.array(0.5) >>> ensure_consistent(L, U) (DeviceArray(0.5, dtype=float32), DeviceArray(0.7, dtype=float32))
- jlnn.core.intervals.ensure_interval(array: Array) Array[source]¶
Validates and corrects an entire interval tensor to ensure mathematical consistency.
This function processes a tensor where the last dimension represents an interval [lower_bound, upper_bound]. It decomposes the tensor, ensures that each lower bound is less than or equal to its corresponding upper bound using ensure_consistent, and reconstructs the tensor.
This is a critical safety utility for neuro-symbolic layers where batch operations or weighted logic transformations might invert interval limits.
- Parameters:
array – A JAX array of shape […, 2], where the last axis contains the interval pairs.
- Returns:
A JAX array of the same shape […, 2] with corrected (sorted) intervals along the last axis.
Example
>>> data = jnp.array([[0.8, 0.2], [0.1, 0.9]]) >>> ensure_interval(data) DeviceArray([[0.2, 0.8], [0.1, 0.9]], dtype=float32)
- jlnn.core.intervals.get_lower(interval: Array) Array[source]¶
Extracts the lower bound from an interval tensor.
In the JLNN architecture, the lower bound represents the minimum degree of confirmed truth of a given statement. If L=1, the statement is considered provably true.
- Parameters:
interval (jnp.ndarray) – A tensor of intervals of the form (…, 2). The last dimension is assumed to contain the pair [L, U].
- Returns:
- A tensor containing only the lower bounds (L).
The resulting shape is (…,), one dimension less than the input.
- Return type:
jnp.ndarray
- jlnn.core.intervals.get_upper(interval: Array) Array[source]¶
Extracts the upper bound (Upper Bound) from the interval tensor.
In LNN logic, the upper bound (U) represents the maximum possible degree of truth that a given statement can have given the absence of evidence of its falsity. If U=0, the statement is provably false (False).
- Parameters:
interval (jnp.ndarray) – A tensor of intervals of the form (…, 2). The last dimension is assumed to contain the pair [L, U].
- Returns:
- A tensor containing only upper bounds (U).
The resulting shape is (…,), one dimension less than the input tensor.
- Return type:
jnp.ndarray
- jlnn.core.intervals.negate(interval: Array) Array[source]¶
Performs a logical negation (NOT) over a truth interval.
- In interval logic JLNN, negation is defined by the relation:
NOT [L, U] = [1 - U, 1 - L].
- This calculation ensures that:
What was strong evidence for truth (high L) becomes strong evidence for falsehood (low U).
The degree of ignorance (interval width) remains unchanged.
- Parameters:
interval (jnp.ndarray) – Input tensor of intervals of the form (…, 2). The last dimension contains the pair [Lower Bound, Upper Bound].
- Returns:
Negated interval tensor of form (…, 2).
- Return type:
jnp.ndarray
- jlnn.core.intervals.uncertainty(interval: Array) Array[source]¶
Calculates the uncertainty as the width of the interval (U - L).
In Logical Neural Networks (LNN), the width of the interval represents the so-called epistemic uncertainty - that is, how much information we lack to be able to decide on a given statement with absolute certainty.
- Meaning of the resulting values:
1.0: Complete ignorance (interval [0, 1]). We have no evidence for the statement.
0.0: Absolute certainty (e.g. [1, 1] for True or [0, 0] for False).
Values close to 0: Signal that the system is approaching a specific conclusion.
Negative values: Indicate a logical contradiction (L > U).
- Parameters:
interval (jnp.ndarray) – A tensor of intervals of the form (…, 2). The last dimension contains the pair [Lower Bound, Upper Bound].
- Returns:
- A tensor containing the width of each interval of the shape (…).
The resulting shape has one less dimension than the input tensor.
- Return type:
jnp.ndarray
Module for working with truth intervals \([L, U]\). In JLNN, truth is not just a single number, but a range that allows for representing uncertainty.
Key operations¶
Creation: Using
create_intervalcombines the lower and upper bounds into a single JAX tensor.Extraction: Functions
get_lowerandget_upperprovide safe access to the bounds.Negation: Implements logical NOT as \([1-U, 1-L]\), preserving the interval width (degree of ignorance).