number-wall-0.1.0.3: Create number walls and save them as images
Copyright(c) Owen Bechtel 2022
LicenseMIT
Safe HaskellSafe-Inferred
LanguageHaskell2010

NumberWall

Description

Example usage:

wall = numberWall (pagoda :: Int -> Mod 2)
color x = case unMod x of
  0 -> (181, 118, 46)
  1 -> (0, 0, 0)
saveImage "pagoda.png" color (0, 256) (0, 128) wall
Synopsis

Creating number walls

type Col = Int Source #

type Row = Int Source #

numberWall :: NumberWall a => (Int -> a) -> Col -> Row -> a Source #

Generate the number wall for a sequence.

type NumberWall a = (Eq a, Ring a, Euclidean a) Source #

The numberWall function works for any Euclidean domain. (In other words, there must be some sort of div function, along with addition and multiplication). Usually, this domain is either Integer or Mod p for some prime number p. Although Int and Mod n for non-prime n also have Euclidean instances, they are not actually Euclidean domains, and using numberWall with them often causes divide-by-zero errors.

Special sequences

pagoda :: Ring a => Int -> a Source #

The pagoda sequence (​A301849). In mod 2, its number wall is a self-similar fractal. In mod 3 and mod 7, all zeros in its number wall are isolated.

rueppel :: Semiring a => Int -> a Source #

The Fredholm-Rueppel sequence (​A036987). rueppel n evaluates to 1 if n + 1 is a power of 2, and 0 otherwise. Its number wall contains zero-windows of exponentially increasing size, and an infinite diagonal line of ones.

ternary :: Ring a => Int -> a Source #

(​A039974). The mod-3 number wall of this sequence has an infinite central region with no zeros.

Displaying number walls

saveImage Source #

Arguments

:: FilePath

File name

-> (a -> Color)

Function assigning each number a color

-> (Col, Col)

Column range

-> (Row, Row)

Row range

-> (Col -> Row -> a)

Number wall

-> IO () 

Save a number wall as a PNG file.

showSection :: (a -> String) -> (Col, Col) -> (Row, Row) -> (Col -> Row -> a) -> String Source #

Convert a section of a number wall into a string.

printSection :: (a -> String) -> (Col, Col) -> (Row, Row) -> (Col -> Row -> a) -> IO () Source #

Print a section of a number wall.

Modular arithmetic