I’ve been trying to see if I can model the following puzzle, which does have at least one solution:
Find the coefficients a, b, and c for this equation such that x = 1, 2, 3, 4 results in a perfect square, but x = 5 is not perfect
f(x) = ax^2 + bx + c
There is a solution at a=46, b=-166, c=184 but I cannot get this model to find it
Is there anything obviously wrong, or is this simply not the type of problem for which Alloy is well-suited? (i.e., I have noted the section on integers in “Software Abstractions”, in which it says Alloy is not suitable for numerical problems)
abstract sig Coefficient {
value: Int
}
one sig A extends Coefficient {}
one sig B extends Coefficient {}
one sig C extends Coefficient {}
fun square (x: Int): Int {
mul[x, x]
}
fun equation (a: A, b: B, c: C, x: Int): Int {
plus[plus[mul[a.value, square[x]], mul[b.value, x]], c.value]
}
pred isPerfect [n: Int] {
one x: {i: Int} | square[x] = n
}
pred solver {
all a: A, b: B, c: C, x: {i: Int | i > 0 and i < 5} |
isPerfect[equation[a, b, c, x]]
and not isPerfect[equation[a, b, c, {5}]]
}
run solver