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
from polytruth.operators import 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)

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 , \/ 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.0.tar.gz (9.8 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.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for polytruth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4369bb27fa4feaf9d7c007744472278426da49a50303620e7f952f688d60873b
MD5 935f2af3dcb2c63b5ab115c3eb76a0ad
BLAKE2b-256 4767d3a7c14af2175325af305c797ad68354bc27ebca57d1f092cb9f777ec7f0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polytruth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84ad9c02b0b4b5a2f0bd53ef804598b12943026efdf9e9e1ac5c90ca7adc8ec9
MD5 bf0dd9b7e71420e43b81ed1e5bb40072
BLAKE2b-256 9839515d155e9151c37beb2532ccc058eed607e52d6f3290dc82f8f9565ce3f6

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