elipl/lib/til/tdd.ex
2025-06-15 11:53:15 +02:00

52 lines
2.0 KiB
Elixir

defmodule Tdd do
@moduledoc """
Ternary decision diagram, used for representing set-theoritic types, akin to cduce.
There are 2 types of nodes:
- terminal nodes (true, false)
- variable nodes
variable nodes consist of:
- the variable being tested
- yes: id of the node if the result of the test is true
- no: id of the node if the result of the test is false
- dc: id of the node if the result of the test is irrelevant for the current operation
the TDD needs to be ordered and reduced (ROBDD)
- 'ordered' if different variables appear in the same order on all paths from the root.
- 'reduced' if the following two rules have been applied to its graph:
- Merge any isomorphic subgraphs.
- Eliminate any node whose two children are isomorphic.
Working notes:
- structure of the ordered variables:
Im thinking of structuring all possible types inside 1 TDD, in contrast to cduce, which uses a `desrc` structure that contains several TDDs (one for each domain, like ints, atoms, functions, etc.), and descr is a union between them.
For this, I need to come up with a variable structure that'll be ordered.
My set types will need to represent types like: atoms, strings, ints, maps, tuples, functions, kinds?
Moreso, those types themselves consist of smaller subsets of types like:
- int < 10
- int in [1, 2, 3]
- string > "prefix_"
- atom == false
- atom == false or atom == true or atom == nil
- map == %{"id" => string} and %{string => any | nil}
- etc.
Dont know how to represent them and make them ordered.
- node cache:
I don't yet know what it should contain, I suspect ids of nodes (TDDs) after reduction. This way a comparison between 2 types is just a pointer (id) check in the node cache. But not yet sure.
- reduction rules: not sure how to approach them
"""
def node(elem, yes, no, dc = _dont_care) do
end
def sum(one, two) do
end
def intersect(one, two) do
end
def negate(one, two) do
end
end