get_single_component_constraint(if_then_else-Type,Constraint) :-
unique_typed_id("i",boolean,TempCondition) ,
unique_typed_id("i",Type,TempIn1) ,
unique_typed_id("i",Type,TempIn2) ,
unique_typed_id("o",Type,TempOut) ,
set_component_id(if_then_else,UniqueComponent) ,
% set information of identifier nodes
add_texpr_infos(TempCondition,[synthesis(type,pred),synthesis(UniqueComponent,condition)],Condition) ,
add_texpr_infos(TempIn1,[synthesis(type,Type),synthesis(UniqueComponent,true_out)],In1) ,
add_texpr_infos(TempIn2,[synthesis(type,Type),synthesis(UniqueComponent,false_out)],In2) ,
add_texpr_infos(TempOut,[synthesis(type,Type),synthesis(UniqueComponent,output)],Out) ,
Node = if_then_else(Condition,In1,In2) ,
Constraint = b(equal(b(Node,Type,[]),Out),pred,[]).
get_single_component_constraint(Component,Constraint) :-
member(Component,[add,minus,multiplication,div,modulo,power_of]) , ! ,
unique_typed_id("i",integer,TempIn1) ,
unique_typed_id("i",integer,TempIn2) ,
unique_typed_id("o",integer,TempOut) ,
set_component_id(Component,UniqueComponent) ,
% set information of identifier nodes
add_texpr_infos(TempIn1,[synthesis(type,integer),synthesis(UniqueComponent,left_input)],In1) ,
add_texpr_infos(TempIn2,[synthesis(type,integer),synthesis(UniqueComponent,right_input)],In2) ,
add_texpr_infos(TempOut,[synthesis(type,integer),synthesis(UniqueComponent,output)],Out) ,
Node =.. [Component,In1,In2] ,
Constraint = b(equal(b(Node,integer,[]),Out),pred,[]).
get_single_component_constraint(skip-Type,b(equal(In,Out),pred,[])) :-
% We can't map inputs to outputs directly since input parameters are located in the first lines of the program
% whereat output parameter are located in the last lines, and thus, their locations can't match.
% Therefore, we use a simple wrapper allowing to connect input to output locations implicitly to skip values.
unique_typed_id("i",Type,TempIn) ,
unique_typed_id("o",Type,TempOut) ,
set_component_id(skip,ComponentName) ,
add_texpr_infos(TempIn,[synthesis(ComponentName,input),synthesis(type,Type)],In) ,
add_texpr_infos(TempOut,[synthesis(ComponentName,output),synthesis(type,Type)],Out).
get_single_component_constraint(Operator,Constraint) :-
member(Operator,[conjunct,disjunct,implication,equivalence]) , ! ,
unique_typed_id("i",boolean,TempIn1) ,
unique_typed_id("i",boolean,TempIn2) ,
unique_typed_id("o",boolean,TempOut) ,
set_component_id(Operator,ComponentName) ,
% set information of identifier nodes
add_texpr_infos(TempIn1,[synthesis(ComponentName,left_input),synthesis(type,pred)],In1) ,
add_texpr_infos(TempIn2,[synthesis(ComponentName,right_input),synthesis(type,pred)],In2) ,
add_texpr_infos(TempOut,[synthesis(ComponentName,output),synthesis(type,pred)],Out) ,
get_logical_constraint(Operator,In1,In2,Out,Truth,Falsity) ,
disjunct_predicates([Truth,Falsity],Constraint).
get_single_component_constraint(convert_bool,Constraint) :-
unique_typed_id("i",boolean,TempIn) ,
unique_typed_id("o",boolean,TempOut) ,
set_component_id(convert_bool,ComponentName) ,
% set information of identifier nodes
add_texpr_infos(TempIn,[synthesis(ComponentName,input),synthesis(type,pred)],In) ,
add_texpr_infos(TempOut,[synthesis(ComponentName,output),synthesis(type,boolean)],Out) ,
Constraint = b(equal(Out,In),pred,[]).
get_single_component_constraint(negation,Constraint) :- ! ,
unique_typed_id("i",boolean,TempIn) ,
unique_typed_id("o",boolean,TempOut) ,
set_component_id(negation,Negation) ,
% set information of identifier nodes
add_texpr_infos(TempIn,[synthesis(Negation,input),synthesis(type,pred)],In) ,
add_texpr_infos(TempOut,[synthesis(Negation,output),synthesis(type,pred)],Out) ,
Truth = b(conjunct(b(equal(In,b(boolean_false,boolean,[])),pred,[]),
b(equal(Out,b(boolean_true,boolean,[])),pred,[])),pred,[]) ,
Falsity = b(conjunct(b(equal(In,b(boolean_true,boolean,[])),pred,[]),
b(equal(Out,b(boolean_false,boolean,[])),pred,[])),pred,[]) ,
disjunct_predicates([Truth,Falsity],Constraint).
get_single_component_constraint(param_constant-global(_),b(truth,pred,[])). % so we skip here and set the constraint below
get_single_component_constraint(param_constant-set(global(IndependentType)),Constraint) :-
get_single_constant_or_set_operator_id(constant-global(IndependentType),TempOutSingle,ConstantSingle) ,
get_single_constant_or_set_operator_id(constant-set(global(IndependentType)),TempOutSet,ConstantSet) , ! ,
get_texpr_id(ConstantSingle,ConstantSingleName) ,
get_texpr_id(ConstantSet,ConstantSetName) ,
ParamId = b(identifier(ParamName),global(IndependentType),[synthesis(ConstantSingleName,output),synthesis(type,global(IndependentType)),synthesis(param_single,ParamName),synthesis(ConstantSetName,output),synthesis(type,set(global(IndependentType))),synthesis(param_set,ParamName)]) , % the same parameter identifier p for both constants c1 = p, c2 = {p}
% set information of identifier node
add_texpr_infos(TempOutSingle,[synthesis(ConstantSingleName,output),synthesis(type,global(IndependentType)),synthesis(param_single,ParamName)],OutSingle) ,
add_texpr_infos(TempOutSet,[synthesis(ConstantSetName,output),synthesis(type,set(global(IndependentType))),synthesis(param_set,ParamName)],OutSet) ,
atom_concat(p_,IndependentType,ParamName) ,
MachineSet = b(identifier(IndependentType),set(global(IndependentType)),[]) ,
Constraint = b(conjunct(b(conjunct(b(member(ParamId,MachineSet),pred,[]),b(equal(b(set_extension([ParamId]),set(global(IndependentType)),[]),OutSet),pred,[])),pred,[]),b(equal(ParamId,OutSingle),pred,[])),pred,[]).
get_single_component_constraint(constant-Type,Constraint) :-
get_single_constant_or_set_operator_id(constant-Type,TempOut,Constant) , ! ,
get_texpr_id(Constant,ConstantName) ,
% set information of identifier node
add_texpr_infos(TempOut,[synthesis(ConstantName,output),synthesis(type,Type)],Out) ,
Constraint = b(equal(Constant,Out),pred,[]).
get_single_component_constraint(Operator,Constraint) :-
get_single_constant_or_set_operator_id(Operator,TempOut,b(_,Type,_)) , ! ,
unique_typed_id("constant_set",Type,b(identifier(ConstantName),Type,Info)) ,
add_texpr_infos(TempOut,[synthesis(ConstantName,output),synthesis(type,Type)],Out) ,
% TODO: define as subset to avoid infinite sets (virtual timeout) ?
Constraint = b(equal(Out,b(identifier(ConstantName),Type,Info)),pred,[]).
get_single_component_constraint(Operator,Constraint) :-
member(Operator,[min,max]) ,
unique_typed_id("i",set(integer),TempIn) ,
unique_typed_id("o",integer,TempOut) ,
set_component_id(Operator,InternalName) ,
add_texpr_infos(TempIn,[synthesis(InternalName,input),synthesis(type,set(integer))],In) ,
add_texpr_infos(TempOut,[synthesis(InternalName,output),synthesis(type,integer)],Out) ,
Node =.. [Operator,In] ,
Constraint = b(equal(b(Node,integer,[]),Out),pred,[]).
get_single_component_constraint(card-SetType,Constraint) :-
unique_typed_id("i",SetType,TempIn) ,
unique_typed_id("o",integer,TempOut) ,
set_component_id(card,InternalName) ,
add_texpr_infos(TempIn,[synthesis(InternalName,input),synthesis(type,SetType)],In) ,
add_texpr_infos(TempOut,[synthesis(InternalName,output),synthesis(type,integer)],Out) ,
Constraint = b(equal(b(card(In),integer,[]),Out),pred,[]).
get_single_component_constraint(Operator-SetType,Constraint) :-
member(Operator,[pow_subset,pow_subset1,fin_subset,fin1_subset]) ,
unique_typed_id("i",SetType,TempIn) ,
unique_typed_id("o",set(SetType),TempOut) ,
set_component_id(Operator,NOperator) ,
add_texpr_infos(TempIn,[synthesis(NOperator,input),synthesis(type,SetType)],In) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output),synthesis(type,set(SetType))],Out) ,
Node =.. [Operator,In] ,
Constraint = b(equal(b(Node,set(SetType),[]),Out),pred,[]).
get_single_component_constraint(Operator-SetType,Constraint) :-
member(Operator,[seq,seq1,iseq]) ,
SetType = set(InnerType) ,
unique_typed_id("i",SetType,TempIn) ,
unique_typed_id("o",set(seq(InnerType)),TempOut) ,
set_component_id(Operator,InternalName) ,
add_texpr_infos(TempIn,[synthesis(InternalName,input),synthesis(type,SetType)],In) ,
add_texpr_infos(TempOut,[synthesis(InternalName,output),synthesis(type,set(seq(InnerType)))],Out) ,
Node =.. [Operator,In] ,
Constraint = b(equal(b(Node,set(seq(InnerType)),[]),Out),pred,[]).
get_single_component_constraint(perm-SeqType,b(equal(b(perm(In),OutputType,[]),Out),pred,[])) :-
get_perm_component_output_type(SeqType,OutputType) ,
unique_typed_id("i",SeqType,TempIn) ,
unique_typed_id("o",OutputType,TempOut) ,
set_component_id(perm,InternalName) ,
add_texpr_infos(TempIn,[synthesis(InternalName,input),synthesis(type,SeqType)],In) ,
add_texpr_infos(TempOut,[synthesis(InternalName,output),synthesis(type,OutputType)],Out).
get_single_component_constraint(interval,b(equal(b(interval(In1,In2),set(integer),[]),Out),pred,[])) :-
unique_typed_id("i",integer,TempIn1) ,
unique_typed_id("i",integer,TempIn2) ,
unique_typed_id("o",set(integer),TempOut) ,
set_component_id(interval,InternalName) ,
add_texpr_infos(TempIn1,[synthesis(InternalName,left_input),synthesis(type,integer)],In1) ,
add_texpr_infos(TempIn2,[synthesis(InternalName,right_input),synthesis(type,integer)],In2) ,
add_texpr_infos(TempOut,[synthesis(InternalName,output),synthesis(type,set(integer))],Out).
get_single_component_constraint(Operator-SetType,Constraint) :-
member(Operator,[closure,reflexive_closure]) ,
unique_typed_id("i",SetType,TempIn) ,
unique_typed_id("o",SetType,TempOut) ,
set_component_id(Operator,NOperator) ,
add_texpr_infos(TempIn,[synthesis(NOperator,input),synthesis(type,SetType)],In) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output),synthesis(type,SetType)],Out) ,
Node =.. [Operator,In] ,
Constraint = b(equal(b(Node,SetType,[]),Out),pred,[]).
get_single_component_constraint(Operator-SetType,Constraint) :-
member(Operator,[union,intersection,concat,insert_front,insert_tail,restrict_front,
restrict_tail,overwrite,set_subtraction,image,cartesian_product,
domain_restriction,domain_subtraction,range_restriction,range_subtraction]) ,
get_single_component_constraint_aux3(Operator-SetType,TempIn1,TempIn2,TempOut,Operator) ,
set_component_id(Operator,NOperator) ,
get_texpr_type(TempIn1,In1Type) ,
get_texpr_type(TempIn2,In2Type) ,
get_texpr_type(TempOut,OutType) ,
add_texpr_infos(TempIn1,[synthesis(NOperator,left_input),synthesis(type,In1Type)],In1) ,
add_texpr_infos(TempIn2,[synthesis(NOperator,right_input),synthesis(type,In2Type)],In2) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output),synthesis(type,OutType)],Out) ,
Node =.. [Operator,In1,In2] ,
Constraint = b(equal(b(Node,SetType,[]),Out),pred,[]).
get_single_component_constraint(Operator-SetType,Constraint) :-
member(Operator,[first,last,front,tail,general_union,general_intersection,reverse,range,domain]) ,
get_single_component_constraint_aux3(Operator-SetType,TempIn,_,TempOut,Operator) ,
set_component_id(Operator,NOperator) ,
get_texpr_type(TempIn,InType) ,
get_texpr_type(TempOut,OutType) ,
add_texpr_infos(TempIn,[synthesis(NOperator,input),synthesis(type,InType)],In) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output),synthesis(type,OutType)],Out) ,
Node =.. [Operator,In] ,
Constraint = b(equal(b(Node,SetType,[]),Out),pred,[]).
get_single_component_constraint(size-SetType,Constraint) :-
get_fn_types(SetType,integer,Type) ,
unique_typed_id("i",seq(Type),TempIn) ,
unique_typed_id("o",integer,TempOut) ,
set_component_id(size,NOperator) ,
add_texpr_infos(TempIn,[synthesis(NOperator,input),synthesis(type,seq(Type))],In) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output),synthesis(type,integer)],Out) ,
Constraint = b(equal(b(size(In),integer,[]),Out),pred,[]).
get_single_component_constraint(Operator,Truth) :-
get_single_component_constraint_aux2(Operator,TempIn1,TempIn2,TempOut,Op) ,
set_component_id(Op,NOperator) ,
add_texpr_infos(TempIn1,[synthesis(NOperator,left_input)],In1) ,
add_texpr_infos(TempIn2,[synthesis(NOperator,right_input)],In2) ,
add_texpr_infos(TempOut,[synthesis(NOperator,output)],Out) ,
TempTrueNode =.. [Op,In1,In2] ,
TrueNode = b(TempTrueNode,pred,[]) ,
BoolNodeTrue = b(equal(Out,b(boolean_true,boolean,[])),pred,[]) ,
create_equivalence(TrueNode,BoolNodeTrue,Truth).