{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"drawing\"\n", "

Experimental Mathematics Using SageMath — AIMS-ZA-2024-25

\n", "\n", "\n", "## Instructors: \n", "\n", "* **Evans Ocansey**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Day 09 — Pieces of Numbers \n", "\n", "[comment]: <> (

Day 08 — Introduction to SageMath: A Mathematics Software for All

)\n", "\n", "We will spend some time learning about a very simple new concept - one that only requires addition. We'll explore it.\n", "\n", "\n", "The outline of the this notebook is as follows:\n", "\n", "\n", "## Table of Contents: \n", "[comment]: <> (The simplest addition)\n", "* [ ] [ Pieces of Numbers](#the-simplest-addition)\n", " * [Exploration](#exploration)\n", " * [Exploration 1](#exploration-1)\n", " * [Questions to Explore](#questions-to-explore)\n", " * [Exploration 2](#exploration-2)\n", " * [Exploration 3](#exploration-3)\n", " * [Exploration 4](#exploration-4)\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pieces of Numbers — The Simplest Addition \n", "\n", "\n", "Here is a question nearly every human could answer.\n", " \n", " \n", "How many ways can you divide a pile of $5$ sticks into (non-empty) piles?\n", "\n", "\n", "\n", "\n", "Let's see.\n", " \n", " \n", " \n", "There is the trivial one where you don't divide it at all.  $5=5$.\n", "There is the one where you just make five piles of one stick each.  $1+1+1+1+1=5$.\n", "You could have four in one pile.  That leaves $4+1=5$.\n", "But if you have three in one pile, there are two ways to do the other two.\n", "\n", "$3+2=5$.\n", "$3+1+1=5$.\n", "\n", "\n", "\n", "\n", "Almost done!  I guess the only other possibility is if there are piles of $2$ and $1$.\n", "\n", " \n", " \n", "$2+2+1=5$.\n", "$2+1+1+1=5$.\n", "\n", "That makes seven ways in total.  We call these things _integer partitions_.  As George Andrews says in [this delightful little book](http://www.cambridge.org/gb/academic/subjects/mathematics/number-theory/integer-partitions): \"An integer partition is a way of splitting a number into integer parts.\"  More precisely, a partition of a nonnegative integer $n$ is a representation of $n$ as a sum of positive integers, called summands or parts of the partition. The order of the summands is irrelevant.\n", "\n", "\n", "The function giving the number of partitions of $n$ is called $p(n)$.  So our example shows that $p(5)=7$.\n", "Amazingly, there are _real physics applications_ of this! See [this list of articles](https://empslocal.ex.ac.uk/people/staff/mrwatkin/zeta/partitioning.htm) and [this more dubious example](https://www8.cs.umu.se/kurser/TDBA77/VT06/algorithms/BOOK/BOOK4/NODE153.HTM).  A typical quote: \"The number partitioning problem can be interpreted physically in terms of a thermally isolated noninteracting Bose gas trapped in a one-dimensional harmonic-oscillator potential.\"\n", " \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exploration \n", "\n", "As always we need data that we can explore so let us generate some. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exploration 1 \n", "Try to compute $p(n)$ for $n\\leq 10$. Divide up this work in groups! Maybe three or four people should work on each one, and then cross-check their work." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mInit signature:\u001b[0m \u001b[0mPartitions\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mis_infinite\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m \n", " \"Partitions(n, **kwargs)\" returns the combinatorial class of\n", " integer partitions of n subject to the constraints given by the\n", " keywords.\n", "\n", " Valid keywords are: \"starting\", \"ending\", \"min_part\", \"max_part\",\n", " \"max_length\", \"min_length\", \"length\", \"max_slope\", \"min_slope\",\n", " \"inner\", \"outer\", \"parts_in\", \"regular\", and \"restricted\". They\n", " have the following meanings:\n", "\n", " * \"starting=p\" specifies that the partitions should all be less\n", " than or equal to p in lex order. This argument cannot be combined\n", " with any other (see\n", " https://github.com/sagemath/sage/issues/15467).\n", "\n", " * \"ending=p\" specifies that the partitions should all be greater\n", " than or equal to p in lex order. This argument cannot be combined\n", " with any other (see\n", " https://github.com/sagemath/sage/issues/15467).\n", "\n", " * \"length=k\" specifies that the partitions have exactly k parts.\n", "\n", " * \"min_length=k\" specifies that the partitions have at least k\n", " parts.\n", "\n", " * \"min_part=k\" specifies that all parts of the partitions are at\n", " least k.\n", "\n", " * \"inner=p\" specifies that the partitions must contain the\n", " partition p.\n", "\n", " * \"outer=p\" specifies that the partitions be contained inside the\n", " partition p.\n", "\n", " * \"min_slope=k\" specifies that the partitions have slope at least\n", " k; the slope at position i is the difference between the (i+1)-th\n", " part and the i-th part.\n", "\n", " * \"parts_in=S\" specifies that the partitions have parts in the set\n", " S, which can be any sequence of pairwise distinct positive\n", " integers. This argument cannot be combined with any other (see\n", " https://github.com/sagemath/sage/issues/15467).\n", "\n", " * \"regular=ell\" specifies that the partitions are \\ell-regular, and\n", " can only be combined with the \"max_length\" or \"max_part\", but not\n", " both, keywords if n is not specified\n", "\n", " * \"restricted=ell\" specifies that the partitions are \\ell-\n", " restricted, and cannot be combined with any other keywords\n", "\n", " The \"max_*\" versions, along with \"inner\" and \"ending\", work\n", " analogously.\n", "\n", " Right now, the \"parts_in\", \"starting\", \"ending\", \"regular\", and\n", " \"restricted\" keyword arguments are mutually exclusive, both of each\n", " other and of other keyword arguments. If you specify, say,\n", " \"parts_in\", all other keyword arguments will be ignored;\n", " \"starting\", \"ending\", \"regular\", and \"restricted\" work the same\n", " way.\n", "\n", " EXAMPLES:\n", "\n", " If no arguments are passed, then the combinatorial class of all\n", " integer partitions is returned:\n", "\n", " sage: Partitions()\n", " Partitions\n", " sage: [2,1] in Partitions()\n", " True\n", "\n", " If an integer n is passed, then the combinatorial class of integer\n", " partitions of n is returned:\n", "\n", " sage: Partitions(3)\n", " Partitions of the integer 3\n", " sage: Partitions(3).list()\n", " [[3], [2, 1], [1, 1, 1]]\n", "\n", " If \"starting=p\" is passed, then the combinatorial class of\n", " partitions greater than or equal to p in lexicographic order is\n", " returned:\n", "\n", " sage: Partitions(3, starting=[2,1])\n", " Partitions of the integer 3 starting with [2, 1]\n", " sage: Partitions(3, starting=[2,1]).list()\n", " [[2, 1], [1, 1, 1]]\n", "\n", " If \"ending=p\" is passed, then the combinatorial class of partitions\n", " at most p in lexicographic order is returned:\n", "\n", " sage: Partitions(3, ending=[2,1])\n", " Partitions of the integer 3 ending with [2, 1]\n", " sage: Partitions(3, ending=[2,1]).list()\n", " [[3], [2, 1]]\n", "\n", " Using \"max_slope=-1\" yields partitions into distinct parts -- each\n", " part differs from the next by at least 1. Use a different\n", " \"max_slope\" to get parts that differ by, say, 2:\n", "\n", " sage: Partitions(7, max_slope=-1).list()\n", " [[7], [6, 1], [5, 2], [4, 3], [4, 2, 1]]\n", " sage: Partitions(15, max_slope=-1).cardinality()\n", " 27\n", "\n", " The number of partitions of n into odd parts equals the number of\n", " partitions into distinct parts. Let's test that for n from 10 to\n", " 20:\n", "\n", " sage: def test(n):\n", " ....: return (Partitions(n, max_slope=-1).cardinality()\n", " ....: == Partitions(n, parts_in=[1,3..n]).cardinality())\n", " sage: all(test(n) for n in [10..20])\n", " True\n", "\n", " The number of partitions of n into distinct parts that differ by at\n", " least 2 equals the number of partitions into parts that equal 1 or\n", " 4 modulo 5; this is one of the Rogers-Ramanujan identities:\n", "\n", " sage: def test(n):\n", " ....: return (Partitions(n, max_slope=-2).cardinality()\n", " ....: == Partitions(n, parts_in=([1,6..n] + [4,9..n])).cardinality())\n", " sage: all(test(n) for n in [10..20])\n", " True\n", "\n", " Here are some more examples illustrating \"min_part\", \"max_part\",\n", " and \"length\":\n", "\n", " sage: Partitions(5, min_part=2)\n", " Partitions of the integer 5 satisfying constraints min_part=2\n", " sage: Partitions(5, min_part=2).list()\n", " [[5], [3, 2]]\n", "\n", " sage: Partitions(3, max_length=2).list()\n", " [[3], [2, 1]]\n", "\n", " sage: Partitions(10, min_part=2, length=3).list()\n", " [[6, 2, 2], [5, 3, 2], [4, 4, 2], [4, 3, 3]]\n", "\n", " Some examples using the \"regular\" keyword:\n", "\n", " sage: Partitions(regular=4)\n", " 4-Regular Partitions\n", " sage: Partitions(regular=4, max_length=3)\n", " 4-Regular Partitions with max length 3\n", " sage: Partitions(regular=4, max_part=3)\n", " 4-Regular 3-Bounded Partitions\n", " sage: Partitions(3, regular=4)\n", " 4-Regular Partitions of the integer 3\n", "\n", " Some examples using the \"restricted\" keyword:\n", "\n", " sage: Partitions(restricted=4)\n", " 4-Restricted Partitions\n", " sage: Partitions(3, restricted=4)\n", " 4-Restricted Partitions of the integer 3\n", "\n", " Here are some further examples using various constraints:\n", "\n", " sage: [x for x in Partitions(4)]\n", " [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]\n", " sage: [x for x in Partitions(4, length=2)]\n", " [[3, 1], [2, 2]]\n", " sage: [x for x in Partitions(4, min_length=2)]\n", " [[3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]\n", " sage: [x for x in Partitions(4, max_length=2)]\n", " [[4], [3, 1], [2, 2]]\n", " sage: [x for x in Partitions(4, min_length=2, max_length=2)]\n", " [[3, 1], [2, 2]]\n", " sage: [x for x in Partitions(4, max_part=2)]\n", " [[2, 2], [2, 1, 1], [1, 1, 1, 1]]\n", " sage: [x for x in Partitions(4, min_part=2)]\n", " [[4], [2, 2]]\n", " sage: [x for x in Partitions(4, outer=[3,1,1])]\n", " [[3, 1], [2, 1, 1]]\n", " sage: [x for x in Partitions(4, outer=[infinity, 1, 1])]\n", " [[4], [3, 1], [2, 1, 1]]\n", " sage: [x for x in Partitions(4, inner=[1,1,1])]\n", " [[2, 1, 1], [1, 1, 1, 1]]\n", " sage: [x for x in Partitions(4, max_slope=-1)]\n", " [[4], [3, 1]]\n", " sage: [x for x in Partitions(4, min_slope=-1)]\n", " [[4], [2, 2], [2, 1, 1], [1, 1, 1, 1]]\n", " sage: [x for x in Partitions(11, max_slope=-1, min_slope=-3, min_length=2, max_length=4)]\n", " [[7, 4], [6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2], [5, 3, 2, 1]]\n", " sage: [x for x in Partitions(11, max_slope=-1, min_slope=-3, min_length=2, max_length=4, outer=[6,5,2])]\n", " [[6, 5], [6, 4, 1], [6, 3, 2], [5, 4, 2]]\n", "\n", " Note that if you specify \"min_part=0\", then it will treat the\n", " minimum part as being 1 (see\n", " https://github.com/sagemath/sage/issues/13605):\n", "\n", " sage: [x for x in Partitions(4, length=3, min_part=0)]\n", " [[2, 1, 1]]\n", " sage: [x for x in Partitions(4, min_length=3, min_part=0)]\n", " [[2, 1, 1], [1, 1, 1, 1]]\n", "\n", " Except for very special cases, counting is done by brute force\n", " iteration through all the partitions. However the iteration itself\n", " has a reasonable complexity (see \"IntegerListsLex\"), which allows\n", " for manipulating large partitions:\n", "\n", " sage: Partitions(1000, max_length=1).list()\n", " [[1000]]\n", "\n", " In particular, getting the first element is also constant time:\n", "\n", " sage: Partitions(30, max_part=29).first()\n", " [29, 1]\n", "\u001b[0;31mInit docstring:\u001b[0m\n", " Initialize \"self\".\n", "\n", " INPUT:\n", "\n", " * \"is_infinite\" -- (Default: \"False\") If \"True\", then the number of\n", " partitions in this set is infinite.\n", "\n", " EXAMPLES:\n", "\n", " sage: Partitions()\n", " Partitions\n", " sage: Partitions(2)\n", " Partitions of the integer 2\n", "\u001b[0;31mFile:\u001b[0m ~/Downloads/sage-10.4/src/sage/combinat/partition.py\n", "\u001b[0;31mType:\u001b[0m ClasscallMetaclass\n", "\u001b[0;31mSubclasses:\u001b[0m Partitions_all, Partitions_all_bounded, Partitions_n, Partitions_nk, Partitions_parts_in, Partitions_starting, Partitions_ending, PartitionsInBox, RegularPartitions, OrderedPartitions, ..." ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Partitions?" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\\(n\\)\\(p(n)\\)
\\(0\\)\\(1\\)
\\(1\\)\\(1\\)
\\(2\\)\\(2\\)
\\(3\\)\\(3\\)
\\(4\\)\\(5\\)
\\(5\\)\\(7\\)
\\(6\\)\\(11\\)
\\(7\\)\\(15\\)
\\(8\\)\\(22\\)
\\(9\\)\\(30\\)
\\(10\\)\\(42\\)
\\(11\\)\\(56\\)
\\(12\\)\\(77\\)
\\(13\\)\\(101\\)
\\(14\\)\\(135\\)
\\(15\\)\\(176\\)
\\(16\\)\\(231\\)
\\(17\\)\\(297\\)
\\(18\\)\\(385\\)
\\(19\\)\\(490\\)
\\(20\\)\\(627\\)
\\(21\\)\\(792\\)
\\(22\\)\\(1002\\)
\\(23\\)\\(1255\\)
\\(24\\)\\(1575\\)
\\(25\\)\\(1958\\)
\\(26\\)\\(2436\\)
\\(27\\)\\(3010\\)
\\(28\\)\\(3718\\)
\\(29\\)\\(4565\\)
\\(30\\)\\(5604\\)
\\(31\\)\\(6842\\)
\\(32\\)\\(8349\\)
\\(33\\)\\(10143\\)
\\(34\\)\\(12310\\)
\\(35\\)\\(14883\\)
\\(36\\)\\(17977\\)
\\(37\\)\\(21637\\)
\\(38\\)\\(26015\\)
\\(39\\)\\(31185\\)
\\(40\\)\\(37338\\)
\\(41\\)\\(44583\\)
\\(42\\)\\(53174\\)
\\(43\\)\\(63261\\)
\\(44\\)\\(75175\\)
\\(45\\)\\(89134\\)
\\(46\\)\\(105558\\)
\\(47\\)\\(124754\\)
\\(48\\)\\(147273\\)
\\(49\\)\\(173525\\)
\\(50\\)\\(204226\\)
\n", "
" ], "text/plain": [ " $n$ $p(n)$\n", "├──────┼──────────┤\n", " $0$ $1$\n", " $1$ $1$\n", " $2$ $2$\n", " $3$ $3$\n", " $4$ $5$\n", " $5$ $7$\n", " $6$ $11$\n", " $7$ $15$\n", " $8$ $22$\n", " $9$ $30$\n", " $10$ $42$\n", " $11$ $56$\n", " $12$ $77$\n", " $13$ $101$\n", " $14$ $135$\n", " $15$ $176$\n", " $16$ $231$\n", " $17$ $297$\n", " $18$ $385$\n", " $19$ $490$\n", " $20$ $627$\n", " $21$ $792$\n", " $22$ $1002$\n", " $23$ $1255$\n", " $24$ $1575$\n", " $25$ $1958$\n", " $26$ $2436$\n", " $27$ $3010$\n", " $28$ $3718$\n", " $29$ $4565$\n", " $30$ $5604$\n", " $31$ $6842$\n", " $32$ $8349$\n", " $33$ $10143$\n", " $34$ $12310$\n", " $35$ $14883$\n", " $36$ $17977$\n", " $37$ $21637$\n", " $38$ $26015$\n", " $39$ $31185$\n", " $40$ $37338$\n", " $41$ $44583$\n", " $42$ $53174$\n", " $43$ $63261$\n", " $44$ $75175$\n", " $45$ $89134$\n", " $46$ $105558$\n", " $47$ $124754$\n", " $48$ $147273$\n", " $49$ $173525$\n", " $50$ $204226$" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table(\n", " [[f\"${latex(k)}$\", f\"${latex(number_of_partitions(k))}$\"] for k in [0..50]],\n", " header_row=[r\"$n$\", r\"$p(n)$\"]\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sage has built-in capabilities to compute partitions. There are two classes for integer partitions in Sage, namely *Partition* and *Partitions*. The former takes a list of non-increasing integers representing a partition of a given integer as an argument, while the latter takes a positive integer. We will be working with the *Partitions* class. But let us take a look at the difference between these two classes.\n", "\n", "The class *Partition*, with a list of non-increasing integers as its argument, instantiates a fixed partition object with the given input list. For example:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[3, 2, 1, 1, 1]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a_fixed_partition_of_eight_object = Partition([3, 2, 1, 1, 1]); a_fixed_partition_of_eight_object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "But the class *Partitions*, with an integer as its argument, instantiates a domain containing all the partitions of $n$. For example, we can create a domain for all the partitions of an integer, say, $8$." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Partitions of the integer 8" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_partitions_of_eight = Partitions(8); all_partitions_of_eight" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Can you create all partitions of $5$?" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Partitions of the integer 5" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_partitions_of_5 = Partitions(5); all_partitions_of_5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With the `list` method, I can list all the partitions of $8$ by doing the following:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "all_partitions_of_eight." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[8]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "one_part = all_partitions_of_eight.list()[0]; one_part" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "([8], [8])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "one_part_list = list(one_part); one_part_list, one_part" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "one_part_list." ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_partitions_of_5.list()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "List all partitions of $5$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Spend some time reading the SAGE documentation on *Partitions*. Get familiar with the syntax and read the remaining part of the notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Partitions?" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "partitions_of_5 = Partitions(5)\n", "partitions_of_5.list()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Questions to Explore \n", "\n", "Let us list some questions that we can explore." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The number of partitions of the integer $n$ whose largest part is $k$ is equal to the number of partitions of $n$ with exactly $k$ parts." ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "from functools import partial\n", "\n", "def is_greater(p, k):\n", " return k >= p\n", "\n", "k = 3\n", "new_function = partial(is_greater, k=k)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[3, 2], [3, 1, 1]]" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[partition for partition in partitions_of_5.list() if k in partition and all(map(new_function, partition)) ]" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[3, 1, 1], [2, 2, 1]]" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[partition for partition in partitions_of_5.list() if len(partition) == k]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exploration 2 \n", "\n", "The question to explore is: \n", "\n", " * _Partitions of $n$ using only _odd_ parts. This is notated $p(n \\mid \\text{ odd parts })$._\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exploration 3 \n", "\n", "The question to explore is: \n", "\n", " * _Partitions of $n$ using only even parts, or $p(n \\mid \\text{ even parts })$._\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Exploration 4 \n", "\n", "The question to explore is: \n", "\n", " * _Partitions of $n$ using _distinct_ parts; that is, all the numbers in the partition are different._\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Try these out for small (!) $n$. See if you find any possible patterns. Again, it is probably best if some larger groups work together and split up the work to make it more efficient." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 10.4", "language": "sage", "name": "sagemath" }, "language": "python", "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" }, "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": 4 }