# Rewriting an expression with different options: convert convertir =>

### 5.23.26 Rewriting an expression with different options: convert convertir =>

Xcas has many commands to convert expressions into different forms; the convert command (or its infixed version =>) is a different way to call many of these functions.

- convert takes two or more arguments:
  - expr, an expression.
  - option, an option specifying which rewrite rules to use. A third argument might be necessary for some options. Possible values of option are:
    - sin, to convert an expression like trigsin (see Section 5.23.23).
    - cos, to convert an expression like trigcos (see Section 5.23.24).
    - sincos, to convert an expression like sincos (see Section 5.23.13).
    - trig, to convert an expression like sincos (see Section 5.23.13).
    - tan, to convert an expression like halftan (see Section 5.23.19).
    - exp, to convert an expression like trig2exp (see Section 5.23.21).
    - ln, to convert an expression like trig2exp (see Section 5.23.21).
    - expln, to convert an expression like trig2exp (see Section 5.23.21).
    - string, to convert a expression into a string.
    - matrix, to convert a list of lists into a matrix.
    - array, to turn a table into an array (see Section 5.46.1).
    - polynom, to convert a series (see Section 5.36.2) into a polynomial by removing the remainder (see Section 5.27.25) or to convert a list representing a polynomial into a polynomial in internal sparse multivariate form (see Section 5.27.2 and Section 5.27.6).
    - parfrac (or partfrac or fullparfrac), to convert a rational function into its partial fraction decomposition (see Section 5.32.9).
    - interval, to convert an expression which evaluates to a number into an interval (see Section 5.38.8).
    - list (or no argument), to convert a polynomial in internal sparse multivariate format (see Section 5.27.2) into a list.
    - unit, a unit, to convert a unit object to a new compatible unit (see Section 11.1.4).
    The values of option that require a third argument:
    - contfrac, to convert a number into a continued fraction. (See Section 5.7.7.) The third argument will be the name of a variable to store the continued fraction into (which must be quoted the variable was assigned).
    - base, to convert a number into a different base (beginning with the units digit). If expr is a number, then the third argument will be base to convert to (see Section 5.4.2), if expr is a list of numbers, then the third argument will be the base to convert from (and expr will be a list of the digits in this base, starting with the units digit).
    Finally, if expr is an expression with units (see Section 11.1.1), then option can be new units to convert to (see Section 11.1.4).
- convert(expr,option[,extraop]) returns the expression with the requested conversions done.

#### Examples.

- Input:
  convert(1.2,confrac,’fc’)
  Output:

  ⎡ ⎣ | 1,5 | ⎤ ⎦

  and fc contains the continued fraction equal to 1.2.
- Input:
  convert(123,base,10)
  Output:

  ⎡ ⎣ | 3,2,1 | ⎤ ⎦

- Input:
  convert([3,2,1],base,10)
  Output:

  123

- Input:
  convert(1000_g,_kg)
  Output:

  1.0 kg