snowflakes work except define
This commit is contained in:
parent
25bcfda65c
commit
a942d79869
@ -13,7 +13,8 @@
|
|||||||
reps/1,
|
reps/1,
|
||||||
reps/2,
|
reps/2,
|
||||||
add/1,
|
add/1,
|
||||||
mul/1
|
mul/1,
|
||||||
|
zero/0, one/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -219,7 +219,7 @@ dot({bm, {rc, 1, Same}, Bits1}, {bm, {rc, Same, 1}, Bits2}) ->
|
|||||||
parity(SummandBits).
|
parity(SummandBits).
|
||||||
|
|
||||||
|
|
||||||
-spec mand(bitstring(), bitstring()) -> bitstring().
|
-spec mand(bm(), bm()) -> bm().
|
||||||
% @doc bitwise-and two matrices of the same shape
|
% @doc bitwise-and two matrices of the same shape
|
||||||
|
|
||||||
mand({bm, Shape, Bits1}, {bm, Shape, Bits2}) ->
|
mand({bm, Shape, Bits1}, {bm, Shape, Bits2}) ->
|
||||||
|
|||||||
@ -32,7 +32,62 @@ default() ->
|
|||||||
|
|
||||||
default_snowflakes() ->
|
default_snowflakes() ->
|
||||||
#{<<"and">> => fun wfc:mul/1,
|
#{<<"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}) ->
|
define(Pat, Sentence, Ctx = #ctx{patterns = OldPatterns}) ->
|
||||||
NewPatterns = maps:put(Pat, Sentence, OldPatterns),
|
NewPatterns = maps:put(Pat, Sentence, OldPatterns),
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
arity/1,
|
arity/1,
|
||||||
tt/1, sf/1,
|
tt/1, sf/1,
|
||||||
sf_to_tt/1, tt_to_sf/1,
|
sf_to_tt/1, tt_to_sf/1,
|
||||||
eval/2,
|
appl_ttf/2, appl/2,
|
||||||
bfls/1,
|
bfls/1,
|
||||||
bfl/2
|
bfl/2
|
||||||
]).
|
]).
|
||||||
@ -73,11 +73,18 @@ sf(List) ->
|
|||||||
{sf, wfc_bm:col(List)}.
|
{sf, wfc_bm:col(List)}.
|
||||||
|
|
||||||
|
|
||||||
-spec eval(sf() | tt(), [wfc:sentence()]) -> wfc:sentence().
|
-spec appl_ttf(fun(), [wfc:sentence()]) -> wfc:sentence().
|
||||||
|
|
||||||
eval(TT = {tt, _}, Sentences) ->
|
appl_ttf(Fun, Sentences) ->
|
||||||
eval(tt_to_sf(TT), Sentences);
|
SF = ttfun_to_sf(Fun),
|
||||||
eval(SF = {sf, SFBM}, Sentences) ->
|
appl(SF, Sentences).
|
||||||
|
|
||||||
|
|
||||||
|
-spec appl(sf() | tt(), [wfc:sentence()]) -> wfc:sentence().
|
||||||
|
|
||||||
|
appl(TT = {tt, _}, Sentences) ->
|
||||||
|
appl(tt_to_sf(TT), Sentences);
|
||||||
|
appl(SF = {sf, SFBM}, Sentences) ->
|
||||||
Arity = arity(SF),
|
Arity = arity(SF),
|
||||||
Arity = length(Sentences),
|
Arity = length(Sentences),
|
||||||
% [0, 0, 0], [1, 0, 0], ...
|
% [0, 0, 0], [1, 0, 0], ...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user