Accelerating the pace of engineering and science

# combine

Combine terms of the same algebraic structure

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```combine(f, <IgnoreAnalyticConstraints>)
combine(f, target, <IgnoreAnalyticConstraints>)
combine(f, [target1, target2, …], <IgnoreAnalyticConstraints>)
```

## Description

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.

combine(f) applies the following rewriting rules to products of powers occurring as subexpressions in an arithmetical expression f:

• ,

• ,

• .

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.

 Note:   Since the MuPAD® 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:

for x and y, such that |xy| < 1.

• target = exp (see Example 4):

• ,

• (where valid, reacting to properties).

• target = gamma (see Example 5):

• ,

• ,

• ,

• ,

• ,

for positive integers n

• target = ln (see Example 6):

The rules do not hold for arbitrary complex values of a, b. Specify appropriate properties for a or b to enable these rewriting rules. These rules are only applied to natural logarithms.

• target = sincos (see Example 3):

• ,

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:

• ,

• 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 9.

If f is an array, a list, or a set, combine is applied to all entries of f. See Example 10. If f is a polynomial or a series expansion, of type Series::Puiseux or Series::gseries, combine is applied to each coefficient. See Example 11.

## Environment Interactions

combine reacts to properties of identifiers appearing in the input.

## Examples

### Example 1

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

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

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

`combine(sqrt(2)*sqrt(3))`

### Example 2

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

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

### 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)`

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

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

### Example 4

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

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

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

### Example 5

With the second argument gamma, several calls to gamma are combined into one or even none. In particular, quotients of gammas are simplified to rational expressions:

`combine(gamma(n+3)*gamma(n+4/3) / gamma(n+1) / gamma(n+10/3), gamma)`

### Example 6

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. In the complex plane, the logarithm of a product does not always equal the sum of the logarithms of its factors. For real positive numbers, however, this rule may be applied:

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

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

`unassume(a): unassume(b):`

### Example 7

If a and b are integer or rational numbers and b is less than 1000, combine returns logarithms as follows:

`combine(3*ln(2), ln)`

If b is greater than or equal to 1000, combine returns results as :

`combine(1234*ln(5), ln)`

You can change the limit on the number b by using the Pref::autoExpansionLimit function. For example, when you use the default value N = 1000, combine returns the following result for this logarithm:

`combine(12*ln(12), ln)`

If you set the value of Pref::autoExpansionLimit to 10, combine returns this logarithm in its original form:

```Pref::autoExpansionLimit(10):
combine(12*ln(12), ln)```

For further computations, restore the default value of Pref::autoExpansionLimit:

`Pref::autoExpansionLimit(NIL):`

### Example 8

The IgnoreAnalyticConstraints option applies a set of purely algebraic simplifications including the equality of sum of logarithms and a logarithm of a product. Using the IgnoreAnalyticConstraints option, you get a simpler result, but one that might be incorrect for some of the values of a:

`combine(ln(a^5) - ln(a^4), ln, IgnoreAnalyticConstraints)`

Without using this option, you get a mathematically correct, but long result:

`combine(ln(a^5) - ln(a^4), ln)`

### Example 9

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])`

### Example 10

combine maps to sets:

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

### Example 11

combine maps to the coefficients of polynomials:

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

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

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

## Parameters

 f An arithmetical expression, an array, a list, a polynomial, or a set target One of the identifiers arctan, exp, gamma, ln, sincos, or sinhcosh

## Options

 IgnoreAnalyticConstraints This option applies purely algebraic simplifications to an expression. For more information see the options for the Simplify command.

## Return Values

Object of the same type as the input object f.

f

## Algorithms

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.