How can I stop Solve returning the value of a root encapsulated in a list?

I have a Solve similar to the following:

Solve[e^2 - c^2 == -15, {e, c}, Integers]
(* {{e -> -7, c -> -8}, {e -> -7, c -> 8}, {e -> -1, c -> -4},
{e -> -1, c -> 4}, {e -> 1, c -> -4}, {e -> 1, c -> 4},
{e -> 7, c -> -8}, {e -> 7, c -> 8}} *)


I need to add a region constraint to get the solution I want from the unconstrained list of solutions. I tried the following:

Solve[e^2 - c^2 == -15 ∧ {e, c} ∈ Interval[{0, 4}], {e, c}, Integers]
(* {{e -> {1}, c -> {4}}} *)


However, when I do this it wraps the variable's solutions in List. Is there a way to turn this off so I just get {{e -> 1, c -> 4}} or {e -> 1, c -> 4} as the result? The current result is a pain as I have to massage it for use with Replace. Also, can any explain why it is doing this when I constrain the variables?

• Whether constrained or not, Solve returns a list of solutions (and this is quite clear from the refguide page). To do otherwise would be a huge incompatibility in form of result. Extracting the first solution, say, is readily done with First or Part. Again, all well documented. Commented Nov 18, 2015 at 21:40
• @DanielLichtblau You've obviously not read the question. Commented Nov 18, 2015 at 22:05
• Actually I read it twice. But it did not improve with the second go round. Commented Nov 18, 2015 at 22:33
• e.g. the constrained one gives e -> {1} instead of e -> 1 as the unconstrained one gives. Commented Nov 18, 2015 at 22:35
• Ah. I should have read it a third time. Not sure what is going on here, it might be a bug. Commented Nov 18, 2015 at 22:41

Interval is a 1D region, so Element[e, Interval[...]] makes e a 1D vector not a scalar. If you want e to be a scalar use Element[{e}, Interval[...]].

In[1]:= Solve[e^2 - c^2 == -15 && Element[{e}|{c}, Interval[{0, 4}]], {e, c}, Integers]

Out[1]= {{e -> 1, c -> 4}}


Compare to:

In[2]:= Solve[Element[e, Disk[]], e, Integers]

Out[2]= {{e -> {-1, 0}}, {e -> {0, -1}}, {e -> {0, 0}}, {e -> {0, 1}},
>    {e -> {1, 0}}}

In[3]:= Solve[Element[{x, y}, Disk[]], {x, y}, Integers]

Out[3]= {{x -> -1, y -> 0}, {x -> 0, y -> -1}, {x -> 0, y -> 0},
>    {x -> 0, y -> 1}, {x -> 1, y -> 0}}

• This was my first thought. Thanks for the confirmation. Commented Nov 18, 2015 at 23:31

The Interval seems to be the problem, it returns an "Interval Object" and, rather than figure out what that is, just use the <= operator to state the conditions explicitly

Solve[
e^2 - c^2 == -15 && 0 <= e <= 4 && 0 <= c <= 4, {e, c}, Integers]
(* {{e -> 1, c -> 4}} *)


or

Solve[{e^2 - c^2 == -15, 0 <= e <= 4, 0 <= c <= 4}, {e,
c}, Integers]
(* {{e -> 1, c -> 4}} *)


The unwanted List also can be replaced after completing Solve.

Solve[e^2 - c^2 == -15 ∧ {e, c} ∈ Interval[{0, 4}], {e, c}, Integers]
/. Rule[z1_, {z2_}] -> Rule[z1, z2]


or

Replace[Solve[e^2 - c^2 == -15 ∧ {e, c} ∈ Interval[{0, 4}], {e, c}, Integers],
List[z_] -> z, -1]

(* {{e -> 1, c -> 4}} *)