{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<small><small><i>\n",
    "All the IPython Notebooks in **Python Functions** lecture series by Dr. Milaan Parmar are available @ **[GitHub](https://github.com/milaan9/04_Python_Functions)**\n",
    "</i></small></small>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Mathematical Functions\n",
    "\n",
    "Learn about all the mathematical functions available in Python and how you can use them in your program."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What is `math` module in Python?\n",
    "\n",
    "The **`math`** **[module](https://github.com/milaan9/04_Python_Functions/blob/main/007_Python_Function_Module.ipynb)** is a standard module in Python and is always available. To use mathematical functions under this module, you have to import the module using **`import math`**.\n",
    "\n",
    "It gives access to the underlying C library functions. For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-06-13T16:56:20.316916Z",
     "start_time": "2021-06-13T16:56:20.289575Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Square root calculation\n",
    "\n",
    "import math\n",
    "math.sqrt(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This module does not support complex datatypes. The **[cmath module](https://docs.python.org/3.0/library/cmath.html)** is the **`complex`** counterpart."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Functions in Python Math Module\n",
    "\n",
    "Here is the list of all the functions and attributes defined in **`math`** module with a brief explanation of what they do.\n",
    "\n",
    "**List of Functions in Python Math Module**\n",
    "\n",
    "| Function | Description |\n",
    "|:----| :--- |\n",
    "| **`ceil(x)`** | Returns the smallest integer greater than or equal to x. | \n",
    "| **`copysign(x, y)`** | Returns x with the sign of y | \n",
    "| **`fabs(x)`** | Returns the absolute value of x | \n",
    "| **`factorial(x)`** | Returns the factorial of x | \n",
    "| **`floor(x)`** | Returns the largest integer less than or equal to x | \n",
    "| **`fmod(x, y)`** | Returns the remainder when x is divided by y | \n",
    "| **`frexp(x)`** | Returns the mantissa and exponent of x as the pair (m, e) | \n",
    "| **`fsum(iterable)`** | Returns an accurate floating point sum of values in the iterable | \n",
    "| **`isfinite(x)`** | Returns True if x is neither an infinity nor a NaN (Not a Number) | \n",
    "| **`isinf(x)`** | Returns True if x is a positive or negative infinity | \n",
    "| **`isnan(x)`** | Returns True if x is a NaN | \n",
    "| **`ldexp(x, i)`** | Returns x * (2**i) | \n",
    "| **`modf(x)`** | Returns the fractional and integer parts of x | \n",
    "| **`trunc(x)`** | Returns the truncated integer value of x | \n",
    "| **`exp(x)`** | Returns e**x | \n",
    "| **`expm1(x)`** | Returns e**x - 1 | \n",
    "| **`log(x[, b])`** | Returns the logarithm of **`x`** to the base **`b`** (defaults to e) | \n",
    "| **`log1p(x)`** | Returns the natural logarithm of 1+x | \n",
    "| **`log2(x)`** | Returns the base-2 logarithm of x | \n",
    "| **`log10(x)`** | Returns the base-10 logarithm of x | \n",
    "| **`pow(x, y)`** | Returns x raised to the power y | \n",
    "| **`sqrt(x)`** | Returns the square root of x | \n",
    "| **`acos(x)`** | Returns the arc cosine of x | \n",
    "| **`asin(x)`** | Returns the arc sine of x | \n",
    "| **`atan(x)`** | Returns the arc tangent of x | \n",
    "| **`atan2(y, x)`** | Returns atan(y / x) | \n",
    "| **`cos(x)`** | Returns the cosine of x | \n",
    "| **`hypot(x, y)`** | Returns the Euclidean norm, sqrt(x*x + y*y) | \n",
    "| **`sin(x)`** | Returns the sine of x | \n",
    "| **`tan(x)`** | Returns the tangent of x | \n",
    "| **`degrees(x)`** | Converts angle x from radians to degrees | \n",
    "| **`radians(x)`** | Converts angle x from degrees to radians | \n",
    "| **`acosh(x)`** | Returns the inverse hyperbolic cosine of x | \n",
    "| **`asinh(x)`** | Returns the inverse hyperbolic sine of x | \n",
    "| **`atanh(x)`** | Returns the inverse hyperbolic tangent of x | \n",
    "| **`cosh(x)`** | Returns the hyperbolic cosine of x | \n",
    "| **`sinh(x)`** | Returns the hyperbolic cosine of x | \n",
    "| **`tanh(x)`** | Returns the hyperbolic tangent of x | \n",
    "| **`erf(x)`** | Returns the error function at x | \n",
    "| **`erfc(x)`** | Returns the complementary error function at x | \n",
    "| **`gamma(x)`** | Returns the Gamma function at x | \n",
    "| **`lgamma(x)`** | Returns the natural logarithm of the absolute value of the Gamma function at x | \n",
    "| **`pi`** | Mathematical constant, the ratio of circumference of a circle to it's diameter (3.14159...) | \n",
    "| **`e`** | mathematical constant e (2.71828...) | "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Visit this page to learn about all the **[mathematical functions defined in Python 3](https://docs.python.org/3/library/math.html)**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}