Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Oct 9, 2023
1 parent 9c72eeb commit ecdafb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions library/clpz.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,7 @@
g(power_var_num(E, V, N)) => [p(pexp(V, N, R))],
m(A*B) => [p(ptimes(A, B, R))],
m(A-B) => [p(pplus(R,B,A))],
m(-A) => [p(ptimes(-1,A,R))],
m(-A) => [p(pplus(A,R,0))],
m(max(A,B)) => [g(A #=< #R), g(B #=< R), p(pmax(A, B, R))],
m(min(A,B)) => [g(A #>= #R), g(B #>= R), p(pmin(A, B, R))],
m(A mod B) => [g(B #\= 0), p(pmod(A, B, R))],
Expand Down Expand Up @@ -2647,6 +2647,7 @@

morphing(pplus).
morphing(ptimes).
morphing(pexp).

morphing_propagator(P0, P, Target) :-
P0 =.. [F|Args0],
Expand Down Expand Up @@ -2823,7 +2824,7 @@
m(var(X) #= var(Y)+var(Z)) => [p(pplus(Y,Z,X))],
m(var(X) #= var(Y)-var(Z)) => [p(pplus(X,Z,Y))],
m(var(X) #= var(Y)*var(Z)) => [p(ptimes(Y,Z,X))],
m(var(X) #= -var(Z)) => [p(ptimes(-1, Z, X))],
m(var(X) #= -var(Y)) => [p(pplus(X,Y,0))],
m_c(any(X) #= any(Y), left_right_linsum_const(X, Y, Cs, Vs, S)) =>
[g(scalar_product_(#=, Cs, Vs, S))],
m_c(var(X) #= abs(var(Y)) + any(V0), X == Y) => [d(V0,V),p(x_eq_abs_plus_v(X,V))],
Expand Down Expand Up @@ -3559,7 +3560,7 @@
m(A+B) => [d(D), p(pplus(A,B,R)), a(A,B,R)],
m(A*B) => [d(D), p(ptimes(A,B,R)), a(A,B,R)],
m(A-B) => [d(D), p(pplus(R,B,A)), a(A,B,R)],
m(-A) => [d(D), p(ptimes(-1,A,R)), a(R)],
m(-A) => [d(D), p(pplus(A,R,0)), a(R)],
m(max(A,B)) => [d(D), p(pgeq(R, A)), p(pgeq(R, B)), p(pmax(A,B,R)), a(A,B,R)],
m(min(A,B)) => [d(D), p(pgeq(A, R)), p(pgeq(B, R)), p(pmin(A,B,R)), a(A,B,R)],
m(abs(A)) => [d(D), g(#R#>=0), p(pabs(A, R)), a(A,R)],
Expand Down Expand Up @@ -4909,7 +4910,7 @@
)
; ( X == Y ->
kill(MState),
{ make_propagator(pexp(X,2,Z), Morph) },
{ make_propagator(pexp(X,2,Z,_), Morph) },
init_propagator_([X,Z], Morph)
; { fd_get(X, XD, XL, XU, XPs),
fd_get(Y, _, YL, YU, _),
Expand Down Expand Up @@ -5436,9 +5437,13 @@
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % Z = X ^ Y

run_propagator(pexp(X,Y,Z), MState) -->
run_propagator(pexp(X,Y,Z,Morph), MState) -->
( X == 1 -> kill(MState), Z = 1
; X == 0 -> kill(MState), queue_goal((Z in 0..1, Y #>= 0, Z #<==> Y #= 0))
; X == 0 ->
kill(MState),
queue_goal((Z in 0..1, Y #>= 0)),
{ make_propagator(reified_eq(1,Y,1,0,[],Z), Morph) },
init_propagator_([Y,Z], Morph)
; Y == 0 -> kill(MState), Z = 1
; Y == 1 -> kill(MState), Z = X
; nonvar(X) ->
Expand Down Expand Up @@ -5498,7 +5503,9 @@
)
; nonvar(Y), Y > 0 ->
( { even(Y) } ->
{ geq(Z, 0) }
{ fd_get(Z, ZD0, ZPs0),
domain_remove_smaller_than(ZD0, 0, ZDG0) },
fd_put(Z, ZDG0, ZPs0)
; true
),
( { fd_get(X, XD, XL, XU, _), fd_get(Z, ZD, ZL, ZU, ZPs) } ->
Expand Down Expand Up @@ -7803,7 +7810,7 @@
attribute_goal_(x_neq_y_plus_z(X,Y,Z)) --> [#X #\= #Y + #Z].
attribute_goal_(x_leq_y_plus_c(X,Y,C)) --> [#X #=< #Y + C].
attribute_goal_(ptzdiv(X,Y,Z)) --> [#X // #Y #= #Z].
attribute_goal_(pexp(X,Y,Z)) --> [#X ^ #Y #= #Z].
attribute_goal_(pexp(X,Y,Z,_)) --> [#X ^ #Y #= #Z].
attribute_goal_(psign(X,Y)) --> [#Y #= sign(#X)].
attribute_goal_(pabs(X,Y)) --> [#Y #= abs(#X)].
attribute_goal_(pmod(X,M,K)) --> [#X mod #M #= #K].
Expand Down
2 changes: 1 addition & 1 deletion src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ static bool are_slots_ok(const query *q, const frame *f)

if (is_empty(c))
return false;
else if (is_indirect(c) /*&& !is_evaluable(c->val_ptr)*/)
else if (is_indirect(c))
return false;
else if (is_cstring(c) && (c->flags & FLAG_CSTR_QUANTUM_ERASER))
return false;
Expand Down

0 comments on commit ecdafb7

Please sign in to comment.