Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ endforeach()

find_package(pybind11)
if(pybind11_FOUND)
pybind11_add_module(pyds ${CMAKE_CURRENT_SOURCE_DIR}/pyds/ds.cc)
target_link_libraries(pyds PRIVATE ${PROJECT_NAME})
set_property(TARGET pyds PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
set_target_properties(pyds PROPERTIES OUTPUT_NAME _ds)
install(TARGETS pyds DESTINATION pyds)
pybind11_add_module(apyds ${CMAKE_CURRENT_SOURCE_DIR}/apyds/ds.cc)
target_link_libraries(apyds PRIVATE ${PROJECT_NAME})
set_property(TARGET apyds PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
set_target_properties(apyds PROPERTIES OUTPUT_NAME _ds)
install(TARGETS apyds DESTINATION apyds)
else()
message(STATUS "pybind11 not found, Python bindings will not be built.")
endif()
Expand Down
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A deductive system for logical inference, implemented in C++. The library provid
## Architecture

- **C++ Core**: The core implementation in `src/` and `include/ds/` provides the fundamental data structures and algorithms
- **Python Bindings**: Built with pybind11, wrapping the C++ core (see `pyds/`)
- **Python Bindings**: Built with pybind11, wrapping the C++ core (see `apyds/`)
- **TypeScript/JavaScript Bindings**: Built with Emscripten, compiling C++ to WebAssembly (see `tsds/`)

## Features
Expand Down Expand Up @@ -38,12 +38,6 @@ The Python package wraps the C++ core via pybind11.
pip install apyds
```

Then import as `pyds`:

```python
import pyds
```

Requires Python 3.10-3.14.

### C++ (Core Library)
Expand Down Expand Up @@ -102,10 +96,10 @@ while (true) {
### Python Example

```python
import pyds
import apyds

# Create a search engine
search = pyds.Search(1000, 10000)
search = apyds.Search(1000, 10000)

# Modus ponens: P -> Q, P |- Q
search.add("(`P -> `Q) `P `Q")
Expand All @@ -120,7 +114,7 @@ search.add("(((! `p) -> (! `q)) -> (`q -> `p))")
search.add("(! (! X))")

# Target: X (double negation elimination)
target = pyds.Rule("X")
target = apyds.Rule("X")

# Execute search until target is found
while True:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions examples/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import time
import pyds
import apyds


def main():
temp_data_size = 1000
temp_text_size = 1000
single_result_size = 10000

pyds.buffer_size(temp_text_size)
search = pyds.Search(temp_data_size, single_result_size)
apyds.buffer_size(temp_text_size)
search = apyds.Search(temp_data_size, single_result_size)

# P -> Q, P |- Q
search.add("(`P -> `Q) `P `Q")
Expand All @@ -22,12 +22,12 @@ def main():
# premise
search.add("(! (! X))")

target = pyds.Rule("X")
target = apyds.Rule("X")

while True:
success = False

def callback(candidate: pyds.Rule) -> bool:
def callback(candidate: apyds.Rule) -> bool:
if candidate == target:
print("Found!")
print(candidate)
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ license = "GPL-3.0-or-later"
Repository = "https://github.com/USTC-KnowledgeComputingLab/ds.git"

[tool.setuptools_scm]
version_file = "pyds/_version.py"
version_file = "apyds/_version.py"
version_scheme = "no-guess-dev"
fallback_version = "0.0.0"

[tool.scikit-build]
wheel.packages = ["pyds"]
wheel.exclude = [".gitignore", "ds.cc"]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
build.verbose = true

Expand Down
36 changes: 18 additions & 18 deletions tests/test_item.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import pytest
import copy
import pyds
import apyds


@pytest.fixture
def i() -> pyds.Item:
return pyds.Item("item")
def i() -> apyds.Item:
return apyds.Item("item")


def test_str(i: pyds.Item) -> None:
def test_str(i: apyds.Item) -> None:
assert str(i) == "item"

with pyds.scoped_buffer_size(4):
with apyds.scoped_buffer_size(4):
with pytest.raises(ValueError):
str(i)


def test_repr(i: pyds.Item) -> None:
def test_repr(i: apyds.Item) -> None:
assert repr(i) == "Item[item]"


def test_copy_hash_and_equality(i: pyds.Item) -> None:
def test_copy_hash_and_equality(i: apyds.Item) -> None:
other = copy.copy(i)
assert other == i
assert hash(other) == hash(i)
assert 1 != i


def test_create_from_same(i: pyds.Item) -> None:
item = pyds.Item(i)
def test_create_from_same(i: apyds.Item) -> None:
item = apyds.Item(i)
assert str(item) == "item"

with pytest.raises(ValueError):
item = pyds.Item(i, 100)
item = apyds.Item(i, 100)


def test_create_from_base(i: pyds.Item) -> None:
item = pyds.Item(i.value)
def test_create_from_base(i: apyds.Item) -> None:
item = apyds.Item(i.value)
assert str(item) == "item"


def test_create_from_text() -> None:
item = pyds.Item("item")
item = apyds.Item("item")
assert str(item) == "item"

# item never fails


def test_create_from_bytes(i: pyds.Item) -> None:
item = pyds.Item(i.data())
def test_create_from_bytes(i: apyds.Item) -> None:
item = apyds.Item(i.data())
assert str(item) == "item"

with pytest.raises(ValueError):
item = pyds.Item(i.data(), 100)
item = apyds.Item(i.data(), 100)


def test_create_fail() -> None:
with pytest.raises(TypeError):
item = pyds.Item(100)
item = apyds.Item(100)


def test_name(i: pyds.Item) -> None:
def test_name(i: apyds.Item) -> None:
assert str(i.name) == "item"
34 changes: 17 additions & 17 deletions tests/test_list.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
import pytest
import copy
import pyds
import apyds


@pytest.fixture
def l() -> pyds.List:
return pyds.List("(a b c)")
def l() -> apyds.List:
return apyds.List("(a b c)")


def test_str(l: pyds.List) -> None:
def test_str(l: apyds.List) -> None:
assert str(l) == "(a b c)"

with pyds.scoped_buffer_size(4):
with apyds.scoped_buffer_size(4):
with pytest.raises(ValueError):
str(l)


def test_repr(l: pyds.List) -> None:
def test_repr(l: apyds.List) -> None:
assert repr(l) == "List[(a b c)]"


def test_copy_hash_and_equality(l: pyds.List) -> None:
def test_copy_hash_and_equality(l: apyds.List) -> None:
other = copy.copy(l)
assert other == l
assert hash(other) == hash(l)
assert 1 != l


def test_create_from_same(l: pyds.List) -> None:
list = pyds.List(l)
def test_create_from_same(l: apyds.List) -> None:
list = apyds.List(l)
assert str(list) == "(a b c)"

with pytest.raises(ValueError):
list = pyds.List(l, 100)
list = apyds.List(l, 100)


def test_create_from_base(l: pyds.List) -> None:
list = pyds.List(l.value)
def test_create_from_base(l: apyds.List) -> None:
list = apyds.List(l.value)
assert str(list) == "(a b c)"


def test_create_from_text() -> None:
list = pyds.List("(a b c)")
list = apyds.List("(a b c)")
assert str(list) == "(a b c)"

# list never fails


def test_create_from_bytes(l: pyds.List) -> None:
list = pyds.List(l.data())
def test_create_from_bytes(l: apyds.List) -> None:
list = apyds.List(l.data())
assert str(list) == "(a b c)"

with pytest.raises(ValueError):
list = pyds.List(l.data(), 100)
list = apyds.List(l.data(), 100)


def test_create_fail() -> None:
with pytest.raises(TypeError):
list = pyds.List(100)
list = apyds.List(100)


def test_len(l) -> None:
Expand Down
Loading