aboutsummaryrefslogtreecommitdiffstats
path: root/src/generators.erl
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2025-11-24 22:40:22 -0300
committerGitHub <noreply@github.com>2025-11-24 22:40:22 -0300
commit62a017ce95ad2f6d9445b5b96f7aeba3f7c0d42f (patch)
treed67f93407ad049e4dc39fae1002146a8d03e4505 /src/generators.erl
parent09be36e5f5e2c5714b9542df8ccc363ab86ac6da (diff)
downloadSakura-62a017ce95ad2f6d9445b5b96f7aeba3f7c0d42f.tar.gz
Sakura-62a017ce95ad2f6d9445b5b96f7aeba3f7c0d42f.zip
Joins with provenance and lineage (#11)
Diffstat (limited to '')
-rw-r--r--src/generators.erl26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/generators.erl b/src/generators.erl
index 1dc363c..9e682d3 100644
--- a/src/generators.erl
+++ b/src/generators.erl
@@ -90,12 +90,27 @@ naturals(Constraints) ->
case extract_bounds(Constraints, value) of
{range, Min, Max} when Min >= 0 ->
make_range_generator(Min, Max, fun(N) -> #{value => N} end);
+ {range, Min, Max} when Min < 0, Max >= 0 ->
+ %% Negative min for naturals: adjust to start at 0
+ make_range_generator(0, Max, fun(N) -> #{value => N} end);
+ {range, _Min, Max} when Max < 0 ->
+ %% Entire range is negative: no naturals exist
+ fun(_) -> done end;
{gte, Min} when Min >= 0 ->
make_unbounded_generator(Min, fun(N) -> #{value => N} end);
+ {gte, Min} when Min < 0 ->
+ %% Negative lower bound for naturals: start at 0
+ make_unbounded_generator(0, fun(N) -> #{value => N} end);
{lte, Max} when Max >= 0 ->
make_range_generator(0, Max, fun(N) -> #{value => N} end);
+ {lte, Max} when Max < 0 ->
+ %% Upper bound is negative: no naturals exist
+ fun(_) -> done end;
{eq, Value} when Value >= 0 ->
make_singleton_generator(#{value => Value});
+ {eq, _Value} ->
+ %% Negative value: not a natural
+ fun(_) -> done end;
{in, List} ->
make_membership_generator(List, fun(N) -> #{value => N} end);
unbounded ->
@@ -474,14 +489,19 @@ make_plus_b_sum_gen([{B, Sum} | Rest]) ->
end.
%% Plus: only sum constrained - generate all non-negative pairs
-make_plus_sum_only_generator(SumValue) ->
+make_plus_sum_only_generator(SumValue) when SumValue >= 0 ->
Pairs = [{A, SumValue - A} || A <- lists:seq(0, SumValue)],
- make_plus_pairs_gen(Pairs).
+ make_plus_pairs_gen(Pairs);
+make_plus_sum_only_generator(_SumValue) ->
+ %% Negative sum: no non-negative pairs exist
+ fun(_) -> done end.
%% Plus: sum range constrained
make_plus_sum_range_generator(SMin, SMax) ->
+ %% Adjust range to non-negative values (naturals only)
+ AdjustedMin = max(0, SMin),
Pairs = [{A, B, S} ||
- S <- lists:seq(SMin, SMax),
+ S <- lists:seq(AdjustedMin, SMax),
A <- lists:seq(0, S),
B <- [S - A]],
make_plus_triple_gen(Pairs).