Opened 2 years ago

Closed 21 months ago

#31452 closed defect (fixed)

Problem with solution_dict in solve

Reported by: gh-GMS103 Owned by:
Priority: major Milestone: sage-9.4
Component: algebra Keywords:
Cc: chapoton Merged in:
Authors: Travis Scrimshaw Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: 3c04187 (Commits, GitHub, GitLab) Commit: 3c041875405b308975c53bd7782a001cfec7d0aa
Dependencies: Stopgaps:

Status badges

Description

This is with

┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.2, Release Date: 2020-10-24                     │
│ Using Python 3.8.5. Type "help()" for help.                        │
└────────────────────────────────────────────────────────────────────┘

All of these work as expected:

sage: solve(x==3,x)                                                                                                                                            
sage: solve([x==3],x)                                                                                                                                          
sage: solve([x==3],[x])                                                                                                                                        
sage: solve(x==3,[x])                                                                                                                                          
sage: solve(x==3,x,solution_dict=True)                                                                                                                         
sage: solve([x==3],x,solution_dict=True)                                                                                                                       

So I wonder why these give an error:

sage: solve(x==3,[x],solution_dict=True)                                                                                                                     
sage: solve([x==3],[x],solution_dict=True)                                                                                                                     
[...]
TypeError: 'sage.symbolic.expression.Expression' object is not iterable

I am sure you have guessed: I am trying to do this in a program where the number of equations and the number of variables are variable.

Is it necessary to test for the case where there is only one variable? I hope not.

Change History (7)

comment:1 Changed 21 months ago by mkoeppe

Milestone: sage-9.3sage-9.4

Moving to 9.4, as 9.3 has been released.

comment:2 Changed 21 months ago by tscrim

Authors: Travis Scrimshaw
Branch: public/symbolics/solution_dict_list-31452
Commit: 3c041875405b308975c53bd7782a001cfec7d0aa
Status: newneeds_review

Simple corner case. I also fix this while I am at it:

sage: solve([x==3], x, solution_dict=True, algorithm='sympy')                                             
[x == 3]
sage: solve([x==3, y==1], [x,y], solution_dict=True, algorithm='sympy')  # good
[{x: 3, y: 1}]

New commits:

3c04187Fixing single function and variable with solution_dict solve() corner case.

comment:3 Changed 21 months ago by tscrim

Cc: chapoton added

Bot is morally green.

comment:4 Changed 21 months ago by chapoton

Reviewers: Frédéric Chapoton
Status: needs_reviewpositive_review

ok

comment:5 Changed 21 months ago by tscrim

Thank you!

comment:6 Changed 21 months ago by gh-GMS103

Wonderful!

Thanks to all of you!

comment:7 Changed 21 months ago by vbraun

Branch: public/symbolics/solution_dict_list-314523c041875405b308975c53bd7782a001cfec7d0aa
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.