Paraconsistent Library
This repository consists of a Python Library designed to help users apply paraconsistent annotated evidential logic (PALet), also known as paraconsistent annotated logic by 2-values (PAL2v), making advanced logic tools accessible and encouraging practical adoption.
How to reference the project:
At EAILab, our mission is to promote science and the use of artificial intelligence. Therefore, if you use the library in academic work, we would be very grateful if you could cite us, helping to further spread and promote the project.
DA CRUZ, Diego Oliveira; ALVES, Bruno. Da Silva; CARVALHO JUNIOR, Arnaldo. Paraconsistent-Lib, Python Library, EAILAB, IFSP, Sao Paulo - Brazil, 2025.
Overview
Paraconsistent logic (PL) is a type of logical reasoning that is interesting to deal with contradictory signals because, contrary to classical logic, it does not consider a contradiction as a foundation for invalidating the entire inference system. PL enables the quantification of the degree of contradiction and certainty of information, allowing conflicting data to be processed in a controlled manner and without loss of consistency.
Main Features:
- Modular architecture based on connectable blocks
- Zero external dependencies, it's necessary only the standard Python library.
- Complete implementation of PAL2v with 12 logical state regions
- Automatic calculation of degrees of certainty, contradiction, and evidence
- Type-safe with full support for Python type hints
- Smart caching for performance optimization
How to install
Requirements: Python 3.9 or higher
The installation is done via pip. To install, simply type the following command in your terminal:
pip install paraconsistent
Theory of Logic
PAL2v works with two degrees of evidence:
- μ (mu): Favorable evidence degree, μ ∈ [0, 1]
- λ (lambda): Unfavorable evidence degree, λ ∈ [0, 1]
From these values, the following are calculated:
- dc (Degree of Certainty): dc = μ - λ, dc ∈ [-1, 1]
- dct (Degree of Contradiction): dct = μ + λ - 1, dct ∈ [-1, 1]
Decision Output:
- 1.0 if μER > FtC (Accept as true)
- 0.0 if μER < FtC (Reject as false)
- 0.5 if μER = FtC (Indecision)
Complementary Metrics
Radial Distance:
- d: Euclidean distance to the nearest vertex
- D: Normalized distance (clamped to [0, 1])
Degree of Real Certainty:
- dcr: dcr = (1 - D) × sign(dc)
Resulting Evidence:
- μE: Evidence based on contradiction: μE = (dc + 1) / 2
- μECT: Evidence of contradiction: μECT = (dct + 1) / 2
- μER: Actual evidence: μER = (dcr + 1) / 2
Certainty Interval:
- φ (phi): φ = 1 - |dct|
Logical State Regions
PAL2v defines 12 regions in the unit square of annotation (QUPC), and your answer will be in one of those regions.
Extreme States:
- t (true): High positive certainty
- f (false): High negative certainty
- ┬ (Inconsistent): High positive contradiction
- ┴ (Paracomplete): High negative contradiction
Transition States:
- Q(t→T) → Quasi-true, tending to inconsistent
- Q(t→⊥) → Quasi-true, tending to paracomplete
- Q(F→T) → Quasi-false, tending to inconsistent
- Q(F→⊥) → Quasi-false, tending to paracomplete
- Q(T→t) → Quasi-inconsistent, tending to true
- Q(T→F) → Quasi-inconsistent, tending to false
- Q(⊥→t) → Quasi-paracomplete, tending to true
- Q(⊥→F) → Quasi-paracomplete, tending to false
User Guide
First of all, to create a block, write this:
from paraconsistent.blocks import ParaconsistentBlock
# Create block with default values
block = ParaconsistentBlock()
Configure the block parameters:
from paraconsistent.blocks import ParaconsistentBlock
block = ParaconsistentBlock()
# Configure certainty control limit (FtC)
block.config.FtC = 0.70
Set Inputs (μ, λ):
# Define levels of evidence
block.input.mu = 0.80 # Favorable evidence
block.input.lam = 0.20 # Unfavorable evidence
How to display the results:
# Access individual results
dc = block.complete.dc # Degree of Certainty
dct = block.complete.dct # Degree of Contradiction
muER = block.complete.muER # Real Evidence
label = block.complete.label # Logical Region
# Or print all results
block.print_complete()
How to Connect Multiple Blocks
# Create a network of two blocks
b1 = ParaconsistentBlock()
b2 = ParaconsistentBlock()
# Configure block 1
b1.config.FtC = 0.70
b1.input.mu = 0.80
b1.input.lam = 0.30
# Use the output of b1 as the input of b2
b2.input.mu = b1.complete.muER
b2.input.lam = 1 - b1.complete.phi
# Result propagated automatically
print(f"Final state: {b2.complete.label}")
API Reference
Builder
ParaconsistentBlock(
*,
mu: float | None = None,
lam: float | None = None,
**param_overrides
)
Parameters:
- μ (mu): Favorable evidence degree (optional)
- λ (lambda): Unfavorable evidence degree (optional)
- **param_overrides: Configuration parameters (FtC)
Configuration (config)
| Parameter | Type | Range | Default | Description |
|---|---|---|---|---|
| FtC | float | [0, 1] | 0.50 | Certainty Tolerance Factor (Certainty Control Limit) |
The FtC input parameter modifies the shape of the QUPC by adjusting the geometry of the Lattice (green line). As an example, we have two images: when FtC is 0.75, it reduces the areas of t and F while expanding the regions of T and Paracomplete; however, when FtC is 0.25, it increases the areas of t and F and decreases those of T and Paracomplete.
Example FtC = 0.75
Example FtC = 0.25
Note: The values VSSC, VICC, VSSCT, and VICCT are automatically calculated based on FtC.
Inputs
# Method 1: Direct assignment
block.input.mu = 0.80
block.input.lam = 0.20
# Method 2: Functional approach
block.input(mu=0.80, lam=0.20)
Values are automatically clamped in the range [0, 1].
Outputs (Complete)
| Field | Type | Range | Description |
|---|---|---|---|
| mu | float | [0, 1] | Favorable level of evidence |
| lam | float | [0, 1] | Unfavorable level of evidence |
| dc | float | [-1, 1] | Degree of Certainty: μ - λ |
| dct | float | [-1, 1] | Degree of Contradiction: μ + λ - 1 |
| d | float | [0, ∞) | Raw radial distance |
| D | float | [0, 1] | Normalized radial distance |
| dcr | float | [-1, 1] | Degree of Real Certainty: (1 - D) × sign(dc) |
| phi | float | [0, 1] | Certainty interval: 1 - |dct| |
| phiE | float | [0, 1] | Certainty interval (alias of phi) |
| muE | float | [0, 1] | Resulting evidence: (dc + 1) / 2 |
| muECT | float | [0, 1] | Contradiction evidence: (dct + 1) / 2 |
| muER | float | [0, 1] | Real evidence: (dcr + 1) / 2 |
| decision_output | float | {0.0, 0.5, 1.0} | Binary decision output |
| label | str | - | Logical region label (t, f, ┬, ┴, etc.) |
| Regions | dict | - | Boolean flags per region |
| FtC | float | [0, 1] | Echo of parameters used in the calculation |
Methods
# Export as a typed dictionary
result: Complete = block.to_dict()
# Print formatted to the console
block.print_complete()
# Set FtC parameter
block.set_params(FtC=0.7)
Examples of a paraconsistent analysis network project using the library
Flowchart of the following example
# Paraconsistent Library developed by Diego Oliveira da Cruz - EAILAB - IFSP
# Oriented by Dr. Arnaldo de Carvalho Junior - EAILAB-IFSP
# Date: 04/nov/2025
# Installing PAL2v Library
%pip install pythonping paraconsistent
# Paraconsistent Analysis Network (PANnet)
# Created by: Dr. Arnaldo de Carvalho Junior
# Date: 04/11/2025
# Example application of the Paraconsistent-Lib Library
# Calls the Paraconsistent Library
from paraconsistent import ParaconsistentBlock
# 1) Create the PAN blocks
PAN1 = ParaconsistentBlock()
PAN2 = ParaconsistentBlock()
PAN3 = ParaconsistentBlock()
# 2) Adjust the Certainty Factor parameter (affects the geometry of the 12 paraconsistent logical states)
# Reference value: 0.5
PAN1.config.FtC = 0.5
PAN2.config.FtC = 0.5
PAN3.config.FtC = 0.5
# 3) Define the mu and lambda
PAN1.input.mu = 0.45
PAN1.input.lam = 0.76
PAN2.input.mu = 1.00
PAN2.input.lam = 0.40
PAN3.input.mu = NAP1.complete.muER
PAN3.input.lam = 1 - NAP2.complete.muER
# Output of the Paraconsistent Analysis Network
print(f"Result of the PAL2v Analysis = {PAN3.complete.muER:.3f}")
More examples:
Architecture
├── blocks/
│ └── block.py — ParaconsistentBlock class
├── core/
│ ├── config.py — Configuration and validation
│ ├── engine.py — Calculation engine
│ ├── metrics.py — Geometric metrics
│ ├── labels.py — Region classification
│ └── types.py — Type definitions
└── __init__.py
Calculation Flow
- Input: Validation and clamping of μ and λ
- Main Degrees: Calculation of dc and dct
- Geometry: Calculation of d, D, and dcr
- Evidence: Calculation of μE, μECT, μER, and φ
- Decision: Comparison of μER with FtC
- Classification: Identification of the logical region
Cache and Performance
The system features an intelligent caching mechanism that automatically refreshes whenever inputs or parameters are modified, guaranteeing result consistency while maintaining optimal performance.
License
MIT License
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.