Skip to main content

Multi-valued Logic Truth Value Computation Framework

Project description

Polytruth - Multi-valued Logic Truth Value Computation Framework

Polytruth is a Python package for modeling and computing truth values in multi-valued logic systems. It supports complex logical expressions, variable management, rule-based reasoning, and external file parsing, making it ideal for multi-valued logic applications.

The name "Polytruth" combines "poly-" (many) with "truth", emphasizing its ability to handle multiple truth values beyond simple binary logic.

Features

  • 🧠 Support for n-valued logic systems (n ≥ 2)

  • 📝 Logical expression parsing and evaluation

  • 🔧 Customizable logical operators

  • 📁 External file loading for logic rules

  • 🚀 NumPy-based vector operations

Installation

pip install polytruth

Quick Start

Basic Usage

import numpy as np
from polytruth import LogicSystem, MultiValuedOperators,And, Not

# Initialize logic system with poly-valued operators
logic_system = LogicSystem(MultiValuedOperators())

# Create variables with multi-dimensional truth values
a = logic_system.new_variable("a", np.array([0.3, 0.7]))  # Ternary logic example
b = logic_system.new_variable("b", np.array([0.5, 0.5]))  # Probability distribution

# Add logical rules
rule1 = And(And(a, b), Not(b))
logic_system.add_rule("rule1", rule1)
logic_system.add_rule("rule2", ~a & (b | a))

# Set variable values
logic_system.set_variable_values({
    "is(a,c)": np.array([0.5, 0.9]),  # Custom predicate
    "b": 0.8  # Scalar truth value
})

# Compute all rules
print("All rule computations:")
print(logic_system.compute())

# Compute specific rule
print("\nSingle rule computation:")
print(logic_system.compute("rule1"))

# View all variables
print("\nSystem variables:")
print(logic_system.variables)
## View all rules
print("\nSystem rules:")
print(logic_system.rules)

File Parsing

from polytruth.parser import parse_file
from polytruth import LogicSystem, MultiValuedOperators
logic_system = LogicSystem(MultiValuedOperators())
parse_file("data.logic",logic_system)
print(logic_system.rules)

File Format Example (data.logic)

test : is(a,c)&b
test2 : ~a -> b

Supported Operators

Operator Class (in code) Symbol (in file) Example Description
Conjunction And &, ,/\ a & b Logical AND
Disjunction Or , \/ a|b Logical OR
Negation Not ~, ¬ ~a Logical NOT
Implication Implies ->, a -> b Material implication
Equivalence Equiv <->, a <-> b Logical equivalence

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polytruth-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polytruth-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file polytruth-0.1.1.tar.gz.

File metadata

  • Download URL: polytruth-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for polytruth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69d79b21c602dbcc0c9aec503b69e5a2c1300c84b97e0412a929ae339731b1b4
MD5 eae61e7df16764e8cc29a65ab441ecef
BLAKE2b-256 72e58f2e92c8f064ab430864dcb22e8722f6a9c6a41c65ed31c6523bcc50afdd

See more details on using hashes here.

File details

Details for the file polytruth-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: polytruth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.4

File hashes

Hashes for polytruth-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4e1ff4a9d846b19e7eb47b82476331149a7440cb419c90b6eb636637cb5c80
MD5 d7e8e2ee857823e25572ca10126cc2ce
BLAKE2b-256 ca9f83ab8a51b3d14c061f61926ad1b5201a98d1114c1f7e1bddbd92a5e28aef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page