[{"id":247457,"date":"2026-07-27T11:03:44","date_gmt":"2026-07-27T16:03:44","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247457"},"modified":"2026-07-27T11:13:29","modified_gmt":"2026-07-27T16:13:29","slug":"counting-permutations-with-roots","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/","title":{"rendered":"Counting permutations with roots"},"content":{"rendered":"<p>My post from <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/\">yesterday<\/a> on permutation roots ends with a Mathematica code for finding the probability that a permutation of <em>n<\/em> elements has a <em>k<\/em>th root. This is done by finding the coefficient of <em>x<\/em><sup><em>n<\/em><\/sup> in the generating function<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/expq11.svg\" alt=\"\\prod_{m=1}^\\infty \\exp_{\\text{gcd}(m, k)} \\left\\frac{x^m}{m}\\right)\" width=\"162\" height=\"54\" \/><\/p>\n<p>I wanted to say more about this, and look at implementing the same code in SymPy. I was curious how well SymPy would do because I&#8217;ve noticed that LLMs often generate SymPy code since it&#8217;s an open source <abbr title=\"computer algebra system\">CAS<\/abbr>.<\/p>\n<p>Wilf [1] describes the infinite product above as the exponential generating function (egf) of <em>f<\/em>(<em>n<\/em>, <em>k<\/em>), the number of permutations of <em>n<\/em> objects that have a <em>k<\/em>th root. Since egfs have a <em>n<\/em>! term in the denominator, this is also the ordinary generating function (ogf) of the <em>probability<\/em> that a randomly chosen permutation on <em>n<\/em> objects has a <em>k<\/em>th root.<\/p>\n<p>My first attempt at using Mathematica to probe the generating function was<\/p>\n<pre>expq[x_, q_] := MittagLefflerE[q, x^q]\t \r\np[n_, k_] :=  SeriesCoefficient[\t \r\n    Product[expq[x^m\/m, GCD[m, k]], {m, 1, Infinity}], {x, 0, n}]\r\n<\/pre>\n<p>This hung forever when I tried to use it on a small example. I realized, but apparently Mathematica did not, that <code>Infinity<\/code> could be replaced by <code>n<\/code> since terms higher than <em>n<\/em> do not contribute to the coefficient of <em>x<\/em><sup><em>n<\/em><\/sup>. With that change, the code ran quickly.<\/p>\n<p>This morning I tried converting the Mathematica code to Sympy; Claude did this in one shot. I also reproduced the table of <em>f<\/em>(<em>n<\/em>, <em>k<\/em>) values on page 150 of [1] to test the code. Since Wilf tabulated <em>f<\/em>(<em>n<\/em>, <em>k<\/em>), not <em>f<\/em>(<em>n<\/em>, <em>k<\/em>)\/<em>n<\/em>!, I multiplied the results by <em>n<\/em>!.<\/p>\n<p>Here is the output:<\/p>\n<pre>k = 2 [1, 1, 3, 12, 60, 270, 1890, 14280, 128520, 1096200]\r\nk = 3 [1, 2, 4, 16, 80, 400, 2800, 22400, 181440, 1814400]\r\nk = 4 [1, 1, 3, 12, 60, 270, 1890, 13020, 117180, 1039500]\r\nk = 5 [1, 2, 6, 24, 96, 576, 4032, 32256, 290304, 2612736]\r\nk = 6 [1, 1, 1, 4, 40, 190, 1330, 8680, 52920, 340200]\r\nk = 7 [1, 2, 6, 24, 120, 720, 4320, 34560, 311040, 3110400]\r\n<\/pre>\n<p>and here is the SymPy code. I edited the main but the rest is verbatim from Claude.<\/p>\n<pre>from sympy import symbols, gcd, factorial, Rational, S\r\n\r\nx = symbols('x')\r\n\r\ndef expq_coeffs(m, q, n):\r\n    \"\"\"\r\n    Truncated (degree &lt;= n) series coefficients of\r\n        expq(x**m\/m, q) = MittagLefflerE(q, (x**m\/m)**q)\r\n    Since q is a positive integer:\r\n        E_q(y^q) = sum_j y^(q*j) \/ (q*j)!\r\n    with y = x**m\/m, so the term of degree m*q*j has coefficient\r\n        1 \/ ( m**(q*j) * (q*j)! ).\r\n    Returns a list c[0..n] of coefficients.\r\n    \"\"\"\r\n    c = [S.Zero] * (n + 1)\r\n    j = 0\r\n    while m * q * j &lt;= n:\r\n        deg = m * q * j\r\n        c[deg] += Rational(1, m**(q * j) * factorial(q * j))\r\n        j += 1\r\n    return c\r\n\r\ndef poly_mult_trunc(a, b, n):\r\n    \"\"\"Multiply two series (lists of coeffs, index = degree) truncated to degree n.\"\"\"\r\n    c = [S.Zero] * (n + 1)\r\n    for i, ai in enumerate(a):\r\n        if ai == 0:\r\n            continue\r\n        max_j = n - i\r\n        for j2 in range(max_j + 1):\r\n            bj = b[j2]\r\n            if bj != 0:\r\n                c[i + j2] += ai * bj\r\n    return c\r\n\r\ndef p(n, k):\r\n    \"\"\"\r\n    SymPy equivalent of:\r\n        expq[x_, q_] := MittagLefflerE[q, x^q]\r\n        p[n_, k_] := SeriesCoefficient[\r\n            Product[expq[x^m\/m, GCD[m, k]], {m, 1, n}], {x, 0, n}]\r\n    \"\"\"\r\n    result = [S.Zero] * (n + 1)\r\n    result[0] = S.One\r\n    for m in range(1, n + 1):\r\n        q = gcd(m, k)\r\n        factor = expq_coeffs(m, q, n)\r\n        result = poly_mult_trunc(result, factor, n)\r\n    return result[n]\r\n\r\n# example\r\nif __name__ == \"__main__\":\r\n    for k in range(2, 8):\r\n        print(\"k =\", k, [factorial(n)*p(n, k) for n in range(1,11)])\r\n<\/pre>\n<p>[1] Herbert Wilf. Generatingfunctionology. Available online <a href=\"https:\/\/www2.math.upenn.edu\/~wilf\/DownldGF.html\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My post from yesterday on permutation roots ends with a Mathematica code for finding the probability that a permutation of n elements has a kth root. This is done by finding the coefficient of xn in the generating function I wanted to say more about this, and look at implementing the same code in SymPy. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[197,87,142],"class_list":["post-247457","post","type-post","status-publish","format-standard","hentry","category-math","tag-combinatorics","tag-mathematica","tag-sympy"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"combinatorics,mathematica,sympy\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Counting permutations with roots\" \/>\n\t\t<meta property=\"og:description\" content=\"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-27T16:03:44+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-27T16:13:29+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Counting permutations with roots\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Counting permutations with roots","description":"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/","robots":"max-image-preview:large","keywords":"combinatorics,mathematica,sympy","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Counting permutations with roots","og:description":"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/","article:published_time":"2026-07-27T16:03:44+00:00","article:modified_time":"2026-07-27T16:13:29+00:00","twitter:card":"summary","twitter:title":"Counting permutations with roots","twitter:description":"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247457","title":null,"description":"Counting permutations that have kth roots. A trick to make Mathematica work and porting the code to SymPy.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-27 15:38:01","updated":"2026-07-27 16:13:29","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCounting permutations with roots\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"Counting permutations with roots","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/counting-permutations-with-roots\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247457"}],"version-history":[{"count":2,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247457\/revisions"}],"predecessor-version":[{"id":247461,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247457\/revisions\/247461"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247449,"date":"2026-07-27T10:34:05","date_gmt":"2026-07-27T15:34:05","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247449"},"modified":"2026-07-27T15:35:18","modified_gmt":"2026-07-27T20:35:18","slug":"float-binary","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/","title":{"rendered":"Printing floating point numbers in binary"},"content":{"rendered":"<p>It&#8217;s well known that you can convert the base 16 (hex) representation of an integer to the base 2 (binary) representation by simply converting each digit from hex to binary. For example,<\/p>\n<p style=\"padding-left: 40px;\">CAFE<sub>hex<\/sub> = 1100 1010 1111 1110<sub>two<\/sub><\/p>\n<p>I imagine it&#8217;s less well known that you can do the same thing with floating point numbers.<\/p>\n<p>I wanted to find the binary representation of a floating point number using Python, and discovered that it has no function to do this. However, there is a method on floats to show a hex representation. For example, here&#8217;s the hex representation of \u03c0.<\/p>\n<pre>&gt;&gt;&gt; import math\r\n&gt;&gt;&gt; (math.pi).hex()\r\n'0x1.921fb54442d18p+1'\r\n<\/pre>\n<p>Curiously, the p+<em>k<\/em> part at the end is an exponent of 2, not an exponent of 16. So after we convert 1.921fb54442d18 to binary, we&#8217;ll need to multiply by 2, i.e. move the fractional point one space to the right.<\/p>\n<p>So first we convert 1.921fb54442d18<sub>hex<\/sub> to binary by converting 1, 9, 2, etc. each to binary.<\/p>\n<p style=\"padding-left: 40px;\">1.1001 0010 0001 1111 1011 0101 0100 0100 0100 0010 1101 0001 1000<sub>two<\/sub><\/p>\n<p>Then after shifting the fraction point to account for the <code>p+1<\/code> part we have<\/p>\n<p style=\"padding-left: 40px;\">\u03c0 = 11.001001000011111101101010100010001000010110100011000<sub>two<\/sub><\/p>\n<p>You could use Python&#8217;s bin() function to convert the fractional part, interpreted as an integer, to hex, though you may need to pad with 0 bits. For example,<\/p>\n<pre>&gt;&gt;&gt; (1.03).hex()\r\n'0x1.07ae147ae147bp+0\r\n\r\n&gt;&gt;&gt; bin(0x7ae147ae147)\r\n'0b1111010111000010100011110101110000101000111'\r\n<\/pre>\n<p>The binary representation of 1.03<sub>ten<\/sub> is<\/p>\n<p style=\"padding-left: 40px;\">1.000001111010111000010100011110101110000101000111<sub>two<\/sub><\/p>\n<p>We added a total of five zero bits, four for the 0 after the fractional point and one for converting 7 to 0111<sub>two<\/sub>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s well known that you can convert the base 16 (hex) representation of an integer to the base 2 (binary) representation by simply converting each digit from hex to binary. For example, CAFEhex = 1100 1010 1111 1110two I imagine it&#8217;s less well known that you can do the same thing with floating point numbers. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5,9],"tags":[271],"class_list":["post-247449","post","type-post","status-publish","format-standard","hentry","category-computing","category-math","tag-number-systems"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"number systems\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Printing floating point numbers in binary\" \/>\n\t\t<meta property=\"og:description\" content=\"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-27T15:34:05+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-27T20:35:18+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Printing floating point numbers in binary\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Printing floating point numbers in binary","description":"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/","robots":"max-image-preview:large","keywords":"number systems","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Printing floating point numbers in binary","og:description":"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/","article:published_time":"2026-07-27T15:34:05+00:00","article:modified_time":"2026-07-27T20:35:18+00:00","twitter:card":"summary","twitter:title":"Printing floating point numbers in binary","twitter:description":"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247449","title":null,"description":"Python has no method to show floating point numbers in binary, but it does have a method for showing them in hex. How to make the former out of the latter.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-27 00:05:27","updated":"2026-07-27 20:35:18","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/computing\/\" title=\"Computing\">Computing<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPrinting floating point numbers in binary\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Computing","link":"https:\/\/www.johndcook.com\/blog\/category\/computing\/"},{"label":"Printing floating point numbers in binary","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/27\/float-binary\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247449"}],"version-history":[{"count":7,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247449\/revisions"}],"predecessor-version":[{"id":247463,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247449\/revisions\/247463"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247440,"date":"2026-07-26T15:32:02","date_gmt":"2026-07-26T20:32:02","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247440"},"modified":"2026-07-27T10:45:23","modified_gmt":"2026-07-27T15:45:23","slug":"permutation-roots","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/","title":{"rendered":"Permutation roots"},"content":{"rendered":"<p>Let \u03c3 be a permutation on <em>n<\/em> elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3.<\/p>\n<p>If we let our <em>n<\/em> elements be the integers 0 through <em>n<\/em> \u2212 1, then we can represent permutations by what they do to this list of numbers. In Python as a tuple of length <em>n<\/em> and compose permutations with the following function:<\/p>\n<pre>import itertools\r\n\r\ndef compose(sigma, tau):\r\n    \"Return the composition \u03c3 \u2218 \u03c4 (apply \u03c4 first, then \u03c3).\"\r\n    return tuple(sigma[j] for j in tau)\r\n<\/pre>\n<p>We can always construct permutations that have square roots by squaring a permutation. If we run the following code<\/p>\n<pre>tau = (3, 1, 4, 5, 2, 0)\r\nsigma = compose(tau, tau)\r\n<\/pre>\n<p>we find \u03c3 = (5, 1, 2, 0, 4, 3), and by construction (3, 1, 4, 5, 2, 0) is a square root of &amp;sigma, though it&#8217;s not the only one.<\/p>\n<p>The following code shows that \u03c3 has four roots.<\/p>\n<pre>import itertools\r\n\r\ndef numroots(sigma):\r\n    n = len(sigma)\r\n    c = 0\r\n    for tau in itertools.permutations(range(n)):\r\n        if sigma == compose(tau, tau):\r\n            c += 1\r\n    return c\r\n\r\nprint( numroots(sigma) )\r\nprint( numroots( (1, 2, 3, 4, 5, 0) ) )\r\n<\/pre>\n<p>It also shows that the rotation (1, 2, 3, 4, 5. 0) has no roots.<\/p>\n<p>The function <code>numroots<\/code> has runtime proportional to <em>n<\/em>! and so it&#8217;s not practical for large permutations. There is a theorem that says a permutation \u03c3 has a square root if and only if the number of cycles it has of every even length is even. See [1].<\/p>\n<p>We can also define cubes and cube roots of permutations, and higher powers and roots.<\/p>\n<p>How common is it for permutations to have square roots, or cube roots, etc.? If you pick a random permutation on <em>n<\/em> elements, what is the probability that it has a <em>k<\/em>th root?<\/p>\n<p>This is a hard question in general, but it is equivalent to finding the coefficient of <em>x<\/em><sup><em>k<\/em><\/sup> in the infinite product<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/expq11.svg\" alt=\"\\prod_{m=1}^\\infty \\exp_{\\text{gcd}(m, k)} \\left(\\frac{x^m}{m}\\right)\" width=\"162\" height=\"54\" \/><\/p>\n<p>This is theorem 4.8.3 in [1]. This theorem was the motivation for writing about exp<sub><em>q<\/em><\/sub> in the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/\">previous post<\/a>.<\/p>\n<p>Although the product is infinite, there&#8217;s no need to compute terms in the product that only contribute powers of <em>x<\/em> higher than you&#8217;re interested in. The following Mathematica code will compute the probability that a permutation on <em>n<\/em> elements has a <em>k<\/em>th root.<\/p>\n<pre>expq[x_, q_] := MittagLefflerE[q, x^q]\t \r\np[n_, k_] :=  SeriesCoefficient[\t \r\n    Product[expq[x^m\/m, GCD[m, k]], {m, 1, n}], {x, 0, n}]\r\n<\/pre>\n<p>So, for example, the probability that a permutation of 10 elements has a square root is 29\/96.<\/p>\n<p>[1] Herbert Wilf. Generatingfunctionology. Available online <a href=\"https:\/\/www2.math.upenn.edu\/~wilf\/DownldGF.html\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-247440","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Permutation roots\" \/>\n\t\t<meta property=\"og:description\" content=\"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-26T20:32:02+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-27T15:45:23+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Permutation roots\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Permutation roots","description":"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Permutation roots","og:description":"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/","article:published_time":"2026-07-26T20:32:02+00:00","article:modified_time":"2026-07-27T15:45:23+00:00","twitter:card":"summary","twitter:title":"Permutation roots","twitter:description":"Let \u03c3 be a permutation on n elements. If there is a permutation \u03c4 such that applying \u03c4 twice has the same effect on the list of elements as applying \u03c3 once, we say \u03c3 = \u03c4\u00b2 and \u03c4 is a square root of \u03c3. If we let our n elements be the integers 0","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247440","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-26 19:13:37","updated":"2026-07-27 15:45:23","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/uncategorized\/\" title=\"Uncategorized\">Uncategorized<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPermutation roots\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Uncategorized","link":"https:\/\/www.johndcook.com\/blog\/category\/uncategorized\/"},{"label":"Permutation roots","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247440"}],"version-history":[{"count":8,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247440\/revisions"}],"predecessor-version":[{"id":247459,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247440\/revisions\/247459"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247432,"date":"2026-07-26T13:20:36","date_gmt":"2026-07-26T18:20:36","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247432"},"modified":"2026-07-26T15:32:54","modified_gmt":"2026-07-26T20:32:54","slug":"exp-q","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/","title":{"rendered":"exp_q"},"content":{"rendered":"<p>The function exp<sub><em>q<\/em><\/sub>(<em>x<\/em>) is defined by taking the power series for exp(<em>x<\/em>) and keeping only the terms whose index is a multiple of <em>q<\/em>. For example, exp<sub>2<\/sub>(<em>x<\/em>) keeps only the even-numbered terms in the exponential power series and so equals cosh(<em>x<\/em>).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expqx.svg\" alt=\"\\exp_2(x) = 1 + \\frac{x^2}{2!} + \\frac{x^4}{4!} + \\frac{x^6}{6!} + \\cdots = \\cosh(x)\" width=\"359\" height=\"44\" \/><\/p>\n<p>In general,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq2.svg\" alt=\"\\exp_q(x) = \\sum_{n=0}^\\infty [q \\mid n] \\frac{x^n}{n!} = \\sum_{n=0}^\\infty \\frac{x^{nq}}{(nq)!}\" width=\"285\" height=\"54\" \/><\/p>\n<p>The first sum uses <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/07\/01\/activation-functions\/\">Iverson&#8217;s bracket notation<\/a>: a Boolean expression in brackets denotes the function that returns 1 when the expression is true and zero when it is false. Here the bracket equals 1 when <em>q<\/em> divides <em>n<\/em> and is zero otherwise.<\/p>\n<h2>Closed forms<\/h2>\n<p>Let \u03c9 = exp(2\u03c0<em>i<\/em> \/ <em>q<\/em>). Then<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq3.svg\" alt=\"\\exp_q(x) = \\frac{1}{q}\\sum_{k=0}^{q-1} \\exp(\\omega^k x)\" width=\"209\" height=\"60\" \/><\/p>\n<p>This lets us find closed-form expressions for exp<sub><em>q<\/em><\/sub>(<em>x<\/em>). For example, when <em>q<\/em> = 4, \u03c9 = <em>i<\/em> and<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq4.svg\" alt=\"\\exp_4(x) = \\frac{1}{2}\\left( \\cosh(x) + \\cos(x) \\right)\" width=\"257\" height=\"40\" \/><\/p>\n<p>Here&#8217;s a proof of the identity above:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq5.svg\" alt=\"\\begin{align*} \\frac{1}{q} \\sum_{k=0}^{q-1} \\exp(\\omega^k x) &amp;= \\frac{1}{q} \\sum_{k=0}^{q-1} \\sum_{n=0}^\\infty \\frac{\\omega^{kn}x^n}{n!} \\\\ &amp;= \\sum_{n=0}^\\infty \\left( \\frac{1}{q} \\sum_{k=0}^{q-1} \\omega^{kn}\\right) \\frac{x^n}{n!} \\\\ &amp;= \\sum_{n=0}^\\infty [q \\mid n] \\frac{x^n}{n!} \\\\ &amp;= \\exp_q(x) \\end{align*} \" width=\"296\" height=\"230\" \/><\/p>\n<p>In the proof we used the identity<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq6.svg\" alt=\"\\frac{1}{q} \\sum_{k=0}^{q-1} \\omega^{kn} = [q \\mid n]\" width=\"150\" height=\"60\" \/><\/p>\n<p>which is important in deriving the properties of the discrete Fourier transform.<\/p>\n<h2>Differential equations<\/h2>\n<p>The first time I saw the function exp<sub><em>q<\/em><\/sub>(<em>x<\/em>) was in differential equations, though I didn&#8217;t know at the time the function had a name.<\/p>\n<p>When a course in differential equations gets to power series solutions, a common example or homework problem is to solve<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq7.svg\" alt=\"y^{(k)}(x) = y(x)\" width=\"117\" height=\"23\" \/><\/p>\n<p>for <em>k<\/em> = 3 or 4, i.e. to find a function that equals its third or fourth derivative.<\/p>\n<p>If the initial conditions are<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq8.svg\" alt=\"y(0) = 0\" width=\"70\" height=\"18\" \/><\/p>\n<p>and<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq9.svg\" alt=\"y^\\prime(0) = y^{\\prime\\prime}(0) = \\cdots = y^{(k-1)}(0) = 0\" width=\"285\" height=\"23\" \/><\/p>\n<p>the unique solution to<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/expq7.svg\" alt=\"y^{(k)}(x) = y(x)\" width=\"117\" height=\"23\" \/><\/p>\n<p>is <em>y<\/em>(<em>x<\/em>) = exp<sub><em>k<\/em><\/sub>(<em>x<\/em>).<\/p>\n<h2>Mathematica and Mittag-Leffler<\/h2>\n<p>Mathematica does not have a built-in function implementing exp<sub><em>q<\/em><\/sub>(<em>x<\/em>), but it does have an implementation of the <a href=\"https:\/\/www.johndcook.com\/blog\/2016\/07\/17\/mittag-leffler-function-and-probability-distribution\/\">Mittag-Leffler function<\/a>, and so thanks to a relation between this function and exp<sub><em>q<\/em><\/sub>(<em>x<\/em>) you can implement the latter as<\/p>\n<pre>expq[x_, q_] := MittagLefflerE[q, x^q]<\/pre>\n<h2>Combinatorics<\/h2>\n<p>The first time I saw the <em>notation<\/em> exp<sub><em>q<\/em><\/sub>(<em>x<\/em>) was in combinatorics. I had intended to include an application from that book here, but I make that the topic for the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/permutation-roots\/\">next post<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The function expq(x) is defined by taking the power series for exp(x) and keeping only the terms whose index is a multiple of q. For example, exp2(x) keeps only the even-numbered terms in the exponential power series and so equals cosh(x). In general, The first sum uses Iverson&#8217;s bracket notation: a Boolean expression in brackets [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[47,129],"class_list":["post-247432","post","type-post","status-publish","format-standard","hentry","category-math","tag-differential-equations","tag-special-functions"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"differential equations,special functions\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"exp_q(x) keeps every qth term in the power series for exp(x)\" \/>\n\t\t<meta property=\"og:description\" content=\"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-26T18:20:36+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-26T20:32:54+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"exp_q(x) keeps every qth term in the power series for exp(x)\" \/>\n\t\t<meta name=\"twitter:description\" content=\"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"exp_q(x) keeps every qth term in the power series for exp(x)","description":"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/","robots":"max-image-preview:large","keywords":"differential equations,special functions","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"exp_q(x) keeps every qth term in the power series for exp(x)","og:description":"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/","article:published_time":"2026-07-26T18:20:36+00:00","article:modified_time":"2026-07-26T20:32:54+00:00","twitter:card":"summary","twitter:title":"exp_q(x) keeps every qth term in the power series for exp(x)","twitter:description":"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247432","title":"exp_q(x) keeps every qth term in the power series for exp(x)","description":"The function exp_q(x) is a generalization of the exponential function. It comes up in numerous applications, such as differential equations and combinatorics.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-26 16:38:25","updated":"2026-07-26 20:32:54","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\texp_q\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"exp_q","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/26\/exp-q\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247432"}],"version-history":[{"count":9,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247432\/revisions"}],"predecessor-version":[{"id":247446,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247432\/revisions\/247446"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247423,"date":"2026-07-25T08:37:30","date_gmt":"2026-07-25T13:37:30","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247423"},"modified":"2026-07-26T08:05:57","modified_gmt":"2026-07-26T13:05:57","slug":"excel-column-numbering","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/","title":{"rendered":"Excel column numbering"},"content":{"rendered":"<p>I was working with a wide spreadsheet from a client the other day and I had to convert between Excel column labels and column numbers. I had never paid attention to how Excel labels columns and implicitly thought it was base 26 using letters rather than digits. But then I realized that&#8217;s not right.<\/p>\n<p>Excel labels columns A through Z, then AA through AZ, then BA through BZ, etc. If this is base 26, then does A correspond to 0? That could work for A through Z, but then what about AA? Then you&#8217;d have to say the first A corresponds to 26 but the second A corresponds to 0.<\/p>\n<p>Does Z correspond to 0? If so then the column numbers would be 1 through 25, followed by 0, then 27. And it would mean that columns ZA through ZZ are the same as A through Z.<\/p>\n<p>In fact nothing in Excel column labeling corresponds to 0. The labels cannot be interpreted as a positional number system.<\/p>\n<p>There&#8217;s a name for this kind of number system: <strong>bijective base 26<\/strong>. The concept extends generally to bijective base\u00a0<em>b<\/em> for any positive integer\u00a0<em>b<\/em>. The idea is ancient, but the name was coined recently. It has also been called <em>k<\/em>-adic numbering. For most of history it didn&#8217;t have a name.<\/p>\n<p>The motivation behind the name bijective base\u00a0<em>b<\/em> is that there is a bijection (a one-to-one correspondence) between these symbols and positive integers; there&#8217;s no possibility of leading zeros that would keep the mapping from being a bijection, unlike say 7 and 07 representing the same number.<\/p>\n<h2>Excel limits<\/h2>\n<p>Before 2007, an Excel file could have a maximum of 2<sup>8<\/sup> = 256 columns, and so the largest column label was IV.<\/p>\n<p>Then in 2007 the column limit was increased to 2<sup>14<\/sup> = 16,384 and the largest column label is XFD.<\/p>\n<h2>Conversion code<\/h2>\n<p>Converting from column labels to integers is easy; going the other way is a little more complicated.<\/p>\n<pre>letter_to_ordinal = lambda c: ord(c) - ord('A') + 1\r\nordinal_to_letter = lambda n: chr(ord('A') + n - 1)\r\n\r\ndef label_to_num(label):\r\n    label = label.upper()\r\n    n = 0\r\n    for c in label:\r\n        n = n*26 + letter_to_ordinal(c)\r\n    return n\r\n\r\ndef num_to_label(n):\r\n    letters = []\r\n    while n &gt; 0:\r\n        n, remainder = divmod(n - 1, 26)\r\n        letters.append(ordinal_to_letter(remainder + 1))\r\n    return ''.join(reversed(letters))\r\n<\/pre>\n<p>Here&#8217;s an <a href=\"https:\/\/www.johndcook.com\/excel_labels.html\">online calculator<\/a> based on the code above.<\/p>\n<h2>Tests<\/h2>\n<p>The following code verifies the assertions above about the maximum number of Excel columns over time.<\/p>\n<pre>assert(num_to_label(256) == \"IV\")\r\nassert(label_to_num(\"IV\") == 256)\r\n\r\nassert(num_to_label(2**14) == \"XFD\")\r\nassert(label_to_num(\"XFD\") == 2**14)\r\n<\/pre>\n<p>The conversion routines are not limited to actual Excel labels but work for arbitrarily large integers and bijective base 26 representations. For example, the following code shows that the bijective base 26 representation of Avogadro&#8217;s number is MUAEKAUDYDXEWOSDD.<\/p>\n<pre>avogadro = 602_214_076_000_000_000_000_000\r\nassert(label_to_num(num_to_label(avogadro)) == avogadro)\r\nprint(num_to_label(avogadro))\r\n<\/pre>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/radix_conversion.html\">Radix conversion calclator<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2020\/03\/16\/round-trip-radix-conversion\/\">When is floating point radix conversion exact?<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2019\/09\/07\/excel-r-bom\/\">Excel, R, and Unicode<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I was working with a wide spreadsheet from a client the other day and I had to convert between Excel column labels and column numbers. I had never paid attention to how Excel labels columns and implicitly thought it was base 26 using letters rather than digits. But then I realized that&#8217;s not right. Excel [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[271],"class_list":["post-247423","post","type-post","status-publish","format-standard","hentry","category-math","tag-number-systems"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"number systems\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Excel column numbering\" \/>\n\t\t<meta property=\"og:description\" content=\"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-25T13:37:30+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-26T13:05:57+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Excel column numbering\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Excel column numbering","description":"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/","robots":"max-image-preview:large","keywords":"number systems","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Excel column numbering","og:description":"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/","article:published_time":"2026-07-25T13:37:30+00:00","article:modified_time":"2026-07-26T13:05:57+00:00","twitter:card":"summary","twitter:title":"Excel column numbering","twitter:description":"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247423","title":null,"description":"Excel labels are sort like base 26 numbers, but not really. What kind of numbers are they? How do you convert between column labels and column numbers?","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-25 12:09:26","updated":"2026-07-26 19:13:30","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tExcel column numbering\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"Excel column numbering","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/25\/excel-column-numbering\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247423"}],"version-history":[{"count":6,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247423\/revisions"}],"predecessor-version":[{"id":247431,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247423\/revisions\/247431"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247418,"date":"2026-07-23T09:04:34","date_gmt":"2026-07-23T14:04:34","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247418"},"modified":"2026-07-23T12:27:59","modified_gmt":"2026-07-23T17:27:59","slug":"an-almost-periodic-function","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/","title":{"rendered":"An almost periodic function"},"content":{"rendered":"<p>This post takes a more abstract view of the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/\">previous post<\/a>. That post looked at the concrete question of whether a number ever has the same sine in radians as in degrees. The relation between radians and degrees is irrelevant except that \u03c0\/180 is an irrational number.<\/p>\n<p>Suppose \u03b1 and \u03b2 are two positive numbers such that \u03b1\/\u03b2 is irrational. In the previous post, \u03b1 = 1 and \u03b2 = \u03c0\/180. Then the function<\/p>\n<p style=\"padding-left: 40px;\"><em>f<\/em>(<em>x<\/em>) = sin(\u03b1<em>x<\/em>) \u2212 sin(\u03b2<em>x<\/em>)<\/p>\n<p>is almost periodic: it is not periodic, but it comes close to being periodic, as close as you&#8217;d like provided you&#8217;re willing to look over a sufficiently long range of <em>x<\/em>&#8216;s.<\/p>\n<p>The identity<\/p>\n<p style=\"padding-left: 40px;\">sin(\u03b1<em>x<\/em>) \u2212 sin(\u03b2<em>x<\/em>) = 2 cos((\u03b1 + \u03b2)<em>x<\/em>\/2) sin((\u03b1 \u2212 \u03b2)<em>x<\/em>\/2)<\/p>\n<p>shows that <em>f<\/em>(<em>x<\/em>) is the product of two periodic functions but is not periodic itself. The periods of the cosine and sine above never coincide because the ratio of their frequencies is irrational.<\/p>\n<p>The zeros of <em>f<\/em> are not periodic, though they can be divided into two subsequences that are periodic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post takes a more abstract view of the previous post. That post looked at the concrete question of whether a number ever has the same sine in radians as in degrees. The relation between radians and degrees is irrelevant except that \u03c0\/180 is an irrational number. Suppose \u03b1 and \u03b2 are two positive numbers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-247418","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"An abstract look at a concrete problem.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"An almost periodic function\" \/>\n\t\t<meta property=\"og:description\" content=\"An abstract look at a concrete problem.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-23T14:04:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-23T17:27:59+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"An almost periodic function\" \/>\n\t\t<meta name=\"twitter:description\" content=\"An abstract look at a concrete problem.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"An almost periodic function","description":"An abstract look at a concrete problem.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"An almost periodic function","og:description":"An abstract look at a concrete problem.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/","article:published_time":"2026-07-23T14:04:34+00:00","article:modified_time":"2026-07-23T17:27:59+00:00","twitter:card":"summary","twitter:title":"An almost periodic function","twitter:description":"An abstract look at a concrete problem.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247418","title":null,"description":"An abstract look at a concrete problem.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-23 13:53:27","updated":"2026-07-25 15:27:32","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAn almost periodic function\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"An almost periodic function","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/23\/an-almost-periodic-function\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247418"}],"version-history":[{"count":3,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247418\/revisions"}],"predecessor-version":[{"id":247421,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247418\/revisions\/247421"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247407,"date":"2026-07-22T07:17:11","date_gmt":"2026-07-22T12:17:11","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247407"},"modified":"2026-07-22T09:29:26","modified_gmt":"2026-07-22T14:29:26","slug":"degrees-radians","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/","title":{"rendered":"When sine of x degrees equals sine of x radians"},"content":{"rendered":"<p>Ordinarily the sine of <em>x<\/em> radians and the sine of <em>x<\/em> degrees are very different numbers. Having your calculator in radian mode when it should be in degree mode, or vice versa, results in a major error.<\/p>\n<p>But sometimes it doesn&#8217;t matter. A trivial example is when <em>x<\/em> = 0. A more interesting example is<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = 180\u03c0\/(180 + \u03c0) = 3.08770208\u2026.<\/p>\n<p>For that value of <em>x<\/em>,<\/p>\n<p style=\"padding-left: 40px;\">sin(<em>x<\/em>) = sin(<em>x<\/em>\u00b0).<\/p>\n<p>In this article I&#8217;ll use the common convention of using radians by default and denoting degrees with \u00b0 as above.<\/p>\n<p>Note that<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em><em>\u00a0= <\/em>\u03c0<em>x<\/em><em>\u00b0<\/em>\/180<\/p>\n<p>and so we are interested in solutions to the equation<\/p>\n<p style=\"padding-left: 40px;\">sin(<em>x<\/em>) = sin(\u03c0<em>x<\/em>\/180)<\/p>\n<p>Now two angles\u00a0<em>A<\/em> and\u00a0<em>B<\/em> have the same sine if they differ by a multiple of 2\u03c0, or if they&#8217;re supplementary (i.e. <em>A<\/em> = \u03c0 \u2212 <em>B<\/em>), or both. To put it another way, if\u00a0<em>A<\/em> and\u00a0<em>B<\/em> have the same sine, they are either equal mod 2\u03c0 or supplementary mod 2\u03c0. This means that<\/p>\n<p style=\"padding-left: 40px;\">sin(<em>x<\/em>) = sin(\u03c0<em>x<\/em>\/180)<\/p>\n<p>if and only if<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = \u03c0<em>x<\/em>\/180 + 2\u03c0<em>k<\/em><\/p>\n<p>or<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = \u03c0 \u2212 \u03c0<em>x<\/em>\/180 + 2\u03c0<em>k<\/em><\/p>\n<p>for some integer\u00a0<em>k<\/em>.<\/p>\n<p>Therefore all solutions have the form<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = 360\u03c0<em>k<\/em>\/(180 \u2212 \u03c0)<\/p>\n<p>or<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = 180\u03c0(2<em>k<\/em> + 1)\/(180 + \u03c0).<\/p>\n<h2>Alternative solution<\/h2>\n<p>The derivation above is correct, but it occurred to me later that a simpler argument would be to use the identity<\/p>\n<p style=\"padding-left: 40px;\">sin(<em>A<\/em>) \u2212 sin(<em>B<\/em>) = 2 cos((<em>A<\/em> +\u00a0<em>B<\/em>)\/2) sin((<em>A<\/em> \u2212 <em>B<\/em>)\/2).<\/p>\n<p>Thus <em>A<\/em> and\u00a0<em>B<\/em> have the same sine if<\/p>\n<p style=\"padding-left: 40px;\">cos((<em>A<\/em> +\u00a0<em>B<\/em>)\/2) = 0<\/p>\n<p>or if<\/p>\n<p style=\"padding-left: 40px;\">sin((<em>A<\/em> \u2212 <em>B<\/em>)\/2) = 0.<\/p>\n<p>These two possibilities correspond to the two families of solutions above.<\/p>\n<h2>Density<\/h2>\n<p>When reduced modulo 2\u03c0, both families are dense in [0, 2\u03c0]. This means that for every\u00a0<em>y<\/em> in [\u22121, 1], there is a number\u00a0<em>x<\/em> such that<\/p>\n<p style=\"padding-left: 40px;\">sin(<em>x<\/em>) = sin(<em>x<\/em>\u00b0) \u2248 <em>y<\/em><\/p>\n<p>and we can make the approximation as good as we&#8217;d like.<\/p>\n<h3>Example 1<\/h3>\n<p>For example, today is July 22, so let&#8217;s set\u00a0<em>y<\/em> = 0.722. We&#8217;d like to find a value of\u00a0<em>x<\/em> such that the sine of\u00a0<em>x<\/em> radians and the sine of <em>x<\/em> degrees both approximately equal 0.722. And let&#8217;s say our approximation tolerance is \u03b5 = 0.0001.<\/p>\n<p>We can search for a value of\u00a0<em>x<\/em> in the first family of solutions by looking for a value of\u00a0<em>k<\/em> with<\/p>\n<p style=\"padding-left: 40px;\">| sin(360\u03c0<em>k<\/em>\/(180 \u2212 \u03c0)) \u2212 0.722 | &lt; 0.0001<\/p>\n<p>and the smallest such\u00a0<em>k<\/em> is 96343 and so<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> = 360\u00d796343 \u03c0\/(180 \u2212 \u03c0) = 616093.78713621\u2026<\/p>\n<p>will do, and sin(<em>x<\/em>) = 0.72191\u2026<\/p>\n<h3>Example 2<\/h3>\n<p>Now let&#8217;s set\u00a0<em>y<\/em> = 0.2026 and look for a solution in the other family of solutions, and this time let&#8217;s set \u03b5 = 10<sup>\u22126<\/sup>. The smallest value of\u00a0<em>k<\/em> such that<\/p>\n<p style=\"padding-left: 40px;\">| sin(180\u03c0(2<em>k<\/em> + 1)\/(180 + \u03c0)) \u2212 0.2026 | &lt; 10<sup>\u22126<\/sup><\/p>\n<p>is\u00a0<em>k<\/em> = 741141. Then<\/p>\n<p style=\"padding-left: 40px;\">sin( 4576848.310950611 ) = sin( 4576848.310950611\u00b0 ) = 0.202600139\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ordinarily the sine of x radians and the sine of x degrees are very different numbers. Having your calculator in radian mode when it should be in degree mode, or vice versa, results in a major error. But sometimes it doesn&#8217;t matter. A trivial example is when x = 0. A more interesting example is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[94],"class_list":["post-247407","post","type-post","status-publish","format-standard","hentry","category-math","tag-number-theory"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"number theory\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"When sine of x degrees equals sine of x radians\" \/>\n\t\t<meta property=\"og:description\" content=\"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-22T12:17:11+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-22T14:29:26+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"When sine of x degrees equals sine of x radians\" \/>\n\t\t<meta name=\"twitter:description\" content=\"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"When sine of x degrees equals sine of x radians","description":"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/","robots":"max-image-preview:large","keywords":"number theory","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"When sine of x degrees equals sine of x radians","og:description":"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/","article:published_time":"2026-07-22T12:17:11+00:00","article:modified_time":"2026-07-22T14:29:26+00:00","twitter:card":"summary","twitter:title":"When sine of x degrees equals sine of x radians","twitter:description":"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247407","title":null,"description":"There are infinitely many values of x such that the sine of x degrees equals the sine of x radians. And for every \u22121 \u2264 y \u2264 1 there such an x with sin(x) \u2248 y.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-22 11:05:06","updated":"2026-07-22 21:49:00","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWhen sine of x degrees equals sine of x radians\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"When sine of x degrees equals sine of x radians","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/22\/degrees-radians\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247407"}],"version-history":[{"count":9,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247407\/revisions"}],"predecessor-version":[{"id":247416,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247407\/revisions\/247416"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247395,"date":"2026-07-21T10:05:04","date_gmt":"2026-07-21T15:05:04","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247395"},"modified":"2026-07-21T17:18:37","modified_gmt":"2026-07-21T22:18:37","slug":"forensic-accounting-in-python","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/","title":{"rendered":"Forensic accounting in Python"},"content":{"rendered":"<p>I recently had a project in which I had to reverse engineer a data analysis. There was some ambiguity regarding which of several possibilities someone chose for several of the variables, something analogous to the following example.<\/p>\n<p>Suppose you have three numbers with uncertain values with a known, or at least purported, sum. The first number could be 31, 41, or 59; the second could be either 26 or 53; the last could be 58, 97, 93, or 23.<\/p>\n<p>The following code enumerates all 3 &times; 2 &times; 4 = 24 possibilities and prints their sums.<\/p>\n<pre>\r\nfrom itertools import product\r\n\r\n# Example input\r\npossibilities = [(31, 41, 59), (26, 53), (58, 97, 93, 23)]\r\n\r\nfor combo in product(*possibilities):\r\n    total = sum(combo) \r\n    print(f\"Combination {combo} sums to: {total}\")\r\n<\/pre>\n<p>In this example all the sums are unique, though of course that might not happen in practice. If, for example, you know the sum is 187, you know the three numbers were 41, 53, and 93. If the reported sum is 200, you know some assumption has been violated because none of the possible choices add up to 200.<\/p>\n<h2>More forensics posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2009\/09\/18\/make-up-your-own-rules-of-probability\/'>Make up your own rules of probability<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2023\/04\/01\/identifiable-to-man-or-machine\/'>Identifiable to man or machine?<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2024\/02\/13\/photo-metadata\/'>Metadata in photos<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2026\/05\/05\/changing-one-character-in-a-pdf\/'>Changing one character in a PDF<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2018\/03\/02\/bits-of-information-in-age-birthday-and-birthdate\/'>Bits of information in age or birthday<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I recently had a project in which I had to reverse engineer a data analysis. There was some ambiguity regarding which of several possibilities someone chose for several of the variables, something analogous to the following example. Suppose you have three numbers with uncertain values with a known, or at least purported, sum. The first [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17],"tags":[],"class_list":["post-247395","post","type-post","status-publish","format-standard","hentry","category-statistics"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Forensic statistics in Python\" \/>\n\t\t<meta property=\"og:description\" content=\"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-21T15:05:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-21T22:18:37+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Forensic statistics in Python\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Forensic statistics in Python","description":"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Forensic statistics in Python","og:description":"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/","article:published_time":"2026-07-21T15:05:04+00:00","article:modified_time":"2026-07-21T22:18:37+00:00","twitter:card":"summary","twitter:title":"Forensic statistics in Python","twitter:description":"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247395","title":"Forensic statistics in Python","description":"Writing Python code to reverse engineer a data analysis, iterating over possibilities to try to make the numbers add up.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-21 02:37:46","updated":"2026-07-21 22:18:58","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/statistics\/\" title=\"Statistics\">Statistics<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tForensic accounting in Python\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Statistics","link":"https:\/\/www.johndcook.com\/blog\/category\/statistics\/"},{"label":"Forensic accounting in Python","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/forensic-accounting-in-python\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247395"}],"version-history":[{"count":6,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247395\/revisions"}],"predecessor-version":[{"id":247406,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247395\/revisions\/247406"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247398,"date":"2026-07-21T07:14:03","date_gmt":"2026-07-21T12:14:03","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247398"},"modified":"2026-07-23T12:35:55","modified_gmt":"2026-07-23T17:35:55","slug":"jacobian-conjecture","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/","title":{"rendered":"Locally everywhere does not imply everywhere"},"content":{"rendered":"<p>A couple days ago, Levent Alp\u00f6ge, a mathematician working at Anthropic, discovered a counterexample to the Jacobian conjecture using Claude Fable 5.<\/p>\n<p>I was curious whether most mathematicians were trying to prove or disprove the conjecture, so I asked Claude.<\/p>\n<blockquote><p>Before a counterexample to the Jacobian conjecture was found, did most mathematicians believe it was true or false?<\/p><\/blockquote>\n<p>Claude&#8217;s response was<\/p>\n<blockquote><p>The premise of this question isn&#8217;t quite right \u2014 no counterexample to the Jacobian conjecture has been found. It remains an open problem in mathematics: no one has proven it true, and no one has found a counterexample disproving it. \u2026 If you encountered a claim that a counterexample was found, do you have a source for that? I&#8217;d be happy to look into it, since that would actually be a major result in algebraic geometry if true.<\/p><\/blockquote>\n<p>Of course Claude doesn&#8217;t <em>know<\/em> that it solved the conjecture. It didn&#8217;t even solve the conjecture. It was an inanimate tool in the hand of a mathematician, just like a piece of chalk or a dry erase marker.<\/p>\n<p>The middle part of Claude&#8217;s response was that mathematicians are (were) divided on whether the conjecture is true. So it was not like the Riemann hypothesis, which most people believe to be true, or the P = NP conjecture, which most people believe to be false.<\/p>\n<p>Now what is the Jacobian conjecture? It says that a polynomial function from \u211d<sup><em>n<\/em><\/sup> to \u211d<sup><em>n<\/em><\/sup> with constant, non-zero Jacobian determinant has a polynomial inverse. (The conjecture was stated more generally for fields of characteristic 0, in which the derivatives defining the Jacobian would have to be defined algebraically, not in terms of limits.)<\/p>\n<p>Alp\u00f6ge came up with a counterexample, a polynomial function from \u211d\u00b3 to \u211d\u00b3 with constant Jacobian determinant \u22122. The function is<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/jacobian_conjecture.svg\" alt=\"\\begin{align*}F(x,y,z)={}\\bigl(~\\!&amp; z (1+xy)^3 + y^2 (1+xy) (4+3xy),\\\\ &amp;y + 3x(1+xy)^2 z + 3xy^2 (4+3xy), \\\\ &amp;2x - 3x^2 y - x^3 z ~\\!\\bigr).\\end{align*}\" width=\"385\" height=\"88\" \/><\/p>\n<p>It&#8217;s a tedious but simple calculus exercise to show that the determinant equals \u22122 everywhere. The inverse function theorem says that a function is locally invertible at any point where the Jacobian determinant is non-zero, so Alp\u00f6ge&#8217;s function is locally invertible everywhere.<\/p>\n<p>However, the function takes on some values more than once. For example, (0, 0, \u22121\/4) and (1, \u22123\/2, 13\/2) both map to (\u22121\/4, 0, 0). Therefore the function is not invertible globally. So not only does the function not have a polynomial inverse, it doesn&#8217;t have an inverse even if you allow non-polynomial functions.<\/p>\n<p>Alp\u00f6ge&#8217;s counterexample disproves the Jacobian conjecture for <em>n<\/em> = 3. It can trivially be extended to all <em>n<\/em> &gt; 3 by defining the function to be Alp\u00f6ge&#8217;s function for three variables and the identity for the rest. The conjecture remains open for <em>n<\/em> = 2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple days ago, Levent Alp\u00f6ge, a mathematician working at Anthropic, discovered a counterexample to the Jacobian conjecture using Claude Fable 5. I was curious whether most mathematicians were trying to prove or disprove the conjecture, so I asked Claude. Before a counterexample to the Jacobian conjecture was found, did most mathematicians believe it was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[154],"class_list":["post-247398","post","type-post","status-publish","format-standard","hentry","category-math","tag-algebraic-geometry"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Expanding on the recent counterexample to the Jacobian conjecture.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"algebraic geometry\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Locally everywhere does not imply everywhere\" \/>\n\t\t<meta property=\"og:description\" content=\"Expanding on the recent counterexample to the Jacobian conjecture.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-21T12:14:03+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-23T17:35:55+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Locally everywhere does not imply everywhere\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Expanding on the recent counterexample to the Jacobian conjecture.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Locally everywhere does not imply everywhere","description":"Expanding on the recent counterexample to the Jacobian conjecture.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/","robots":"max-image-preview:large","keywords":"algebraic geometry","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Locally everywhere does not imply everywhere","og:description":"Expanding on the recent counterexample to the Jacobian conjecture.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/","article:published_time":"2026-07-21T12:14:03+00:00","article:modified_time":"2026-07-23T17:35:55+00:00","twitter:card":"summary","twitter:title":"Locally everywhere does not imply everywhere","twitter:description":"Expanding on the recent counterexample to the Jacobian conjecture.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247398","title":null,"description":"Expanding on the recent counterexample to the Jacobian conjecture.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-21 11:46:59","updated":"2026-07-25 15:27:32","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tLocally everywhere does not imply everywhere\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"Locally everywhere does not imply everywhere","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/21\/jacobian-conjecture\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247398"}],"version-history":[{"count":5,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247398\/revisions"}],"predecessor-version":[{"id":247422,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247398\/revisions\/247422"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247378,"date":"2026-07-20T09:35:21","date_gmt":"2026-07-20T14:35:21","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247378"},"modified":"2026-07-20T09:35:21","modified_gmt":"2026-07-20T14:35:21","slug":"volume-area-regular-solids","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/","title":{"rendered":"Volume to Area ratio for Regular Solids"},"content":{"rendered":"<p>The volume of a sphere of radius <em>r<\/em> is<\/p>\n<p style=\"padding-left: 40px;\"><em>V<\/em> = 4\u03c0<em>r<\/em>\u00b3 \/ 3<\/p>\n<p>and the surface area is<\/p>\n<p style=\"padding-left: 40px;\"><em>A<\/em> = 4\u03c0<em>r<\/em>\u00b2<\/p>\n<p>and so the ratio of volume to area is<\/p>\n<p style=\"padding-left: 40px;\"><em>V<\/em> \/ <em>A<\/em> = <em>r<\/em> \/ 3.<\/p>\n<p>Surprisingly, the same ratio holds for all regular solids if\u00a0<em>r<\/em> is the radius of the largest sphere that can be inscribed inside the regular solid.<\/p>\n<p>For example, if the edge of a cube is\u00a0<em>a<\/em>, then\u00a0<em>r<\/em> =\u00a0<em>a<\/em>\/2. The volume is 8<em>r<\/em>\u00b3, the area is 24<em>r<\/em>\u00b2, and the ratio is\u00a0<em>r<\/em>\/3.<\/p>\n<p>The relationship between edge length and radius, and between radius and volume, is more complicated for the four other regular solids (tetrahedron, octahedron, dodecahedron, and icosahedron). However, in each case the ratio of volume to area is\u00a0<em>r<\/em>\/3.<\/p>\n<p>The proof is surprisingly simple. Pick a face and form a pyramid by connecting each face vertex to the center of the inscribed sphere. The pyramid has height <em>r<\/em> and volume equal to\u00a0<em>B<\/em>\/3 where\u00a0<em>B<\/em> is the area of the base. If the regular solid has\u00a0<em>f<\/em> faces, the volume of the solid is\u00a0<em>fBr<\/em> \/ 3 and the area is\u00a0<em>fB<\/em>. So the ratio of volume to area is\u00a0<em>r<\/em>\/3.<\/p>\n<p>The theorem generalizes to <em>n<\/em> &gt; 3 dimensions. The formula for the volume of a pyramid in <em>n<\/em> dimensions is\u00a0<em>Bh<\/em>\/<em>n<\/em> where\u00a0<em>B<\/em> is the (<em>n<\/em> \u2212 1)-dimensional volume of the base, and so the ratio of <em>n<\/em>-dimensional volume of a regular solid to (<em>n<\/em> \u2212 1)-dimensional volume of its boundary is <em>r<\/em>\/<em>n<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The volume of a sphere of radius r is V = 4\u03c0r\u00b3 \/ 3 and the surface area is A = 4\u03c0r\u00b2 and so the ratio of volume to area is V \/ A = r \/ 3. Surprisingly, the same ratio holds for all regular solids if\u00a0r is the radius of the largest sphere [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[224],"class_list":["post-247378","post","type-post","status-publish","format-standard","hentry","category-math","tag-geometry"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"geometry\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"John D. Cook | Applied Mathematics Consulting\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Volume to Area ratio for Regular Solids\" \/>\n\t\t<meta property=\"og:description\" content=\"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-07-20T14:35:21+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-07-20T14:35:21+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Volume to Area ratio for Regular Solids\" \/>\n\t\t<meta name=\"twitter:description\" content=\"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Volume to Area ratio for Regular Solids","description":"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/","robots":"max-image-preview:large","keywords":"geometry","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Volume to Area ratio for Regular Solids","og:description":"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/","article:published_time":"2026-07-20T14:35:21+00:00","article:modified_time":"2026-07-20T14:35:21+00:00","twitter:card":"summary","twitter:title":"Volume to Area ratio for Regular Solids","twitter:description":"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247378","title":null,"description":"The ratio of the volume to surface area of a regular solid is r\/3 where r is the radius of the inscribed sphere.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-07-19 17:32:21","updated":"2026-07-20 16:38:00","ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.johndcook.com\/blog\/category\/math\/\" title=\"Math\">Math<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tVolume to Area ratio for Regular Solids\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Math","link":"https:\/\/www.johndcook.com\/blog\/category\/math\/"},{"label":"Volume to Area ratio for Regular Solids","link":"https:\/\/www.johndcook.com\/blog\/2026\/07\/20\/volume-area-regular-solids\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=247378"}],"version-history":[{"count":3,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247378\/revisions"}],"predecessor-version":[{"id":247394,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247378\/revisions\/247394"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]