> 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/functions/getting-started.md).

# Getting Started

### Class `Function`

You can quickly declare mathematical functions, execute them, and plot them via the `Function` class. You can also find the roots of the function numerically and also its minimum and maximum points depending on the type of the function, Support for derivatives, partial derivatives, and integrals is supported or developed for certain types of functions.

#### Properties

* `function_string` - A string that represents the function. For instance, `"f(x) = x^2"`
* `function_signature` - The signature of a function is the function declaration on the `function_string` property. For instance, `"f(x)"`, `"g(x,y)"`.
* `function_expression` - A string that represents only the expression of the function; For instance, the expression of the function `"f(x) = x^2"`
* `lambda_expression` - A lambda expression that represents the function. If one cannot be generated, it will be set to `None`.
* `variables_dict` - A list of all of the variables\_dict that appear in the function. For instance, it will be `['x','y']` for the function `"f(x,y) = x+y"`.
* `num_of_variables` - the number of variables\_dict that appear in the function.
* `classification` - Experimental feature - classifying functions. The classification is presented via the class `Function.Classification`. Namely, the Classification class is nested within the Function class, and inherits from `Enum`.

  ```python
   class Classification(Enum):
      linear = 1,
      quadratic = 2,
      polynomial = 3,
      trigonometric = 4,
      logarithmic = 5,
      exponent = 6,
      constant = 7,
      command = 8,
      linear_several_parameters = 8,
      non_linear_several_parameters = 9,
      exponent_several_parameters = 10,
      predicate = 11
                              
  ```

#### Creating a new Function object

```python
# The __init__ method's signature
def __init__(self, func=None):
                    
```

There are several ways to create a new Function object:

1. **Entering a string in mathematical format**

   The string representation of the function must follow this syntax:

   ```
                                   "function_name(a,b,c...) = ......"
                               
   ```

   For example:

   ```python
   # Creating a new Function object, with a string in math syntax
   sine = Function("f(x)=sin(x)")
                               
   ```
2. **Entering a string in a lambda syntax**

   You can also define your function with a lambda-like syntax.\
   Either in a more pythonic syntax:

   ```python
   # Creating a Function object via a string in python-like lambda expression syntax.
   sine = Function("lambda x:sin(x)")
                               
   ```
3. **or in a more C# or Javascript like manner:**

   ```python
   sine = Function("x => sin(x)")
                               
   ```

   You can also enter strings that represent lambdas with multiple parameters, separated by commas.

   For instance, a function that takes three parameters, and returns their sum:

   ```python
   three_sum = Function("x, y, z => x + y + z")
                               
   ```
4. **Entering a Mono or Poly expression**

   You can also create a function by entering a monomial (Mono) and polynomial(Poly). These two classes are documented later in this documentation. For example:

   <pre class="language-python"><code class="lang-python"><strong>x = Var('x')
   </strong>func = Function(-x**2 + 6*x + 7)

                      
   </code></pre>

   Keep in mind that while this method is rather simple, it's a bit slower, since extra steps are being taken for the conversions.
5. **Entering a lambda expression**

   Entering a lambda expression as a parameter is not highly recommended, however, it will work rather fast if, and only if, you declare the lambda expression inside the constructor, and not in previous lines. For example:

   ```python
   from math import sin,pi
   sine = Function(lambda x:sin(x))
   print(sine(pi/2))

   # output:
   # 1.0

                               
   ```

#### Calling the function

You can call the function simply like you would do in mathematics, by writing its name and specifying all the parameters inside parentheses. Here's the signature of the call method behind the scenes:

```python
def __call__(self, *parameters):
```

**Parameters**

\*parameters - an unlimited number of parameters. these parameters will be assigned respectively to the Function's object variables\_dict. For example:

```python
parabola = Function("f(x)=x**2")
print(parabola(5))
```

Output:

```bash
25.0
                   
  
```

Here's some additional examples, that showcase the true flexible nature of the Function class:

```python
three_sum = Function("g(a,b,c)=a+b+c")
print(three_sum(6,5,4))
# output:
#15.0
```

```python
# Creating functions that return True or False
equality = Function("f(a,b) = a==b")
print(equality(5,5))
print(equality(4,6))

# output:
# True
# False
```

```python
from math import pi
trigo_op = Function("f(x) = -sin(x) + 2cos(2x)")
print(trigo_op(math.pi/2))
# output:
# -3.0
```

**Getting the variables that appear in the function**

functions can contain several variables, and sometimes it is necessary to find out what variables\_dict does a function contain. For that, you can either use the `variables`property, or the square brackets operator. If you choose to use the square brackets operator, you can enter an index to the function or use list slicing. If an index is given to the function the variable name (type str) in the specified index will be returned. In case of list slicing, a list of all function's variables\_dict between the specified indices will be returned. For example:

```python
# Retrieving the variables appearing in a function
three_sum = Function("g(a,b,c)=a+b+c")
print(three_sum.variables)
print(three_sum[0])
print(three_sum[1:3])
               
```
