Pairwise addition

From Esolang
Jump to navigation Jump to search

Pairwise addition is an esoteric rewriting rule for natural numbers invented by User:Hakerh400 around 2006 and published in 2022.

Definition

We specify rewriting function in the following way. Given natural number (non-negative integer). If , then . Otherwise, is equal to the concatenated results of adding each two consecutive digits of in base 10.

We say that a number is trivial iff it is of the form , where and are decimal digits and is a natural number.

We say that a number is simple iff it contains two consecutive zeros.

Examples

For example, we start with number . Consecutive digits are , and . The sums are , and , so the next number is . We apply the same rules: , , , , so the next number is . We can continue, until we reach a single-digit number:

1990
10189
11917
210108
31118
4229
6411
1052
157
612
73
10
1

We say that reduces to digit . There are numbers that do not terminate, i.e. never reach a digit. The smallest non-terminating number is :

991
1810
991
...

After two steps, it reduces to itself. If we reverse the number, it terminates and reduces to digit :

199
1018
119
210
31
4

There are numbers that do not terminate, but do not create a cycle:

9999
181818
99999
18181818
9999999
...

Properties

If concatenated with terminates for some numbers and , then both and terminate. (proof omitted)

If some does not terminate, then any number containing in its decimal expansion also does not terminate. (proof omitted)

The smallest non-terminating number is . (proof omitted)

If an -digit number terminates, where , then that number contains in its decimal expansion. (proof omitted)

A number terminates iff in the sequence there is no number whose decimal expansion contains one of the following patterns:

  • two s, followed by digit
  • three s, followed by digit
  • four s

(proof omitted)

Any trivial number terminates. (proof omitted)

The longest terminating sequence for a non-simple number is 37. (proof omitted)

The largest non-trivial terminating number is 11000000000000008. (proof omitted)

Notable numbers

Number produces a sequence of length 37. It is the longest sequence for a non-simple number.

221027
43129
74311
11742
28116
10927
19119
1010210
111231
22354
4589
91317
10448
14812
51293
631112
94223
13645
49109
131019
441110
85221
13743
410117
51128
62310
8541
1395
41214
5335
868
1414
555
1010
111
22
4

The largest non-trivial terminating number:

11000000000000008
2100000000000008
310000000000008
41000000000008
5100000000008
610000000008
71000000008
8100000008
910000008
101000008
11100008
2210008
431008
74108
11518
2669
81215
9336
1269
3815
1196
21015
3116
427
69
15
6

Implementation

Implementation in Haskell:

type N = Integer
infixr 0 #
(#) = id

n :: N
n = 1234

digits :: N -> [N]
digits = map (read . pure) . show

f :: N -> N -> [N]
f a b = digits # a + b

step :: [N] -> [N]
step xs = concat # zipWith f xs # tail xs

run :: [N] -> [[N]]
run xs = xs : if length xs == 1 then [] else run # step xs

main :: IO ()
main = mapM_ (putStrLn . (>>= show)) # run # digits n