snowflakes work except define

This commit is contained in:
2025-10-11 15:04:00 -06:00
parent 25bcfda65c
commit a942d79869
4 changed files with 71 additions and 8 deletions
+56 -1
View File
@@ -32,7 +32,62 @@ default() ->
default_snowflakes() ->
#{<<"and">> => fun wfc:mul/1,
<<"xor">> => fun wfc:add/1}.
<<"xor">> => fun wfc:add/1,
<<"ior">> =>
fun IOR([S1 | Rest]) ->
case IOR(Rest) of
{ok, S2} -> {ok, sf_ior(S1, S2)};
Error -> Error
end;
IOR([]) ->
{ok, wfc:one()}
end,
<<"not">> =>
fun ([S]) -> {ok, sf_not(S)};
(Bad) -> {error, wfc_utils:str("not/1: wrong number of arguments: ~p", [Bad])}
end,
<<"implies">> =>
fun ([A, B]) -> {ok, sf_implies(A, B)};
(Bad) -> {error, wfc_utils:str("implies/2: wrong number of arguments: ~p", [Bad])}
end,
<<"impliedby">> =>
fun ([A, B]) -> {ok, sf_impliedby(A, B)};
(Bad) -> {error, wfc_utils:str("impliedby/2: wrong number of arguments: ~p", [Bad])}
end,
<<"iff">> =>
fun ([A, B]) -> {ok, sf_iff(A, B)};
(Bad) -> {error, wfc_utils:str("iff/2: wrong number of arguments: ~p", [Bad])}
end
}.
sf_ior(A, B) ->
wfc_sftt:appl_ttf(fun ttf_ior/2, [A, B]).
sf_not(A) ->
{ok, Result} = wfc:add([wfc_sentence:one(), A]),
Result.
sf_implies(A, B) ->
wfc_sftt:appl_ttf(fun ttf_implies/2, [A, B]).
sf_impliedby(A, B) ->
sf_implies(B, A).
sf_iff(A, B) ->
{ok, Result} = wfc:mul([sf_implies(A, B), sf_impliedby(A, B)]),
Result.
ttf_ior(0, 0) -> 0;
ttf_ior(1, 0) -> 1;
ttf_ior(0, 1) -> 1;
ttf_ior(1, 1) -> 1.
ttf_implies(0, 0) -> 1;
ttf_implies(1, 0) -> 0;
ttf_implies(0, 1) -> 1;
ttf_implies(1, 1) -> 1.
define(Pat, Sentence, Ctx = #ctx{patterns = OldPatterns}) ->
NewPatterns = maps:put(Pat, Sentence, OldPatterns),