alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'dom', UtilFunName),
!,
TCall = domain(BPOS,TRelation).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'ran', UtilFunName),
!,
TCall = range(BPOS,TRelation).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TDomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'total', UtilFunName),
!,
ID0 = identifier(BPOS,x),
LHS = member(BPOS,ID0,TDomain),
RHS = not_equal(BPOS,image(BPOS,TRelation,set_extension(BPOS,[ID0])),empty_set(BPOS)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TDomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'functional', UtilFunName),
!,
ID0 = identifier(BPOS,x),
LHS = member(BPOS,ID0,TDomain),
RHS = less_equal(BPOS,card(BPOS,image(BPOS,TRelation,set_extension(BPOS,[ID0]))),integer(BPOS,1)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TDomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'function', UtilFunName),
!,
ID0 = identifier(BPOS,x),
LHS = member(BPOS,ID0,TDomain),
RHS = equal(BPOS,card(BPOS,image(BPOS,TRelation,set_extension(BPOS,[ID0]))),integer(BPOS,1)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TCodomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'injective', UtilFunName),
!,
ID0 = identifier(BPOS,y),
LHS = member(BPOS,ID0,TCodomain),
RHS = less_equal(BPOS,card(BPOS,image(BPOS,reverse(BPOS,TRelation),set_extension(BPOS,[ID0]))),integer(BPOS,1)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TCodomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'surjective', UtilFunName),
!,
ID0 = identifier(BPOS,y),
LHS = member(BPOS,ID0,TCodomain),
RHS = not_equal(BPOS,image(BPOS,reverse(BPOS,TRelation),set_extension(BPOS,[ID0])),empty_set(BPOS)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation,TCodomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'bijective', UtilFunName),
!,
ID0 = identifier(BPOS,y),
LHS = member(BPOS,ID0,TCodomain),
RHS = equal(BPOS,card(BPOS,image(BPOS,reverse(BPOS,TRelation),set_extension(BPOS,[ID0]))),integer(BPOS,1)),
TCall = forall(BPOS,[ID0],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [Relation,Domain,Codomain], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'bijection', UtilFunName),
!,
atom_concat(RelationAlias, '\'function', Function),
atom_concat(RelationAlias, '\'bijective', Bijective),
alloy_to_b_relational_utility_function(Function, [Relation,Domain], BPOS, IsFunction),
alloy_to_b_relational_utility_function(Bijective, [Relation,Codomain], BPOS, IsBijective),
TCall = conjunct(BPOS,IsFunction,IsBijective).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation1,TRelation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'reflexive', UtilFunName),
!,
TCall = subset(BPOS,identity(BPOS,TRelation2),TRelation1).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'irreflexive', UtilFunName),
!,
TCall = equal(BPOS,intersection(BPOS,identity(BPOS,domain(BPOS,TRelation)),TRelation),empty_set(BPOS)).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'symmetric', UtilFunName),
!,
TCall = subset(BPOS,reverse(BPOS,TRelation),TRelation).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'antisymmetric', UtilFunName),
!,
Intersection = intersection(BPOS,reverse(BPOS,TRelation),TRelation),
TCall = subset(BPOS,Intersection,identity(BPOS,domain(BPOS,TRelation))).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'transitive', UtilFunName),
!,
TCall = subset(BPOS,composition(BPOS,TRelation,TRelation),TRelation).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation1,TRelation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'acyclic', UtilFunName),
!,
ID0 = identifier(BPOS,x),
TCall = forall(BPOS,[ID0],implication(BPOS,member(BPOS,ID0,TRelation2),
not_member(BPOS,couple(BPOS,ID0,ID0),closure(BPOS,TRelation1)))).
alloy_to_b_relational_utility_function(UtilFunName, [TRelation1,TRelation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'complete', UtilFunName),
!,
ID0 = identifier(BPOS,x),
ID1 = identifier(BPOS,y),
LHS = conjunct(BPOS,conjunct(BPOS,member(BPOS,ID0,TRelation2),member(BPOS,ID1,TRelation2)),not_equal(BPOS,ID0,ID1)),
RHS = member(BPOS,couple(BPOS,ID0,ID1),union(BPOS,TRelation1,reverse(BPOS,TRelation1))),
TCall = forall(BPOS,[ID0,ID1],implication(BPOS,LHS,RHS)).
alloy_to_b_relational_utility_function(UtilFunName, [Relation1,Relation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'preorder', UtilFunName),
!,
atom_concat(RelationAlias, '\'reflexive', Reflexive),
atom_concat(RelationAlias, '\'transitive', Transitive),
alloy_to_b_relational_utility_function(Reflexive, [Relation1,Relation2], BPOS, IsReflexive),
alloy_to_b_relational_utility_function(Transitive, [Relation1], BPOS, IsTransitive),
TCall = conjunct(BPOS,IsReflexive,IsTransitive).
alloy_to_b_relational_utility_function(UtilFunName, [Relation1,Relation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'equivalence', UtilFunName),
!,
atom_concat(RelationAlias, '\'preorder', Preorder),
atom_concat(RelationAlias, '\'symmetric', Symmetric),
alloy_to_b_relational_utility_function(Preorder, [Relation1,Relation2], BPOS, IsReflexive),
alloy_to_b_relational_utility_function(Symmetric, [Relation1], BPOS, IsTransitive),
TCall = conjunct(BPOS,IsReflexive,IsTransitive).
alloy_to_b_relational_utility_function(UtilFunName, [Relation1,Relation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'partialOrder', UtilFunName),
!,
atom_concat(RelationAlias, '\'preorder', Preorder),
atom_concat(RelationAlias, '\'antisymmetric', Antisymmetric),
alloy_to_b_relational_utility_function(Preorder, [Relation1,Relation2], BPOS, IsReflexive),
alloy_to_b_relational_utility_function(Antisymmetric, [Relation1], BPOS, IsTransitive),
TCall = conjunct(BPOS,IsReflexive,IsTransitive).
alloy_to_b_relational_utility_function(UtilFunName, [Relation1,Relation2], BPOS, TCall) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_concat(RelationAlias, '\'totalOrder', UtilFunName),
!,
atom_concat(RelationAlias, '\'partialOrder', Partialorder),
atom_concat(RelationAlias, '\'complete', Complete),
alloy_to_b_relational_utility_function(Partialorder, [Relation1,Relation2], BPOS, IsReflexive),
alloy_to_b_relational_utility_function(Complete, [Relation1,Relation2], BPOS, IsTransitive),
TCall = conjunct(BPOS,IsReflexive,IsTransitive).
alloy_to_b_relational_utility_function(FunName, _, BPOS, truth(BPOS)) :-
module_in_scope_but_root('util\'relation', RelationAlias),
atom_prefix(RelationAlias, FunName),
!,
add_error(alloy_to_b_relational_utility_function, 'Function from util/relation currently not supported', [], BPOS).