Skip to main content

Primitive Logic Directed Acyclic Graph

The Primitive Logic Directed Acyclic Graph (PL-DAG) is a data structure based on a Directed Acyclic Graph (DAG) where each node represents a logical relationship and leaf nodes correspond to literals. Each node encapsulates information about how its incoming nodes or leaves are logically related. For example, a node might represent an AND operation, meaning that if it evaluates to true, all of its incoming nodes or leaves must also evaluate to true.

How It Works

Each composite (node) is represented as a linear inequality of the form A = a + b + c >= 0. A primitive (leaf) is a named alias connected to a literal. A literal is represented as a complex number with two values: -1+3j indicates the lowest value a variable can take (-1) and the highest value (+3). For example, a boolean primitive has the literal value 1j since it can only be 0 or 1. A primitive with value 52j (representing weeks, for instance) could take any discrete value between 0 and 52, though it is expressed only by its bounds.

Example

from pldag import PLDAG

# Initialize model
model = PLDAG()

# Set x, y, and z as boolean variables in the model
model.set_primitives("xyz")

# Create a simple AND operation connected to alias "A"
# This is equivalent to A = x + y + z - 3 >= 0
# The ID for this proposition is returned. We can also assign an alias to it.
id_ref = model.set_and(["x","y","z"], alias="A")

# Later, if we forget the ID, we can retrieve it like this
id_ref_again = model.id_from_alias("A")
assert id_ref == id_ref_again

# When all x, y, and z are set to 1, we expect `id_ref` to be 1+1j
assert model.propagate({"x": 1+1j, "y": 1+1j, "z": 1+1j}).get(id_ref) == 1+1j

# When not all are set, we get 1j (meaning the model doesn't know whether it's true or false)
assert model.propagate({"x": 1+1j, "y": 1+1j, "z": 1j}).get(id_ref) == 1j

# However, if we know that any variable is not set (equal to 0), the model knows the composite is false (0j)
assert model.propagate({"x": 1+1j, "y": 1+1j, "z": 0j}).get(id_ref) == 0j

Using a Solver

There is no built-in solver, but PL-DAG supports integration with existing solvers. Install the package:

pip install pldag

Then use it as follows:

from pldag import Solver

# Maximize [x=1, y=0, z=0] such that the model's rules hold and `id_ref` must be true
solution = next(iter(model.solve(objectives=[{"x": 1}], assume={id_ref: 1+1j}, solver=Solver.DEFAULT)))

# Since x=1 and `id_ref` must be true (i.e., all(x,y,z) must be true),
# we expect all variables to be set
assert solution.get(id_ref) == 1+1j

Release files for pldag 0.10.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pldag 0.10.17
File Size Uploaded
pldag-0.10.17.tar.gz 22.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pldag 0.10.17
File Interpreter ABI Platform
pldag-0.10.17-py3-none-any.whl Python 3 none any Details

Total release size: 45.2 kB

Release files / pldag-0.10.17.tar.gz

Download URL pldag-0.10.17.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c1d29584f093c0a3fe481a8e04711f317a2285d39fbb5f8846dd9891cba3ddc2
BLAKE2b-256 checksum
How to use checksums
476e074899b0ad1ec6d61a56b5d7c211649c1d4902dfc6aadfd3fcfe0e0d3133
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.15 Darwin/24.6.0

Release files / pldag-0.10.17-py3-none-any.whl

Download URL pldag-0.10.17-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2804c55f132cae59d35b1c99bb842f425d5ec8f2c27bba641191da9b7ab39b0d
BLAKE2b-256 checksum
How to use checksums
255528c7c2f40879af445d4709aa50d97e08e89e8e3d84d3e2d596031c61b350
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.10.15 Darwin/24.6.0

Release history Release notifications | RSS feed

This release

0.10.17 This release

2 release files

0.10.9

2 release files

0.10.8

2 release files

0.10.7

2 release files

0.10.6

2 release files

0.10.5

2 release files

0.10.0

2 release files

0.9.17

2 release files

0.9.16

2 release files

0.9.15

2 release files

0.9.11

2 release files

0.9.10

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.64

2 release files

0.8.63

2 release files

0.8.62

2 release files

0.8.61

2 release files

0.8.51

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.9

2 release files

0.7.8

2 release files

0.7.7

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page