[{"id":246947,"date":"2026-04-05T18:04:46","date_gmt":"2026-04-05T23:04:46","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246947"},"modified":"2026-04-05T18:08:27","modified_gmt":"2026-04-05T23:08:27","slug":"hipaa-compliant-ai","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/05\/hipaa-compliant-ai\/","title":{"rendered":"HIPAA compliant AI"},"content":{"rendered":"<p>The best way to run AI and remain HIPAA compliant is to run it locally on your own hardware, instead of transferring protected health information (PHI) to a remote server by using a cloud-hosted service like ChatGPT or Claude. [1].<\/p>\n<p>There are HIPAA-compliant cloud options, but they&#8217;re both restrictive and expensive. Even enterprise options are not &#8220;HIPAA compliant&#8221; out of the box. Instead, they are &#8220;HIPAA eligible&#8221; or that they &#8220;support HIPAA compliance,&#8221; because you still need the right Business Associate Agreement (BAA), configuration, logging, access controls, and internal process around it, and the end product often ends up far less capable than a frontier model. The least expensive and therefore most accessible services do not even allow this as an option.<\/p>\n<p>Specific examples:<\/p>\n<ul>\n<li style=\"margin-bottom: 20px;\">Only sales-managed ChatGPT Enterprise or Edu customers are eligible for a BAA, and OpenAI explicitly says it does not offer a BAA for ChatGPT Business. The consumer ChatGPT Health product says HIPAA and BAAs do not apply. ChatGPT for Healthcare pricing is based on ChatGPT Enterprise, depends on organization size and deployment needs, and requires contacting sales. Even within Enterprise, OpenAI&#8217;s Regulated Workspace <a href=\"https:\/\/cdn.openai.com\/osa\/chatgpt-regulated-workspace.pdf\">spec<\/a> lists Codex and the multi-step Agent feature as &#8220;Non-Included Functionality,&#8221; i.e. off limits for PHI.<\/li>\n<li style=\"margin-bottom: 20px;\">Google says Gemini can support HIPAA workloads in Workspace, but NotebookLM is not covered by Google&#8217;s BAA, and Gemini in Chrome is automatically blocked for BAA customers. If a work or school account does not have enterprise-grade data protections, chats in the Gemini app may be reviewed by humans and used to improve Google&#8217;s products.<\/li>\n<li style=\"margin-bottom: 20px;\">GitHub Copilot, despite being a Microsoft product, is not under Microsoft&#8217;s BAA. Azure OpenAI Service is, but only for text endpoints. While Microsoft is working on their own models, it is unlikely that they will deviate significantly here.<\/li>\n<li style=\"margin-bottom: 20px;\">Anthropic says its BAA covers only certain &#8220;HIPAA-ready&#8221; services, namely the first-party API and a HIPAA-ready Enterprise plan, and does not cover Claude Free, Pro, Max, Team, Workbench, Console, Cowork, or Claude for Office. The HIPAA-ready Enterprise offering is sales-assisted only. Bundled Claude Code seats are not covered. AWS Bedrock API calls can work, but this requires extensive configuration and carries its own complexities and restrictions.<\/li>\n<\/ul>\n<p>Running AI locally is already practical as of early 2026. Open-weight models that approach the quality of commercial coding assistants run on consumer hardware. A single high-end GPU or a recent Mac with enough unified memory can run a 70B-parameter model at a reasonable token speed.<\/p>\n<p>There&#8217;s an interesting interplay between economies of scale and diseconomies of scale. Cloud providers can run a data center at a lower cost per server than a small company can. That&#8217;s the economies of scale. But running HIPAA-compliant computing in the cloud, particularly with AI providers, incurs a large direct costs and indirect bureaucratic costs. That&#8217;s the diseconomies of scale. Smaller companies may benefit more from local AI than larger companies if they need to be HIPAA-compliant.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/expert-hipaa-deidentification\/'>HIPAA expert determination<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2026\/03\/02\/an-ai-odyssey-part-1-correctness-conundrum\/'>An AI Odyssey<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2022\/01\/15\/queueing-and-scale\/'>Queueing and economies of scale<\/a><\/li>\n<\/ul>\n<p>[1] This post is not legal advice. My clients are often lawyers, but I&#8217;m not a lawyer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The best way to run AI and remain HIPAA compliant is to run it locally on your own hardware, instead of transferring protected health information (PHI) to a remote server by using a cloud-hosted service like ChatGPT or Claude. [1]. There are HIPAA-compliant cloud options, but they&#8217;re both restrictive and expensive. Even enterprise options are [&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":[260],"tags":[202,103],"class_list":["post-246947","post","type-post","status-publish","format-standard","hentry","category-ai","tag-artificial-intelligence","tag-privacy"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246947","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=246947"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246947\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246946,"date":"2026-04-04T10:00:14","date_gmt":"2026-04-04T15:00:14","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246946"},"modified":"2026-04-04T13:31:00","modified_gmt":"2026-04-04T18:31:00","slug":"kalman-bayes","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/04\/kalman-bayes\/","title":{"rendered":"Kalman and Bayes average grades"},"content":{"rendered":"<p>This post will look at the problem of updating an average grade as a very simple special case of Bayesian statistics and of Kalman filtering.<\/p>\n<p>Suppose you&#8217;re keeping up with your average grade in a class, and you know your average after <em>n<\/em> tests, all weighted equally.<\/p>\n<p style=\"padding-left: 40px;\"><em>m<\/em> = (<em>x<\/em><sub>1<\/sub> + <em>x<\/em><sub>2<\/sub> + <em>x<\/em><sub>3<\/sub> + \u2026 + <em>x<\/em><sub><em>n<\/em><\/sub>) \/ <em>n<\/em>.<\/p>\n<p>Then you get another test grade back and your new average is<\/p>\n<p style=\"padding-left: 40px;\"><em>m<\/em>\u2032 = (<em>x<\/em><sub>1<\/sub> + <em>x<\/em><sub>2<\/sub> + <em>x<\/em><sub>3<\/sub> + \u2026 + <em>x<\/em><sub><em>n<\/em><\/sub> + <em>x<\/em><sub><em>n<\/em>+1<\/sub>) \/ (<em>n<\/em> + 1).<\/p>\n<p>You don&#8217;t need the individual test grades once you&#8217;ve computed the average; you can instead remember the average\u00a0<em>m<\/em> and the number of grades\u00a0<em>n<\/em> [1]. Then you know the sum of the first\u00a0<em>n<\/em> grades is\u00a0<em>nm<\/em> and so<\/p>\n<p style=\"padding-left: 40px;\"><em>m<\/em>\u2032 = (<em>nm<\/em> + <em>x<\/em><sub><em>n<\/em>+1<\/sub>) \/ (<em>n<\/em> + 1).<\/p>\n<p>You could split that into<\/p>\n<p style=\"padding-left: 40px;\"><em>m<\/em>\u2032 = <em>w<\/em><sub>1<\/sub> <em>m<\/em> + <em>w<\/em><sub>2<\/sub> <em>x<\/em><sub><em>n<\/em>+1<\/sub><\/p>\n<p>where <em>w<\/em><sub>1<\/sub> = <em>n<\/em>\/(<em>n<\/em> + 1) and <em>w<\/em><sub>2<\/sub> = 1\/(<em>n<\/em> + 1). In other words, the new mean is the weighted average of the previous mean and the new score.<\/p>\n<p>A <strong>Bayesian<\/strong> perspective would say that your posterior expected grade <em>m<\/em>\u2032 is a compromise between your prior expected grade\u00a0<em>m<\/em> and the new data <em>x<\/em><sub><em>n<\/em>+1<\/sub>. [2]<\/p>\n<p>You could also rewrite the equation above as<\/p>\n<p style=\"padding-left: 40px;\"><em>m<\/em>\u2032 =\u00a0<em>m<\/em> + (<em>x<\/em><sub><em>n<\/em>+1<\/sub> \u2212 <em>m<\/em>)\/(<em>n<\/em> + 1) = <em>m<\/em> + <em>K<\/em>\u0394<\/p>\n<p>where <em>K<\/em> = 1\/(<em>n<\/em> + 1) and \u0394 = <em>x<\/em><sub><em>n<\/em>+1<\/sub> \u2212 <em>m<\/em>. In <strong>Kalman<\/strong> filter terms,\u00a0<em>K<\/em> is the gain, the proportionality constant for how the change in your state is proportional to the difference between what you saw and what you expected.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2011\/09\/27\/bayesian-amazon\/\">A Bayesian view of Amazon Resellers<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2016\/07\/14\/kalman-filters-and-functional-programming\/\">Kalman filters and functional programming<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2016\/05\/24\/kalman-filters-and-bottom-up-learning\/\">Kalman filters and bottom-up learning<\/a><\/li>\n<\/ul>\n<p>[1] In statistical terms, the mean is a <a href=\"https:\/\/www.johndcook.com\/blog\/2016\/09\/12\/insufficient-statistics\/\">sufficient statistic<\/a>.<\/p>\n<p>[2] You could flesh this out by using a normal likelihood and a flat improper prior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will look at the problem of updating an average grade as a very simple special case of Bayesian statistics and of Kalman filtering. Suppose you&#8217;re keeping up with your average grade in a class, and you know your average after n tests, all weighted equally. m = (x1 + x2 + x3 + [&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":[183],"class_list":["post-246946","post","type-post","status-publish","format-standard","hentry","category-math","tag-kalman-filter"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246946","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=246946"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246946\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246945,"date":"2026-04-03T11:31:54","date_gmt":"2026-04-03T16:31:54","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246945"},"modified":"2026-04-03T11:33:00","modified_gmt":"2026-04-03T16:33:00","slug":"roman-moon-greek-moon","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/03\/roman-moon-greek-moon\/","title":{"rendered":"Roman moon, Greek moon"},"content":{"rendered":"<p>I used the term <strong>perilune<\/strong> in <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/02\/artemis-apollo\/\">yesterday&#8217;s post<\/a> about the flight path of Artemis II. When Artemis is\u00a0<em>closest<\/em> to the moon it will be <em>furthest<\/em> from earth because its closest approach to the moon, its perilune, is on the side of the moon opposite earth.<\/p>\n<p>Perilune is sometimes called <strong>periselene<\/strong>. The two terms come from two goddesses associated with the moon, the Roman Luna and the Greek Selene. Since the peri- prefix is Greek, perhaps periselene would be preferable. But we&#8217;re far more familiar with words associated with the moon being based on Luna than Selene.<\/p>\n<p>The neutral terms for closest and furthest points in an orbit are <strong>periapsis<\/strong> and <strong>apoapsis<\/strong>. but there are more colorful terms that are specific to orbiting particular celestial objects. The terms <strong>perigee<\/strong> and <strong>apogee<\/strong> for orbiting earth (from the Greek Gaia) are most familiar, and the terms <strong>perihelion<\/strong> and <strong>aphelion<\/strong> (not apohelion) for orbiting the sun (from the Greek Helios) are the next most familiar.<\/p>\n<p>The terms <strong>perijove<\/strong> and <strong>apojove<\/strong> are unfamiliar, but you can imagine what they mean. Others like <strong>periareion<\/strong> and <strong>apoareion<\/strong>, especially the latter, are truly arcane.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I used the term perilune in yesterday&#8217;s post about the flight path of Artemis II. When Artemis is\u00a0closest to the moon it will be furthest from earth because its closest approach to the moon, its perilune, is on the side of the moon opposite earth. Perilune is sometimes called periselene. The two terms come from [&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":[213],"class_list":["post-246945","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-orbital-mechanics"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246945","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=246945"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246945\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246944,"date":"2026-04-02T20:38:49","date_gmt":"2026-04-03T01:38:49","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246944"},"modified":"2026-04-02T20:38:49","modified_gmt":"2026-04-03T01:38:49","slug":"hyperbolic-napier-mnemonic","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/02\/hyperbolic-napier-mnemonic\/","title":{"rendered":"Hyperbolic version of Napier&#8217;s mnemonic"},"content":{"rendered":"<p>I was looking through an old geometry book [1] and saw a hyperbolic analog of Napier&#8217;s mnemonic for spherical trigonometry. In hindsight of course there&#8217;s a hyperbolic analog: there&#8217;s a hyperbolic analog of everything. But I was surprised because I&#8217;d never thought of this before. I suppose the spherical version is famous because of its practical use in navigational calculations, while the hyperbolic analog is of more theoretical interest.<\/p>\n<p><a href=\"https:\/\/www.johndcook.com\/blog\/2012\/12\/23\/napiers-mnemonic\/\">Napier&#8217;s mnemonic<\/a> is a clever way to remember 10 equations in spherical trig. See the linked post for the meanings of the variables.<\/p>\n<p style=\"padding-left: 40px;\">sin\u00a0<em>a<\/em>\u00a0= sin\u00a0<em>A<\/em>\u00a0sin\u00a0<em>c<\/em>\u00a0= tan\u00a0<em>b<\/em>\u00a0cot\u00a0<em>B<\/em><br \/>\nsin\u00a0<em>b<\/em>\u00a0= sin\u00a0<em>B<\/em>\u00a0sin\u00a0<em>c<\/em>\u00a0= tan\u00a0<em>a<\/em>\u00a0cot\u00a0<em>A<\/em><br \/>\ncos\u00a0<em>A<\/em>\u00a0= cos\u00a0<em>a<\/em>\u00a0sin B = tan\u00a0<em>b<\/em>\u00a0cot\u00a0<em>c<\/em><br \/>\ncos\u00a0<em>B<\/em>\u00a0= cos\u00a0<em>b<\/em>\u00a0sin A = tan\u00a0<em>a<\/em>\u00a0cot\u00a0<em>c<\/em><br \/>\ncos\u00a0<em>c<\/em>\u00a0= cot\u00a0<em>A<\/em>\u00a0cot\u00a0<em>B<\/em>\u00a0= cos\u00a0<em>a<\/em>\u00a0cos\u00a0<em>b<\/em><\/p>\n<p>The hyperbolic analog replaces every circular function of\u00a0<em>a<\/em>,\u00a0<em>b<\/em>, or\u00a0<em>c<\/em> with its hyperbolic counterpart.<\/p>\n<p style=\"padding-left: 40px;\">sinh <em>a<\/em>\u00a0= sin\u00a0<em>A<\/em> sinh\u00a0<em>c<\/em> = tanh\u00a0<em>b<\/em>\u00a0cot\u00a0<em>B<\/em><br \/>\nsinh <em>b<\/em>\u00a0= sin\u00a0<em>B<\/em> sinh\u00a0<em>c<\/em> = tanh\u00a0<em>a<\/em>\u00a0cot\u00a0<em>A<\/em><br \/>\ncos\u00a0<em>A<\/em> = cosh\u00a0<em>a<\/em> sin B = tanh\u00a0<em>b<\/em> coth\u00a0<em>c<\/em><br \/>\ncos\u00a0<em>B<\/em> = cosh\u00a0<em>b<\/em> sin A = tanh\u00a0<em>a<\/em> coth\u00a0<em>c<\/em><br \/>\ncosh <em>c<\/em>\u00a0= cot\u00a0<em>A<\/em>\u00a0cot\u00a0<em>B<\/em> = cosh\u00a0<em>a<\/em> cosh\u00a0<em>b<\/em><\/p>\n<p>[1] D. M. Y. Sommerville. The Elements of Non-Euclidean Geometry. 1919.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was looking through an old geometry book [1] and saw a hyperbolic analog of Napier&#8217;s mnemonic for spherical trigonometry. In hindsight of course there&#8217;s a hyperbolic analog: there&#8217;s a hyperbolic analog of everything. But I was surprised because I&#8217;d never thought of this before. I suppose the spherical version is famous because of its [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[224,220],"class_list":["post-246944","post","type-post","status-publish","format-standard","hentry","category-math","tag-geometry","tag-memory"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246944","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=246944"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246944\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246941,"date":"2026-04-02T09:14:44","date_gmt":"2026-04-02T14:14:44","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246941"},"modified":"2026-04-02T09:50:10","modified_gmt":"2026-04-02T14:50:10","slug":"artemis-apollo","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/02\/artemis-apollo\/","title":{"rendered":"Artemis II, Apollo 8, and Apollo 13"},"content":{"rendered":"<p>The Artemis II mission launched yesterday. Much like the Apollo 8 mission in 1968, the goal is to go around the moon in preparation for a future mission that will land on the moon. And like Apollo 13, the mission will swing around the moon rather than entering lunar orbit. Artemis II will deliberately follow the trajectory around the moon that Apollo 13 took as a fallback. <\/p>\n<p>Apollo 8 spent 2 hours and 44 minutes in low earth orbit (LEO) before performing trans-lunar injection (TLI) and heading toward the moon. Artemis II made one low earth orbit before moving to high earth orbit (HEO) where it will stay for around 24 hours before TLI. The Apollo 8 LEO was essentially circular at an altitude of around 100 nautical miles. The Artemis II HEO is highly eccentric with an apogee of around 40,000 nautical miles.<\/p>\n<p>Apollo 8 spent roughly three days traveling to the moon, measured as the time between TLI and lunar insertion orbit. Artemis II will not orbit the moon but instead swing past the moon on a &#8220;lunar free-return trajectory&#8221; like Apollo 13. The time between Artemis&#8217; TLI and perilune (the closest approach to the moon, on the far side) is expected to be about four days. For Apollo 13, this period was three days.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.johndcook.com\/artemis.png\" width=\"500\" height=\"268\" class=\"aligncenter size-medium\" \/><\/p>\n<p>The furthest any human has been from earth was the Apollo 13 perilune at about 60 nautical miles above the far side of the moon. Artemis is expected to break this record with a perilune of between 3,500 and 5,200 nautical miles.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2022\/12\/15\/sphere-of-infuence\/'>Sphere of influence<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2020\/02\/08\/arenstorf-orbit\/'> Arenstorf&#8217;s orbit<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2020\/06\/12\/new-math-for-going-to-the-moon\/'>Math developed for going to the moon<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The Artemis II mission launched yesterday. Much like the Apollo 8 mission in 1968, the goal is to go around the moon in preparation for a future mission that will land on the moon. And like Apollo 13, the mission will swing around the moon rather than entering lunar orbit. Artemis II will deliberately follow [&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":[213],"class_list":["post-246941","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-orbital-mechanics"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246941","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=246941"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246941\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246933,"date":"2026-04-01T08:23:42","date_gmt":"2026-04-01T13:23:42","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246933"},"modified":"2026-04-01T08:28:48","modified_gmt":"2026-04-01T13:28:48","slug":"truncated-triangular-numbers","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/01\/truncated-triangular-numbers\/","title":{"rendered":"Pentagonal numbers are truncated triangular numbers"},"content":{"rendered":"<p>Pentagonal numbers are truncated triangular numbers. You can take the diagram that illustrates the\u00a0<em>n<\/em>th pentagonal number and warp it into the base of the image that illustrates the (2<em>n<\/em> \u2212 1)st triangular number. If you added a diagram for the (<em>n<\/em> \u2212 1)st triangular number to the bottom of the image on the right, you&#8217;d have a diagram for the (2<em>n<\/em> \u2212 1)st triangular number.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/pent_trunk.svg\" width=\"587\" height=\"224\" \/><\/p>\n<p>In short,<\/p>\n<p style=\"padding-left: 40px;\"><em>P<\/em><sub><em>n<\/em><\/sub> = <em>T<\/em><sub>2<em>n<\/em> \u2212 1<\/sub> \u2212 <em>T<\/em><sub><em>n<\/em>.<\/sub><\/p>\n<p>This is trivial to prove algebraically, though the visual proof above is more interesting.<\/p>\n<p>The proof follows immediately from the definition of pentagonal numbers<\/p>\n<p style=\"padding-left: 40px;\"><em>P<\/em><sub><em>n<\/em><\/sub> = (3<em>n<\/em>\u00b2 \u2212 <em>n<\/em>)\/2<\/p>\n<p>and triangular numbers<\/p>\n<p style=\"padding-left: 40px;\"><em>T<\/em><sub><em>n<\/em><\/sub> = (<em>n<\/em>\u00b2 \u2212 <em>n<\/em>)\/2.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2021\/11\/10\/partitions-and-pentagons\/'>Partitions and pentagons<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2018\/06\/07\/tetrahedral-numbers-2\/'>Tetrahedral numbers<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2023\/04\/14\/euclid-xiii-10\/'> A pentagon, hexagon, and decagon walk into a bar \u2026<br \/>\n <\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Pentagonal numbers are truncated triangular numbers. You can take the diagram that illustrates the\u00a0nth pentagonal number and warp it into the base of the image that illustrates the (2n \u2212 1)st triangular number. If you added a diagram for the (n \u2212 1)st triangular number to the bottom of the image on the right, you&#8217;d [&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-246933","post","type-post","status-publish","format-standard","hentry","category-math","tag-number-theory"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246933","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=246933"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246933\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246932,"date":"2026-03-31T09:43:06","date_gmt":"2026-03-31T14:43:06","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246932"},"modified":"2026-04-01T09:09:47","modified_gmt":"2026-04-01T14:09:47","slug":"quantum-y2k","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/03\/31\/quantum-y2k\/","title":{"rendered":"Quantum Y2K"},"content":{"rendered":"<p>I&#8217;m skeptical that quantum computing will become practical. However, if it does become practical before we&#8217;re prepared, the world&#8217;s financial system could collapse. Everyone agrees we should prepare for quantum computing, even those of us who doubt it will be practical any time soon.<\/p>\n<p>Quantum computers exist now, but the question is when and if a cryptographically relevant quantum computer (CRQC) is coming. At the moment, a quantum computer cannot factor 21 without cheating (i.e. not implementing circuits that you know\u00a0<em>a priori<\/em> won&#8217;t be needed). But that could change suddenly. And some believe quantum computers could quickly go from being able to factor numbers with two digits to being able to factor numbers with thousands of digits (i.e. breaking RSA encryption) without much incremental transition between.<\/p>\n<p>The move to post-quantum encryption may be a lot like Y2K, fixing vast amounts of 20th century software that represented years with two digits. Y2K turned out to be a big nothingburger, but only because the world spent half a trillion dollars on preparation to make sure it would be a big nothingburger.<\/p>\n<p>Programmers in the 1970s obviously knew that the year 2000 was coming, but they also knew that they needed to conserve bytes at the time. And they assumed, reasonably but incorrectly, that their software would all be replaced before two-digit dates became a problem.<\/p>\n<p>Programmers still need to conserve bytes, though this is less obvious today. Quantum-resistant signatures and encryption keys are one or two orders of magnitude bigger. This takes up bandwidth and storage space, which may or may not be a significant problem, depending on context. Programmers may conclude that it&#8217;s not (yet) worth the extra overhead to use post-quantum encryption. Like their counterparts 50 years ago, they may assume, rightly or wrongly, that their software will be replaced by the time it needs to be.<\/p>\n<p>Moving to post-quantum cryptography ASAP is not a great idea if you can afford to be more strategic. It takes many years to gain confidence that new encryption algorithms are secure. The SIKE algorithm, for example, was a semi-finalist the NIST post-quantum encryption competition, but someone found a way to break it using an hour of computing on a laptop.<\/p>\n<p>Another reason to not be in a hurry is that it may be possible to be more clever than simply replacing pre-quantum algorithms with post-quantum analogs. For example, some blockchains are exploring zero-knowledge proofs as a way to aggregate signatures. Simply moving to post-quantum signatures could make every transaction block 100 times bigger. But replacing a set of signatures by a (post-quantum) zero-knowledge proof of the existence of the signatures, transaction blocks could be\u00a0<em>smaller<\/em> than now.<\/p>\n<p>As with Y2K, the move to post-quantum cryptography will be gradual. Some things have already moved, and some are in transition now. You may have seen the following warning when connecting to a remote server.<\/p>\n<pre>** WARNING: connection is not using a post-quantum key exchange algorithm.\r\n** This session may be vulnerable to \"store now, decrypt later\" attacks.\r\n** The server may need to be upgraded. See https:\/\/openssh.com\/pq.html\r\n<\/pre>\n<p>Key sizes don&#8217;t matter as much to <code>sftp<\/code> connections as they do to blockchains. And the maturity of post-quantum algorithms is mitigated by OpenSSH using hybrid encryption: well-established encryption (like ECDH) wrapped by newer quantum-resistant encryption (like MK-KEM). If the newer algorithm isn&#8217;t as secure as expected, you&#8217;re no worse off than if you had only used the older algorithm.<\/p>\n<p>When clocks rolled over from 1999 to 2000 without incident, many people felt the concern about Y2K had been overblown. Maybe something similar will happen with quantum computing. Let&#8217;s hope so.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2019\/03\/23\/code-based-cryptography\/\">Mixing error-correcting codes and cryptography<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2019\/02\/22\/regression-modular-arithmetic-and-pqc\/\">Regression ond PQC<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/crypto\/\">Blockchains and cryptocurrency<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m skeptical that quantum computing will become practical. However, if it does become practical before we&#8217;re prepared, the world&#8217;s financial system could collapse. Everyone agrees we should prepare for quantum computing, even those of us who doubt it will be practical any time soon. Quantum computers exist now, but the question is when and if [&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":[43],"class_list":["post-246932","post","type-post","status-publish","format-standard","hentry","category-computing","tag-cryptography"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246932","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=246932"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246932\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246931,"date":"2026-03-31T07:12:31","date_gmt":"2026-03-31T12:12:31","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246931"},"modified":"2026-03-31T07:12:31","modified_gmt":"2026-03-31T12:12:31","slug":"morse-code-tree","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/03\/31\/morse-code-tree\/","title":{"rendered":"Morse code tree"},"content":{"rendered":"<p><a href=\"https:\/\/x.com\/PeterVogel\/status\/2038637417868267567\">Peter Vogel<\/a> posted the following image on X yesterday.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/morse_code_tree.jpeg\" width=\"400\" height=\"659\" \/><\/p>\n<p>The receive side of the coin is a decision tree for decoding Morse code. The shape is what makes this one interesting.<\/p>\n<p>Decision trees are typically not very compact. Each branch is usually on its own horizontal level, with diagonal lines going down from each node to its children. But by making the lines either horizontal or vertical, the tree fits nicely into a circle.<\/p>\n<p>I thought for a second that the designer had made the choices of horizontal or vertical segments in order to make the tree compact, but that&#8217;s not so. The direction of the path through the tree changes when and only when the Morse code switches from dot to dash or dash to dot.<\/p>\n<p>It would be fun to play around with this, using the same design idea for other binary trees.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2016\/05\/03\/family-tree-numbering\/'>Family tree numbering<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2022\/02\/21\/q-codes-in-seveneves\/'>Q code tree<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2025\/04\/23\/qrq\/'>Morse code and psychological limits<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Peter Vogel posted the following image on X yesterday. The receive side of the coin is a decision tree for decoding Morse code. The shape is what makes this one interesting. Decision trees are typically not very compact. Each branch is usually on its own horizontal level, with diagonal lines going down from each node [&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":[218],"class_list":["post-246931","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-morse-code"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246931","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=246931"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246931\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246929,"date":"2026-03-27T11:06:18","date_gmt":"2026-03-27T16:06:18","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246929"},"modified":"2026-03-27T11:06:18","modified_gmt":"2026-03-27T16:06:18","slug":"an-ai-odyssey-part-3-lost-needle-in-the-haystack","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/03\/27\/an-ai-odyssey-part-3-lost-needle-in-the-haystack\/","title":{"rendered":"An AI Odyssey, Part 3: Lost Needle in the Haystack"},"content":{"rendered":"<p>While shopping on a major e-commerce site, I wanted to get an answer to an obscure question about a certain product.<\/p>\n<p>Not finding the answer immediately on the product page, I thought I&#8217;d try clicking the AI shopping assistant helper tool to ask this question.<\/p>\n<p>I waited with anticipation for an answer I would expect be more informative and useful than a standard search result. But it was not to be. The AI tool had nothing worthwhile.<\/p>\n<p>Then I decided on an old-fashioned keyword search across all the product reviews. And, lo and behold, I immediately found several credible reviews addressing my question.<\/p>\n<p>It is not good usability when multiple search mechanisms exist but only one of them is reliable. And it is surprising that a retrieval-based approach (e.g., RAG) could not at least match the effectiveness of a simple keyword search over reviews.<\/p>\n<p>Models are capable, but effective integration can be lacking. Without improvements for cases like this, customers will not be satisfied users of these new AI tools.<\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2026\/03\/02\/an-ai-odyssey-part-1-correctness-conundrum\/\">An AI Odyssey, Part 1: Correctness Conundrum<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2026\/03\/04\/an-ai-odyssey-part-2-prompting-peril\/\">An AI Odyssey, Part 2: Prompting Peril<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>While shopping on a major e-commerce site, I wanted to get an answer to an obscure question about a certain product. Not finding the answer immediately on the product page, I thought I&#8217;d try clicking the AI shopping assistant helper tool to ask this question. I waited with anticipation for an answer I would expect [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[260,261],"tags":[315,321],"class_list":["post-246929","post","type-post","status-publish","format-standard","hentry","category-ai","category-artificial-intelligence","tag-ai-reliability","tag-usability"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246929","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246929"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246929\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246928,"date":"2026-03-27T06:33:04","date_gmt":"2026-03-27T11:33:04","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246928"},"modified":"2026-03-27T11:40:08","modified_gmt":"2026-03-27T16:40:08","slug":"complex-argument","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/03\/27\/complex-argument\/","title":{"rendered":"Computing sine and cosine of complex arguments with only real functions"},"content":{"rendered":"<p>Suppose you have a calculator or math library that only handles real arguments but you need to evaluate sin(3 + 4<em>i<\/em>). What do you do?<\/p>\n<p>If you&#8217;re using Python, for example, and you don&#8217;t have NumPy installed, you can use the built-in math library, but it will not accept complex inputs.<\/p>\n<pre>&gt;&gt;&gt; import math\r\n&gt;&gt;&gt; math.sin(3 + 4j)\r\nTraceback (most recent call last):\r\nFile \"&lt;stdin&gt;\", line 1, in &lt;module&gt;\r\nTypeError: must be real number, not complex\r\n<\/pre>\n<p>You can use the following identities to calculate sine and cosine for complex arguments using only real functions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/complex_sincos1.svg\" alt=\"\\begin{align*} \\sin(x + iy) &amp;= \\sin x \\cosh y + i \\cos x \\sinh y \\\\ \\cos(x + iy) &amp;= \\cos x \\cosh y - i \\sin x \\sinh y \\\\ \\end{align*}\" width=\"324\" height=\"47\" \/><\/p>\n<p>The proof is very simple: just use the addition formulas for sine and cosine, and the following identities.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/complex_sincos4.svg\" alt=\"\\begin{align*} \\sin iz &amp;= i \\sinh z \\\\ \\cos iz &amp;= \\cosh z \\end{align*}\" width=\"122\" height=\"43\" \/><\/p>\n<p>The following code implements sine and cosine for complex arguments using only the built-in Python functions that accept real arguments. It then tests these against the NumPy versions that accept complex arguments.<\/p>\n<pre>\r\nfrom math import *\r\nimport numpy as np\r\n\r\ndef complex_sin(z):\r\n    x, y = z.real, z.imag\r\n    return sin(x)*cosh(y) + 1j*cos(x)*sinh(y)\r\n\r\ndef complex_cos(z):\r\n    x, y = z.real, z.imag\r\n    return cos(x)*cosh(y) - 1j*sin(x)*sinh(y)\r\n\r\nz = 3 + 4j\r\nmysin = complex_sin(z)\r\nmycos = complex_cos(z)\r\nnpsin = np.sin(z)\r\nnpcos = np.cos(z)\r\nassert(abs(mysin - npsin) < 1e-14)\r\nassert(abs(mycos - npcos) < 1e-14)\r\n<\/pre>\n<h2>Related posts<\/h2>\n<ul>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2013\/04\/23\/why-j-for-imaginary-unit\/'>Why <em>j<\/em> for imaginary unit?<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2021\/01\/05\/bootstrapping-math-library\/'>Bootstrapping a minimal math library<\/a><\/li>\n<li class='link'><a href='https:\/\/www.johndcook.com\/blog\/2024\/08\/20\/osborn-rule\/'>Osborn's rule<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Suppose you have a calculator or math library that only handles real arguments but you need to evaluate sin(3 + 4i). What do you do? If you&#8217;re using Python, for example, and you don&#8217;t have NumPy installed, you can use the built-in math library, but it will not accept complex inputs. &gt;&gt;&gt; import math &gt;&gt;&gt; [&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":[181,169],"class_list":["post-246928","post","type-post","status-publish","format-standard","hentry","category-math","tag-complex-analysis","tag-python"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246928","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=246928"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246928\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]