{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6fc01cbe-c0f2-47cf-9e63-d36025f14198",
   "metadata": {},
   "source": [
    "# Normen"
   ]
  },
  {
   "attachments": {
    "d843217e-952b-46e6-8a43-0ab6e38fe50d.png": {
     "image/png": "[encoded data, 66992 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "9c937dc2-2946-4835-bf9c-c53a0337e869",
   "metadata": {},
   "source": [
    "![grafik.png](attachment:d843217e-952b-46e6-8a43-0ab6e38fe50d.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0efc8c51-d7ee-4912-92a6-c3c0f93b4895",
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import sqrt\n",
    "\n",
    "def l1(x: list[float]) -> float:\n",
    "    a=0\n",
    "    for i in x:\n",
    "        a+= abs(i)\n",
    "    return a\n",
    "\n",
    "def l2(x: list[float]) -> float:\n",
    "    a=0\n",
    "    for i in x:\n",
    "        a+= i**2\n",
    "    return sqrt(a)\n",
    "\n",
    "def li(x: list[float]) -> float:\n",
    "    return max(x)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a96e8b6e-563d-4a3c-9f74-865f19f69884",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, Math, Latex\n",
    "\n",
    "def norms(x: list[float]):\n",
    "    display(Math(f\"$x = {x}$\"))\n",
    "    display(Math(f\"$||x||_{{l1}} = {l1(x)}$\"))\n",
    "    display(Math(f\"$||x||_{{l2}} = {l2(x)}$\"))\n",
    "    display(Math(f\"$||x||_{{l \\\\infty}} = {li(x)}$\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d98ecf8f-0a20-4914-b183-a5a1ed347058",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle x = (1, 3, 2)$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l1} = 6$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l2} = 3.7416573867739413$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l \\infty} = 3$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle x = (20, 3, 2)$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l1} = 25$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l2} = 20.322401432901575$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle ||x||_{l \\infty} = 20$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = (1,3,2)\n",
    "norms(x)\n",
    "x = (20,3,2)\n",
    "norms(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "689e658e-1eb5-4e1a-93f4-82b0fa065eb9",
   "metadata": {},
   "source": [
    "# Metriken"
   ]
  },
  {
   "attachments": {
    "87611157-5376-4e9d-bc57-bc2072304dc7.png": {
     "image/png": "[encoded data, 83704 characters]"
    },
    "ecffa3c8-4a1b-4041-99eb-dea0676bc39c.png": {
     "image/png": "[encoded data, 35348 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "ec76ba02-f936-454e-9096-9aa0ce248091",
   "metadata": {},
   "source": [
    "![grafik.png](attachment:87611157-5376-4e9d-bc57-bc2072304dc7.png)\n",
    "\n",
    "---\n",
    "\n",
    "![grafik.png](attachment:ecffa3c8-4a1b-4041-99eb-dea0676bc39c.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "dddde255-6445-4913-b2c6-036331b4d318",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "def distance(x: list[float], y: list[float], norm = l2) -> float:\n",
    "    return abs(norm(np.array(x) - np.array(y)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "0a0172b2-c513-4ad4-adb2-509146773140",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle a = (1, 2, 3)$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle b = (2, -1, 5)$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle d(a,b) = 3.7416573867739413$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle d(a,b)_{L1} = 6$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle d(a,b)_{L\\infty} = 3$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = (1,2,3)\n",
    "b = (2,-1,5)\n",
    "display(Math(f\"$a = {a}$\"))\n",
    "display(Math(f\"$b = {b}$\"))\n",
    "display(Math(f\"$d(a,b) = {distance(a,b)}$\"))\n",
    "display(Math(f\"$d(a,b)_{{L1}} = {distance(a,b, norm=l1)}$\"))\n",
    "display(Math(f\"$d(a,b)_{{L\\\\infty}} = {distance(a,b, norm=li)}$\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
