## `sqrt` -- the square root function

#### Introduction

`sqrt``(z)` represents the square root of z.

#### Call(s)

`sqrt(z)`

#### Parameters

`z` | - | an arithmetical expression

#### Returns

an arithmetical expression.

### Overloadable:

`z`

#### Side Effects

When called with a floating point argument, the function is sensitive to the environment variable `DIGITS` which determines the numerical working precision.

#### Related Functions

`_power`, `isqrt`, `numlib::issqr`

#### Details

- x=sqrt(z) represents the solution of x^2=z that has a nonnegative real part. In particular, it represents the positive root for real positive z. For real negative z, it represents the complex root with positive imaginary part.
- A floating point result is returned for floating point arguments. Note that the branch cut is chosen as the negative real semi-axis. The values returned by `sqrt` jump when crossing this cut. Cf. example 2.
- Certain simplifications of the argument may occur. In particular, positive integer factors are extracted from some symbolic products. Cf. example 3.
- Note that sqrt(x^2) cannot be simplified to x for all complex numbers (e.g., sqrt(x^2)=-x for real x<0). Cf. example 4.
- Mathematically, `sqrt(z)` coincides with `z^(1/2)` = `_power``(z,1/2)`. However, `sqrt` provides more simplifications than `_power`. Cf. example 5.

#### Example 1

We demonstrate some calls with exact and symbolic input data:

    >> sqrt(2), sqrt(4), sqrt(36*7), sqrt(127)

                               1/2        1/2     1/2
                              2   , 2, 6 7   , 127

    >> sqrt(1/4), sqrt(1/2), sqrt(3/4), sqrt(25/36/7), sqrt(4/127)

                               1/2   1/2     1/2       1/2
                              2     3     5 7     2 127
                         1/2, ----, ----, ------, --------
                               2     2      42      127

    >> sqrt(-4), sqrt(-1/2), sqrt(1 + I)

                                        1/2         1/2
                            2 I, 1/2 I 2   , (1 + I)

    >> sqrt(x), sqrt(4*x^(4/7)), sqrt(4*x/3), sqrt(4*(x + I))

                      1/2     2/7  / 4 x \1/2             1/2
                     x   , 2 x   , | --- |   , (4 x + 4 I)
                                   \  3  /

#### Example 2

Floating point values are computed for floating point arguments:

    >> sqrt(1234.5), sqrt(-1234.5), sqrt(-2.0 + 3.0*I)

             35.13545218, 35.13545218 I, 0.8959774761 + 1.674149228 I

A jump occurs when crossing the negative real semi axis:

    >> sqrt(-4.0), sqrt(-4.0 + I/10^100), sqrt(-4.0 - I/10^100)

                     2.0 I, 2.5e-101 + 2.0 I, 2.5e-101 - 2.0 I

#### Example 3

The square root of symbolic products involving positive integer factors is simplified:

    >> sqrt(20*x*y*z)

                                          1/2  1/2
                                 2 (x y z)    5

#### Example 4

Square roots of squares are not simplified, unless the argument is real and its sign is known:

    >> sqrt(x^2*y^4)

                                      2  4 1/2
                                    (x  y )

    >> assume(x > 0): sqrt(x^2*y^4)

                                         4 1/2
                                     x (y )

    >> assume(x < 0): sqrt(x^2*y^4)

                                          4 1/2
                                    - x (y )

#### Example 5

`sqrt` provides more simplifications than the `_power` function:

    >> sqrt(4*x), (4*x)^(1/2) = _power(4*x, 1/2)

                               1/2       1/2        1/2
                            2 x   , (4 x)    = (4 x)

#### Changes

- no changes

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