0
votes

Can anyone tell me how to output a binary relation using a function in Alloy? For example, the student is linked with the teacher, and the student is also linked with the course. How can i take the student as input, then output the binary relation between the teacher and the course?

1

1 Answers

4
votes

Something like this?

sig Course {}
sig Teacher {}
sig Student {
  teacher: one Teacher, 
  course: some Course
}

fun binrel [s: Student]: Teacher -> Course {
  s.teacher -> s.course
}

run {
  some s: Student | (#binrel[s] > 2)
}

There are no special rules for returning a binary relation from a function. I assume your question was more about the relational product operator (->) which you need to use in this case to construct a binary relation from two scalars (or two unary relations)