## `prog::find` -- find operands of expressions

#### Introduction

`prog::find(`ex, opr`)` returns all ``paths'' to the operand `opr` in the expression `ex`.

#### Call(s)

`prog::find(ex, opr)`

#### Parameters

`ex` | - | any MuPAD expression of type `DOM_EXPR`
`opr` | - | any MuPAD object

#### Returns

a list of numbers that determine the position of the given object inside of the given expression, or a sequence of lists, if the expression contains the object several times

#### Related Functions

`op`, `subsop`, `prog::exprtree`

#### Details

- `prog::find(`ex, obj`)` returns the position of the object `obj` in the expression `ex` as list. The list represents a ``path'' to the given object. With this list and the functions `op` and `subsop`, the object can directly be accessed.
- A path to an object is a list that contains integers `i1, ..., in`.

  The meaning is that the object is the `in`-th operand of the `(in - 1)`-st operand etc. of the `i1`-st operand of the expression `ex`.

  Stated differently, ``op(ex, [i1, ..., in])` = opr`.

- If the expression contains the object several times, a sequence of lists is returned.

#### Example 1

The identifier `a` is the first operand of the expression:

    >> prog::find(a + b + c, a)

                                        [1]

The number `1` occurs several times:

    >> prog::find(f(1, 1, 1), 1)

                                   [1], [2], [3]

#### Example 2

The identifier `a` is the first operand of the second operand of the first operand of the expression:

    >> prog::find(b*(a - 1) + b*(x - 1), a)

                                     [1, 2, 1]

The result of `prog::find` can be used to access the element with `op` or replace it with `subsop`:

    >> op(b*(a - 1) + b*(x - 1), [1, 2, 1]);
       subsop(b*(a - 1) + b*(x - 1), [1, 2, 1] = A)

                                         a

                               b (A - 1) + b (x - 1)

#### Background

- `prog::find` can be used to manipulate complex MuPAD objects with `subsop`.

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000