Logical Gates (Stateful)¶
- class jlnn.nn.gates.BulkAnd(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleNon-trainable pure stateless bulk AND reduction gate.
Reduces a sequence of multiple truth intervals along the specified feature axis into a single intersection interval. This is an unparameterized structural block representing traditional multi-input fuzzy logic conjunction.
- method¶
Pure fuzzy framework selector (‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’, ‘lukasiewicz’).
- Type:
str
- __call__(x: Array) Array[source]¶
Performs structural bulk reduction using fuzzy AND axioms.
- Parameters:
x (jnp.ndarray) – Input multi-channel tensor structured as (…, num_inputs, 2).
- Returns:
Consolidated reduction interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the provided method is unknown or unhandled.
- class jlnn.nn.gates.BulkOr(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleNon-trainable pure stateless bulk OR reduction gate.
Reduces a sequence of multiple truth intervals along the specified feature axis into a single union interval. This is an unparameterized structural block representing traditional multi-input fuzzy logic disjunction.
- method¶
Pure fuzzy framework selector (‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’, ‘lukasiewicz’).
- Type:
str
- __call__(x: Array) Array[source]¶
Performs structural bulk reduction using fuzzy OR axioms.
- Parameters:
x (jnp.ndarray) – Input multi-channel tensor structured as (…, num_inputs, 2).
- Returns:
Consolidated reduction interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the provided method is unknown or unhandled.
- class jlnn.nn.gates.PhysicalAnd(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleSpace-curved entropic physical AND gate with localized field configurations.
Implements a field-theoretic physical fuzzy logic (PFL) conjunction. It simulates physical logic intersections across space-curved boundary zones using entropic hyperparameters.
- method¶
Target physical framework (‘physical_godel’, ‘physical_kleene_dienes’, ‘physical_product’, ‘physical_reichenbach’, ‘physical_lukasiewicz’).
- Type:
str
- gamma¶
Space curvature dissipation coefficient parameter.
- Type:
float
- mode¶
Activation field blending mode configuration (e.g., ‘sigmoid’).
- Type:
str
- slope¶
Physical boundary transition slope parameter.
- Type:
float
- offset¶
Physical potential zero-point offset.
- Type:
float
- __call__(x: Array) Array[source]¶
Computes physical space-curved conjunction field dynamics.
- Parameters:
x (jnp.ndarray) – Input physical interval tensor structured as (…, num_inputs, 2).
- Returns:
Synthesized output field interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the selected physical AND setup is not recognized.
- __init__(method: str = 'physical_kleene_dienes', gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5)[source]¶
Initializes the parameter-free PhysicalAnd field gate.
- Parameters:
method (str, optional) – Selected PFL operational semantics. Defaults to ‘physical_kleene_dienes’.
gamma (float, optional) – Field interaction scaling. Defaults to 0.2.
mode (str, optional) – Wave/field mapping activation mode. Defaults to ‘sigmoid’.
slope (float, optional) – Curvature transition coefficient. Defaults to 1.0.
offset (float, optional) – Geometric field center shift. Defaults to 0.5.
- class jlnn.nn.gates.PhysicalImplication(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleParameter-free space-curved rule gateway (A -> B).
Evaluates rule mappings based on Physical Fuzzy Logic (PFL) metrics. It monitors field potentials at logical boundary intersections (including continuous singularity zones) without utilizing learning states.
- method¶
Selected physical implication kernel configuration.
- Type:
str
- gamma¶
Space curvature dissipation coefficient parameter.
- Type:
float
- mode¶
Activation field blending mode configuration.
- Type:
str
- slope¶
Physical boundary transition slope parameter.
- Type:
float
- offset¶
Physical potential zero-point offset.
- Type:
float
- __call__(int_a: Array, int_b: Array) Array[source]¶
Computes the physical implication output based on causal field distributions.
- Parameters:
int_a (jnp.ndarray) – Physical antecedent field interval tensor structured as (…, 2).
int_b (jnp.ndarray) – Physical consequent field interval tensor structured as (…, 2).
- Returns:
Rules validity interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- __init__(method: str = 'physical_kleene_dienes', gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5)[source]¶
Initializes the non-parametric PhysicalImplication rule connector.
- Parameters:
method (str, optional) – Target PFL implication mapping. Defaults to ‘physical_kleene_dienes’.
gamma (float, optional) – Field interaction scaling. Defaults to 0.2.
mode (str, optional) – Wave/field mapping activation mode. Defaults to ‘sigmoid’.
slope (float, optional) – Curvature transition coefficient. Defaults to 1.0.
offset (float, optional) – Geometric field center shift. Defaults to 0.5.
- class jlnn.nn.gates.PhysicalNand(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleParameter-free physical NAND gate.
Composes a non-parametric field-theoretic physical AND operation followed by a rigid physical inversion layer (NOT).
- and_gate¶
Internal physical intersection processor layer.
- Type:
- not_gate¶
Internal physical logic negation layer.
- Type:
- __call__(x: Array) Array[source]¶
Executes physical conjunction followed immediately by field negation.
- Parameters:
x (jnp.ndarray) – Input physical interval tensor structured as (…, num_inputs, 2).
- Returns:
Evaluated physical NAND interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- __init__(method: str = 'physical_kleene_dienes', gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5)[source]¶
Initializes the compound PhysicalNand gate structure.
- Parameters:
method (str, optional) – Underlying PFL operational semantics. Defaults to ‘physical_kleene_dienes’.
gamma (float, optional) – Field interaction scaling. Defaults to 0.2.
mode (str, optional) – Wave/field mapping activation mode. Defaults to ‘sigmoid’.
slope (float, optional) – Curvature transition coefficient. Defaults to 1.0.
offset (float, optional) – Geometric field center shift. Defaults to 0.5.
- class jlnn.nn.gates.PhysicalNor(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleParameter-free physical NOR gate.
Composes a non-parametric field-theoretic physical OR operation followed by a rigid physical inversion layer (NOT).
- or_gate¶
Internal physical disjunction processor layer.
- Type:
- not_gate¶
Internal physical logic negation layer.
- Type:
- __call__(x: Array) Array[source]¶
Executes physical disjunction followed immediately by field negation.
- Parameters:
x (jnp.ndarray) – Input physical interval tensor structured as (…, num_inputs, 2).
- Returns:
Evaluated physical NOR interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- __init__(method: str = 'physical_kleene_dienes', gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5)[source]¶
Initializes the compound PhysicalNor gate structure.
- Parameters:
method (str, optional) – Underlying PFL operational semantics. Defaults to ‘physical_kleene_dienes’.
gamma (float, optional) – Field interaction scaling. Defaults to 0.2.
mode (str, optional) – Wave/field mapping activation mode. Defaults to ‘sigmoid’.
slope (float, optional) – Curvature transition coefficient. Defaults to 1.0.
offset (float, optional) – Geometric field center shift. Defaults to 0.5.
- class jlnn.nn.gates.PhysicalNot(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleParameter-free physical inversion (NOT) gate.
Provides a clean, static logic negation wrapper for structural logic field inversion without any trainable parameter constraints.
- class jlnn.nn.gates.PhysicalOr(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleSpace-curved entropic physical OR gate with localized field configurations.
Implements a field-theoretic physical fuzzy logic (PFL) disjunction. It projects multi-input truth intervals into non-Euclidean space, evaluating field interactions using explicit physical hyperparameters rather than learnable structural weights.
- method¶
Target physical framework (‘physical_godel’, ‘physical_kleene_dienes’, ‘physical_product’, ‘physical_reichenbach’, ‘physical_lukasiewicz’).
- Type:
str
- gamma¶
Space curvature dissipation coefficient parameter.
- Type:
float
- mode¶
Activation field blending mode configuration (e.g., ‘sigmoid’).
- Type:
str
- slope¶
Physical boundary transition slope parameter.
- Type:
float
- offset¶
Physical potential zero-point offset.
- Type:
float
- __call__(x: Array) Array[source]¶
Computes physical space-curved disjunction field dynamics.
- Parameters:
x (jnp.ndarray) – Input physical interval tensor structured as (…, num_inputs, 2).
- Returns:
Synthesized output field interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the selected physical OR setup is not recognized.
- __init__(method: str = 'physical_kleene_dienes', gamma: float = 0.2, mode: str = 'sigmoid', slope: float = 1.0, offset: float = 0.5)[source]¶
Initializes the parameter-free PhysicalOr field gate.
- Parameters:
method (str, optional) – Selected PFL operational semantics. Defaults to ‘physical_kleene_dienes’.
gamma (float, optional) – Field interaction scaling. Defaults to 0.2.
mode (str, optional) – Wave/field mapping activation mode. Defaults to ‘sigmoid’.
slope (float, optional) – Curvature transition coefficient. Defaults to 1.0.
offset (float, optional) – Geometric field center shift. Defaults to 0.5.
- class jlnn.nn.gates.WeightedAnd(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy AND gate supporting standard t-norms.
This module implements a stateful intersection layer that combines multiple input interval truth values into a single consolidated truth interval. It employs learnable weights to scale feature importance and a learnable beta parameter as an intensity bias.
- method¶
Target logical framework selector (‘lukasiewicz’, ‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’).
- Type:
str
- weights¶
Trainable input importance weights structured as (num_inputs,).
- Type:
nnx.Param
- beta¶
Trainable gate activation sensitivity threshold scalar (bias).
- Type:
nnx.Param
- __call__(x: Array) Array[source]¶
Executes the parameterized forward pass for the fuzzy AND operation.
- Parameters:
x (jnp.ndarray) – Input interval tensor structured as (…, num_inputs, 2), where the final dimension contains the lower and upper bounds [L, U].
- Returns:
Evaluated collective truth interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the specified method is not supported by the parametric AND layer.
- __init__(num_inputs: int, rngs: Rngs, method: str = 'lukasiewicz')[source]¶
Initializes the stateful WeightedAnd gate with corresponding optimization parameters.
- Parameters:
num_inputs (int) – Number of input streams to aggregate.
rngs (nnx.Rngs) – Flax NNX random number generator collection.
method (str, optional) – Fuzzy logic framework to employ. Defaults to ‘lukasiewicz’.
- class jlnn.nn.gates.WeightedImplication(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric implication gate (A -> B).
Maps a causal rule structure where an antecedent interval tensor (A) implies a consequent interval tensor (B). The gateway learns input relative scaling and standard bounds corrections to preserve fuzzy logical constraints.
- method¶
Target implication framework selector (e.g., ‘lukasiewicz’, ‘reichenbach’, ‘kleene_dienes’).
- Type:
str
- weights¶
Trainable rule component scaling weights structured as (2,).
- Type:
nnx.Param
- beta¶
Trainable rule sensitivity threshold parameter (bias).
- Type:
nnx.Param
- __call__(int_a: Array, int_b: Array) Array[source]¶
Computes the parametric fuzzy rule implication forward pass.
- Parameters:
int_a (jnp.ndarray) – Antecedent truth interval tensor structured as (…, 2).
int_b (jnp.ndarray) – Consequent truth interval tensor structured as (…, 2).
- Returns:
Calculated rule validity interval tensor structured as (…, 2).
- Return type:
jnp.ndarray
- class jlnn.nn.gates.WeightedNand(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy NAND gate.
This module performs a parametric fuzzy conjunction (AND) across multiple input interval channels, followed by a logical inversion (NOT) wrapper, using trainable logic mechanics.
- method¶
Target logical framework selector (‘lukasiewicz’, ‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’).
- Type:
str
- weights¶
Trainable input importance weights structured as (num_inputs,).
- Type:
nnx.Param
- beta¶
Trainable gate activation sensitivity threshold scalar (bias).
- Type:
nnx.Param
- __call__(x: Array) Array[source]¶
Executes the parameterized forward pass for the fuzzy NAND operation.
- Parameters:
x (jnp.ndarray) – Input interval tensor structured as (…, num_inputs, 2), where the final dimension contains the lower and upper bounds [L, U].
- Returns:
Inverted collective truth interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the specified method is not supported by the parametric NAND layer.
- __init__(num_inputs: int, rngs: Rngs, method: str = 'lukasiewicz')[source]¶
Initializes the stateful WeightedNand gate with corresponding optimization parameters.
- Parameters:
num_inputs (int) – Number of input streams to aggregate.
rngs (nnx.Rngs) – Flax NNX random number generator collection.
method (str, optional) – Fuzzy logic framework to employ. Defaults to ‘lukasiewicz’.
- class jlnn.nn.gates.WeightedNor(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy NOR gate.
This module performs a parametric fuzzy disjunction (OR) across multiple input interval channels, followed by a logical inversion (NOT) wrapper, using trainable logic mechanics.
- method¶
Target logical framework selector (‘lukasiewicz’, ‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’).
- Type:
str
- weights¶
Trainable input importance weights structured as (num_inputs,).
- Type:
nnx.Param
- beta¶
Trainable gate activation sensitivity threshold scalar (bias).
- Type:
nnx.Param
- __call__(x: Array) Array[source]¶
Executes the parameterized forward pass for the fuzzy NOR operation.
- Parameters:
x (jnp.ndarray) – Input interval tensor structured as (…, num_inputs, 2), where the final dimension contains the lower and upper bounds [L, U].
- Returns:
Inverted collective truth interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the specified method is not supported by the parametric NOR layer.
- __init__(num_inputs: int, rngs: Rngs, method: str = 'lukasiewicz')[source]¶
Initializes the stateful WeightedNor gate with corresponding optimization parameters.
- Parameters:
num_inputs (int) – Number of input streams to aggregate.
rngs (nnx.Rngs) – Flax NNX random number generator collection.
method (str, optional) – Fuzzy logic framework to employ. Defaults to ‘lukasiewicz’.
- class jlnn.nn.gates.WeightedNot(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy NOT inversion gate.
Applies a parameterized logic negation to an incoming interval tensor, allowing the optimization routine to moderate or invert the intensity of the negative mapping via a learnable weight.
- weight¶
Trainable inversion scaling factor parameter.
- Type:
nnx.Param
- class jlnn.nn.gates.WeightedOr(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy OR gate supporting standard t-conorms.
This module aggregates multiple input interval streams into a single truth interval using a parameterized t-conorm operation. It optimizes individual input importance via learnable weights and adjusts the global activation threshold using a learnable bias parameter (beta).
- method¶
Target logical framework selector (‘lukasiewicz’, ‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’).
- Type:
str
- weights¶
Trainable input importance weights structured as (num_inputs,).
- Type:
nnx.Param
- beta¶
Trainable gate activation sensitivity threshold scalar (bias).
- Type:
nnx.Param
- __call__(x: Array) Array[source]¶
Executes the parameterized forward pass for the fuzzy OR operation.
- Parameters:
x (jnp.ndarray) – Input interval tensor structured as (…, num_inputs, 2), where the final dimension contains the lower and upper bounds [L, U].
- Returns:
Evaluated collective truth interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the specified method is not supported by the parametric OR layer.
- __init__(num_inputs: int, rngs: Rngs, method: str = 'lukasiewicz')[source]¶
Initializes the stateful WeightedOr gate with corresponding optimization parameters.
- Parameters:
num_inputs (int) – Number of input streams to aggregate.
rngs (nnx.Rngs) – Flax NNX random number generator collection.
method (str, optional) – Fuzzy logic framework to employ. Defaults to ‘lukasiewicz’.
- class jlnn.nn.gates.WeightedXor(*args: Any, **kwargs: Any)[source]¶
Bases:
ModuleTrainable parametric fuzzy XOR (Exclusive OR) gate.
A binary trainable fuzzy logic layer that evaluates the strict difference or exclusive disjunction between two distinct truth interval vectors under parameterized conditions.
- method¶
Target logical framework selector (‘lukasiewicz’, ‘godel’, ‘kleene_dienes’, ‘product’, ‘reichenbach’).
- Type:
str
- weights¶
Trainable binary input interaction weights structured as (2,).
- Type:
nnx.Param
- beta¶
Trainable activation sensitivity threshold scalar (bias).
- Type:
nnx.Param
- __call__(int_a: Array, int_b: Array) Array[source]¶
Executes the parameterized forward pass for the binary fuzzy XOR operation.
- Parameters:
int_a (jnp.ndarray) – First input interval tensor structured as (…, 2).
int_b (jnp.ndarray) – Second input interval tensor structured as (…, 2).
- Returns:
Evaluated XOR truth interval structured as (…, 2).
- Return type:
jnp.ndarray
- Raises:
ValueError – If the specified method is not supported by the parametric XOR layer.
This module contains an implementation of logical gates implemented as state objects (modules) in the modern Flax NNX framework. Each parametric gate encapsulates its own trainable parameters (input importance weights and activation thresholds) that it optimizes using gradient descent, while physical gates model nonlinear truth space deformations.
Stateful Gates vs. Stateless Functions¶
Unlike the functional interface in the Functional Logic Kernels module, the gateways in this module:
They store their internal state (weight and threshold matrices) by encapsulating them in
nnx.Param.They are fully compatible with Flax NNX array injection mechanisms and automatic parameter search using optimizers.
They serve as basic building blocks that the compiler assembles into deep neuro-symbolic structures and knowledge graphs.
To access tensor values inside JAX operations, they strictly use the modern NNX syntax with ellipsis:
self.weights[...]andself.beta[...].
1. Traditional parametric logic gates¶
These gates implement learning logical operators over truth intervals. Using weights, the network can selectively suppress irrelevant inputs and use the beta (bias) parameter to adjust the stringency of the logical evaluation.
WeightedAnd: Implements weighted conjunction. By default, it uses the Łukasiewicz t-norm based on the accumulation of “negative evidence” of inputs. It also supports Kleene-Dienes and Reichenbach semantics.
WeightedOr: Implements weighted disjunction (t-conorm). In the Łukasiewicz variant, the
betaparameter determines how much positive evidence is needed to saturate to the absolute truth of 1.0.WeightedNot: Single-input trainable negation, where the weighting coefficient defines the degree (stringency) of the interval inversion.
WeightedImplication: Encapsulates causal rules of type \(A \rightarrow B\). Allows training independent weights for the premise and conclusion of the rule.
WeightedXor: N-ary exclusive disjunction implemented as a hierarchical tree of binary XOR operations. This structure allows for efficient learning of complex parity functions.
Compound gates (WeightedNand, WeightedNor): Combination of weighted operators followed by negation. Key for detecting logical contradictions and penalizing violations of knowledge base integrity.
2. Bulk Gates¶
Bulk operators are used to aggregate large tensor structures along a specified dimension (the axis parameter), which is ideal for evaluating quantifiers (general \(\forall\) and existential \(\exists\)) over vector fields.
BulkAnd: Bulk conjunction reducing the selected tensor axis using Gödel’s minimum or Product (probabilistic) operator.
BulkOr: Bulk disjunction evaluating the maximum or probabilistic union along a specified axis.
3. Space-time-curved physics gates (PFL)¶
These gates represent parameter-free modules that, instead of learning weights, transform logical operations through topological curvature of the truth field proportional to the local Shannon entropy.
PhysicalAnd / PhysicalOr: Evaluates conjunction and disjunction in curved space. The
gammaparameter determines the intensity of the gravitational field of the center of uncertainty (0.5) that attracts unstable states.PhysicalImplication: Pure physical mapping of causal relationships. Supports advanced PFL semantics (
physical_kleene_dienes,physical_reichenbach,physical_lukasiewicz) that eliminate vanishing gradients in regions of high system entropy.PhysicalNot / PhysicalNand / PhysicalNor: Physical invariants for inversion and composite negation working with topological fields without the need to store internal weights in GPU memory.