> For the complete documentation index, see [llms.txt](https://jona-projects.gitbook.io/kiwicalc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jona-projects.gitbook.io/kiwicalc/symbolic-computation/root.md).

# Root

\*experimental feature

```python
 class Root(IExpression, IPlottable, IScatterable):      
```

You can create algebraic expressions with roots via the `Root` class. Each `Root` object represents an expression in the form $$a \sqrt\[n]{x}$$ , where $$a,n \in \mathbb{R}$$. This interface is still experimental, and it will be extended in the future for better support of arithmetic operations, derivatives, integrals, etc. However, it still offers a decent set of features for handling roots, such as assigning values, plotting, and scattering.

#### Properties

* `coefficient` - the coefficient of the expression. Either algebraic expression or number
* `inside` - the internal expression inside the root. Either algebraic expression or number
* `root` - The root. default is 2.
* `variables` - The variables that appear in the expression.

#### Creating a new instance

You can create a new instance of `Root` via the `__init__()` method. Here is the signature of the method:

```python
def __init__(self, inside: Union[IExpression, float, int], root_by: Union[IExpression, float, int] = 2
                 , coefficient: Union[int, float, IExpression] = Mono(1)):
                    
```

For example, this is how you can create the expression \`\root(3)(2x+5)\`:

```python
x = Var('x')
my_root = Root(2*x+5, 3)
print(my_root)       
```

You can also use the subclass `Sqrt` to create Square roots in a more explicit way:

```python
x = Var('x')
my_root = Sqrt(x**2 + 6*x + 8)  
```

This is equivalent to:

```python
x = Var('x')
my_root = Root(x**2 + 6*x + 8, 2)          
```

#### Addition

You can add `Root` objects via the `+` operator. For instance:

```python
print(Sqrt(2 * x) + Sqrt(2 * x))
print(Sqrt(4) + Sqrt(6))           
```

#### Subtraction

You can subtract `Root` objects via the `-` operator

```python
print(2*Sqrt(x) - Sqrt(x))
print(Sqrt(6) - Sqrt(4))        
```

#### Multiplication

You can multiply `Root` objects via the `*` operator

```python
print(2 * Sqrt(x) * Sqrt(x))
print(Sqrt(6) * Sqrt(4))          
```

#### Division

You can divide `Root` objects via the `/` operator

```python
print(2 * Sqrt(x) / Sqrt(x))
print(Sqrt(16) / Sqrt(4))   
```

#### Power

You can raise a root by a power (and even cancel the root) by the `**` operator. For instance:

```python
print(Sqrt(x) ** 2)
print(Sqrt(5) ** 2)  
```

#### Assign values

You can assign values to the expression via the `assign()` method. If you don't want to change the original expression, you can use the `when()` method. For example:

```python
my_root = Sqrt(x)
print(my_root.when(x=5))
my_root.assign(x=4)
print(my_root)
```

#### Evaluate to `int` or `float`

You can try to evaluate `Root` objects to `int` or `float` via the `try_evaluate()` method. For instance:

```python
print(Sqrt(25).try_evaluate())
print(Sqrt(x).try_evaluate())
```

#### Plotting

You can plot and scatter Root objects via the `plot()` and `scatter()` methods. For instance:

```
                        Sqrt(x).plot()
Sqrt(x).scatter()
                    
```

For more information about this method, view the relevant section in class `IExpression`.
