Opened 11 years ago

Closed 10 years ago

# solve with solution_dict=True doesn't always return a list

Reported by: Owned by: mhampton burcin major sage-4.7.2 symbolics solve, solution_dict kcrisman sage-4.7.2.alpha2 Leif Leonhardy Karl-Dieter Crisman N/A #8553

As pointed out in a post on sage-support:

```var('x')
g(x)=0
print solve(g(x)==0,x)
print solve(g(x)==0,x,solution_dict=True)
```

gives

```[x == r1]
{x: r1}
```

It should be `[{x: r1}]` to be consistent.

### comment:1 Changed 11 years ago by leif

Yep:

```       * ``solution_dict`` - bool (default: False); if True or non-zero,
return a list of dictionaries containing the solutions. If there
are no solutions, return an empty list (rather than a list
containing an empty dictionary). Likewise, if there's only a
single solution, return a list containing one dictionary with
that solution.
```

A doctest for a similar case got deleted by a reviewer, which still works though:

```sage: solve([x+y==6, x-y==4], x, y, solution_dict=-1)
[{y: 1, x: 5}]
```

And also the following works as expected:

```sage: solve([x==0],x,solution_dict=True)
[{x: 0}]
```

(Sage 4.7.1.{alpha2,rc0})

### comment:2 Changed 11 years ago by leif

• Authors set to Leif Leonhardy
• Status changed from new to needs_review

The attached patch fixes the inconsistency and adds a doctest for the case given.

I've removed superfluous parentheses (and white space) and also converted some tabs to spaces. (I thought the merge script would reject patches introducing new tabs after all got converted a while ago.)

### comment:3 follow-up: ↓ 4 Changed 11 years ago by leif

Hmmm,

```ans = [ {x: self.parent().var('r1')} ]
```

would perhaps have been a bit more readable...

### Changed 11 years ago by leif

Sage library patch. (Updated version.) Based on Sage 4.7.1.rc0.

### comment:4 in reply to: ↑ 3 Changed 11 years ago by leif

[...] would perhaps have been a bit more readable.

I've updated the patch to directly construct the solution dictionary.

(Leif doesn't work without coffee.)

Hey patchbot, apply: trac_11618-fix_solution_dict_for_infinitely_many_solutions.sagelib.patch!

### comment:5 Changed 11 years ago by leif

• Dependencies set to #8553

The dependency I've added is (more or less) just for the patchbot. (#8553 was merged into Sage 4.7.1.alpha2.)

### comment:6 Changed 11 years ago by kcrisman

Thanks for posting this patch - I'll try to take a look at this (relatively) soon, as it looks straightforward.

### comment:7 Changed 10 years ago by kcrisman

• Description modified (diff)
• Reviewers set to Karl-Dieter Crisman
• Status changed from needs_review to positive_review

Patch looks good. Performs as advertised. Thanks!

### comment:8 Changed 10 years ago by jdemeyer

• Merged in set to sage-4.7.2.alpha2
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.