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