From b756444016e50a3ed53c78b4a898480532db24c5 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 9 Nov 2022 23:36:32 +1300 Subject: Added article for Number Wall program --- project/assets/css/accordian.css | 39 + project/assets/css/numberwall.css | 38 + project/assets/css/steelman.css | 39 - project/assets/img/pagoda_wall_mod_5.png | Bin 0 -> 12030 bytes project/complexity.yml | 1 + project/context/articles.json | 6 + project/templates/numberwall.xhtml | 1234 ++++++++++++++++++++++++++++++ project/templates/steelman.xhtml | 1 + 8 files changed, 1319 insertions(+), 39 deletions(-) create mode 100644 project/assets/css/accordian.css create mode 100644 project/assets/css/numberwall.css create mode 100644 project/assets/img/pagoda_wall_mod_5.png create mode 100644 project/templates/numberwall.xhtml diff --git a/project/assets/css/accordian.css b/project/assets/css/accordian.css new file mode 100644 index 0000000..9c52e5d --- /dev/null +++ b/project/assets/css/accordian.css @@ -0,0 +1,39 @@ + + +div.accordian { + margin: 1em 2em 2em 2em; +} + + +.accordian > input[name="collapse"] { + display: none; +} + + +.accordian .hidden_content { + overflow: hidden; + height: 0; +} + + +.accordian label { + color: #ffffff; + cursor: pointer; + font-weight: normal; + padding: 0.5em; + background: #808080; +} + + +.accordian label:hover, +.accordian label:focus { + color: #ffffff; + background: #000000; +} + + +.accordian > input[name="collapse"]:checked ~ .hidden_content { + height: auto; +} + + diff --git a/project/assets/css/numberwall.css b/project/assets/css/numberwall.css new file mode 100644 index 0000000..8efcea8 --- /dev/null +++ b/project/assets/css/numberwall.css @@ -0,0 +1,38 @@ + + +table { + margin: 2em auto 2em auto; +} + + + + +table.rule { + border: 1px solid gray; + width: 90%; +} + +table.rule th { + border: 1px solid gray; + width: 33%; +} + +table.rule td { + padding: 0.5em 1em 0.5em 1em; + border: 1px solid gray; +} + + + + +table.wall { + border: none; + text-align: center; +} + +table.wall td { + padding: 0.5em 0.4em 0.5em 0.4em; + border: none; +} + + diff --git a/project/assets/css/steelman.css b/project/assets/css/steelman.css index 14bc84b..5b6b5c9 100644 --- a/project/assets/css/steelman.css +++ b/project/assets/css/steelman.css @@ -1,44 +1,5 @@ -div.accordian { - margin: 1em 2em 2em 2em; -} - - -.accordian > input[name="collapse"] { - display: none; -} - - -.accordian .hidden_content { - overflow: hidden; - height: 0; -} - - -.accordian label { - color: #ffffff; - cursor: pointer; - font-weight: normal; - padding: 0.5em; - background: #808080; -} - - -.accordian label:hover, -.accordian label:focus { - color: #ffffff; - background: #000000; -} - - -.accordian > input[name="collapse"]:checked ~ .hidden_content { - height: auto; -} - - - - table { margin: 2em auto 2em auto; max-width: 60em; diff --git a/project/assets/img/pagoda_wall_mod_5.png b/project/assets/img/pagoda_wall_mod_5.png new file mode 100644 index 0000000..4634d6b Binary files /dev/null and b/project/assets/img/pagoda_wall_mod_5.png differ diff --git a/project/complexity.yml b/project/complexity.yml index 58b56ca..0f14072 100644 --- a/project/complexity.yml +++ b/project/complexity.yml @@ -19,6 +19,7 @@ unexpanded_templates: - "index.xhtml" - "integral.xhtml" - "links.xhtml" + - "numberwall.xhtml" - "packrat.xhtml" - "sokoban.xhtml" - "steelman.xhtml" diff --git a/project/context/articles.json b/project/context/articles.json index fef380d..50611ab 100644 --- a/project/context/articles.json +++ b/project/context/articles.json @@ -1,5 +1,11 @@ [ + { + "title": "Number Wall Visualiser", + "anchor": "/numberwall.xhtml", + "taglist": ["application", "mathematics", "programming"], + "postdate": "9/11/2022" + }, { "title": "Contributions to Other Projects", "anchor": "/contributions.xhtml", diff --git a/project/templates/numberwall.xhtml b/project/templates/numberwall.xhtml new file mode 100644 index 0000000..0e343ed --- /dev/null +++ b/project/templates/numberwall.xhtml @@ -0,0 +1,1234 @@ + +{%- extends "base_math.xhtml" -%} + + + +{%- block title -%}Number Wall Visualiser{%- endblock -%} + + + +{%- block footer -%}{{ math_footer ("numberwall.xhtml") }}{%- endblock -%} + + + +{%- block style %} + + +{% endblock -%} + + + +{%- block content %} +

Number Wall Visualiser

+ +

Git repository: Link
+Mathologer video: +Invidious +Youtube

+ +
9/11/2022
+ + +
Overview
+ +

On August 27, 2022, a youtube mathematician called the Mathologer published an interesting video +on the mathematical constructs known as number walls. In the description of that video he also +published a coding challenge of creating an implementation of the number wall algorithm.

+ +

This is not an entry into that coding challenge. This is just a tribute.

+ +

For various reasons this didn't end up finished in the time period required, and in any case it +is not an online implementation and so doesn't qualify. But this project still has some fun tools to +play around with for anyone with an interest in math. Amongst other things, elaborate pictures of +the fractal square patterns produced by large number walls can be made.

+ +
+ Number wall of the Pagoda sequence modulo 5 +
Number wall of the + Pagoda sequence with cells equal to 0 mod 5 in orange and others in blue
+
+ +

It is strongly recommended that you watch the Mathologer's video for an explanation of what +exactly a number wall is. If, for some reason, you don't want to do that or the video is +inaccessible, then the rules of how to construct a number wall are detailed in the appendix.

+ + +
Tools
+ +

There are three programs provided:

+ + +

An example of using wallsolve to calculate the next number in the sequence of integer +cubes:

+
+
+> wallsolve -i 1,8,27,64,125,216,343,512,729,1000
+S(n) = 4S(n-1) - 6S(n-2) + 4S(n-3) - S(n-4)
+Next: 1331
+>
+
+
+ +

An example of visualwall has already been given in the overview in the form of the picture +of the Pagoda sequence number wall, and the output of wallgen is too verbose to show here. +

+ + +
Implementation Details
+ +

All calculations to produce the number walls in these programs are done using the simple +construction rules in the appendix. No determinants were used, as that method would be more +computationally intensive.

+ +

Since the methods of constructing a number wall given by the Mathologer assume a sequence that is +infinite in both directions and any sequence used by these programs is finite, some compromises had +to be made. In particular, visualwall uses a longer sequence to generate its number wall and +then fits the largest square viewing area it can inside the resulting triangle of calculated values. +

+ +

The polynomial library made for wallsolve assumes that coefficients will always be +integers. This applies even to the division implementation, with only integer division being used +and the remainder term becoming larger than it may otherwise be expected to be if rationals were +permitted. As a number wall calculated from an integer sequence (or a sequence of polynomials with +integer coefficients) will always have integer values, this isn't actually a problem. But care had +to be taken in number wall construction so that division operations were always left until last.

+ +

The modulus values allowed by visualwall are not limited to prime numbers. If a composite +modulus is selected then the highlighted portions of cells equal to zero modulo that number may not +produce squares. The resulting pictures are, however, still interesting to examine.

+ +

At present visualwall only has the option to display either the Pagoda sequence or a +sequence of random numbers, unless a comma separated value formatted sequence is supplied in an +external file. It would not be hard for anyone with a passing knowledge of OCaml to add in different +sequences, but at this stage there is no need.

+ + +
Appendix: How to Construct a Number Wall
+ +

A number wall is a grid of numbers that extends infinitely left, right, and down. It begins with +an infinite row of ones at the top, then below that a row containing the input sequence. All other +cells are computed according to the following rules.

+ +
+ + +
+ + + + + + + + + + + + +
PatternRelationNotes
+ + + + + + + + + + + + + + + + +
  + + a + +  
+ + b + + + + c + + + + d + +
  + + e + +  
+
+ + + a + + e + + + b + + d + = + + c + 2 + + + +
+
+ or alternatively +
+
+ + + e + = + + + + c + 2 + + - + b + + d + + a + + + +
+
+ where + + + a + + 0 + + +
+ This rule is used to calculate the vast majority of cells. +
+ +
+
+ +
+ + +
+ + + + + + + + + + + + +
PatternRelationNotes
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   + + a + +   
   + + b + +   
+ + c + + + + d + +   + + e + + + + f + +
   + + g + +   
   + + h + +   
+
+ + + + b + 2 + + + h + + + a + + + g + 2 + + = + + d + 2 + + + f + + + c + + + e + 2 + + + +
+
+ or alternatively +
+
+ + + h + = + + + + d + 2 + + + f + + + c + + + e + 2 + + - + a + + + g + 2 + + + + b + 2 + + + + +
+
+ where + + b + + 0 + +
+ If cell + + a + + goes out of bounds of the wall, it is considered equal to zero. +
+ +
+
+ +
+ + +
+ + + + + + + + + + + + +
PatternRelationNotes
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + a + + + + b + + + + c + + + + d + + + + e + + + + f + +
+ + g + + 0000 + + h + +
+ + i + + 0000 + + j + +
+ + k + + 0000 + + l + +
+ + m + + 0000 + + n + +
+ + o + + + + p + + + + q + + + + r + + + + s + + + + t + +
+
+ + + + + W + + X + + + Y + + Z + + + = + S + + + where +
+
+ + W + + is the common ratio of the arithmetic sequence + + + a + , + b + , + c + , + d + , + e + , + f + + +
+
+ + X + + is the common ratio of the arithmetic sequence + + + t + , + s + , + r + , + q + , + p + , + o + + +
+
+ + Y + + is the common ratio of the arithmetic sequence + + + a + , + g + , + i + , + k + , + m + , + o + + +
+
+ + Z + + is the common ratio of the arithmetic sequence + + + t + , + n + , + l + , + j + , + h + , + f + + +
+
+ + S + + is equal to + + 1 + + if the dimension of the zero square is even, or + + -1 + + if the dimension is odd +
+ All cells surrounding a square of zeros are guaranteed to be nonzero.
+
+ This rule is applicable to squares of zeros of any finite size, but for the sake of + simplicity the previous rule should be used for isolated zeros.
+
+ The cells that this rule should be targeted at calculating are those on the bottom row + below the square of zeros. Reformulating the math to solve for those cells is left as an + exercise to the reader. +
+ +
+
+ +
+ + +
+ + + + + + + + + + + + +
PatternRelationNotes
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   + + + a + 1 + + + + + + a + 2 + + + + + + a + 3 + + + + + + a + 4 + + +   
   + + + b + 1 + + + + + + b + 2 + + + + + + b + 3 + + + + + + b + 4 + + +   
+ + + c + 1 + + + + + + d + 1 + + + 0000 + + + f + 4 + + + + + + e + 4 + + +
+ + + c + 2 + + + + + + d + 2 + + + 0000 + + + f + 3 + + + + + + e + 3 + + +
+ + + c + 3 + + + + + + d + 3 + + + 0000 + + + f + 2 + + + + + + e + 2 + + +
+ + + c + 4 + + + + + + d + 4 + + + 0000 + + + f + 1 + + + + + + e + 1 + + +
   + + + h + 4 + + + + + + h + 3 + + + + + + h + 2 + + + + + + h + 1 + + +   
   + + + g + 4 + + + + + + g + 3 + + + + + + g + 2 + + + + + + g + 1 + + +   
+
+ + + Y + + + + a + n + + + b + n + + + + + s + + W + + + + c + n + + + d + n + + + = + Z + + + + g + n + + + h + n + + + + + s + + X + + + + e + n + + + f + n + + + + +
+
+ where +
+
+ + + W + , + X + , + Y + , + Z + + + are the common ratios of the arithmetic sequences along the sides of the square of zeros + as in the Horseshoe Rule
+
+ + s + + is equal to + + -1 + + if + + n + + is odd and + + 1 + + if + + n + + is even +
+ As with the Horseshoe Rule, this rule is applicable to squares of zeros of any finite + size.
+
+ The cells that this rule should be targeted at are those along the bottom denoted as + + + g + n + + + but as with the previous rule, reformulating the math to solve for those cells is left + as an exercise to the reader.
+
+ As with the Long Cross Rule, if any of the cells + + + a + n + + + go out of bounds of the wall they are considered to be equal to zero. This can occur if + there are non-isolated zeros in the input sequence. +
+ +
+
+ +

An example of a number wall:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1111111
641252163435127291000
721180137817057120971944129701
20164140734411844178562559635280
1296129612961296129612961296
0000000
+ +

The above excerpt was taken from the number wall generated by the sequence of integer cubes. In +this case, the wall essentially ends in a row of all zeros as all subsequent rows below that will +also be zeros. Note however that this does not always happen.

+ +

A property of number walls is that zeros will always be arranged in squares. A singular isolated +zero is considered to be a 1x1 square and a wall ending in rows of zeros as above is considered to +be the start of a square of zeros of infinite size. This property can be used to supplement the +calculation rules.

+ +{% endblock -%} + + diff --git a/project/templates/steelman.xhtml b/project/templates/steelman.xhtml index 94a7721..77ed0b6 100644 --- a/project/templates/steelman.xhtml +++ b/project/templates/steelman.xhtml @@ -13,6 +13,7 @@ {%- block style %} + {% endblock -%} -- cgit