elipl/lib/tilly/bdd/integer_bool_ops.ex
Kacper Marzecki 748f87636a checkpoint
checkpoint

failing test

after fixing tests

checkpoint

checkpoint

checkpoint

re-work

asd

checkpoint

checkpoint

checkpoint

mix proj

checkpoint mix

first parser impl

checkpoint

fix tests

re-org parser

checkpoint strings

fix multiline strings

tuples

checkpoint maps

checkpoint

checkpoint

checkpoint

checkpoint

fix weird eof expression parse error

checkpoint before typing

checkpoint

checpoint

checkpoint

checkpoint

checkpoint ids in primitive types

checkpoint

checkpoint

fix tests

initial annotation

checkpoint

checkpoint

checkpoint

union subtyping

conventions

refactor - split typer

typing tuples

checkpoint test refactor

checkpoint test refactor

parsing atoms

checkpoint atoms

wip lists

checkpoint typing lists

checkopint

checkpoint

wip fixing

correct list typing

map discussion

checkpoint map basic typing

fix tests checkpoint

checkpoint

checkpoint

checkpoint

fix condition typing

fix literal keys in map types

checkpoint union types

checkpoint union type

checkpoint row types discussion & bidirectional typecheck

checkpoint

basic lambdas

checkpoint lambdas typing application

wip function application

checkpoint

checkpoint

checkpoint cduce

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint
2025-06-13 23:48:07 +02:00

88 lines
2.3 KiB
Elixir

defmodule Tilly.BDD.IntegerBoolOps do
@moduledoc """
BDD Operations module for BDDs where elements are integers and leaves are booleans.
"""
@doc """
Compares two integer elements.
Returns `:lt`, `:eq`, or `:gt`.
"""
def compare_elements(elem1, elem2) when is_integer(elem1) and is_integer(elem2) do
cond do
elem1 < elem2 -> :lt
elem1 > elem2 -> :gt
true -> :eq
end
end
@doc """
Checks if two integer elements are equal.
"""
def equal_element?(elem1, elem2) when is_integer(elem1) and is_integer(elem2) do
elem1 == elem2
end
@doc """
Hashes an integer element.
"""
def hash_element(elem) when is_integer(elem) do
elem
end
@doc """
Returns the leaf value representing emptiness (false).
"""
def empty_leaf(), do: false
@doc """
Returns the leaf value representing universality (true).
"""
def any_leaf(), do: true
@doc """
Checks if the leaf value represents emptiness.
"""
def is_empty_leaf?(leaf_val) when is_boolean(leaf_val) do
leaf_val == false
end
@doc """
Computes the union of two boolean leaf values.
The `_typing_ctx` is ignored for this simple ops module.
"""
def union_leaves(_typing_ctx, leaf1, leaf2) when is_boolean(leaf1) and is_boolean(leaf2) do
leaf1 or leaf2
end
@doc """
Computes the intersection of two boolean leaf values.
The `_typing_ctx` is ignored for this simple ops module.
"""
def intersection_leaves(_typing_ctx, leaf1, leaf2)
when is_boolean(leaf1) and is_boolean(leaf2) do
leaf1 and leaf2
end
@doc """
Computes the negation of a boolean leaf value.
The `_typing_ctx` is ignored for this simple ops module.
"""
def negation_leaf(_typing_ctx, leaf) when is_boolean(leaf) do
not leaf
end
# def difference_leaves(_typing_ctx, leaf1, leaf2) when is_boolean(leaf1) and is_boolean(leaf2) do
# leaf1 and (not leaf2)
# end
@doc """
Tests a leaf value to determine if it represents an empty, full, or other set.
For boolean leaves with integers, this mirrors AtomBoolOps and StringBoolOps.
Returns `:empty`, `:full`, or `:other`.
"""
def test_leaf_value(true), do: :full
def test_leaf_value(false), do: :empty
# If integer BDDs could have non-boolean leaves that are not empty/full:
# def test_leaf_value(_other_leaf_value), do: :other
end