SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "markdown",
  5.    "metadata": {
  6.     "canopy_exercise": {
  7.      "cell_type": "<None>"
  8.     },
  9.     "slideshow": {
  10.      "slide_type": "-"
  11.     }
  12.    },
  13.    "source": [
  14.     "# L1 Analyse: TP1 Dénombrements, nombres réels\n",
  15.     "\n",
  16.     "##  Rappels et exemples de syntaxe Python\n",
  17.     "\n",
  18.     "Pour calculer $S_n=\\sum_{i=1}^n i$, on peut procéder par une boucle."
  19.    ]
  20.   },
  21.   {
  22.    "cell_type": "code",
  23.    "execution_count": 1,
  24.    "metadata": {
  25.     "collapsed": true
  26.    },
  27.    "outputs": [],
  28.    "source": [
  29.     "# Ces commandes servent à charger les environnements graphiques et de calcul\n",
  30.     "\n",
  31.     "%matplotlib inline\n",
  32.     "from matplotlib.pyplot import *\n",
  33.     "from numpy import *\n"
  34.    ]
  35.   },
  36.   {
  37.    "cell_type": "code",
  38.    "execution_count": 2,
  39.    "metadata": {
  40.     "canopy_exercise": {
  41.      "cell_type": "<None>"
  42.     },
  43.     "collapsed": true,
  44.     "slideshow": {
  45.      "slide_type": "-"
  46.     }
  47.    },
  48.    "outputs": [],
  49.    "source": [
  50.     "def somme(n):\n",
  51.     "    s=0\n",
  52.     "    for i in range(1,n+1):\n",
  53.     "        s=s+i\n",
  54.     "    return s  \n"
  55.    ]
  56.   },
  57.   {
  58.    "cell_type": "code",
  59.    "execution_count": 3,
  60.    "metadata": {
  61.     "slideshow": {
  62.      "slide_type": "-"
  63.     }
  64.    },
  65.    "outputs": [
  66.     {
  67.      "data": {
  68.       "text/plain": [
  69.        "0"
  70.       ]
  71.      },
  72.      "execution_count": 3,
  73.      "metadata": {},
  74.      "output_type": "execute_result"
  75.     }
  76.    ],
  77.    "source": [
  78.     "somme(-5)\n"
  79.    ]
  80.   },
  81.   {
  82.    "cell_type": "code",
  83.    "execution_count": 4,
  84.    "metadata": {},
  85.    "outputs": [
  86.     {
  87.      "data": {
  88.       "text/plain": [
  89.        "190"
  90.       ]
  91.      },
  92.      "execution_count": 4,
  93.      "metadata": {},
  94.      "output_type": "execute_result"
  95.     }
  96.    ],
  97.    "source": [
  98.     "somme(19)\n"
  99.    ]
  100.   },
  101.   {
  102.    "cell_type": "markdown",
  103.    "metadata": {
  104.     "canopy_exercise": {
  105.      "cell_type": "<None>"
  106.     }
  107.    },
  108.    "source": [
  109.     "On peut aussi procéder de manière récursive. On utilise dans ce qui suit une structure conditionnelle, pour éviter des problèmes en cas d'entrée négative (lesquels ?)\n",
  110.     "\n"
  111.    ]
  112.   },
  113.   {
  114.    "cell_type": "code",
  115.    "execution_count": 5,
  116.    "metadata": {
  117.     "collapsed": true
  118.    },
  119.    "outputs": [],
  120.    "source": [
  121.     "def sommer(n):\n",
  122.     "    if n<=0: \n",
  123.     "        return ' erreur : valeur négative '\n",
  124.     "    elif n == 1:\n",
  125.     "        return 1\n",
  126.     "    else:\n",
  127.     "        return n+sommer(n-1)"
  128.    ]
  129.   },
  130.   {
  131.    "cell_type": "code",
  132.    "execution_count": 6,
  133.    "metadata": {},
  134.    "outputs": [
  135.     {
  136.      "data": {
  137.       "text/plain": [
  138.        "190"
  139.       ]
  140.      },
  141.      "execution_count": 6,
  142.      "metadata": {},
  143.      "output_type": "execute_result"
  144.     }
  145.    ],
  146.    "source": [
  147.     "sommer(19)\n"
  148.    ]
  149.   },
  150.   {
  151.    "cell_type": "code",
  152.    "execution_count": 7,
  153.    "metadata": {},
  154.    "outputs": [
  155.     {
  156.      "data": {
  157.       "text/plain": [
  158.        "' erreur : valeur négative '"
  159.       ]
  160.      },
  161.      "execution_count": 7,
  162.      "metadata": {},
  163.      "output_type": "execute_result"
  164.     }
  165.    ],
  166.    "source": [
  167.     "sommer(-1)"
  168.    ]
  169.   },
  170.   {
  171.    "cell_type": "markdown",
  172.    "metadata": {},
  173.    "source": [
  174.     "## Exercice 1 : Définition d'une application - Application itérée  "
  175.    ]
  176.   },
  177.   {
  178.    "cell_type": "markdown",
  179.    "metadata": {},
  180.    "source": [
  181.     "Définir une application fpi(n) qui associe au nombre entier $n$  la valeur $n/2$ si $n$ est pair \n",
  182.     "et $(n+1)/2$ si $n$ est impair. En tant qu'application  de $\\mathbb{N} \\rightarrow \\mathbb{N}$  fpi est-elle injective, surjective ? \n",
  183.     "\n",
  184.     "Fonctions Python utiles : \n",
  185.     "\n",
  186.     "a // b : quotient de la division euclidienne de a par b\n",
  187.     "\n",
  188.     "a % b : reste de la division euclidienne de a par b\n",
  189.     "\n"
  190.    ]
  191.   },
  192.   {
  193.    "cell_type": "code",
  194.    "execution_count": 8,
  195.    "metadata": {
  196.     "collapsed": true
  197.    },
  198.    "outputs": [],
  199.    "source": [
  200.     "def fpi(n):\n",
  201.     "    if n%2 == 0:\n",
  202.     "        return n/2\n",
  203.     "    else:\n",
  204.     "        return (n+1)/2"
  205.    ]
  206.   },
  207.   {
  208.    "cell_type": "markdown",
  209.    "metadata": {},
  210.    "source": [
  211.     "Déterminer la liste des valeurs de l'application fpi pour $n =0, \\ldots,N.$ Prendre $N=10, N=100, N=1000.$    "
  212.    ]
  213.   },
  214.   {
  215.    "cell_type": "code",
  216.    "execution_count": 9,
  217.    "metadata": {},
  218.    "outputs": [
  219.     {
  220.      "name": "stdout",
  221.      "output_type": "stream",
  222.      "text": [
  223.       "N = 10\n",
  224.       "0.0\n",
  225.       "1.0\n",
  226.       "1.0\n",
  227.       "2.0\n",
  228.       "2.0\n",
  229.       "3.0\n",
  230.       "3.0\n",
  231.       "4.0\n",
  232.       "4.0\n",
  233.       "5.0\n",
  234.       "5.0\n"
  235.      ]
  236.     }
  237.    ],
  238.    "source": [
  239.     "def fpi(n):\n",
  240.     "    if n%2 == 0:\n",
  241.     "        return n/2\n",
  242.     "    else:\n",
  243.     "        return (n+1)/2\n",
  244.     "nMax = int(input('N = '))\n",
  245.     "for n in range(nMax+1):\n",
  246.     "  print(fpi(n))"
  247.    ]
  248.   },
  249.   {
  250.    "cell_type": "markdown",
  251.    "metadata": {},
  252.    "source": [
  253.     "Donner sous forme graphique en utilisant la fonction plot de Python les  listes obtenues. \n",
  254.     "Interpréter les résultats \n",
  255.     "observés et démontrer mathématiquement les propriétés de l'application fpi (monotonie, constance par morceaux).   \n"
  256.    ]
  257.   },
  258.   {
  259.    "cell_type": "code",
  260.    "execution_count": 11,
  261.    "metadata": {},
  262.    "outputs": [
  263.     {
  264.      "name": "stdout",
  265.      "output_type": "stream",
  266.      "text": [
  267.       "N = 100\n"
  268.      ]
  269.     },
  270.     {
  271.      "data": {
  272.       "text/plain": [
  273.        "[<matplotlib.lines.Line2D at 0x84e0278>]"
  274.       ]
  275.      },
  276.      "execution_count": 11,
  277.      "metadata": {},
  278.      "output_type": "execute_result"
  279.     },
  280.     {
  281.      "data": {
  282.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAH5lJREFUeJzt3Xl4VOXB/vHvkz0QQth3CIgIiBIgIoj1tWpbxAU3VESL\niqJQ3Psqtm+1rdq6tBZbFaWlShEwiBtF61I3fmgVSMIeoBB2AgmQjewz8/z+mJGiBROSmZyZM/fn\nuriSc5hccx9OuK8nT85zjrHWIiIikS/G6QAiIhIcKnQREZdQoYuIuIQKXUTEJVToIiIuoUIXEXEJ\nFbqIiEuo0EVEXEKFLiLiEnHN+Wbt27e36enpzfmWIiIRLzs7+4C1tkN9r2vWQk9PT2flypXN+ZYi\nIhHPGLOjIa/TlIuIiEuo0EVEXEKFLiLiEip0ERGXUKGLiLhEg65yMcZsB8oBL+Cx1mYaY9oCWUA6\nsB242lpbHJqYIiJSnxMZoX/fWpthrc0MbE8HPrLWngx8FNgWERGHNOU69LHAuYHP5wCfAg80MY+I\nSMQ7eLiGV1fsoqbOe2TfxLPSaZeSGNL3bWihW+ADY4wFX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B/5MBmYGK0TYFzrN+DBqp1hrC6y1OYHPy/H/J++G/zjnBF42B7jMmYShYYzpDlwE/CWwbYDz\ngEWBl7jqmI0xqcA5wGwAa22ttbYEl59n/LfpTjbGxAEtgAJcdp6ttUuBQ9/afbzzOhb4m/X7Ekgz\nxnQJRo5IKPRmexh1ODDGpANDgK+ATtbaAvCXPtDRuWQhMQO4H/AFttsBJdZaT2Dbbee6D1AEvBSY\nZvqLMaYlLj7P1to9wO+AnfiLvBTIxt3n+WvHO68h67RIKPQGPYzaDYwxKcDrwN3W2jKn84SSMeZi\noNBam3307mO81E3nOg4YCsy01g4BKnDR9MqxBOaNxwK9ga5AS/xTDt/mpvNcn5B9n0dCoTfoYdSR\nzhgTj7/M51lr3wjs3v/1j2KBj4VO5QuBUcClxpjt+KfRzsM/Yk8L/GgO7jvXu4Hd1tqvAtuL8Be8\nm8/zBcA2a22RtbYOeAM4C3ef568d77yGrNMiodBd/zDqwNzxbCDPWvv0UX+1GJgY+Hwi8HZzZwsV\na+2D1tru1tp0/Of0Y2vtBOAT4KrAy9x2zPuAXcaYUwK7zgc24OLzjH+qZYQxpkXg+/zrY3bteT7K\n8c7rYuDHgatdRgClX0/NNJm1Nuz/AGOAzcBW4OdO5wnB8Z2N/0euNcCqwJ8x+OeUPwL+HfjY1ums\nITr+c4Elgc/7AMuBLcBrQKLT+YJ8rBnAysC5fgto4/bzDPwK2AisA+YCiW47z8AC/L8jqMM/Ap90\nvPOKf8rluUCfrcV/BVBQcmilqIiIS0TClIuIiDSACl1ExCVU6CIiLqFCFxFxCRW6iIhLqNBFRFxC\nhS4i4hIqdBERl/j/pCKruPtqPiMAAAAASUVORK5CYII=\n",
  283.       "text/plain": [
  284.        "<matplotlib.figure.Figure at 0x50c0eb8>"
  285.       ]
  286.      },
  287.      "metadata": {},
  288.      "output_type": "display_data"
  289.     }
  290.    ],
  291.    "source": [
  292.     "from matplotlib.pyplot import plot\n",
  293.     "def fpi(n):\n",
  294.     "    if n%2 == 0:\n",
  295.     "        return n/2\n",
  296.     "    else:\n",
  297.     "        return (n+1)/2\n",
  298.     "nMax = int(input('N = '))\n",
  299.     "valuesY = [] #because values are distant by 1 on X axis\n",
  300.     "for n in range(nMax+1):\n",
  301.     "    valuesY.append(fpi(n))\n",
  302.     "plot(valuesY)"
  303.    ]
  304.   },
  305.   {
  306.    "cell_type": "markdown",
  307.    "metadata": {},
  308.    "source": [
  309.     "Définir une fonction iterf(f,x,n) donnant la valeur de $f^n(x)$ ($ f^n = f \\circ f \\circ \\cdots \\circ f$, $f$ itérée $n$ fois). Donner une version utilisant une boucle for et une version récursive. \n"
  310.    ]
  311.   },
  312.   {
  313.    "cell_type": "code",
  314.    "execution_count": null,
  315.    "metadata": {
  316.     "collapsed": true
  317.    },
  318.    "outputs": [],
  319.    "source": [
  320.     "def iterf(f,x,n):\n",
  321.     "    if n<1:\n",
  322.     "        raise Exception(\"nous ne pouvons pas répeter f \" + str(n) + \" fois\")  \n",
  323.     "    for i in range(n):\n",
  324.     "        x = f(x)\n",
  325.     "    return x\n",
  326.     "\n",
  327.     "def iteref(f,x,n):\n",
  328.     "    if n<1:\n",
  329.     "        raise Exception(\"nous ne pouvons pas répeter f \" + str(n) + \" fois\")  \n",
  330.     "    elif n == 1:\n",
  331.     "        return f(x)\n",
  332.     "    return iterf(f,f(x),n-1)"
  333.    ]
  334.   },
  335.   {
  336.    "cell_type": "markdown",
  337.    "metadata": {},
  338.    "source": [
  339.     "Tracer le graphe de la fonction fpi itérée trois fois à partir de la liste (de longueur $N=100$) de ses valeurs. Interpréter les résultats graphiques. \n",
  340.     "\n",
  341.     "En utilisant la fonction count, compter le nombre de fois où la fonction itérée prend une valeur donnée. Démontrer mathématiquement les résultats observés. \n",
  342.     "\n",
  343.     "\n",
  344.     "Montrer également que $f^n(2^n)=1$ et que $f^n(k) = 1, \\, \\forall k \\leq 2^n, \\, k \\neq 0.$   \n"
  345.    ]
  346.   },
  347.   {
  348.    "cell_type": "code",
  349.    "execution_count": 21,
  350.    "metadata": {},
  351.    "outputs": [
  352.     {
  353.      "name": "stdout",
  354.      "output_type": "stream",
  355.      "text": [
  356.       "N = 100\n",
  357.       "La fonction a pris la valeur  2 8  fois\n"
  358.      ]
  359.     },
  360.     {
  361.      "data": {
  362.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFMRJREFUeJzt3X2MXfV95/H31w9gbGxsYxvMmLEhJQZim+BMdknpNg8k\nEiHZkqqsmjTpstuoVtVuQqpIaaLuqtrVarXdjbpN26itFWjSBLFRCLuJaJWCSLpRtIlTm9CZsU14\nCE9zbbBd4zu2YWyP57t/zB12MH6auec+nHPfL2nkudfHv/s9nPGH49/3d86JzESSVH5zOl2AJKkY\nBrokVYSBLkkVYaBLUkUY6JJUEQa6JFWEgS5JFWGgS1JFGOiSVBHz2vlhK1asyHXr1rXzIyWp9Hbs\n2HEgM1eea7u2Bvq6devYvn17Oz9SkkovIp47n+2ccpGkijDQJakiDHRJqggDXZIqwkCXpIow0CWp\nIgx0SaqItq5Dl6Qqqb96gq/+8FmOj0+cc9tf3ryGq1Ysamk9BrokzdK3Hqvx+YeeACDi7NtuXrvM\nQJekbjU4UufSRRew/d+/lzhXoreBc+iSNEvDtTob+i7pijAHA12SZmXsxEme3HeETWsu6XQprzHQ\nJWkWdu0d5eREsqHPQJekUhsaqQOw0UCXpHIbqk02RFdfsqDTpbzGQJekWei2higY6JI0Y68e776G\nKBjokjRj3dgQBQNdkmZsuNZ9DVEw0CVpxrqxIQrnEegRcU9E7IuI4Wnv/feIeDwiBiPif0XE0taW\nKUndoxsbonB+Z+hfBm495b2HgQ2ZuQl4AvhcwXVJUlfq1oYonMfNuTLz+xGx7pT3Hpr28kfAHcWW\nJUnN23d4jMEX6oWO+fzBV7qyIQrF3G3xN4Cvn+k3I2ILsAWgv7+/gI+TpPPze/cP8r2f7i983Llz\ngrde2X0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  363.       "text/plain": [
  364.        "<matplotlib.figure.Figure at 0x84d4c18>"
  365.       ]
  366.      },
  367.      "metadata": {},
  368.      "output_type": "display_data"
  369.     }
  370.    ],
  371.    "source": [
  372.     "from matplotlib.pyplot import plot\n",
  373.     "def fpi(n):\n",
  374.     "    if n%2 == 0:\n",
  375.     "        return n/2\n",
  376.     "    else:\n",
  377.     "        return (n+1)/2\n",
  378.     "\n",
  379.     "def iterf(f,x,n):\n",
  380.     "    if n<1:\n",
  381.     "        raise Exception(\"nous ne pouvons pas répeter f \" + str(n) + \" fois\")  \n",
  382.     "    for i in range(n):\n",
  383.     "        x = f(x)\n",
  384.     "    return x\n",
  385.     "\n",
  386.     "nMax = int(input('N = '))\n",
  387.     "valuesY = [] #because values are distant by 1 on X axis\n",
  388.     "for n in range(nMax+1):\n",
  389.     "    valuesY.append(iterf(fpi,n,3))\n",
  390.     "plot(valuesY)\n",
  391.     "valueToCount = 2\n",
  392.     "print(\"La fonction a pris la valeur \", valueToCount, valuesY.count(valueToCount), \" fois\")"
  393.    ]
  394.   },
  395.   {
  396.    "cell_type": "markdown",
  397.    "metadata": {},
  398.    "source": [
  399.     "Définir une fonction collatz(n) qui associe au nombre entier $n$  la valeur $n/2$ si $n$ est pair \n",
  400.     "et $(3 n + 1)/2$ si $n$ est impair. Cette application (que l'on note $S$)  $S : \\mathbb{N} \\rightarrow \\mathbb{N}$ est liée à une conjecture (dite conjecture de Syracuse) qui reste à ce jour non démontrée. \n",
  401.     "\n",
  402.     "La conjecture de Syracure affirme que $\\forall k \\in \\mathbb{N}^*$, il existe $n \\in \\mathbb{N}^*$ (suffisamment grand) tel que $S^n(k) = 1$. A partir de la valeur 1 l'application  boucle sur les valeurs $2,1,2,1,2, \\ldots$  (cycle trivial). \n",
  403.     "\n"
  404.    ]
  405.   },
  406.   {
  407.    "cell_type": "code",
  408.    "execution_count": null,
  409.    "metadata": {
  410.     "collapsed": true
  411.    },
  412.    "outputs": [],
  413.    "source": [
  414.     "def collatz(n):\n",
  415.     "    if n%2 == 0:\n",
  416.     "        return n/2\n",
  417.     "    else:\n",
  418.     "        return (3*n+1)/2"
  419.    ]
  420.   },
  421.   {
  422.    "cell_type": "markdown",
  423.    "metadata": {},
  424.    "source": [
  425.     "Expérimenter le caractère erratique de la fonction collatz en traçant le graphe des différentes applications itérées $S^n$ pour $n=1, \\ldots, 10$ (pour chaque application $S^n$ tracer le graphe de la liste des valeurs $S^n(k), \\, k=0, \\ldots,N,$ avec $N=100$). \n",
  426.     "\n",
  427.     "Pour chaque application itérée $S^n$ compter le nombre de fois où l'application prend la valeur 1. \n"
  428.    ]
  429.   },
  430.   {
  431.    "cell_type": "code",
  432.    "execution_count": 23,
  433.    "metadata": {},
  434.    "outputs": [
  435.     {
  436.      "name": "stdout",
  437.      "output_type": "stream",
  438.      "text": [
  439.       "La fonction a pris la valeur  2 2  fois\n",
  440.       "La fonction a pris la valeur  2 4  fois\n",
  441.       "La fonction a pris la valeur  2 8  fois\n",
  442.       "La fonction a pris la valeur  2 16  fois\n",
  443.       "La fonction a pris la valeur  2 32  fois\n",
  444.       "La fonction a pris la valeur  2 36  fois\n",
  445.       "La fonction a pris la valeur  2 0  fois\n",
  446.       "La fonction a pris la valeur  2 0  fois\n",
  447.       "La fonction a pris la valeur  2 0  fois\n",
  448.       "La fonction a pris la valeur  2 0  fois\n"
  449.      ]
  450.     },
  451.     {
  452.      "data": {
  453.       "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd8VFX6x/HPSW+EEEoIBAxVQGqISLOziihiR4oioiiI\nimUVZH92XVFXsaIsIIiAoSkICCqKLCgCSegBhBAgEJKQ3pOZOb8/ZmTRhUwgM7lTnvfrFZO5ntx5\nbu7ky82Zc85VWmuEEEK4Px+jCxBCCOEYEuhCCOEhJNCFEMJDSKALIYSHkEAXQggPIYEuhBAeQgJd\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qVULNAD+A2I0lpngDX0gSbGVeYU04BnAIvtcUMgX2tt\nsj32tHPdGsgGPrN1M81USoXiwedZa30ceBs4ijXIC4BEPPs8/+Fc59VpmeYOgV6jm1F7AqVUGLAU\nmKi1LjS6HmdSSt0EZGmtE8/cfJamnnSu/YA4YLrWugdQggd1r5yNrd94CNAKaAaEYu1y+CtPOs/2\nOO117g6BXqObUbs7pZQ/1jCfr7VeZtuc+cefYrbPWUbV5wT9gJuVUmlYu9GuwXrFHmH70xw871yn\nA+la699sj5dgDXhPPs8DgMNa62ytdRWwDOiLZ5/nP5zrvDot09wh0D3+ZtS2vuNZQIrW+p0z/tcK\nYJTt61HA8rquzVm01pO11jFa61is5/RHrfUI4CfgDlszTzvmk8AxpdTFtk3XAnvx4POMtault1Iq\nxPY6/+OYPfY8n+Fc53UFcK9ttEtvoOCPrpla01q7/AcwCDgAHAKmGF2PE46vP9Y/uXYC220fg7D2\nKa8Dfrd9jjS6Vicd/1XAStvXrYEtwEFgMRBodH0OPtbuwDbbuf4aaODp5xl4CdgH7AbmAYGedp6B\nhVjfI6jCegU+5lznFWuXy0e2PNuFdQSQQ+qQmaJCCOEh3KHLRQghRA1IoAshhIeQQBdCCA8hgS6E\nEB5CAl0IITyEBLoQQngICXQhhPAQEuhCCOEh/h8d5pcL6isJPAAAAABJRU5ErkJggg==\n",
  454.       "text/plain": [
  455.        "<matplotlib.figure.Figure at 0x87256d8>"
  456.       ]
  457.      },
  458.      "metadata": {},
  459.      "output_type": "display_data"
  460.     }
  461.    ],
  462.    "source": [
  463.     "from matplotlib.pyplot import plot\n",
  464.     "def collatz(n):\n",
  465.     "    if n%2 == 0:\n",
  466.     "        return n/2\n",
  467.     "    else:\n",
  468.     "        return (3*n+1)/2\n",
  469.     "\n",
  470.     "def iterf(f,x,n):\n",
  471.     "    if n<1:\n",
  472.     "        raise Exception(\"nous ne pouvons pas répeter f \" + str(n) + \" fois\")  \n",
  473.     "    for i in range(n):\n",
  474.     "        x = f(x)\n",
  475.     "    return x\n",
  476.     "\n",
  477.     "for n in range(1,10+1):\n",
  478.     "    nMax = 100\n",
  479.     "    valuesY = [] #because values are distant by 1 on X axis\n",
  480.     "    for k in range(nMax+1):\n",
  481.     "        valuesY.append(iterf(fpi,k,n))\n",
  482.     "    plot(valuesY)\n",
  483.     "    valueToCount = 2\n",
  484.     "    print(\"La fonction a pris la valeur \", valueToCount, valuesY.count(valueToCount), \" fois\")"
  485.    ]
  486.   },
  487.   {
  488.    "cell_type": "markdown",
  489.    "metadata": {
  490.     "canopy_exercise": {
  491.      "cell_type": "question"
  492.     }
  493.    },
  494.    "source": [
  495.     "## Exercice 2 : Calcul de la factorielle \n",
  496.     "a) Définir une fonction fact(n) qui associe à un entier $n$ la valeur $n!$ en utilisant une boucle for. "
  497.    ]
  498.   },
  499.   {
  500.    "cell_type": "code",
  501.    "execution_count": null,
  502.    "metadata": {
  503.     "collapsed": true
  504.    },
  505.    "outputs": [],
  506.    "source": [
  507.     "def fact(n):\n",
  508.     "    y = 1\n",
  509.     "    for i in range(1,n+1):\n",
  510.     "        y*=i\n",
  511.     "    return y"
  512.    ]
  513.   },
  514.   {
  515.    "cell_type": "markdown",
  516.    "metadata": {},
  517.    "source": [
  518.     "b) Définir une fonction factr(n) qui retourne $n!$ en utilisant une méthode récursive."
  519.    ]
  520.   },
  521.   {
  522.    "cell_type": "code",
  523.    "execution_count": null,
  524.    "metadata": {
  525.     "collapsed": true
  526.    },
  527.    "outputs": [],
  528.    "source": [
  529.     "def factr(n):\n",
  530.     "    if n == 0:\n",
  531.     "        return 1\n",
  532.     "    else:\n",
  533.     "        return n*factr(n-1)"
  534.    ]
  535.   },
  536.   {
  537.    "cell_type": "markdown",
  538.    "metadata": {},
  539.    "source": [
  540.     "c) Calculer plusieurs valeurs de ces fonctions, déterminer leur type. Comparer les valeurs et la rapidité des deux fonctions."
  541.    ]
  542.   },
  543.   {
  544.    "cell_type": "code",
  545.    "execution_count": null,
  546.    "metadata": {
  547.     "collapsed": true
  548.    },
  549.    "outputs": [],
  550.    "source": [
  551.     "from time import time\n",
  552.     "from random import random\n",
  553.     "def factr(n):\n",
  554.     "    if n == 0:\n",
  555.     "        return 1\n",
  556.     "    else:\n",
  557.     "        return n*factr(n-1)\n",
  558.     "def fact(n):\n",
  559.     "    y = 1\n",
  560.     "    for i in range(1,n+1):\n",
  561.     "        y*=i\n",
  562.     "    return y\n",
  563.     "def compareTimes(f1,f2,value):\n",
  564.     "    "
  565.    ]
  566.   },
  567.   {
  568.    "cell_type": "markdown",
  569.    "metadata": {},
  570.    "source": [
  571.     "## Exercice 3 : Ensemble des permutations des éléments d'une liste \n",
  572.     "\n"
  573.    ]
  574.   },
  575.   {
  576.    "cell_type": "markdown",
  577.    "metadata": {},
  578.    "source": [
  579.     "Définir une fonction \"permut\" donnant la liste de l'ensemble des permutations des éléments d'une liste L donnée. \n",
  580.     "\n",
  581.     "Exemple : à partir de la liste L=[1,2,3], la fonction donne la liste de toutes les listes obtenues par permutations de la liste [1,2,3] : [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]].\n",
  582.     "Il y en a $n!$ si $n$ est le nombre d'éléments de la liste L.\n",
  583.     "On voit que cette fonction donne l'ensemble des bijections de l'ensemble des éléments de la liste L (supposés distincts) dans lui-même.\n",
  584.     "\n",
  585.     "On pourra pour cela utiliser la récursivité du language Python pour appeler la fonction \"permut\" avec une liste de taille $n-1$. \n",
  586.     "\n",
  587.     "Fonctions Python utiles : \n",
  588.     "\n",
  589.     "len (longueur d'une liste), \n",
  590.     "\n",
  591.     "[ ] (liste vide)\n",
  592.     "\n",
  593.     "del (élimination d'un élément d'une liste), \n",
  594.     "\n",
  595.     "a+b (concaténation de la liste a et de la liste b), \n",
  596.     "\n",
  597.     "a=b[:] (affectation de la liste b dans la liste a - la valeur de a peut être modifiée sans que la valeur de b soit modifiée - la simple affectation a=b aurait aussi modifié la valeur de b)  \n",
  598.     "\n"
  599.    ]
  600.   },
  601.   {
  602.    "cell_type": "code",
  603.    "execution_count": null,
  604.    "metadata": {
  605.     "collapsed": true
  606.    },
  607.    "outputs": [],
  608.    "source": []
  609.   },
  610.   {
  611.    "cell_type": "markdown",
  612.    "metadata": {},
  613.    "source": [
  614.     "## Exercice 4 :  Nombre d'injections\n",
  615.     "1) Construire une fonction inj(p,n) qui calcule le nombre d'injections d'un ensemble à p éléments dans un ensemble à n éléments. On notera que le cours donne deux formules, qui mènent à des codes différents.\n",
  616.     "\n"
  617.    ]
  618.   },
  619.   {
  620.    "cell_type": "code",
  621.    "execution_count": null,
  622.    "metadata": {
  623.     "collapsed": true
  624.    },
  625.    "outputs": [],
  626.    "source": []
  627.   },
  628.   {
  629.    "cell_type": "markdown",
  630.    "metadata": {},
  631.    "source": [
  632.     "Calculer pour $p$ entre 1 et 40, la proportion d'applications injectives parmi toutes les applications partant d'un ensemble de cardinal $p$ à valeur dans un ensemble de cardinal 365.\n",
  633.     "\n"
  634.    ]
  635.   },
  636.   {
  637.    "cell_type": "code",
  638.    "execution_count": null,
  639.    "metadata": {
  640.     "collapsed": true
  641.    },
  642.    "outputs": [],
  643.    "source": []
  644.   },
  645.   {
  646.    "cell_type": "code",
  647.    "execution_count": null,
  648.    "metadata": {
  649.     "collapsed": true
  650.    },
  651.    "outputs": [],
  652.    "source": [
  653.     "# Attention, la division entre entiers est comprise comme la division euclidienne. \n",
  654.     "# On transforme un des termes en nombre réel avec float, pour forcer une division exacte.\n",
  655.     "  \n"
  656.    ]
  657.   },
  658.   {
  659.    "cell_type": "markdown",
  660.    "metadata": {},
  661.    "source": [
  662.     "Quel est le plus petit nombre $k$ tel que si l'on choisit $k$ personnes au hasard, on a plus d'une chance sur deux que deux d'entre elles fêtent leur anniversaire le même jour?\n",
  663.     "\n"
  664.    ]
  665.   },
  666.   {
  667.    "cell_type": "code",
  668.    "execution_count": null,
  669.    "metadata": {
  670.     "collapsed": true
  671.    },
  672.    "outputs": [],
  673.    "source": []
  674.   },
  675.   {
  676.    "cell_type": "markdown",
  677.    "metadata": {},
  678.    "source": [
  679.     "## Exercice 5 : Coefficients du binôme $\\Bigl(^n_p\\Bigr)$\n",
  680.     "\n",
  681.     "a) Définir deux fonctions combin(n,p) et combinr(n,p) pour calculer \"p parmi n\" respectivement en utilisant une boucle et de façon récursive. Puis tester ces deux méthodes.\n",
  682.     "\n"
  683.    ]
  684.   },
  685.   {
  686.    "cell_type": "code",
  687.    "execution_count": null,
  688.    "metadata": {
  689.     "collapsed": true
  690.    },
  691.    "outputs": [],
  692.    "source": []
  693.   },
  694.   {
  695.    "cell_type": "markdown",
  696.    "metadata": {},
  697.    "source": [
  698.     "b) On souhaite afficher les premières lignes du triangle de Pascal. On pourra le faire de deux manières : en utilisant la fonction combin définie plus haut, et en tirant parti de la formule ${n\\choose p}={n-1\\choose p}+{n-1\\choose p-1}$ pour calculer les lignes l'une après l'autre. Laquelle vous paraît la plus efficace ?\n",
  699.     "\n"
  700.    ]
  701.   },
  702.   {
  703.    "cell_type": "code",
  704.    "execution_count": null,
  705.    "metadata": {
  706.     "collapsed": true
  707.    },
  708.    "outputs": [],
  709.    "source": []
  710.   },
  711.   {
  712.    "cell_type": "markdown",
  713.    "metadata": {},
  714.    "source": [
  715.     "Expliquez pourquoi les puissances de 11 apparaissent sur les 5 premières lignes du triangle (et pas sur les suivantes).\n",
  716.     "\n"
  717.    ]
  718.   },
  719.   {
  720.    "cell_type": "code",
  721.    "execution_count": null,
  722.    "metadata": {
  723.     "collapsed": true
  724.    },
  725.    "outputs": [],
  726.    "source": [
  727.     "11**2, 11**3, 11**4, 11**5\n"
  728.    ]
  729.   },
  730.   {
  731.    "cell_type": "markdown",
  732.    "metadata": {},
  733.    "source": [
  734.     "Dans un jeu de loto (simplifié) un tirage consiste à choisir 5 numéros entre 1 et 49. L'ordre de tirage ne compte pas. Calculer le nombre de tirages possibles.\n",
  735.     "\n"
  736.    ]
  737.   },
  738.   {
  739.    "cell_type": "code",
  740.    "execution_count": null,
  741.    "metadata": {
  742.     "collapsed": true
  743.    },
  744.    "outputs": [],
  745.    "source": []
  746.   },
  747.   {
  748.    "cell_type": "markdown",
  749.    "metadata": {},
  750.    "source": [
  751.     "Un joueur mise sur $\\{1,2,3,4,5\\}$. Pour combien de tirages possibles le joueur a-t-il $k$ bons numéros? (pour $k$ valant 0,1, 2, 3, 4 ou 5).\n",
  752.     "\n"
  753.    ]
  754.   },
  755.   {
  756.    "cell_type": "code",
  757.    "execution_count": null,
  758.    "metadata": {
  759.     "collapsed": true
  760.    },
  761.    "outputs": [],
  762.    "source": []
  763.   },
  764.   {
  765.    "cell_type": "markdown",
  766.    "metadata": {},
  767.    "source": [
  768.     "## Exercice 6 : Une suite apparemment simple"
  769.    ]
  770.   },
  771.   {
  772.    "cell_type": "markdown",
  773.    "metadata": {},
  774.    "source": [
  775.     "On se propose de faire des expérimentations pour deviner la valeur de la borne supérieur de l'ensemble $\\{ \\cos(n); \\; n \\ge 1\\}.$"
  776.    ]
  777.   },
  778.   {
  779.    "cell_type": "code",
  780.    "execution_count": null,
  781.    "metadata": {
  782.     "collapsed": true
  783.    },
  784.    "outputs": [],
  785.    "source": []
  786.   },
  787.   {
  788.    "cell_type": "markdown",
  789.    "metadata": {},
  790.    "source": [
  791.     "Extraire de la liste des valeurs de $\\cos(n)$ les valeurs plus grandes que 0.9999 (prendre les valeurs de $\\cos(n)$ pour $n=1, \\ldots, 1000$).\n"
  792.    ]
  793.   },
  794.   {
  795.    "cell_type": "code",
  796.    "execution_count": null,
  797.    "metadata": {
  798.     "collapsed": true
  799.    },
  800.    "outputs": [],
  801.    "source": []
  802.   }
  803.  ],
  804.  "metadata": {
  805.   "anaconda-cloud": {},
  806.   "celltoolbar": "Raw Cell Format",
  807.   "kernelspec": {
  808.    "display_name": "Python 3",
  809.    "language": "python",
  810.    "name": "python3"
  811.   },
  812.   "language_info": {
  813.    "codemirror_mode": {
  814.     "name": "ipython",
  815.     "version": 3
  816.    },
  817.    "file_extension": ".py",
  818.    "mimetype": "text/x-python",
  819.    "name": "python",
  820.    "nbconvert_exporter": "python",
  821.    "pygments_lexer": "ipython3",
  822.    "version": "3.6.2"
  823.   }
  824.  },
  825.  "nbformat": 4,
  826.  "nbformat_minor": 1
  827. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top