Skip to content

Commit 1bc5ddc

Browse files
committed
add arithmetic.ISZERO term
1 parent 05180e8 commit 1bc5ddc

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

lambda_calculus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .terms import Variable, Abstraction, Application
66

7-
__version__ = "2.0.1"
7+
__version__ = "2.1.0"
88
__author__ = "Eric Niklas Wolf"
99
__email__ = "[email protected]"
1010
__all__ = (

lambda_calculus/terms/arithmetic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
"""Implementations of natural numbers and arithmetic operators"""
44

55
from . import Term, Variable, Abstraction, Application
6+
from .logic import TRUE, FALSE
67

78
__all__ = (
9+
"ISZERO",
810
"SUCCESSOR",
911
"PREDECESSOR",
1012
"ADD",
@@ -14,6 +16,8 @@
1416
"number"
1517
)
1618

19+
ISZERO = Variable("n").apply_to(FALSE.abstract("x"), TRUE).abstract("n")
20+
1721
SUCCESSOR = Abstraction.curried(
1822
("n", "f", "x"),
1923
Application(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "lambda_calculus"
3-
version = "2.0.1"
3+
version = "2.1.0"
44
description = "Implementation of the Lambda calculus"
55
requires-python = ">=3.10"
66
keywords = []

tests/terms/test_arithmetic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from unittest import TestCase
66
from lambda_calculus.visitors.normalisation import BetaNormalisingVisitor
7-
from lambda_calculus.terms import Application, arithmetic
7+
from lambda_calculus.terms import Application, arithmetic, logic
88

99

1010
class OrderingTest(TestCase):
@@ -16,6 +16,21 @@ def setUp(self) -> None:
1616
"""create a visitor"""
1717
self.visitor = BetaNormalisingVisitor()
1818

19+
def test_iszero(self) -> None:
20+
"""test iszero term"""
21+
self.assertEqual(
22+
self.visitor.skip_intermediate(
23+
arithmetic.ISZERO.apply_to(arithmetic.number(0))
24+
),
25+
logic.TRUE
26+
)
27+
self.assertEqual(
28+
self.visitor.skip_intermediate(
29+
arithmetic.ISZERO.apply_to(arithmetic.number(1))
30+
),
31+
logic.FALSE
32+
)
33+
1934
def test_successor(self) -> None:
2035
"""test successor term"""
2136
self.assertEqual(

0 commit comments

Comments
 (0)