#12834: Modify subs so that it can accept multiple equations just like subs_expr
-------------------------------------+-------------------------------------
       Reporter:  JoalHeagney        |        Owner:  AlexGhitza
           Type:  enhancement        |       Status:  needs_info
       Priority:  minor              |    Milestone:  sage-6.4
      Component:  algebra            |   Resolution:
       Keywords:  subs algebra       |    Merged in:
  solving                            |    Reviewers:  Vincent Delecroix,
        Authors:  Michael Orlitzky,  |  Michael Orlitzky
  Vincent Delecroix                  |  Work issues:
Report Upstream:  N/A                |       Commit:
         Branch:  public/12384       |  045eebfd67858405c6665acfa1eea5f22ca7fc6f
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by {'newvalue': u'Michael Orlitzky, Vincent Delecroix', 'oldvalue': 
u'Michael Orlitzky'}):

 * reviewer:   => Vincent Delecroix, Michael Orlitzky
 * author:  Michael Orlitzky => Michael Orlitzky, Vincent Delecroix


Old description:

> This came up as a method of passing solutions from solve back into
> symbolic equations:
>
> {{{
>     f(x,y) = (1-x)^2 + 100*(y - x^2)^2
>     solution = solve([f.diff(ar) for ar in f.args()],f.args())[0]
>
> Gives me a list of solutions as:
>
>     [x=1;y=1]
>
> Is there any way to programatically substitute this list of equalities
> back into f?
> }}}
>
> The solution provided by Michael Orlitzky was
> {{{
> f(x,y).subs_expr(*solution)
> }}}
>
> Anycase, as noted by Michael, it would be nice if subs had the same
> behaviour:
> {{{
> Passing it one equation does work,
>
>   sage: f.subs(x == 1)
>   y + z + 1
>
> But more than one doesn't,
>
>   sage: f.subs(x == 1, y == 2)
>   ...
>   TypeError: substitute() takes at most 1 positional argument (2 given)
>
> I guess all that's missing is the ability to pass it multiple equations,
> like `subs_expr`. It would probably be easy to add that ability to
> `subs` if you want to create a ticket for something.
> }}}
>

> With the branch applied we have:
> {{{
> sage: f(x,y) = (1-x)^2 + 100*(y - x^2)^2
> sage: solution = solve([f.diff(ar) for ar in f.args()],f.args())
> sage: solution
> [[x == 1, y == 1]]
> sage: f.subs(solution[0])
> (x, y) |--> 0
> }}}

New description:

 In this ticket:
  - we make `expr.substitute(in_dict, **kwds)` as `expr.substitute(*args,
 **kwds)` and make it accepts any kind of arguments (symbolic equalities,
 dictionnaries or lists of them)
  - we deprecate `subs_expr` as a duplicate of `subs`

 This came up as a method of passing solutions from solve back into
 symbolic equations:

 {{{
     f(x,y) = (1-x)^2 + 100*(y - x^2)^2
     solution = solve([f.diff(ar) for ar in f.args()],f.args())[0]

 Gives me a list of solutions as:

     [x=1;y=1]

 Is there any way to programatically substitute this list of equalities
 back into f?
 }}}

 The solution provided by Michael Orlitzky was
 {{{
 f(x,y).subs_expr(*solution)
 }}}

 Anycase, as noted by Michael, it would be nice if subs had the same
 behaviour:
 {{{
 Passing it one equation does work,

   sage: f.subs(x == 1)
   y + z + 1

 But more than one doesn't,

   sage: f.subs(x == 1, y == 2)
   ...
   TypeError: substitute() takes at most 1 positional argument (2 given)

 I guess all that's missing is the ability to pass it multiple equations,
 like `subs_expr`. It would probably be easy to add that ability to
 `subs` if you want to create a ticket for something.
 }}}


 With the branch applied we have:
 {{{
 sage: f(x,y) = (1-x)^2 + 100*(y - x^2)^2
 sage: solution = solve([f.diff(ar) for ar in f.args()],f.args())
 sage: solution
 [[x == 1, y == 1]]
 sage: f.subs(solution[0])
 (x, y) |--> 0
 }}}

--

--
Ticket URL: <http://trac.sagemath.org/ticket/12834#comment:17>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to