Alloy analyser - only natural numbers - no integer set

44 Views Asked by At

Is there a way to declare the natural numbers as in Int in Alloy?

Currently I have util/integer and if I run run 6 Int I get:

integers={-32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}

what I want is util/naturalsand 3 Natural resulting in: naturals={0, 1, 2, 3, 4, 5, 6, 7, 8,...}

and not: natural/Natural={natural/Natural$0, natural/Natural$1, natural/Natural$2...}

1

There are 1 best solutions below

2
Loïc Gammaitoni On

If you want your numbers to be displayed so, without any signature name, you're IMHO pretty bound to use Int.

What you could do is thus to use a LET expression to define Natural as being the set of integer >=0.

I'd do it like this in Alloy 4.2


let Natural = {i : Int | i>=0}


sig A{
 a: Natural
}

run {} for 4 Int 

You should pay attention to enable "prevent overflow" in the Settings to be sure Natural doesn't contain negative number.