{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7ea6c41e-ad5c-4cd1-9f5b-562eb01697b5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import math\n",
    "import scipy.integrate as integ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ceeba640-ebc4-4ce5-b18b-a275e0df5c04",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1.6536436208636118, 2.5977144691772644e-14)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integ.quad(math.sin, 0, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e36ff1cc-0ff2-463a-8430-8baac76e9ce2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def int_x2(f):\n",
    "    \"\"\" restituisce l'integrale di f(x^2) in [0,1]\"\"\"\n",
    "    def g(x):\n",
    "        return f(x*x)\n",
    "    return integ.quad(g, 0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3f871f6d-1a61-45c9-afa8-d9567cdf928a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.3102683017233811, 3.444670123846428e-15)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int_x2(math.sin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "39ade89d-6f99-40d9-93e8-aff6f47e6a6e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def f_x2(f):\n",
    "    def g(x):\n",
    "        return f(x*x)\n",
    "    return g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "fd82e249-7a9a-49c1-ae53-b539bb9c8638",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "v=f_x2(math.sin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "58776e2d-008a-48b3-bb86-77b04b0f47c7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "function"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a65e268c-27d1-4b4a-bc70-9c3aef7c1ee6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8414709848078965"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v(1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "acab77f4-f84f-4f11-b92e-6bd12d226f6c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def f_2x(f):\n",
    "    def g(x):\n",
    "        return f(2*x)\n",
    "    return g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4f6976f0-a93b-4136-9852-a333996b43a9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def f_x2b(f):\n",
    "    return (lambda x: f(x*x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c905cd74-1965-4d6f-ad77-11ec19bb0774",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.f_x2b.<locals>.<lambda>(x)>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f_x2b(math.sin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "873ae53a-601e-41ec-b8ac-1c6fae3881e5",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def f_ax(f,a):\n",
    "    return (lambda x: f(x*a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "79951797-f61c-4713-839e-6ddc30968c19",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "sin2x=f_ax(math.sin,2)\n",
    "sin3x=f_ax(math.sin,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "6b654268-8de3-4a6a-b63b-beaf5846be78",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def int_x2b(f):\n",
    "    \"\"\" restituisce l'integrale di f(x^2) in [0,1]\"\"\"\n",
    "    #def g(x):\n",
    "    #    return f(x*x)\n",
    "    #g=(lambda x: f(x*x))\n",
    "    return integ.quad((lambda x: f(x*x)), 0, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f4ec9a58-0d60-491b-a540-6be4b86c800f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.3102683017233811, 3.444670123846428e-15)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "int_x2b(math.sin)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ecda159f-9379-40a0-bccd-5c59575e4c1e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4121184852417566"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(lambda x: math.sin(x*x))(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d62c7881-94d6-4d42-94a2-f8b5fc516a30",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4121184852417566"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.sin(3*3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66d33ac0-be87-476b-b1d0-34f37a586507",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
