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

# TrigoExprs

\*experimental feature

```python
class TrigoExprs(ExpressionSum, IPlottable, IScatterable):
                    
```

The `TrigoExprs` class is used in order to represent a collection of `TrigoExpr` objects. For instance, the expression $$sin(x)\*cos(y) + tan(x)$$ is composed of 2 `TrigoExprs` objects.

#### Creating a new instance

You have several ways to create a new `TrigoExprs` object.

1. As a result of of an operation - you can actually generate `TrigoExprs`objects without explicitly calling the constructor, but by executing operations on `TrigoExpr` objects. For example:

   ```python
   x = Var('x')
   result = Sin(x) + Cos(x)
   print(type(result))
                               
   ```

   &#x20;                       &#x20;
2. Entering a string - you can choose to enter a string that represents the trigonometric expressions. You also need to enter the datatype of the expressions inside the trigonometric functions, so they will be processed accordingly. The default datatype is `'poly'`, and hence if the `dtype` parameter is not specified, the internal expressions will be processed as polynomials. It is possible that in next versions the strings will be classified and processed without any help from the user. Here are some examples for entering a string to the constructor:

   ```python
   print(TrigoExprs("3sin(x) - 2cos(x)"))
                           
   ```

#### Addition

You can add `TrigoExprs` objects via the `+` operator. For example:

```python
first = TrigoExprs("sin(x)^2 + 5cos(y) + 7")
second = TrigoExprs("4cos(y) + 5tan(2x)")
print(first+second)
                    
```

#### Subtraction

You can subtract `TrigoExprs` objects via the `-` operator. For example:

```python
first = TrigoExprs("3sin(x) + 4cos(x)")
second = TrigoExprs("2sin(x) - cos(x) + 4")
print(first-second)
                    
```

#### Multiplication

You can multiply `TrigoExprs` objects via the `*` operator. For example:

```python
x= Var('x')
first = Sin(x) + Cos(x)
second = Sin(x) - Cos(x)
print(first * second)
                    
```

#### Division

You can divide `TrigoExprs` objects via the `/` operator. For example:

```python
x = Var('x')
first = 3*Sin(x)**2 + 3*Cos(x)*Sin(x)
second = Sin(x)
print(first / second)
                    
```

#### Power

You can use the `**` operator for raising a trigonometric expression by a power. For instance:

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

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

You can try to evaluate the expression to `int` or `float` via the `try_evaluate()` method. If not possible, `None` will be returned. For example:

```python
import math
my_trigo = Sin(math.pi/2) + Cos(math.pi/2)
print(my_trigo.try_evaluate())
                    
```

#### Assign values

You can assign values to variables in the expression via the `assign()` method. For example:

```python
import math
x = Var('x')
my_trigo = Sin(x) + Cos(2*x)
print(my_trigo.assign(x=math.pi/2))
                    
```

#### `to_lambda()`

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

```python
import math
x, y = Var('x'), Var('y')
my_trigo = Sin(x)*Cos(y) + Sin(y)*Cos(x)
my_lambda = my_trigo.to_lambda()
print(my_lambda(math.pi/4, math.pi/3))
                    
```

```python
import math
x = Var('x')
my_trigo = Sin(x) + Cos(x)
my_lambda = my_trigo.to_lambda()
print(my_lambda(math.pi/2))
                    
```

#### Plot

You can plot the `TrigoExprs` object in 2D or 3D via the `plot()` method. For example:

```python
x = Var('x')
my_trigo= Sin(x) + Cos(x)
my_trigo.plot()
                    
```

```python
x = Var('x')
y = Var('y')
my_trigo = Sin(x) * Cos(y)
my_trigo.plot()         
                    
```

#### Scatter

You can scatter the `TrigoExprs` object in 2D or 3D via the `plot()` method. For example:

```python
x = Var('x')
my_trigo= Sin(x) + Cos(x)
my_trigo.scatter()
                    
```

```python
x = Var('x')
y = Var('y')
my_trigo = Sin(x) * Cos(y)
my_trigo.scatter()      
                    
```
