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

# Log

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

You can handle with logarithms via the `Log` class. You can apply arithmetic operations to the logarithms, and integrate them with other types of expressions. Each Log object represent an expression of the form $$nlog\_m(b)^k$$, where $$n$$ is the coefficient, $$m$$ is the base, $$b$$ is the internal expression and the power is $$k$$. The interface is designed to be quite flexible - for instance, you can represent logarithms of both numbers and algebraic expressions, including polynomials, trigonometric expressions, other logarithms, and even factorials. However, this interface still requires further polishing, and therefore further support will be added in next versions. As for now, it is considered an experimental feature.

#### Creating a new instance

Parameters

* `expression` - the internal expression inside the logarithm. You can enter here a string, an `IExpression` object, or a number. Read below about the different ways to use this parameter.
* `base`(optional). The type of the base is `float` or `int`. The default is \`10\`.
* `coefficient`(optional) - The coefficient of the expression. The type of the coefficient is `IExpression` and the default is `Mono(1)`

You can specify the internal expression in several ways:

1. Entering a string - You can enter a string that represents the logarithm. The string will be internally parsed and processed. However, you have to specify the type of the expression inside the logarithm. For example:

   ```python
   my_log = Log("x^2 + 6x + 8", base=2, dtype='poly')
   other_log = Log("sin(x) + cos(2x)", base=10, dtype='trigo')
                               
   ```
2. Entering an `IExpression` - you can also enter an algebraic expression. For instance:

   ```python
   x = Var('x')
   my_log = Log(3*x+5, base=2)
   other_log = Log(Sin(x), base=5)
                               
   ```
3. Entering a number - You can also enter an `int` or a `float`. For instance:

   ```python
   my_log = Log(100, base=10)
   print(my_log.try_evaluate())
                               
   ```

#### Addition

You can add `Log` objects, or other expressions via the `+` operator. When adding Log objects with the same base, the result will be evaluated via the formula \`log\_a(x) + log\_a(y) = log\_a(xy)\`. For example:

```python
x = Var('x')
my_log = Log(2*x)
other_log = Log(x)
print(my_log+other_log)
                    
```

#### Subtraction

You can subtract `Log` objects, or other algebraic expressions via the `-` operator. When subtracting Log objects with the same base, the result will be evaluated via the formula \`log\_a(x) - log\_a(y) = log\_a(\frac(x)(y))\`. For example:

```python
x = Var('x')
my_log = Log(x**2 + 6*x + 8)
other_log = Log(x+4)
print(my_log-other_log)
                    
```

#### Multiplication

You can multiply `Log` objects by other expressions via the `*` operator.

```python
n = Var('n')
my_log = Log(n+5, base=2)
my_log *= 3
my_log *= 2*n**2
print(my_log)
                    
```

#### Division

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

```python
x = Var('x')
my_log = 3 * Log(x) ** 2
other_log = 2*Log(x)
print(my_log / other_log)
                    
```

#### Power

You can raise a `Log` object by a power via the `**` operator. For example:

```python
x = Var('x')
print(Log(x) ** 2)
                    
```

#### Equating logarithms

You can check the equality of `Log` objects via the `==` operator. Currently, the algorithm does not cover every case, and therefore there might be some false negatives in abnormal cases.

```python
x = Var('x')
my_log = Log(2*x+10, base=2)
other_log = Log(2*x+10, base=2)
print(my_log == other_log)
                    
```

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

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

```python
x = Var('x')
my_log = Log(2*x, base=2)
print(my_log.try_evaluate())
my_log.assign(x=4)
print(my_log.try_evaluate())
                    
```
