Spaces:
Sleeping
Sleeping
Download src/tools/math_tools.py from Thanos/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 4.23 kB
-
https://huggingface.co/spaces/Thanos/Final_Assignment_Template/resolve/main/src/tools/math_tools.py
- Command line
-
hf download hf://spaces/Thanos/Final_Assignment_Template/src/tools/math_tools.py
-
curl -L -o math_tools.py https://huggingface.co/spaces/Thanos/Final_Assignment_Template/resolve/main/src/tools/math_tools.py
4.23 kB
| import cmath | |
| from langchain_core.tools import tool | |
| def add(a: float | int, b: float | int) -> float | int: | |
| """Adds two numbers. | |
| Args: | |
| a (float | int): The first number. | |
| b (float | int): The second number. | |
| Returns: | |
| float | int: A number representing the result of the addition | |
| between a and b. | |
| """ | |
| return a + b | |
| def subtract(a: float | int, b: float | int) -> float | int: | |
| """Subtracts two numbers. | |
| Args: | |
| a (float | int): The first number (minuend). | |
| b (float | int): The second number (subtrahend). | |
| Returns: | |
| float | int: A number representing the result of substracting b from a. | |
| """ | |
| return a - b | |
| def multiply(a: float | int, b: float | int) -> float | int: | |
| """Multiplies two numbers. | |
| Args: | |
| a (float | int): The first number. | |
| b (float | int): The second number. | |
| Returns: | |
| float | int: A number representing the result of the multiplication | |
| between a and b. | |
| """ | |
| return a * b | |
| def divide(a: float | int, b: float | int) -> float | int: | |
| """Divides two numbers. | |
| This function divides `a` by `b`. If `b` is zero, then it raises | |
| a ValueError. | |
| Args: | |
| a (float | int): The first number (dividend). | |
| b (float | int): The second number (divisor). | |
| Returns: | |
| float | int: A number representing the result of dividing a by b. | |
| """ | |
| if b == 0: | |
| raise ValueError("Cannot divided by zero.") | |
| return a / b | |
| def modulus(a: int, b: int) -> int: | |
| """Calculates the modulus of two numbers. | |
| This function calculates the expression `a` modulo `b`. If `b` is zero, | |
| then it raises a ValueError. | |
| Args: | |
| a (int): The first number (dividend). | |
| b (int): The second number (divisor). | |
| Returns: | |
| int: A number representing the reminder of a modulo b. | |
| """ | |
| if b == 0: | |
| raise ValueError("Cannot divided by zero.") | |
| return a % b | |
| def power(a: float | int, b: float | int) -> float | int: | |
| """Calculates the result of a to the power of b. | |
| Args: | |
| a (float | int): The first number. | |
| b (float | int): The second number. | |
| Returns: | |
| float | int: A number representing the result of a to the power of b. | |
| """ | |
| return a**b | |
| def square_root(a: float | int) -> float | complex: | |
| """Calculates the square root of a number. | |
| Args: | |
| a (float | int): The number of which to get the square root. | |
| Returns: | |
| float | complex: A number representing the result of the square root | |
| of a. | |
| """ | |
| if a >= 0: | |
| return a**0.5 | |
| return cmath.sqrt(a) | |
| def is_greater(a: float | int, b: float | int) -> bool: | |
| """Checks if a > b. | |
| Args: | |
| a (float | int): The number on the left of the greater (>) operator. | |
| b (float | int): The number on the right of the greater (>) operator. | |
| Returns: | |
| bool: A boolean indicating whether a is greater than b. | |
| """ | |
| return a > b | |
| def is_less(a: float | int, b: float | int) -> bool: | |
| """Checks if a < b. | |
| Args: | |
| a (float | int): The number on the left of the less (<) operator. | |
| b (float | int): The number on the right of the less (<) operator. | |
| Returns: | |
| bool: A boolean indicating whether a is less than b. | |
| """ | |
| return a < b | |
| def is_equal(a: float | int, b: float | int) -> bool: | |
| """Checks if a == b. | |
| Args: | |
| a (float | int): The number on the left of the equal (==) operator. | |
| b (float | int): The number on the right of the equal (==) operator. | |
| Returns: | |
| bool: A boolean indicating whether a is equal to b. | |
| """ | |
| return a == b | |