create_new_local_state2(forall(IDs, LHS, _), true, State, LocalState, NewLocalState) :- !,
(get_any(IDs, LHS, State, LocalState, NewLocalState)
-> true /* there is a solution for LHS */
; /* Forall true because no solution for LHS */
get_any(IDs, b(truth,pred,[]), State, LocalState, NewLocalState)
).
create_new_local_state2(forall(IDs, LHS, RHS), false,State, LocalState, NewLocalState) :- !,
safe_create_texpr(negation(RHS), pred, NotRHS),
conjunct_predicates([LHS, NotRHS], Condition),
get_any(IDs, Condition, State, LocalState, NewLocalState).
create_new_local_state2(let_expression(Ids,AssignmentExprs,Expr), Value, State, LocalState, NewLocalState) :- !,
create_typed_id('$VALUE',EType,TID), get_texpr_type(Expr,EType),
construct_pred([TID],[Expr],[],Preds0),
construct_pred(Ids,AssignmentExprs,Preds0,Preds),
conjunct_predicates(Preds,NewPred),
EXISTS = exists([TID|Ids],NewPred), %translate:print_bexpr(b(EXISTS,pred,[])),nl,
(Value=unknown -> ExValue = undefined ; ExValue=true),
create_new_local_state2(EXISTS, ExValue, State, LocalState, NewLocalState).
create_new_local_state2(let_predicate(Ids,AssignmentExprs,Pred), Value, State, LocalState, NewLocalState) :-
construct_pred(Ids,AssignmentExprs,[Pred],Preds),
conjunct_predicates(Preds,NewPred),
EXISTS = exists(Ids,NewPred),
create_new_local_state2(EXISTS, Value, State, LocalState, NewLocalState).
create_new_local_state2(exists(IDs, LHS), true, State, LocalState, NewLocalState) :- !,
get_any(IDs, LHS, State, LocalState, NewLocalState).
create_new_local_state2(exists(IDs, LHS), Status, State, LocalState, NewLocalState) :-
(Status=false ; Status=undefined),!, % for Status=undefined get_any can fail but get_any_most_satisfier should always succeed
get_any_most_satisfier(IDs, LHS, State, LocalState, NewLocalState).
create_new_local_state2(X, undefined, State, LocalState, NewLocalState) :- !,
create_new_local_state2(X, true, State, LocalState, NewLocalState).
create_new_local_state2(X, x_both_true_and_not_true, State, LocalState, NewLocalState) :-
%print(x_both_true_and_not_true(X)),nl, % probably means a PROB BUG !
(X = forall(_,_,_) -> VAL=false ; VAL=true),
create_new_local_state2(X, VAL, State, LocalState, NewLocalState).
create_new_local_state2(comprehension_set(IDs, Body), Val, State, LocalState, NewLocalState) :- !,
% TODO: we could extract values from the context; e.g., if we have x:{y|Pred} we could use value assigned to x for y
% format(user_output,'Comprehension set ~w, Val=~w~n~n',[IDs,Val]),
(is_empty_set_value(Val) ->
get_any_most_satisfier(IDs, Body, State, LocalState, NewLocalState)
% we could have a symbolic value; which we do not know if it is empty or not; Body could also have a WD error
; get_any_if_possible(IDs, Body, State, LocalState, NewLocalState)).
create_new_local_state2(general_sum(IDs, CondPred, _Expr), _Val, State, LocalState, NewLocalState) :- !,
get_any_if_possible(IDs, CondPred, State, LocalState, NewLocalState).
create_new_local_state2(general_product(IDs, CondPred, _Expr), _Val, State, LocalState, NewLocalState) :- !,
get_any_if_possible(IDs, CondPred, State, LocalState, NewLocalState).
create_new_local_state2(quantified_union(IDs, CondPred, _Expr), _Val, State, LocalState, NewLocalState) :- !,
get_any_if_possible(IDs, CondPred, State, LocalState, NewLocalState).
create_new_local_state2(quantified_intersection(IDs, CondPred, _Expr), _Val, State, LocalState, NewLocalState) :- !,
get_any_if_possible(IDs, CondPred, State, LocalState, NewLocalState).
create_new_local_state2(Expr, Value, _State, _LocalState, _NewLocalState) :-
add_error(bvisual,'Uncovered Expr in create_new_local_state: ',Expr:Value),
fail.