{"id":6119,"date":"2023-12-01T00:01:11","date_gmt":"2023-12-01T08:01:11","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6119"},"modified":"2023-12-08T17:37:06","modified_gmt":"2023-12-09T01:37:06","slug":"tetration","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6119","title":{"rendered":"Tetration"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9733;<\/h2>\n<p>Tetration is a mathematical process that generates obnoxiously huge numbers quickly. It&#8217;s exponentiation on overdrive. The concept is insane, but it&#8217;s also something you can code in C.<br \/>\n<!--more--><br \/>\nTo understand tetration, start with exponentiation. The expression 2<sup>3<\/sup> reads as &#8220;two to the third power.&#8221; It&#8217;s shorthand for <code>2 * 2 * 2<\/code>. Tetration takes this concept higher, but first consider this operation:<\/p>\n<p>2<sup>3<sup>5<\/sup><\/sup><\/p>\n<p>The expression above is valid. It&#8217;s calculated as 3<sup>5<\/sup>, which is 243. Then you get 2<sup>243<\/sup>, which is 1.4134776518227074636666380005943e+73. Neat-o.<\/p>\n<p>Stacking powers in this manner is called nesting exponents. They work from the top-down. Tetration works similarly, but with a singe value:<\/p>\n<p>2<sup>2<sup>2<\/sup><\/sup><\/p>\n<p>This expression is evaluated the same: 2<sup>2<\/sup> is 4, and 2<sup>4<\/sup> is 16: 2<sup>2<sup>2<\/sup><\/sup> = 16.<\/p>\n<p>One way to express tetration is to use this notation: <sup>2<\/sup>2, with the exponent coming before the number. Another way is to use Knuth&#8217;s up-arrow notation: 2\u2191\u21912. In computerdom, two carets are often used: 2^^2.<\/p>\n<p>Regardless of the notation, with tetration values can get quite large quickly. Peruse <a href=\"https:\/\/www.youtube.com\/watch?v=0poh3w_Vm_A\" rel=\"noopener\" target=\"_blank\">this YouTube video<\/a> is you want to completely blow your brain. After watching, you may understand why this topic isn&#8217;t taught in school or why a tetration function isn&#8217;t available in the standard C library. But that doesn&#8217;t mean you can&#8217;t write one yourself!<\/p>\n<p>This month&#8217;s C programming Exercise is to write a tertration function. Pass to the function the base value and the tetration exponent. For the expression <sup>5<\/sup>2, the base is 2 and the exponent is 5. This is the same expression depicted in Figure 1. Your function must calculate and return the result.<\/p>\n<div id=\"attachment_6127\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6127\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/12\/12ex-figure1.png\" alt=\"\" width=\"550\" height=\"171\" class=\"size-full wp-image-6127\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/12\/12ex-figure1.png 550w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/12\/12ex-figure1-300x93.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2023\/12\/12ex-figure1-500x155.png 500w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><p id=\"caption-attachment-6127\" class=\"wp-caption-text\">Figure 1. Examples of tetration notation.<\/p><\/div>\n<p>You can ignore base values less than 2. I&#8217;m unaware whether a rule exists, but I&#8217;ve seen nothing regarding a tetration expression like <sup>1<\/sup>2, which is just two squared, 2<sup>2<\/sup>, or <sup>0<\/sup>2, which would be one (or would it be two?). Because I&#8217;ve not found any documentation to address these low tetration values, just cut off the exponent values below two in your solution.<\/p>\n<p>Here is output from my solution:<\/p>\n<p><code>Base: 4<br \/>\nExponent: 3<br \/>\n4^^3 = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096<\/code><\/p>\n<p>These numbers get huge quickly! Many of them cannot be calculated when using the standard C library. For example, from Figure 1:<\/p>\n<p><code>Base: 2<br \/>\nExponent: 5<br \/>\n2^^5 = inf<\/code><\/p>\n<p>Don&#8217;t worry about using <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5532\">a large number library<\/a> to obtain the results, as that&#8217;s not part of this exercise.<\/p>\n<p>Please try this challenge on your own. My solution <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6140\">is available here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to generate huge values with very little effort. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6119\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-6119","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6119"}],"version-history":[{"count":13,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6119\/revisions"}],"predecessor-version":[{"id":6160,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6119\/revisions\/6160"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}