Search code examples
modelingalloy

Adding elements of a set in Alloy


For the set time: {1,2,3,4}, how can we compute the sum of the elements in the set in Alloy? Is there a way to use Alloy's add function for sets?

pred addTime[time: set Time]{
    add[time] = 10
}

Solution

  • You can sum a set of Int with the sum operator

     let s = 1 + 2 + 3 | 6 = sum s
    

    However, if you use Time as in Jackson's book then you cannot add them since they are not Int's. So I am a bit confused what you want to model?