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
90 lines
2.4 KiB
Elixir
90 lines
2.4 KiB
Elixir
defmodule Tilly.BDD.AtomBoolOps do
|
|
@moduledoc """
|
|
BDD operations module for sets of atoms.
|
|
Elements are atoms, and leaf values are booleans.
|
|
"""
|
|
|
|
@doc """
|
|
Compares two atoms.
|
|
Returns `:lt`, `:eq`, or `:gt`.
|
|
"""
|
|
def compare_elements(elem1, elem2) when is_atom(elem1) and is_atom(elem2) do
|
|
cond do
|
|
elem1 < elem2 -> :lt
|
|
elem1 > elem2 -> :gt
|
|
true -> :eq
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Checks if two atoms are equal.
|
|
"""
|
|
def equal_element?(elem1, elem2) when is_atom(elem1) and is_atom(elem2) do
|
|
elem1 == elem2
|
|
end
|
|
|
|
@doc """
|
|
Hashes an atom.
|
|
"""
|
|
def hash_element(elem) when is_atom(elem) do
|
|
# erlang.phash2 is suitable for term hashing
|
|
:erlang.phash2(elem)
|
|
end
|
|
|
|
@doc """
|
|
The leaf value representing an empty set of atoms (false).
|
|
"""
|
|
def empty_leaf(), do: false
|
|
|
|
@doc """
|
|
The leaf value representing the universal set of atoms (true).
|
|
This is used if a BDD simplifies to a state where all atoms of this kind are included.
|
|
"""
|
|
def any_leaf(), do: true
|
|
|
|
@doc """
|
|
Checks if a leaf value represents an empty set.
|
|
"""
|
|
def is_empty_leaf?(leaf_val) when is_boolean(leaf_val) do
|
|
leaf_val == false
|
|
end
|
|
|
|
@doc """
|
|
Computes the union of two leaf values.
|
|
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
|
|
"""
|
|
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 leaf values.
|
|
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
|
|
"""
|
|
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 leaf value.
|
|
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
|
|
"""
|
|
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.
|
|
Returns `:empty`, `:full`, or `:other`.
|
|
"""
|
|
def test_leaf_value(true), do: :full
|
|
def test_leaf_value(false), do: :empty
|
|
# Add a clause for other types if atoms could have non-boolean leaf values
|
|
# def test_leaf_value(_other), do: :other
|
|
end
|