# combine

Combine terms of 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)` rewrites 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 these 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, such as when b is an integer. Except for the third rule, this behavior of `combine` is the inverse functionality of `expand`. See Example 1.

 Note:   In certain cases, the MuPAD® internal simplifier automatically applies these rules in the reverse direction, and `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. For most of the rules, `combine` implements the inverse functionality of `expand`. This list shows the rewriting rules for the targets.

• `target = arctan`:

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

• `target = exp` (see Example 4):

• ,

• ,

where valid, reacting to properties.

• `target = int` (see Example 5):

• $a\int f\left(x\right)dx=\int af\left(x\right)dx.$

• $\int f\left(x\right)dx+\int g\left(x\right)dx=\int f\left(x\right)+g\left(x\right)dx.$

• ${\int }_{a}^{b}f\left(x\right)dx+{\int }_{a}^{b}g\left(x\right)dx={\int }_{a}^{b}f\left(x\right)+g\left(x\right)dx.$

• ${\int }_{a}^{b}f\left(x\right)dx+{\int }_{a}^{b}g\left(y\right)dy={\int }_{a}^{b}f\left(y\right)+g\left(y\right)dy.$

• ${\int }_{a}^{b}yf\left(x\right)dx+{\int }_{a}^{b}xg\left(y\right)dy={\int }_{a}^{b}yf\left(c\right)+xf\left(c\right)dc.$

• `target = gamma` (see Example 6):

• ,

• ,

• ,

• ,

• ,

for positive integers `n`.

• `target = ln` (see Example 7):

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):

• ,

where similar rules apply to sin(x) cos(y) and cos(x) cos(y):

• .

• `target = sinhcosh`:

• ,

where similar rules apply to sinh(x) cosh(y) and cosh(x) cosh(y).

• These rules apply 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 10.

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

## Environment Interactions

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

## Examples

### Example 1

Combine powers of the same base using `combine`.

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

`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

Rewrite products of sines and cosines as a sum of sines and cosines by setting the second argument to `sincos`:

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

Rewrite sums of sines and cosines by setting the second argument to `sincos`:

`combine(cos(a) + sin(a), sincos)`

Powers of sines or cosines with negative integer exponents are not rewritten:

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

### Example 4

Combine terms with the exponential function by specifying the second argument as `exp`.

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

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

### Example 5

Rewrite integrals by setting the second argument to `int`.

`combine(int(f(x),x)+int(g(x),x),int)`

`combine` combines a constant term with the integral.

`combine(a*int(f(x),x),int)`

`combine` combines integrals with the same limits.

`combine(int(f(x),x=a..b)+int(g(y),y=a..b),int)`

### Example 6

Combine calls to `gamma` by specifying the target as `gamma`. The `combine` function simplifies quotients of gammas to rational expressions.

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

### Example 7

This example shows the application of rules for the logarithm, and their 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 can apply.

Try to combine terms with calls to `ln` by specifying the target as `ln`.

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

`combine` does not combine the terms. Set the appropriate assumptions to combine the terms.

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

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

### Example 8

If a and b are integer or rational numbers and b is less than `1000`, `combine` returns logarithms.

`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 9

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 logarithms using the `IgnoreAnalyticConstraints` option.

`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 10

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

Rewrite `ln` and `sincos` terms in the expression.

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

### Example 11

`combine` maps to sets:

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

### Example 12

`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`, `int`, `gamma`, `ln`, `sincos`, or `sinhcosh`

## Options

 `IgnoreAnalyticConstraints` Apply 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. To extend functionality, define a new slot `target` of `combine`. To define a new slot, you need to first unprotect the identifier `combine` using unprotect. 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`.