Previous Page Next Page Contents

subsop -- replace operands

Introduction

subsop(object, i = new) returns a copy of the object in which the i-th operand is replaced by the value new.

Call(s)

subsop(object, i1 = new1, i2 = new2... <, Unsimplified>)

Parameters

object - any MuPAD object
i1, i2... - integers or lists of integers
new1, new2... - arbitrary MuPAD objects

Options

Unsimplified - prevents simplification of the returned object after substitution

Returns

the input object with replaced operands or FAIL.

Overloadable:

object

Related Functions

extnops, extop, extsubsop, map, match, op, subs, subsex

Details

Option: Unsimplified

Example 1

We demonstrate how to replace one or more operands of an expression:

>> x := a + b: subsop(x, 2 = c)
                                   a + c
>> subsop(x, 1 = 2, 2 = c)
                                   c + 2

Also the 0-th operand of an expression (the ``operator'') can be replaced:

>> subsop(x, 0 = _mult)
                                    a b

The variable x itself was not affected by the substitutions:

>> x
                                   a + b
>> delete x:

Example 2

The following call specifies the suboperand c by a list of integers:

>> subsop([a, b, f(c)], [3, 1] = x)
                               [a, b, f(x)]

Example 3

This example demonstrates the effect of simplification. The following substitution replaces the first operand a by 2. The result simplifies to 3:

>> subsop(a + 1, 1 = 2)
                                     3

The option Unsimplified suppresses the simplification:

>> subsop(a + 1, 1 = 2, Unsimplified)
                                   2 + 1

The next call demonstrates the difference between simplification and evaluation. After substitution of PI for x, the identifier sin is not evaluated, i.e., the body of the system function sin is not executed:

>> subsop(sin(x),  1 = PI)
                                  sin(PI)

Evaluation of sin simplifies the result:

>> eval(%)
                                     0

Example 4

The order of operands may change by substitutions. Substituting z for the identifier b changes the internal order of the terms in x:

>> x := a + b + c: op(x)
                                  a, b, c
>> x := subsop(x, 2 = z): op(x)
                                  a, c, z
>> delete x:

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000