first-order
Pure Python first-order logic evaluator
from first_order import ForAll, Term
w = Term("w")
x = Term("x")
y = Term("y")
s1 = x & y
s2 = w | ~x
s3 = s1 >> s2
print(ForAll(x, s3))
# output: (∀ x: ((x & y) >> (w | ~x)))
print(s3 @ {"x": True, "y": True, "w": False})
# output: False
Installation
From pypi:
pip install first-order
Latest commit:
pip install git+https://github.com/olivi-r/first-order.git#egg=first-order
Syntax
This project uses simple constructs to abstract the creation of first-order logic sentences:
&conjunction|disjunction~negation>>implication
Two special functions are required to create sentences with quantifiers:
Existsexistential quantifierForAlluniversal quantifier
from first_order import Exists, ForAll, Term
x = Term("x")
z = Term("z")
s_forall = ForAll(z, x | z)
s_exists = Exists(z, x | z)
print(s_forall @ {"x": False})
# output: False
print(s_exists @ {"x": False})
# output: True
Interpretations
Interpretations can be applied to the sentence through the usage of the @ operator (as seen in previous examples), this takes a mapping from the names of terms used in the sentence and their respective values.
Unbound terms result in an error being thrown.
from first_order import Term
x = Term("x")
y = Term("y")
print((x | y) @ {"x": True})
# output:
# Traceback (most recent call last):
# ...
# KeyError: 'y'
Terms attatched to quantifiers do not need to be in the interpretation (unless the same term name is used elsewhere)
from first_order import Exists, Term
x = Term("x")
y = Term("y")
print(Exists(y, x | y) @ {"x": True})
# output: True
Metadata
Release files for first-order 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| first_order-0.1.0.tar.gz | 3.9 kB | Without provenance | Details for first_order-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| first_order-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for first_order-0.1.0-py3-none-any.whl |
Total release size: 8.5 kB
Release files / first_order-0.1.0.tar.gz
| Download URL | first_order-0.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26e0a219341b15d8d4ffe7a21e42f78a174bad92ed245581c507e8312e3901fb
|
|
BLAKE2b-256 checksum How to use checksums |
112aab62999c288cc3bb135f37647829de135f71aaf81d15146820a2a74ec144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / first_order-0.1.0-py3-none-any.whl
| Download URL | first_order-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a5ce66aad25c46be5d3d2b392597a7e8e5367dbe3c73fa0ac2e97be06ef2052
|
|
BLAKE2b-256 checksum How to use checksums |
40188b3ab92a8c04748e20be513aca356dad727e063d605f61302abc61b55b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Security for first-order 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.