## `combine` -- combine terms of the same algebraic structure

#### Introduction

`combine(`f`)` tries to rewrite products of powers in the expression `f` as a single power.

`combine(`f, target`)` combines several calls to the target function(s) in the expression `f` to a single call.

#### Call(s)

`combine(f)`
`combine(f, target)`
`combine(f, [target1, target2, ...])`

#### Parameters

`f` | - | an arithmetical expression, an array, a list, a polynomial, or a set
`target` | - | one of the identifiers `arctan`, `exp`, `ln`, sincos, or sinhcosh

#### Returns

an object of the same type as the input object `f`.

#### Side Effects

`combine` reacts to properties of identifiers appearing in the input.

### Overloadable:

`f`

#### Further Documentation

Chapter ``Manipulating Expressions'' of the Tutorial.

#### Related Functions

`denom`, `expand`, `factor`, `normal`, `numer`, `radsimp`, `rectform`, `rewrite`, `simplify`

#### Details

- `combine(`f`)` applies the following rewriting rules to products of powers occurring as subexpressions in an arithmetical expression `f`:
  - x^a*x^b = x^(a + b)
  - x^b*y^b = (x*y)^a
  - (x^a)^b=x^(a*b)
  The last two rules are only valid under certain additional restrictions, e.g., when b is an integer. Except for the third rule, this behavior of `combine` is the inverse functionality of `expand`. See example 1.

  Since MuPAD's internal simplifier automatically applies the above rules in the reverse direction in certain cases, `combine` sometimes has no effect. See example 2.

- `combine(`f, target`)` applies rewriting rules applicable to the target function(s) to an arithmetical expression `f`. Some of the rules are only valid under certain additional restrictions. With respect to most of the rules, `combine` implements the inverse functionality of `expand`. Here is a list of the rewriting rules for the various targets:

  `target = arctan`:

  - arctan(x) + arctan(y) = arctan((x + y)/(1 - x*y))

  `target = exp` (see example 4:)

  - exp(a)*exp(b) = exp(a + b)
  - exp(a)^b = exp(a*b)
  `target = ln` (see example 5:)
  - ln(a) + ln(b) = ln(a*b)
  - b*ln(a) = ln(a^b)
  `target = sincos` (see example 3):
  - sin(x)*sin(y) = cos(x - y)/2 - cos(x + y)/2
  - similar rules for sin(x)*cos(y) and cos(x)*cos(y)
  - the rules above are applied recursively to powers of sin and cos with positive integral exponents

  `target = sinhcosh`:

  - sinh(x)*sinh(y) = cosh(x + y)/2 - cosh(x - y)/2
  - similar rules for sinh(x)*cosh(y) and cosh(x)*cosh(y)
  - the rules above are applied recursively to powers of sinh and cosh with positive integral exponents
- `combine` works recursively on the subexpressions of `f`.
- If the second argument is a list of targets, then `combine` is applied to `f` subsequently for each of the targets in the list. See example 6.
- If `f` is array, a list, or a set, `combine` is applied to all entries of `f`; see example 7. If `f` is a polynomial or a series expansion, of type `Series::Puiseux` or `Series::gseries`, `combine` is applied to each coefficient; see example 8.

#### Example 1

Without a second argument, `combine` combines powers of the same base:

    >> combine(sin(x) + x*y*x^(exp(1)))

                                          exp(1) + 1
                              sin(x) + y x

Moreover, `combine` also combines powers with the same exponent in certain cases:

    >> combine(sqrt(2)*sqrt(3))

                                        1/2
                                       6

#### Example 2

In most cases, however, `combine` does not combine powers with the same exponent:

    >> combine(y^5*x^5)

                                        5  5
                                       x  y

#### Example 3

With the second argument sincos, `combine` rewrites products of sines and cosines as a sum of sines and cosines with more complicated arguments:

    >> combine(sin(a)*cos(b) + sin(b)^2, sincos)

                     sin(a + b)   cos(2 b)   sin(a - b)
                     ---------- - -------- + ---------- + 1/2
                         2           2           2

Note that powers of sines or cosines with negative integer exponents are not rewritten:

    >> combine(sin(b)^(-2), sincos)

                                         1
                                      -------
                                            2
                                      sin(b)

#### Example 4

With the second argument `exp`, the well-known rules for the exponential function are applied:

    >> combine(exp(3)*exp(2), exp)

                                      exp(5)

    >> combine(exp(a)^2, exp)

                                     exp(2 a)

#### Example 5

This example shows the application of rules for the logarithm, and at the same time the dependence on properties of the identifiers appearing in the input. The logarithm of a product does not always equal the sum of the logarithms of its factors; but for positive numbers, this rule may be applied:

    >> combine(ln(a)+ln(b), ln)

                                   ln(a) + ln(b)

    >> assume(a>0): assume(b>0):
       combine(ln(a)+ln(b), ln)

                                      ln(a b)

    >> unassume(a): unassume(b):

#### Example 6

The second argument may also be a list of targets. Then the rewriting rules for each of the targets in the list are applied:

    >> combine(ln(2)+ln(3)+sin(a)*cos(a), [ln, sincos])

                                         sin(2 a)
                                 ln(6) + --------
                                            2

#### Example 7

`combine` maps to sets:

    >> combine({sqrt(2)*sqrt(5), sqrt(2)*sqrt(11)})

                                     1/2    1/2
                                  {10   , 22   }

#### Example 8

`combine` maps to the coefficients of polynomials:

    >> combine(poly(sin(x)*cos(x)*y, [y]), sincos)

                                / / sin(2 x) \        \
                            poly| | -------- | y, [y] |
                                \ \    2     /        /

However, it does not touch the polynomial's indeterminates:

    >> combine(poly(sin(x)*cos(x)), sincos)

                       poly(sin(x) cos(x), [sin(x), cos(x)])

#### Background

- Advanced users can extend the functionality of `combine` by implementing additional rewriting rules for other target functions. This works by defining a new slot `"target"` of `combine`; you need to unprotect the identifier `combine` first in order to do that. Afterwards, the command `combine(`f, target`)` leads to the call `combine::target(f)` of the corresponding slot routine.
- By default, `combine` handles a subexpression `g(x1,x2,...)` of `f` by calling itself recursively for the operands `x1`, `x2`, etc. Users can change this behavior for their own mathematical function given by a function environment `g` by implementing a `"`combine" slot of `g`. To handle the subexpression `g(x1,x2,...)`, `combine` then calls the slot routine `g::combine` with the argument sequence `x1,x2,...` of `g`.

#### Changes

- The targets `_power` and `sqrt` are obsolete; their functionality is covered by a call to `combine` without a second argument.
- `combine` now reacts to properties of identifiers in the input.

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