# Find integers $a, b, c, d, m, n, p$ so equation has six distinct solutions

By hand, I found that the equation $$\left| -2 x+5\right| +\left| -2 x+9\right| -x^2+7 x-16=0$$

has six solutions $$1, 2, 3, 4, 5, 6$$.

Another equations I want to find a set of integers $$a, b, c, d, m, n, p$$ so the following equation has six solutions $$1, 2, 3, 4, 7, 9$$:

$$\left|a\ x + b\right| +\left| c\ x + d\right| + m\ x^2 + n\ x + p=0,$$ where $$m \neq 0$$.

I tried

 f[x_] := Abs[a x + b] + Abs[c x + d] + m x^2 + n x + p

Reduce[
{
f == 0, f == 0, f == 0, f == 0, f == 0, f == 0,
-2 <= a <= -1, -2 <= b <= 3, -3 <= c <= 3, -3 <= d <= 10,
-2 <= m <= -1, -3 <= n <= 8, -20 <= p <= 1
},
{a, b, c, d, m, n, p}, Integers
]


My computer runs too long. How can I find integer numbers $$a, b, c, d, m, n, p$$ so that the equation has six distinct integer solutions?

• Why not use FindInstance instead of Reduce? I get {a -> -2, b -> 2, c -> 0, d -> 1, m -> 0, n -> -2, p -> 1} with FindInstance. – Carl Woll Jan 13 at 16:26
• You should make it an answer, @Carl – MikeY Jan 13 at 17:19
• @CarlWoll How about if m !=0? – minhthien_2016 Jan 13 at 23:37

Just use Solve instead of Reduce. We can eliminate $$p$$ by setting

f[x_] = Abs[a x + b] + Abs[c x + d] + m x^2 + n x;


and looking for $$f(1)=f(2)=f(3)=f(4)=f(7)=f(9)=-p$$ (which is necessarily integer when all parameters are integers). As suggested by @Akku14, enlarging the search space yields solutions for $$m\neq 0$$:

Solve[Join[{Equal @@ f /@ {1, 2, 3, 4, 7, 9},
m != 0,
a >= 0, c >= 0, b <= d},
Thread[-100 <= {a, b, c, d, n} <= 100]],
{a, b, c, d, m, n}, Integers]

(*    {{a -> 9, b -> -51, c -> 4, d -> -10, m -> -2, n -> 19}}    *)


I've added the condition $$b\le d$$ to eliminate some duplicate solutions, i.e., solutions that differ only by interchanging $$(a,b)$$ with $$(c,d)$$. Further, I've added the conditions $$a\ge0$$ and $$c\ge0$$ to eliminate duplicate solutions that differ only in the sign of $$(a,b)\leftrightarrow(-a,-b)$$ or that of $$(c,d)\leftrightarrow(-c,-d)$$.

Further enlarging the search space gives more solutions:

Solve[Join[{Equal @@ f /@ {1, 2, 3, 4, 7, 9},
m != 0,
a >= 0, c >= 0, b <= d},
Thread[-1000 <= {a, b, c, d, n} <= 1000]],
{a, b, c, d, m, n}, Integers]

(*    {{a -> 9, b -> -51, c -> 4, d -> -10, m -> -2, n -> 19},
{a -> 18, b -> -102, c -> 8, d -> -20, m -> -4, n -> 38},
{a -> 27, b -> -153, c -> 12, d -> -30, m -> -6, n -> 57},
{a -> 36, b -> -204, c -> 16, d -> -40, m -> -8, n -> 76},
{a -> 45, b -> -255, c -> 20, d -> -50, m -> -10, n -> 95},
{a -> 54, b -> -306, c -> 24, d -> -60, m -> -12, n -> 114},
{a -> 63, b -> -357, c -> 28, d -> -70, m -> -14, n -> 133},
{a -> 72, b -> -408, c -> 32, d -> -80, m -> -16, n -> 152},
{a -> 81, b -> -459, c -> 36, d -> -90, m -> -18, n -> 171},
{a -> 90, b -> -510, c -> 40, d -> -100, m -> -20, n -> 190},
{a -> 99, b -> -561, c -> 44, d -> -110, m -> -22, n -> 209},
{a -> 108, b -> -612, c -> 48, d -> -120, m -> -24, n -> 228},
{a -> 117, b -> -663, c -> 52, d -> -130, m -> -26, n -> 247},
{a -> 126, b -> -714, c -> 56, d -> -140, m -> -28, n -> 266},
{a -> 135, b -> -765, c -> 60, d -> -150, m -> -30, n -> 285},
{a -> 144, b -> -816, c -> 64, d -> -160, m -> -32, n -> 304},
{a -> 153, b -> -867, c -> 68, d -> -170, m -> -34, n -> 323},
{a -> 162, b -> -918, c -> 72, d -> -180, m -> -36, n -> 342},
{a -> 171, b -> -969, c -> 76, d -> -190, m -> -38, n -> 361}}    *)


which are all just integer multiples of the first solution.

• These are all solutions with m == 0 . You get solutions with nonzero m if you enlarge the parameter range: Solve[{f == 0, f == 0, f == 0, f == 0, f == 0, f == 0, -100 <= a <= 100, -100 <= b <= 100, -100 <= c <= 100, -100 <= d <= 100, -100 <= m <= 100, -100 <= n <= 100, -100 <= p <= 100, m != 0}, {a, b, c, d, m, n, p}, Integers] or even +- 1000. – Akku14 Jan 14 at 6:36
• Thanks @Akku14, I've updated the answer to reflect the updated question. – Roman Jan 14 at 7:34
• @Roman How can I find all equations has 6 integer solutions x from 1 to 10? – minhthien_2016 Jan 14 at 23:47
• @Roman I tried this code f[x_] = Abs[(a x + b) (c x + d)] + Abs[m x + n] + p x^2 + q x ; Solve[Join[{Equal @@ f /@ {1, 2, 3, 4, -5, -4, -3, -2}, p != 0, a >= 1, c >= 1, b <= d}, Thread[-500 <= {a, b, c, d, m, n, q} <= 500]], {a, b, c, d, m, n, p, q}, Integers] my computer runs too long, about 1 h. I can not get result. – minhthien_2016 Jan 15 at 4:09
• @minhthien_2016 it looks like a tough problem. I suppose that to some extent, integer problems are internally solved by enumeration (after domain restrictions), which tend to scale exponentially with the number of unknowns. – Roman Jan 15 at 8:00