| Copyright | (c) Owen Bechtel 2022 |
|---|---|
| License | MIT |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
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
- type Col = Int
- type Row = Int
- numberWall :: NumberWall a => (Int -> a) -> Col -> Row -> a
- type NumberWall a = (Eq a, Ring a, Euclidean a)
- pagoda :: Ring a => Int -> a
- rueppel :: Semiring a => Int -> a
- ternary :: Ring a => Int -> a
- saveImage :: FilePath -> (a -> Color) -> (Col, Col) -> (Row, Row) -> (Col -> Row -> a) -> IO ()
- showSection :: (a -> String) -> (Col, Col) -> (Row, Row) -> (Col -> Row -> a) -> String
- printSection :: (a -> String) -> (Col, Col) -> (Row, Row) -> (Col -> Row -> a) -> IO ()
- module Data.Mod.Word
Creating number walls
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
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
module Data.Mod.Word