[{"id":247593,"date":"2026-08-09T12:17:42","date_gmt":"2026-08-09T17:17:42","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247593"},"modified":"2026-08-09T12:18:48","modified_gmt":"2026-08-09T17:18:48","slug":"dna-and-bessel-functions","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/","title":{"rendered":"DNA and Bessel functions"},"content":{"rendered":"<p>I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions.<\/p>\n<p>According to Claude,<\/p>\n<blockquote><p>When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &#8220;layer lines.&#8221; Cochran, Crick, and Vand showed mathematically that the diffracted amplitude on the <em>n<\/em>-th layer line is proportional to a Bessel function of the first kind, order <em>n<\/em>:<\/p>\n<p style=\"padding-left: 40px;\"><em>J<\/em><sub><em>n<\/em><\/sub>(2\u03c0\u2009<em>r\u2009R<\/em>)<\/p>\n<p>where <em>r<\/em> is the radius of the helix and <em>R<\/em> is the distance out from the center (the meridian) in the diffraction pattern.<\/p><\/blockquote>\n<p>The citation for this paragraph is a paper from 1952 [2] that amazingly is behind a paywall.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/05\/mr-bessels-eponymous-functions\/\">Mr. Bessel\u2019s eponymous functions<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/06\/from-kepler-to-bessel\/\">From Kepler to Bessel<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2024\/01\/31\/bessel-zero-spacing\/\">Bessel zero spacing<\/a><\/li>\n<\/ul>\n<p>[1] Watson and Crick didn&#8217;t &#8220;discover DNA&#8221; as is commonly said. DNA was discovered in 1878. Watson and Crick discovered the <em>structure<\/em> of DNA in 1953.<\/p>\n<p>[2] Cochran, W., Crick, F. H. C., &amp; Vand, V. (1952). &#8220;The Structure of Synthetic Polypeptides. I. The Transform of Atoms on a Helix.&#8221; Acta Crystallographica, 5(5), 581\u2013586.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &#8220;layer lines.&#8221; Cochran, Crick, and Vand [&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":[15],"tags":[166,129],"class_list":["post-247593","post","type-post","status-publish","format-standard","hentry","category-science","tag-math","tag-special-functions"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &quot;layer lines.&quot; Cochran, Crick, and Vand\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"math,special functions\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"DNA and Bessel functions\" \/>\n\t\t<meta property=\"og:description\" content=\"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &quot;layer lines.&quot; Cochran, Crick, and Vand\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-09T17:17:42+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-09T17:18:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"DNA and Bessel functions\" \/>\n\t\t<meta name=\"twitter:description\" content=\"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &quot;layer lines.&quot; Cochran, Crick, and Vand\" \/>\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":"DNA and Bessel functions","description":"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal \"layer lines.\" Cochran, Crick, and Vand","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/","robots":"max-image-preview:large","keywords":"math,special functions","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"DNA and Bessel functions","og:description":"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &quot;layer lines.&quot; Cochran, Crick, and Vand","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/","article:published_time":"2026-08-09T17:17:42+00:00","article:modified_time":"2026-08-09T17:18:48+00:00","twitter:card":"summary","twitter:title":"DNA and Bessel functions","twitter:description":"I was reading a book on the history of the discovery of the structure of DNA [1] and was surprised by a few passing references to Bessel functions. According to Claude, When X-rays are diffracted by a helical structure, the resulting diffraction pattern breaks into a series of horizontal &quot;layer lines.&quot; Cochran, Crick, and Vand","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247593","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-08-09 16:59:20","updated":"2026-08-09 21:16: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\/science\/\" title=\"Science\">Science<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tDNA and Bessel functions\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.johndcook.com\/blog"},{"label":"Science","link":"https:\/\/www.johndcook.com\/blog\/category\/science\/"},{"label":"DNA and Bessel functions","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/dna-and-bessel-functions\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247593","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=247593"}],"version-history":[{"count":2,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247593\/revisions"}],"predecessor-version":[{"id":247595,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247593\/revisions\/247595"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247580,"date":"2026-08-09T11:46:59","date_gmt":"2026-08-09T16:46:59","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247580"},"modified":"2026-08-09T16:16:33","modified_gmt":"2026-08-09T21:16:33","slug":"simple-range-reduction","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/","title":{"rendered":"A simple range reduction method"},"content":{"rendered":"<p>At the end of my post on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/\">how not to calculate cosine<\/a> I said that the first step in calculating cosine, particularly cosine of a large number, would be to do range reduction. This post will present a simple range reduction method by Cody and Waite that is adequate for moderately large arguments.<\/p>\n<p>If you want to compute the sine or cosine of an angle\u00a0<em>x<\/em> you could start by reducing\u00a0<em>x<\/em> mod 2\u03c0 since that would not change the result. However, accurately reducing a number mod 2\u03c0 is not trivial; that&#8217;s why range reduction is an area of algorithm development.<\/p>\n<h2>Range reduction mod \u03c0\/2<\/h2>\n<p>Even better would be to reduce <em>x<\/em> mod \u03c0\/2. Reducing to a smaller range means that power series method, and other methods such as rational approximation, will be more efficient.<\/p>\n<p>So suppose you can find an integer <em>k<\/em> such that<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> \u2212 <em>k<\/em> \u03c0\/2 = <em>y<\/em><\/p>\n<p>where 0 \u2264 <em>y<\/em> \u2264 \u03c0\/2. Then sin(<em>x<\/em>) is \u00b1sin(<em>y<\/em>) or \u00b1cos(<em>y<\/em>), depending on <em>k<\/em> mod 4 equals 0, 1, 2, or 3.<\/p>\n<pre>from math import *\r\n\r\ndef reduced_sin(x, k):\r\n     match k % 4:\r\n        case 0: return sin(x)\r\n        case 1: return cos(x)\r\n        case 2: return -sin(x)\r\n        case 3: return -cos(x)\r\n<\/pre>\n<h2>Naive range reduction<\/h2>\n<p>Now let&#8217;s set\u00a0<em>x<\/em> = 500. Then <em>k<\/em> = 318 because that&#8217;s the multiple of \u03c0\/2 we need to subtract to bring <em>x<\/em> into range, and the sine of <em>x<\/em> should be the negative of the sine of the reduced value <em>y<\/em> because 318 = 2 mod 4.<\/p>\n<p>The following code computes sin(<em>x<\/em>) with naive range reduction<\/p>\n<pre>def naive_sin(x):\r\n    k = floor(x \/ (pi\/2))\r\n    y = x % (pi\/2)\r\n    return reduced_sin(y, k)\r\n<\/pre>\n<p>and when <em>x<\/em> = 500 the error is on the order of 1.7 \u00d7 10<sup>\u221214<\/sup>.<\/p>\n<h2>Better range reduction<\/h2>\n<p>The value of <em>k<\/em> above is fine, but we&#8217;d like to calculate <em>y<\/em> more accurately. The following code is much better.<\/p>\n<pre>def Cody_Waite_sin(x):\r\n    C1 = 1686629713 \/ 2**30\r\n    C2 = 4701928774853425 \/ 2**86\r\n\r\n    k = floor(x \/ (pi\/2))\r\n    y = (x - k*C1) - k*C2\r\n    return reduced_sin(y, k)\r\n<\/pre>\n<p>This will compute sin(500) to full machine precision. What kind of magic is this?<\/p>\n<p>The trick is that the exact value of C1 + C2 equals \u03c0\/2 to more precision than is possible in a single float [1]. You can confirm, with <em>bc<\/em> or some other extended precision software, that the difference between C1 + C2 and \u03c0\/2 is roughly 2<sup>\u221288<\/sup>, while the limit of float precision is 2<sup>\u221252<\/sup>.<\/p>\n<p>If we compute<\/p>\n<pre>y = x - k*(C1 + C2)<\/pre>\n<p>then we&#8217;re doing the same calculation as <code>naive_sin<\/code> and will get the same error. But if we compute<\/p>\n<pre>y = (x - k*C1) - k*C2<\/pre>\n<p>we will get a more accurate result, provided\u00a0<em>x<\/em> isn&#8217;t too large.<\/p>\n<p>You can use the following code to play around and see how large <em>x<\/em>\u00a0can be before errors start to creep in. For small enough <em>x<\/em>, like 500, the Cody and Waite sine returns full precision. For larger <em>x<\/em> it&#8217;s better than naive sine but does not return full precision. And for large enough <em>x<\/em> it completely breaks down.<\/p>\n<pre>def compare(x):\r\n    y0 = naive_sin(x) \r\n    y1 = Cody_Waite_sin(x)\r\n    y2 = sin(x)\r\n    print(\"Naive error:     \", y2 - y0)\r\n    print(\"Cody Waite error:\", y2 - y1)\r\n<\/pre>\n<p>Now this may seem circular since we&#8217;re using <code>math.sin<\/code> as our gold standard. However, this function is calling the sine function on your CPU, which is using sophisticated range reduction to compute its result accurately down to the last bit, assuming you run the code on a computer that&#8217;s less than 40 years old.<\/p>\n<p>The Cody and Waite algorithm is inadequate for large\u00a0<em>x<\/em>, but it&#8217;s a good place to begin studying range reduction.\u00a0It shows there are clever ways of squeezing out more precision than seems possible.<\/p>\n<p>&nbsp;<\/p>\n<p>[1] The numerator <em>n<\/em><sub>1<\/sub> of C1 is \u230a2<sup>30<\/sup> \u03c0\/2\u230b. The numerator <em>n<\/em><sub>2<\/sub> of C2 is the solution to<\/p>\n<p style=\"padding-left: 40px;\">2<sup>86\u221230<\/sup> <em>n<\/em><sub>1<\/sub> + <em>n<\/em><sub>2<\/sub> = \u230a2<sup>86<\/sup> \u03c0\/2\u230b.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At the end of my post on how not to calculate cosine I said that the first step in calculating cosine, particularly cosine of a large number, would be to do range reduction. This post will present a simple range reduction method by Cody and Waite that is adequate for moderately large arguments. If you [&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],"tags":[],"class_list":["post-247580","post","type-post","status-publish","format-standard","hentry","category-computing"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.\" \/>\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\/08\/09\/simple-range-reduction\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Simple range reduction algorithm by Cody and Waite\" \/>\n\t\t<meta property=\"og:description\" content=\"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-09T16:46:59+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-09T21:16:33+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Simple range reduction algorithm by Cody and Waite\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.\" \/>\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":"Simple range reduction algorithm by Cody and Waite","description":"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/","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":"Simple range reduction algorithm by Cody and Waite","og:description":"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/","article:published_time":"2026-08-09T16:46:59+00:00","article:modified_time":"2026-08-09T21:16:33+00:00","twitter:card":"summary","twitter:title":"Simple range reduction algorithm by Cody and Waite","twitter:description":"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247580","title":"Simple range reduction algorithm by Cody and Waite","description":"A simple range reduction method. Not the state of the art, but simple and better than naive range reduction.","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-08-09 02:17:58","updated":"2026-08-09 21:16: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\/computing\/\" title=\"Computing\">Computing<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tA simple range reduction method\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":"A simple range reduction method","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247580","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=247580"}],"version-history":[{"count":9,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247580\/revisions"}],"predecessor-version":[{"id":247596,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247580\/revisions\/247596"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247576,"date":"2026-08-07T20:20:25","date_gmt":"2026-08-08T01:20:25","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247576"},"modified":"2026-08-07T20:20:25","modified_gmt":"2026-08-08T01:20:25","slug":"corrupted-apostrophes","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/","title":{"rendered":"Corrupted apostrophes"},"content":{"rendered":"<p>I have a program that shares files between my laptop and my phone. It works well, except for apostrophes.<\/p>\n<p>When I type an apostrophe <code>'<\/code> on my laptop, it becomes <code>\u00e2\u20ac&#x2122;<\/code> on my phone. And when I type <code>'s<\/code> on my phone, it becomes <code>\u75f4<\/code> on my laptop.<\/p>\n<p>Apparently the phone turns the apostrophe (U+0027) into a right single quote (U+2019), then bungles bytes in the UTF-8 encoding of U+2019 as three Windows-1252 characters. The bytes E28099<sub>hex<\/sub> are interpreted as <code>\u00e2<\/code> (E2<sub>hex<\/sub>), <code>\u20ac<\/code> (80<sub>hex<\/sub>), and <code>&#x2122;<\/code> (99<sub>hex<\/sub>).<\/p>\n<p>When I type <code>'s<\/code> on my phone, it is encoded as two Windows-1252 characters 92<sub>hex<\/sub> and 73<sub>hex<\/sub>. Then by the time the text appears on my laptop, the bytes 9273<sub>hex<\/sub> are interpreted as a Shift-JIS encoding of the CJK character <code>\u75f4<\/code> (U+75F4).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a program that shares files between my laptop and my phone. It works well, except for apostrophes. When I type an apostrophe &#8216; on my laptop, it becomes \u00e2\u20ac&#x2122; on my phone. And when I type &#8216;s on my phone, it becomes \u75f4 on my laptop. Apparently the phone turns the apostrophe (U+0027) [&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],"tags":[135],"class_list":["post-247576","post","type-post","status-publish","format-standard","hentry","category-computing","tag-unicode"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"I have a program that shares files between my laptop and my phone. It works well, except for apostrophes. When I type an apostrophe &#039; on my laptop, it becomes \u00e2\u20ac\u2122 on my phone. And when I type &#039;s on my phone, it becomes \u75f4 on my laptop. Apparently the phone turns the apostrophe (U+0027)\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"unicode\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Corrupted apostrophes\" \/>\n\t\t<meta property=\"og:description\" content=\"Autopsy of how apostrophes are corrupted between my phone and laptop.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-08T01:20:25+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-08T01:20:25+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Corrupted apostrophes\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Autopsy of how apostrophes are corrupted between my phone and laptop.\" \/>\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":"Corrupted apostrophes","description":"I have a program that shares files between my laptop and my phone. It works well, except for apostrophes. When I type an apostrophe ' on my laptop, it becomes \u00e2\u20ac\u2122 on my phone. And when I type 's on my phone, it becomes \u75f4 on my laptop. Apparently the phone turns the apostrophe (U+0027)","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/","robots":"max-image-preview:large","keywords":"unicode","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"Corrupted apostrophes","og:description":"Autopsy of how apostrophes are corrupted between my phone and laptop.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/","article:published_time":"2026-08-08T01:20:25+00:00","article:modified_time":"2026-08-08T01:20:25+00:00","twitter:card":"summary","twitter:title":"Corrupted apostrophes","twitter:description":"Autopsy of how apostrophes are corrupted between my phone and laptop.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247576","title":null,"description":null,"keywords":null,"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":"Autopsy of how apostrophes are corrupted between my phone and laptop.","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-08-08 00:46:32","updated":"2026-08-09 13:20:55","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\tCorrupted apostrophes\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":"Corrupted apostrophes","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/corrupted-apostrophes\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247576","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=247576"}],"version-history":[{"count":1,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247576\/revisions"}],"predecessor-version":[{"id":247577,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247576\/revisions\/247577"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247572,"date":"2026-08-07T10:11:10","date_gmt":"2026-08-07T15:11:10","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247572"},"modified":"2026-08-09T11:52:29","modified_gmt":"2026-08-09T16:52:29","slug":"how-not-to-calculate-cos","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/","title":{"rendered":"How not to calculate cosine"},"content":{"rendered":"<p>Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don&#8217;t. I worked on the implementation of trig functions in hardware, and I can assure you we didn&#8217;t just use power series.<\/p>\n<p>Power series are an excellent way to calculate functions <em>near the center of the series<\/em>, such as computing <a href=\"https:\/\/www.johndcook.com\/blog\/2010\/07\/27\/sine-approximation-for-small-x\/\">sine for small angles<\/a>. But the further you get from the center, the less useful power series are.<\/p>\n<p>Let&#8217;s suppose you want to calculate cos(200) using the power series for cosine. The\u00a0<em>n<\/em>th term of that series is<\/p>\n<p style=\"padding-left: 40px;\">(\u22121)<sup><em>n<\/em><\/sup> <em>x<\/em><sup>2<em>n<\/em><\/sup> \/ (2<em>n<\/em>)!<\/p>\n<p>This is an alternating series, and so the error in truncating the series after <em>n<\/em> terms is bounded by the size of the <em>n<\/em>+1 term, <em>if<\/em> you&#8217;ve gone far enough out in the series that the terms are monotonically decreasing in absolute value.<\/p>\n<p>To calculate cos(200) to machine precision, i.e. with an error of less than 2<sup>\u221252<\/sup>, we&#8217;d need to sum the series up to <em>n<\/em> where<\/p>\n<p style=\"padding-left: 40px;\">| 200<sup>2<em>n<\/em>+2<\/sup> \/ (2<em>n<\/em> + 2)! | &lt; 2<sup>\u221252<\/sup><\/p>\n<p>Actually, that will ensure that the <em>absolute<\/em> error is small enough, but not that the <em>relative<\/em> error is small enough; if the value of cos(200) is small, we&#8217;d need more terms. Let&#8217;s ignore that and assume we&#8217;re only concerned with absolute error.<\/p>\n<p>Turns out we&#8217;d need 287 terms. That&#8217;s a lot of terms. But you might say &#8220;That&#8217;s fine. I&#8217;m not in a hurry, and it&#8217;s just more work for the computer, not for me.&#8221; OK, so let&#8217;s try.<\/p>\n<pre>from math import *\r\n\r\ns = 0\r\nfor n in range(288):\r\n    s += (-1)**n * 200**(2*n) \/ factorial(2*n)\r\nprint(s)\r\n<\/pre>\n<p>This prints -3.6840358571084123e+67. You may suspect the answer is incorrect since values of cosine are on the order of 1, not on the order of 10<sup>67<\/sup>. Something went spectacularly bad. On closer inspection, it&#8217;s remarkable the code didn&#8217;t crash.<\/p>\n<p>If you changed <code>200<\/code> to <code>200.0<\/code> above, the code would crash. Calculating <code>200.0**(2*n)<\/code> overflows when <em>n<\/em> = 67. But when we calculate <code>200**(2*n)<\/code>, the result is an integer. And we&#8217;re dividing by <code>factorial(2*n)<\/code>, which is also an integer. Both of these integers become too large to fit in a float, but their <em>ratio<\/em> has a maximum value of around 10<sup>80<\/sup>, smaller than the maximum float, which is on the order of 10<sup>308<\/sup>.<\/p>\n<p>When we don&#8217;t overflow, we have a different problem: catastrophic cancellation. You can&#8217;t calculate a number between \u22121 and 1 as an alternating sum of numbers as large as 10<sup>80<\/sup>. You&#8217;d need more than 80 + 16 = 96 decimal places of precision to compute the sum accurately, and floating point only gives you between 15 and 16 decimal places of precision.<\/p>\n<p>So how <em>would<\/em> you calculate cos(200)? The first step would be to use some sort of range reduction on 200. You could reduce 200 mod 2\u03c0 to get a smaller number to work with.<\/p>\n<pre>&gt;&gt;&gt; from math import cos, pi\r\n&gt;&gt;&gt; x = 200 % (2*pi)\r\n&gt;&gt;&gt; x\r\n5.221255477432827\r\n<\/pre>\n<p>Using a power series to compute the cosine of 5.221255477432827 is feasible, but not optimal. There&#8217;s also another problem: the naive range reduction above loses some precision.<\/p>\n<pre>&gt;&gt;&gt; cos(x)\r\n0.48718767500701254\r\n&gt;&gt;&gt; cos(x) - cos(200)\r\n6.661338147750939e-15\r\n<\/pre>\n<p>The error is small, but it&#8217;s still an order of magnitude larger than machine precision. You can&#8217;t simply reduce <em>n<\/em> mod 2\u03c0 with ordinary float division because the integer part of <em>n<\/em> \/ 2\u03c0 pushes some digits of precision off the right end. I intend to write about how range reduction works in future posts.<\/p>\n<p><strong>Update<\/strong>: See <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/09\/simple-range-reduction\/\">this post<\/a> for a simple range reduction algorithm that is fine for values of <em>x<\/em> such as 200, but not adequate for much larger values.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don&#8217;t. I worked on the implementation of trig functions in hardware, and I can assure you we didn&#8217;t just use power series. Power series are an excellent way to calculate functions near the center of [&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":[],"class_list":["post-247572","post","type-post","status-publish","format-standard","hentry","category-computing","category-math"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don&#039;t.\" \/>\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\/08\/07\/how-not-to-calculate-cos\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"How not to calculate cosine\" \/>\n\t\t<meta property=\"og:description\" content=\"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don&#039;t.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-07T15:11:10+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-09T16:52:29+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How not to calculate cosine\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don&#039;t.\" \/>\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":"How not to calculate cosine","description":"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don't.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/","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":"How not to calculate cosine","og:description":"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don't.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/","article:published_time":"2026-08-07T15:11:10+00:00","article:modified_time":"2026-08-09T16:52:29+00:00","twitter:card":"summary","twitter:title":"How not to calculate cosine","twitter:description":"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don't.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247572","title":null,"description":"Calculus professors with no experience in numerical computing will tell students that computers calculate trig functions with power series. They don't.","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-08-07 14:02:31","updated":"2026-08-09 21:16: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\/computing\/\" title=\"Computing\">Computing<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow not to calculate cosine\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":"How not to calculate cosine","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/how-not-to-calculate-cos\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247572","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=247572"}],"version-history":[{"count":6,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247572\/revisions"}],"predecessor-version":[{"id":247592,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247572\/revisions\/247592"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247561,"date":"2026-08-07T08:19:07","date_gmt":"2026-08-07T13:19:07","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247561"},"modified":"2026-08-07T21:50:17","modified_gmt":"2026-08-08T02:50:17","slug":"cos200","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/","title":{"rendered":"cos(200!)"},"content":{"rendered":"<p>In a footnote to the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/\">previous post<\/a>, I said that Python&#8217;s math library can calculate the logarithm of extremely large numbers but not the cosine. This post will expand on that comment.<\/p>\n<p>In this post I&#8217;ll use <em>n<\/em> = 200! as my example rather than 1000! because this value of <em>N<\/em> is larger than the largest representable floating point number but small enough to be more convenient to work with.<\/p>\n<p>Suppose someone calculates 200! for you:<\/p>\n<pre>78865786736479050355236321393218506229513597768717326329474253324435\\\r\n94499634033429203042840119846239041772121389196388302576427902426371\\\r\n05061926624952829931113462857270763317237396988943922445621451664240\\\r\n25403329186413122742829485327752424240757390324032125740557956866022\\\r\n60319041703240623517008587961789222227896237038973747200000000000000\\\r\n00000000000000000000000000000000000\r\n<\/pre>\n<p>You could now calculate log(<em>n<\/em>) using<\/p>\n<p style=\"padding-left: 40px;\"><em>n<\/em> = 7.886578673647905 \u00d7 10<sup>374<\/sup><\/p>\n<p>and so<\/p>\n<p style=\"padding-left: 40px;\">log(<em>n<\/em>) = log(7.886578673647905 \u00d7 10<sup>374<\/sup>)<br \/>\n= log(7.886578673647905) + 374 log(10) = 863.2319871924055.<\/p>\n<p>The key thing that makes this possible is that the least significant digits of <em>n<\/em> only affect the least significant digits of log(<em>n<\/em>). In the calculation above I kept the first 16 digits of\u00a0<em>n<\/em>. Python couldn&#8217;t make use of any more digits, and had no need of any more digits, in order to produce the logarithm to machine precision.<\/p>\n<p>Cosine doesn&#8217;t work that way. The cosine of\u00a0<em>n<\/em> depends on the remainder when\u00a0<em>n<\/em> is divided by 2\u03c0, and that remainder depends on every single digit of <em>n<\/em>. I&#8217;ll illustrate that below.<\/p>\n<p>Using <code>bc -l<\/code> and setting the scale to 400, I can calculated <em>n<\/em> then calculate<\/p>\n<p style=\"padding-left: 40px;\">cos(<em>n<\/em> + 10<sup><em>i<\/em><\/sup>)<\/p>\n<p>for i running from 0 to 374, tweaking each digit one at a time. (Except when a digit is a 9 and the addition results in a carry.)<\/p>\n<pre>    n = 1\r\n    for (i = 1; i &lt;= 200; i++) n *= i\r\n    scale = 400\r\n    for (i = 1; i &lt;= 374; i++) {\r\n        x = c(n+10^i)\r\n        scale = 16\r\n        print x\/1, \"\\n\"\r\n        scale = 400\r\n    }\r\n<\/pre>\n<p>Here&#8217;s what a plot of the results look like.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/cos200factorial1.png\" width=\"480\" height=\"360\" \/><\/p>\n<p>The value of cos(<em>n<\/em>) is about \u22120.985, but the values above are all over the map. We can look at the range by projecting all the points over to the left edge then rotating a quarter turn:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/cos200factorial2.png\" width=\"360\" height=\"15\" \/><\/p>\n<p>The remarkable thing about this image is that there are a few gaps, i.e. a few values the cosine does <em>not<\/em> take on.<\/p>\n<p>Here&#8217;s a more sophisticated way to look at it. The sequence 10<sup><em>i<\/em><\/sup> mod 2\u03c0 is dense in [0, 2\u03c0], and so by going far enough out in the sequence, we can find a value that shifts the phase of <em>n<\/em> by any desired amount within any given tolerance.<\/p>\n<p>Every digit in\u00a0<em>n<\/em> matters, and changing any digit can change the value of cosine to be essentially any value. You cannot calculate the cosine of an enormous number without using some kind of extended precision arithmetic. There are clever range reduction algorithms that minimize the amount of extended arithmetic necessary, but extended arithmetic cannot be completely eliminated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a footnote to the previous post, I said that Python&#8217;s math library can calculate the logarithm of extremely large numbers but not the cosine. This post will expand on that comment. In this post I&#8217;ll use n = 200! as my example rather than 1000! because this value of N is larger than the [&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],"tags":[],"class_list":["post-247561","post","type-post","status-publish","format-standard","hentry","category-computing"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.\" \/>\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\/08\/07\/cos200\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Calculating the cosine of numbers outside the range of floats\" \/>\n\t\t<meta property=\"og:description\" content=\"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-07T13:19:07+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-08T02:50:17+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Calculating the cosine of numbers outside the range of floats\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.\" \/>\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":"Calculating the cosine of numbers outside the range of floats","description":"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/","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":"Calculating the cosine of numbers outside the range of floats","og:description":"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/","article:published_time":"2026-08-07T13:19:07+00:00","article:modified_time":"2026-08-08T02:50:17+00:00","twitter:card":"summary","twitter:title":"Calculating the cosine of numbers outside the range of floats","twitter:description":"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247561","title":"Calculating the cosine of numbers outside the range of floats","description":"Why you can calculate the log of a huge number more easily than the cosine. Demonstration that every digit is maximally important.","keywords":null,"keyphrases":{"focus":[],"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-08-07 11:54:58","updated":"2026-08-09 13:20:56","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\tcos(200!)\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":"cos(200!)","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247561","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=247561"}],"version-history":[{"count":10,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247561\/revisions"}],"predecessor-version":[{"id":247579,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247561\/revisions\/247579"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247553,"date":"2026-08-06T08:23:43","date_gmt":"2026-08-06T13:23:43","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247553"},"modified":"2026-08-07T08:42:02","modified_gmt":"2026-08-07T13:42:02","slug":"log1000","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/","title":{"rendered":"Calculating log(1000!)"},"content":{"rendered":"<p>The <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/\">previous post<\/a> pointed out that the following code such as the following unexpectedly works.<\/p>\n<pre>&gt;&gt;&gt; from math import log, factorial\r\n&gt;&gt;&gt; log(factorial(1000))\r\n5912.128178488163\r\n<\/pre>\n<p>If you don&#8217;t find this unexpected, note that if you replace <code>math.log<\/code> with <code>numpy.log<\/code> the code will fail [1]. Functions like natural logarithm operate on real numbers. Real numbers are represented as floating point numbers in programming languages, and 1000! factorial is too large to represent as a standard floating point number. (More on that <a href=\"https:\/\/www.johndcook.com\/blog\/2009\/04\/06\/anatomy-of-a-floating-point-number\/\">here<\/a>.)<\/p>\n<p>In this post I&#8217;d like to look at how you might calculate log(1000!) with less capable software, and even without software.<\/p>\n<p>One approach would be to sum the logarithms of the numbers 1 through 1000. This will give essentially the same result as above, with a little difference in the last couple decimal places due to rounding error.<\/p>\n<p>If you have a way to calculate 1000! but not a way to cast it to a floating point number, you could do this manually.<\/p>\n<pre>&gt;&gt;&gt; s = str(factorial(1000))\r\n&gt;&gt;&gt; s[:16]\r\n'4023872600770937'\r\n&gt;&gt;&gt; len(s)\r\n2568\r\n<\/pre>\n<p>This tells us 1000! = 4.023872600770937 \u00d7 10<sup>2567<\/sup>. Therefore<\/p>\n<p style=\"padding-left: 40px;\">log(1000!) = log(4.023872600770937) + 2567 log(10)<\/p>\n<p>which only requires working with numbers of modest size.<\/p>\n<h2>Calculating by hand<\/h2>\n<p>Now suppose it&#8217;s 1964. You don&#8217;t have a computer, or even a calculator, but you do have a copy of the recently published Handbook of Mathematical Functions by Abramowitz and Stegun (A&amp;S). You turn to Table 6.6 &#8220;Factorials for large arguments.&#8221; This has values of factorial for 100, 200, 300, \u2026, 1000, so you can simply look up your answer to 20 decimal places.<\/p>\n<p>That was too easy; I didn&#8217;t expect that to be there when I started writing this post. If you wanted to compute log(950!), for example, you&#8217;d have to work harder. You could find A&amp;S equation 6.1.41 (Stirling&#8217;s series) which says<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/AS6.1.41.svg\" alt=\"\\begin{align*} \\ln \\Gamma(z) &amp;\\sim (z - \\tfrac{1}{2}) \\ln z - z + \\tfrac{1}{2} \\ln 2\\pi + \\frac{1}{12z} - \\frac{1}{360z^3} \\\\ &amp;+ \\frac{1}{1260z^5} - \\frac{1}{680z^7} + \\cdots \\end{align*}\" width=\"401\" height=\"90\" \/><\/p>\n<p>So how would you use this formula to calculate log(1000!)? Since <em>n<\/em>! = \u0393(<em>n<\/em> + 1), you set <em>z<\/em> = 1001.<\/p>\n<p>You&#8217;d need to decide how many terms you need to use. Assuming the error is on the order of the first term you leave out, you&#8217;d reason that you could probably stop with the 1\/12<em>z<\/em> term because the next term is between 10<sup>\u221211<\/sup> and 10<sup>\u221212<\/sup>.<\/p>\n<p>You find Table 4.2 has natural logarithms, but not for 1001. You can look up log(1.001), however, and at the bottom of the same page is log(10) to 16 decimal places, and you can find log(10) to 24 decimal places in Table 1.1. So you calculate<\/p>\n<p style=\"padding-left: 40px;\">log(1001) = log(1.001 \u00d7 10\u00b3) = log(1.001) + 3 log(10).<\/p>\n<p>You can find log(2) and log(\u03c0) in Table 1.1, and average them to find \u00bd log(2\u03c0).<\/p>\n<p>Here&#8217;s Python code to simulate the hand calculations.<\/p>\n<pre>log2     = 0.6931_47180_55994_53094_172321 # Table 1.1\r\nlog10    = 2.3025_85092_99404_56840_179915 # Table 1.1\r\nlogpi    = 1.1447_29885_84940_01741_43427  # Table 1.1\r\nlog1_001 = 0.00099_95003_330835            # Table 4.2\r\n\r\nz = 1001\r\nlogz = log1_001 + 3*log10\r\ns = (z - 0.5)*logz - z + (log2 + logpi)\/2 + 1\/(12*z)\r\n\r\nprint(s)\r\n<\/pre>\n<p>This result differs from the one at the top of the post only in the last decimal place.<\/p>\n<h2>Related posts<\/h2>\n<p>Doing calculations with tables is not as simple as &#8220;just look it up.&#8221; It takes a bit of skill.<\/p>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2024\/06\/03\/using-a-table-of-logarithms\/\">Using a table of logarithms<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2024\/06\/25\/trig-tables\/\">Using a trig table<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2026\/03\/26\/table-precision\/\">How much precision can you squeeze out of a table?<\/a><\/li>\n<\/ul>\n<p>[1] The code will also fail if you replace <code>math.log<\/code> with <code>math.cos<\/code>. Both logarithm and cosine return moderate sized real numbers when given enormous inputs like 1000!, so representing the output as a float is not the problem. But logarithms of huge numbers can be computed with ordinary precision functions, as above. But computing the cosine of a huge number requires extended precision.<\/p>\n<p><strong>Update<\/strong>: The <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/07\/cos200\/\">next post<\/a> expands on why computing the cosine of a large number is more difficult than computing the log.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous post pointed out that the following code such as the following unexpectedly works. &gt;&gt;&gt; from math import log, factorial &gt;&gt;&gt; log(factorial(1000)) 5912.128178488163 If you don&#8217;t find this unexpected, note that if you replace math.log with numpy.log the code will fail [1]. Functions like natural logarithm operate on real numbers. Real numbers are represented [&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-247553","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?\" \/>\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\/08\/06\/log1000\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Calculating log(1000!)\" \/>\n\t\t<meta property=\"og:description\" content=\"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-06T13:23:43+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-07T13:42:02+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Calculating log(1000!)\" \/>\n\t\t<meta name=\"twitter:description\" content=\"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?\" \/>\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":"Calculating log(1000!)","description":"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/","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":"Calculating log(1000!)","og:description":"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/","article:published_time":"2026-08-06T13:23:43+00:00","article:modified_time":"2026-08-07T13:42:02+00:00","twitter:card":"summary","twitter:title":"Calculating log(1000!)","twitter:description":"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247553","title":null,"description":"How would you compute log(1000!) without software that handles enormous numbers? How would you calculate it by hand?","keywords":null,"keyphrases":{"focus":[],"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-08-06 11:14:31","updated":"2026-08-09 13:20:56","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\tCalculating log(1000!)\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":"Calculating log(1000!)","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/06\/log1000\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247553","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=247553"}],"version-history":[{"count":8,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247553\/revisions"}],"predecessor-version":[{"id":247571,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247553\/revisions\/247571"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247547,"date":"2026-08-05T13:26:25","date_gmt":"2026-08-05T18:26:25","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247547"},"modified":"2026-08-06T05:56:48","modified_gmt":"2026-08-06T10:56:48","slug":"math-log","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/","title":{"rendered":"The code that didn&#8217;t break"},"content":{"rendered":"<p>Last week I wrote a <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/07\/28\/keys-and-cards\/\">post<\/a> on hiding cryptographic keys in decks of cards. I wrote some code for that post that shouldn&#8217;t work, but before fixing I noticed that it in fact did work.<\/p>\n<p>The code computes logarithms for integers larger than the largest representable float. For example, the largest float is on the order of 10<sup>308<\/sup>, and yet the following code works.<\/p>\n<pre>&gt;&gt;&gt; import math\r\n&gt;&gt;&gt; math.log10(10**400)\r\n400.0\r\n<\/pre>\n<p>The <code>log<\/code>, <code>log2<\/code>, and <code>log10<\/code> functions have some code inside that handles large integers specially. It doesn&#8217;t simply convert the integers to floats before taking the logarithm. If it did, it would overflow. If you replace <code>math<\/code> with <code>numpy<\/code> above, the code will fail. NumPy&#8217;s implementation of logarithms is more what I would expect.<\/p>\n<p>While playing around with this I also noticed that you can define floats larger than the largest float without warnings.<\/p>\n<pre>&gt;&gt;&gt; math.log(1e308)\r\n709.1962086421661\r\n&gt;&gt;&gt; math.log(1e309)\r\ninf\r\n<\/pre>\n<p>This isn&#8217;t a feature of <code>math.log<\/code> but of how Python handles scientific notation. The expression <code>1e308<\/code> is the floating point representation of 10<sup>308<\/sup>. It is a float, not an int.<\/p>\n<pre>&gt;&gt;&gt; type(1e308)\r\n&lt;class 'float'&gt;\r\n<\/pre>\n<p>The expression <code>1e309<\/code> is also a float. But since it&#8217;s larger than is possible for a float, Python interprets it as <code>inf<\/code>. The code<\/p>\n<pre>math.log(1e309)<\/pre>\n<p>returns <code>inf<\/code> based on the reasoning that log(\u221e) = \u221e.<\/p>\n<p>That explains the following behavior:<\/p>\n<pre>&gt;&gt;&gt; 1e309 == 1e310\r\nTrue\r\n<\/pre>\n<p>The expressions <code>1e309<\/code> and <code>1e310<\/code> are equal because both are alternate ways of writing <code>inf<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I wrote a post on hiding cryptographic keys in decks of cards. I wrote some code for that post that shouldn&#8217;t work, but before fixing I noticed that it in fact did work. The code computes logarithms for integers larger than the largest representable float. For example, the largest float is on the [&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":[169],"class_list":["post-247547","post","type-post","status-publish","format-standard","hentry","category-math","tag-python"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"A couple oddities in math with very large numbers in Python\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"John\"\/>\n\t<meta name=\"keywords\" content=\"python\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"The code that didn\u2019t break\" \/>\n\t\t<meta property=\"og:description\" content=\"A couple oddities in math with very large numbers in Python\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-05T18:26:25+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-06T10:56:48+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"The code that didn\u2019t break\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A couple oddities in math with very large numbers in Python\" \/>\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":"The code that didn\u2019t break","description":"A couple oddities in math with very large numbers in Python","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/","robots":"max-image-preview:large","keywords":"python","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"John D. Cook | Applied Mathematics Consulting","og:type":"article","og:title":"The code that didn\u2019t break","og:description":"A couple oddities in math with very large numbers in Python","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/","article:published_time":"2026-08-05T18:26:25+00:00","article:modified_time":"2026-08-06T10:56:48+00:00","twitter:card":"summary","twitter:title":"The code that didn\u2019t break","twitter:description":"A couple oddities in math with very large numbers in Python","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247547","title":null,"description":"A couple oddities in math with very large numbers in Python","keywords":null,"keyphrases":{"focus":[],"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-08-05 17:47:04","updated":"2026-08-09 13:20:56","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\tThe code that didn\u2019t break\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":"The code that didn&#8217;t break","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/math-log\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247547","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=247547"}],"version-history":[{"count":4,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247547\/revisions"}],"predecessor-version":[{"id":247551,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247547\/revisions\/247551"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247540,"date":"2026-08-05T09:49:35","date_gmt":"2026-08-05T14:49:35","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247540"},"modified":"2026-08-06T06:10:52","modified_gmt":"2026-08-06T11:10:52","slug":"enumerating-trees-and-circles","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/enumerating-trees-and-circles\/","title":{"rendered":"Enumerating trees and circles"},"content":{"rendered":"<p>A few days ago I wrote a post on <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/01\/counting-rooted-trees\/\">counting rooted trees<\/a>. That post looked at the sequence <em>c<\/em>(<em>n<\/em>) which counts the number of rooted trees with <em>n<\/em> nodes. Here one node is distinguished as the root, but the nodes below the root are not distinguished from each other; all that matters is how the nodes are connected.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/rooted_trees_order_1_to_4.svg\" width=\"680\" height=\"600\" \/><\/p>\n<p>The number of rooted trees with <em>n<\/em> nodes is the same as the number of ways to configure <em>n<\/em> \u2212 1 non-overlapping circles. Not only are the counts the same, there is a natural correspondence between the trees and the circles. It&#8217;s not obvious that there should be such a correspondence, with the right notation the correspondence is sort of a pun.<\/p>\n<p>The standard way to represent unlabeled trees is as a <a href=\"https:\/\/www.johndcook.com\/blog\/2022\/10\/26\/multisets\/\">multiset<\/a> of their children. We use a multiset, not a set, because some elements will be repeated. We represent a leaf as a pair of parentheses: <code>()<\/code>.<\/p>\n<p>There is only one rooted tree with one node: <code>()<\/code>.<\/p>\n<p>There is only one rooted tree with one two nodes: <code>(())<\/code>. Here the outer parentheses represent the root node and the inner parentheses represent its child.<\/p>\n<p>There are two rooted trees with three nodes, and we can represent them as <code>((()))<\/code> and <code>((),())<\/code>. The first is the straight line tree: a node that has a single child node that has a single child node. The second is a node that branches to two nodes. (Here&#8217;s where we need multisets.)<\/p>\n<p>The four rooted trees with four nodes can be represented as <code>(((())))<\/code>, <code>((((),()))<\/code>, <code>((),(()))<\/code>, and <code>((),(),(),())<\/code>.<\/p>\n<p>Here are the nine rooted trees with five nodes:<\/p>\n<pre>((((()))))\r\n((((),())))\r\n(((),(())))\r\n(((),(),()))\r\n((()),(()))\r\n((),((())))\r\n((),((),()))\r\n((),(),(()))\r\n((),(),(),())\r\n<\/pre>\n<p>The correspondence with non-overlapping circles removes the outer parentheses then joins the rest to form circles, with nested parentheses corresponding to concentric circles. A more geometric way to see the correspondence is to start at the bottom of the tree, replace leaves with circles, then work your way up circling connected components.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonoverlapping_circles2.png\" width=\"362\" height=\"896\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few days ago I wrote a post on counting rooted trees. That post looked at the sequence c(n) which counts the number of rooted trees with n nodes. Here one node is distinguished as the root, but the nodes below the root are not distinguished from each other; all that matters is how the [&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-247540","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"There&#039;s a one-to-one correspondence between rooted trees and non-overlapping circles\" \/>\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\/08\/05\/enumerating-trees-and-circles\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Enumerating trees and circles\" \/>\n\t\t<meta property=\"og:description\" content=\"There&#039;s a one-to-one correspondence between rooted trees and non-overlapping circles\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/enumerating-trees-and-circles\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-05T14:49:35+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-06T11:10:52+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Enumerating trees and circles\" \/>\n\t\t<meta name=\"twitter:description\" content=\"There&#039;s a one-to-one correspondence between rooted trees and non-overlapping circles\" \/>\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":"Enumerating trees and circles","description":"There's a one-to-one correspondence between rooted trees and non-overlapping circles","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/enumerating-trees-and-circles\/","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":"Enumerating trees and circles","og:description":"There's a one-to-one correspondence between rooted trees and non-overlapping circles","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/enumerating-trees-and-circles\/","article:published_time":"2026-08-05T14:49:35+00:00","article:modified_time":"2026-08-06T11:10:52+00:00","twitter:card":"summary","twitter:title":"Enumerating trees and circles","twitter:description":"There's a one-to-one correspondence between rooted trees and non-overlapping circles","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247540","title":null,"description":"There's a one-to-one correspondence between rooted trees and non-overlapping circles","keywords":null,"keyphrases":{"focus":[],"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-08-05 12:48:37","updated":"2026-08-09 13:20:56","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\tEnumerating trees and circles\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":"Enumerating trees and circles","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/05\/enumerating-trees-and-circles\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247540","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=247540"}],"version-history":[{"count":4,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247540\/revisions"}],"predecessor-version":[{"id":247543,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247540\/revisions\/247543"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247536,"date":"2026-08-04T08:18:58","date_gmt":"2026-08-04T13:18:58","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247536"},"modified":"2026-08-04T20:20:01","modified_gmt":"2026-08-05T01:20:01","slug":"metallic-alchemy","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/metallic-alchemy\/","title":{"rendered":"Mathematical alchemy"},"content":{"rendered":"<p>After writing the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/\">previous post<\/a> about metallic ratios, I thought about the analogy to alchemy and the attempt to make precious metals out of base metals.<\/p>\n<p>When can you make one metallic ratio out of another? Can you make the golden ratio out of the lead ratio?<\/p>\n<p>Before we can make gold out of lead, we have to say what lead is.<\/p>\n<h2>Defining metallic ratios<\/h2>\n<p>The metallic ratios\u00a0<em>M<\/em>(<em>n<\/em>) can be defined several ways. The most interesting definition is the number whose continued fraction representation contains all <em>n<\/em>s. A more prosaic but more convenient definition is the larger number that equals its reciprocal plus <em>n<\/em>, which can be found using the quadratic formula.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/metallic_ratio_def.svg\" alt=\"M(n) = n + \\cfrac{1}{n+\\cfrac{1}{n+\\cfrac{1}{n+\\cdots}}} = \\frac{n + \\sqrt{n^2 + 4}}{2}\" width=\"344\" height=\"110\" \/><\/p>\n<p>The golden ratio is\u00a0<em>M<\/em>(1), the silver ratio is\u00a0<em>M<\/em>(2), and the bronze ratio is\u00a0<em>M<\/em>(3).<\/p>\n<h2>Gold from silver and bronze?<\/h2>\n<p>Can you make the golden ratio out of the silver and bronze ratios? Not by integer arithmetic. The golden ratio involves \u221a5, the silver ratio \u221a2 and the bronze ratio \u221a13. No integer operations on the latter two radicals will produce the former, though you can come arbitrarily close.<\/p>\n<h2>Gold from lead<\/h2>\n<p>The metallic ratios for <em>n<\/em> &gt; 3 don&#8217;t have standard names, but let&#8217;s call <em>M<\/em>(4) the lead ratio. Can you make the golden ratio out of the lead ratio? Yes you can:<\/p>\n<p style=\"padding-left: 40px;\"><em>M<\/em>(1) = (<em>M<\/em>(4) \u2212 1)\/2.<\/p>\n<h2>General solution<\/h2>\n<p>In general, when can you make\u00a0<em>M<\/em>(<em>n<\/em>) out of\u00a0<em>M<\/em>(<em>m<\/em>)? In abstract terms the question is when the fields<\/p>\n<p style=\"padding-left: 40px;\">\u211a(\u221a(<em>n<\/em>\u00b2 + 4))<\/p>\n<p>and<\/p>\n<p style=\"padding-left: 40px;\">\u211a(\u221a(<em>m<\/em>\u00b2 + 4))<\/p>\n<p>are the same, i.e. when adjoining \u221a(<em>n<\/em>\u00b2 + 4) to the rational numbers gives the same field as adjoining \u221a(<em>m<\/em>\u00b2 + 4) to the rational numbers. This occurs if and only if<\/p>\n<p style=\"padding-left: 40px;\">(<em>n<\/em>\u00b2 + 4)\/(<em>m\u00b2<\/em> + 4)<\/p>\n<p>is the square of a rational number.<\/p>\n<h2>Bronze from copper and tin<\/h2>\n<p>Can you make bronze out of copper and tin? Yes, if you define\u00a0<em>M<\/em>(36) to be the copper ratio and\u00a0<em>M<\/em>(393) to be the tin ratio, because<\/p>\n<p style=\"padding-left: 40px;\">(3\u00b2 + 4)\/(36\u00b2 + 4) = (1\/10)\u00b2<\/p>\n<p>and<\/p>\n<p style=\"padding-left: 40px;\">(3\u00b2 + 4)\/(292\u00b2 + 4) = (1\/109)\u00b2.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After writing the previous post about metallic ratios, I thought about the analogy to alchemy and the attempt to make precious metals out of base metals. When can you make one metallic ratio out of another? Can you make the golden ratio out of the lead ratio? Before we can make gold out of lead, [&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-247536","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 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?\" \/>\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\/08\/04\/metallic-alchemy\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Metallic alchemy: making one metallic ratio from another\" \/>\n\t\t<meta property=\"og:description\" content=\"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/metallic-alchemy\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-04T13:18:58+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-05T01:20:01+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Metallic alchemy: making one metallic ratio from another\" \/>\n\t\t<meta name=\"twitter:description\" content=\"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?\" \/>\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":"Metallic alchemy: making one metallic ratio from another","description":"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/metallic-alchemy\/","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":"Metallic alchemy: making one metallic ratio from another","og:description":"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/metallic-alchemy\/","article:published_time":"2026-08-04T13:18:58+00:00","article:modified_time":"2026-08-05T01:20:01+00:00","twitter:card":"summary","twitter:title":"Metallic alchemy: making one metallic ratio from another","twitter:description":"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247536","title":"Metallic alchemy: making one metallic ratio from another","description":"By analogy with alchemy, can you make gold from lead? i.e. can you make the golden ratio by integer operations on the lead ratio?","keywords":null,"keyphrases":{"focus":[],"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-08-04 12:23:52","updated":"2026-08-09 13:20:56","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\tMathematical alchemy\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":"Mathematical alchemy","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/metallic-alchemy\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247536","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=247536"}],"version-history":[{"count":3,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247536\/revisions"}],"predecessor-version":[{"id":247539,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247536\/revisions\/247539"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":247532,"date":"2026-08-04T06:41:49","date_gmt":"2026-08-04T11:41:49","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=247532"},"modified":"2026-08-04T06:41:49","modified_gmt":"2026-08-04T11:41:49","slug":"ratio-of-metallic-ratios","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/","title":{"rendered":"Ratio of metallic ratios"},"content":{"rendered":"<p>The golden ratio is the first and best known of the metallic ratios. I&#8217;ve written about the silver ratio a few times, most recently <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/06\/30\/silver-kings\/\">here<\/a>. And I&#8217;ve mentioned the <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/04\/14\/metallic-ratios\/\">bronze ratio<\/a> a couple times. The metallic ratios after bronze don&#8217;t have standard names.<\/p>\n<p>The <em>n<\/em>th metallic ratio <em>M<\/em>(<em>n<\/em>) is the number whose continued fraction representation contains all <em>n<\/em>s.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/metallic_ratio.svg\" alt=\"n + \\cfrac{1}{n+\\cfrac{1}{n+\\cfrac{1}{n+\\cdots}}} = \\frac{n + \\sqrt{n^2 + 4}}{2}\" width=\"276\" height=\"95\" \/><\/p>\n<p>When <em>n<\/em> = 1, 2, and 3 we get the gold, silver, and bronze ratios.<\/p>\n<p>You can approximate any positive real number as a ratio of metallic ratios. To see this, note that for large\u00a0<em>n<\/em>, <i>M<\/i>(<em>n<\/em>)\u00a0is approximately\u00a0<em>n<\/em>. For any positive rational number <em>a<\/em>\/<em>b<\/em>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/metallic_ratio_ratio.svg\" alt=\"\\lim_{n\\to\\infty} \\frac{M(na)}{M(nb)} = \\frac{a}{b}\" width=\"131\" height=\"45\" \/><\/p>\n<p>and so you can make\u00a0<em>M<\/em>(<em>na<\/em>) \/\u00a0<em>M<\/em>(<em>nb<\/em>) as close to\u00a0<em>a<\/em>\/<em>b<\/em> as you like by taking\u00a0<em>n<\/em> large enough. And since the rationals are dense in the reals, you can approximate any positive real number as close as you&#8217;d like.<\/p>\n<p>Let&#8217;s look for metallic ratios whose ratios approximate \u03c0 to within 0.001 with the following Python code.<\/p>\n<pre>from math import pi, sqrt\r\n\r\nM = lambda n: 0.5*(n + sqrt(n**2 + 4))\r\n\r\nfor n in range(1, 100):\r\n    a = round(pi*n)\r\n    b = n\r\n    r = M(a)\/M(b)\r\n    if abs(r - pi) &lt; 0.001:\r\n        print(a, b, r)\r\n<\/pre>\n<p>This shows<\/p>\n<p style=\"padding-left: 40px;\">\u03c0 \u2248\u00a0<em>M<\/em>(132) \/\u00a0<em>M<\/em>(42) = 3.1412\u2026<\/p>\n<p>Could we find smaller numbers that work? The following code shows the answer is no.<\/p>\n<pre>k = 132 + 42\r\n# loop over numbers whose sum is less than k\r\nfor n in range(1, k):\r\n    for a in range(1, n):\r\n        b = n - a\r\n        r = M(a)\/M(b)\r\n        if abs(r - pi) &lt; 0.001:\r\n            print(a, b, r)\r\n            exit()\r\n<\/pre>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2024\/09\/01\/pell-numbers\/'>Pell is to silver as Fibonacci is to gold<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2024\/10\/10\/golden-ellipse\/'>Golden ellipse<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2026\/06\/29\/derivative-equals-inverse\/'>Derivative equals inverse<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The golden ratio is the first and best known of the metallic ratios. I&#8217;ve written about the silver ratio a few times, most recently here. And I&#8217;ve mentioned the bronze ratio a couple times. The metallic ratios after bronze don&#8217;t have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation [&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-247532","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"The golden ratio is the first and best known of the metallic ratios. I&#039;ve written about the silver ratio a few times, most recently here. And I&#039;ve mentioned the bronze ratio a couple times. The metallic ratios after bronze don&#039;t have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation\" \/>\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\/08\/04\/ratio-of-metallic-ratios\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\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=\"Ratio of metallic ratios\" \/>\n\t\t<meta property=\"og:description\" content=\"The golden ratio is the first and best known of the metallic ratios. I&#039;ve written about the silver ratio a few times, most recently here. And I&#039;ve mentioned the bronze ratio a couple times. The metallic ratios after bronze don&#039;t have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-08-04T11:41:49+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-08-04T11:41:49+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Ratio of metallic ratios\" \/>\n\t\t<meta name=\"twitter:description\" content=\"The golden ratio is the first and best known of the metallic ratios. I&#039;ve written about the silver ratio a few times, most recently here. And I&#039;ve mentioned the bronze ratio a couple times. The metallic ratios after bronze don&#039;t have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation\" \/>\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":"Ratio of metallic ratios","description":"The golden ratio is the first and best known of the metallic ratios. I've written about the silver ratio a few times, most recently here. And I've mentioned the bronze ratio a couple times. The metallic ratios after bronze don't have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation","canonical_url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/","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":"Ratio of metallic ratios","og:description":"The golden ratio is the first and best known of the metallic ratios. I've written about the silver ratio a few times, most recently here. And I've mentioned the bronze ratio a couple times. The metallic ratios after bronze don't have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation","og:url":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/","article:published_time":"2026-08-04T11:41:49+00:00","article:modified_time":"2026-08-04T11:41:49+00:00","twitter:card":"summary","twitter:title":"Ratio of metallic ratios","twitter:description":"The golden ratio is the first and best known of the metallic ratios. I've written about the silver ratio a few times, most recently here. And I've mentioned the bronze ratio a couple times. The metallic ratios after bronze don't have standard names. The nth metallic ratio M(n) is the number whose continued fraction representation","twitter:image":"https:\/\/www.johndcook.com\/blog\/wp-content\/uploads\/2022\/05\/twittercard.png"},"aioseo_meta_data":{"post_id":"247532","title":null,"description":null,"keywords":null,"keyphrases":{"focus":[],"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":null,"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":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"created":"2026-08-04 10:51:59","updated":"2026-08-09 13:20:56","ai":null,"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\tRatio of metallic ratios\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":"Ratio of metallic ratios","link":"https:\/\/www.johndcook.com\/blog\/2026\/08\/04\/ratio-of-metallic-ratios\/"}],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247532","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=247532"}],"version-history":[{"count":1,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247532\/revisions"}],"predecessor-version":[{"id":247535,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/247532\/revisions\/247535"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=247532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=247532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=247532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]