Skip to content

subs_expr claims to take a dictionary, but doesn't #2404

@dandrake

Description

@dandrake

The docstring for subs_expr (in calculus.py) says:

Given a dictionary of key:value pairs, substitute all occurences of key for value in self.

...but the function does not accept a dictionary:

def subs_expr(self, *equations):

It'll take an arbitrary number of regular parameters (which must be SymbolicEquations), but not a dictionary.

I tried to modify the function to something like the following, but couldn't get it to work. Someone familiar with this code should have no problem implementing it correctly:

def subs_expr(self, *equations, **equationsdict):
  for x in equations:
    if not isinstance(x, SymbolicEquation):
      raise TypeError, "each expression must be an equation"

  R = self.parent()
  v = ','.join(['%s=%s'%(x.lhs()._maxima_init_(), x.rhs()._maxima_init_()) \
                    for x in equations])
  v = v + ','.join(['%s=%s' % (key._maxima_init_(), \
    equationsdict[key]._maxima_init_()) for key in equationsdict.keys()]
  return R(self._maxima_().subst(v))

Component: calculus

Keywords: substitution, subs_expr

Issue created by migration from https://trac.sagemath.org/ticket/2404

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions