{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Texte d'oral de modélisation - Agrégation Option Informatique" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Préparation à l'agrégation - ENS de Rennes, 2016-17" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- *Date* : 29 mai 2017\n", "- *Auteur* : [Lilian Besson](https://GitHub.com/Naereen/notebooks/)\n", "- *Texte*: [Circuits (public2010-D1)](http://agreg.org/Textes/public2010-D1.pdf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## À propos de ce document" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Ceci est une *proposition* de correction, partielle et probablement non-optimale, pour la partie implémentation d'un [texte d'annale de l'agrégation de mathématiques, option informatique](http://Agreg.org/Textes/).\n", "- Ce document est un [notebook Jupyter](https://www.Jupyter.org/), et [est open-source sous Licence MIT sur GitHub](https://github.com/Naereen/notebooks/tree/master/agreg/), comme les autres solutions de textes de modélisation que [j](https://GitHub.com/Naereen)'ai écrite cette année.\n", "- L'implémentation sera faite en OCaml, version 4+ :" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The OCaml toplevel, version 4.04.2\n" ] }, { "data": { "text/plain": [ "- : int = 0\n" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Sys.command \"ocaml -version\";;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> Notez que certaines fonctions des modules usuels [`List`](http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html) et [`Array`](http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html) ne sont pas disponibles en OCaml 3.12.\n", "> J'essaie autant que possible de ne pas les utiliser, ou alors de les redéfinir si je m'en sers." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question de programmation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "La question de programmation pour ce texte était donnée en page 6, et était assez courte :\n", "\n", "> \"Écrire un programme prenant en entrée deux nombres $a$, $b$, représentés par des écritures en base $B$ avec des chiffres signés entre $-\\beta$ et $\\beta$, et retournant un résultat ternaire indiquant si $a < b$, si $a = b$ ou si $a > b$. On supposera que $\\beta < B < 2 \\beta$, et que les écritures de $a$ et $b$ ont même longueur.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Réponse à l'exercice requis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Structure de données\n", "\n", "Pour représenter ces entiers, on stocke leur base et le tableau de leur coefficients." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "type entier = { base : int; t : int array; }\n" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type entier = {\n", " base : int;\n", " t : int array\n", "}\n", ";;" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exemples" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val quatre : entier = {base = 10; t = [|4|]}\n" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let quatre = {\n", " base = 10;\n", " t = [| 4 |]\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Le \"bit\" de poids faible est, par convention du texte, à gauche au début du tableau :" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val quarantedeux : entier = {base = 10; t = [|2; 4|]}\n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let quarantedeux = {\n", " base = 10;\n", " t = [| 2; 4 |]\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Avec l'exemple du texte :" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val n2006 : entier = {base = 10; t = [|6; 0; 0; 2|]}\n" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let n2006 = {\n", " base = 10;\n", " t = [| 6; 0; 0; 2 |]\n", "}" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val n2006 : entier = {base = 10; t = [|6; 0; 0; 2|]}\n" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let n2006 = {\n", " base = 10;\n", " t = [| 6; 0; 0; 2 |]\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val n2006_2 : entier = {base = 10; t = [|-4; 1; 0; 2|]}\n" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let n2006_2 = {\n", " base = 10;\n", " t = [| -4; 1; 0; 2 |]\n", "}" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val n2006_3 : entier = {base = 10; t = [|6; 0; 0; -8; 1|]}\n" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let n2006_3 = {\n", " base = 10;\n", " t = [| 6; 0; 0; -8; 1 |]\n", "}" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val n2006_4 : entier = {base = 10; t = [|-4; 1; 0; -8; 1|]}\n" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let n2006_4 = {\n", " base = 10;\n", " t = [| -4; 1; 0; -8; 1 |]\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fonctions intermédiaires" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Caml, dans sa toute beauté, ne permet pas de calculer $x^k$ facilement si $x$ est entier..." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "val puissance : int -> int -> int =