> 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/expressionsum.md).

# ExpressionSum

```
                        class ExpressionSum(IExpression, IPlottable, IScatterable):
                    
```

The `ExpressionSum` class is responsible for handling with collection of expressions with different types ( even though all inherit from `IExpression`). Usually, you won't have to create the `ExpressionSum` object manually, as it will be generated automatically as a result of arithmetic operations between expressions of different types, if needed. This interface doesn't do some fancy stuff like advanced derivatives ( yet 😉 ), but it supports arithmetic operations, assigning values, plotting and scattering in 2D/3D, and more. It was developed to give an answer to edge cases that aren't included in the other classes. Quite interestingly, the `ExpressionSum` class actually also implements the `IExpression` interface, as it's an algebraic expression too. For instance:

```
                        expressions = 3*x + Ln(x) + Sin(x)
other_expressions = ExpressionSum([3*x, Ln(x), Sin(x)])
                        
                    
```

#### Addition

You can add `ExpressionSum` objects via the `+` operator.

```
                        x = Var('x')
expressions = Sin(x) + Ln(x)
other_expressions = Cos(x) + 2*x
print(expressions+other_expressions)
                    
```

#### Subtraction

You can subtract `ExpressionSum` objects via the `-` operator.

```
                        x = Var('x')
expressions = Sin(x) - Ln(x)
expressions -= Cos(x)
                    
```

#### Multiplication

You can multiply `ExpressionSum` objects via the `+` operators.

```
                        x, y = Var('x'), Var('y')
one = Sin(x) + Cos(x)
two = 3*x
print(one * two)
                    
```

#### Division

You can divide `ExpressionSum` objects via the `/` operator. For instance:

```
                        x = Var('x')
        print((x ** 2 + Sin(x)) / x)
                    
```

#### Power

You can raise the `ExpressionSum` object via the `**` operator. For example:

```
                        x = Var('x')
        print((x+Sin(x))**2)
                    
```

#### Assign values

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

You can try to evaluate the `ExpressionSum` object into `float` or `int` via the `try_evaluate()` method. For instance:

```
                        x = Var('x')
my_expressions = Sin(x) + Ln(x) + 4
my_expressions.assign(x=5)
                    
```

#### `to_lambda()`

You can generate a lambda expression from the `ExpressionSum` object via the `to_lambda()` method. For instance:

```
                        x = Var('x')
my_expressions = Sin(x) + Ln(x) + 4
print(my_expressions.to_lambda())
                    
```

#### Plot

You can plot an `ExpressionSum` object by using the `plot()` method. Here is the signature of the method:

```
                        def plot(self, start: float = -6, stop: float = 6, step: float = 0.3, ymin: float = -10,
        ymax: float = 10, title: str = None, formatText: bool = False,
        show_axis: bool = True, show: bool = True, fig=None, ax=None, values=None):
                    
```

Here is an example in 2D:

```
                        x = Var('x')
result = Sin(x)*Cos(Ln(x**3 - 6)) + Root(2*x-5)
result.plot()
                    
```

And here is an example in 3D:

```
                        x = Var('x')
y = Var('y')
result = Sin(x) + Cos(y) * Ln(x)
result.plot()
```

This is how it actually looks in matplotlib:

#### Scatter

You can also scatter an `ExpressionSum` object in 2D/3D via the `scatter()`method.

For instance:

```
                        x = Var('x')
y = Var('y')
result = Sin(x) + Cos(y) * Ln(x)
result.scatter()
                    
```
