This project is an implementation of a library for mathematical and logical operations using combinatory logic. It provides a set of templates and utilities for constructing complex functions using recursive, combinatorial, and functional programming principles.
- Combinators: Implements standard combinators such as
Z,N,S,U, andRfor building mathematical logic. - Recursive Formulas: Provides recursive definitions for arithmetic operations like addition, subtraction, multiplication, division, and modulus.
- Fast Arithmetic Operations: Includes optimized (fast) versions of operations for improved runtime performance of more complex operations.
- Boolean Logic: Constructs logical operations such as cast to boolean, negation, boolean folds, and all type of comparisons.
- Prime Number Utilities:
- Check if a number is prime.
- Count primes.
- Retrieve the nth prime.
- Stack Implementation:
- Create stacks.
- Append elements.
- Peek at the top element.
- Pop elements.
- Check if the stack is empty.
Natural: A type alias forint, representing natural numbers.
Z: Always returns0.N: Increments a value by1.U<K, N>: Projection combinator for selecting the K-th argument from N arguments.S<G, Fs...>: Super combinator for applying functions in sequence.R<F, G>: Recursive combinator for defining functions with base and recursive cases.
- Arithmetic:
add: Addition.sub: Subtraction.mul: Multiplication.power: Exponentiation.
- Comparisons:
eq: Equality.leq: Less than or equal.geq: Greater than or equal.greater: Greater than.less: Less than.
- Division and Modulus:
divide: Integer division.mod: Modulus.
return_yesandreturn_no: Boolean constants.negate: Logical NOT.or_foldandand_fold: Logical OR and AND.
is_complex: Check if a number is complex.is_prime: Check if a number is prime.prime_count: Count primes up to a given number.get_prime_by_index: Get the nth prime number.
create_stack: Create an empty stack.append: Append elements to a stack.peek: Retrieve the top element of a stack.pop: Remove the top element of a stack.empty: Check if the stack is empty.
apply<add>(3, 4); // Returns 7apply<fast::is_prime>(7); // Returns trueNatural stack = apply<create_stack>();
stack = apply<append>(stack, 5);
Natural top = apply<peek>(stack); // Returns 5
stack = apply<pop>(stack);
bool stack_is_empty = apply<empty>(stack); // Returns trueClone the repository:
git clone git@github.com:IPodtsepko/logic-primitives.git
cd logic-primitivesInstall dependencies (e.g., GoogleTest as a submodule):
git submodule update --init --recursiveBuild the project using CMake:
mkdir build && cd build
cmake ..
makeRun tests:
./tests