Numerical digit Created 2026-10-14 Updated 2026-10-20
A numerical digit is one symbol in a positional notation string, denoting an integer from zero through one less than the radix.
Palindromic number 2026-10-20
A nonnegative integer whose positional notation reads the same forwards and backwards, with no leading zeros. This property depends on the base: is a palindromic number in both decimal representation and binary representation, since .
With its default argument and a nonnegative integer input, it prints the decimal digits of in order, one per line. For example, mystery4(407) prints 4, then 0, then 7. Integer division removes the final digit, recursion handles the preceding digits, and the remainder gives the final digit. The function returns None.
There is a subtlety for a nondefault base: the recursive call omits m, so it resets to . For and , the actual output is the decimal digits of , followed by the remainder . For example, mystery4(13, 2) prints 6, then 1, rather than the binary digits of . Passing m on to the recursive call would give a consistent base- positional notation. The interpretation as digits assumes and ; arbitrary integer arguments need not satisfy those conditions.
Validate the complete input before doing the addition. The arrays use most-significant-digit-first positional notation. The result has one extra leading position, which contains either zero or the final carry.
def binaryAddition(x: Array[Int], y: Array[Int]): Array[Int] = {
  require(x != null && y != null, "arrays must not be null")
  require(x.length == y.length, "lengths must match")
  val n = x.length
  var k = 0
  while (k < n) {
    require((x(k) == 0 || x(k) == 1) &&
            (y(k) == 0 || y(k) == 1), "digits must be 0 or 1")
    k += 1
  }
  val answer = new Array[Int](n + 1)
  var carry = 0
  var j = n - 1
  while (j >= 0) {
    val column = x(j) + y(j) + carry
    answer(j + 1) = column % 2
    carry = column / 2
    j -= 1
  }
  answer(0) = carry
  answer
}
A failed require throws IllegalArgumentException, covering mismatched lengths, invalid binary digits and null arrays. The largest column sum is three, so the carry always lies in . The binary-addition carry invariant says that the already processed input suffixes equal the written result suffix plus the carry shifted to the next column. After the final column, placing that carry at position zero proves the returned value is the sum. Neither input array is modified. Equal empty inputs are accepted as zero and return Array(0); the specification imposes no positive-length restriction. Running time and result storage are .
Place value 2026-10-14
The place value is the weight of a position in positional notation. A numeral digit at that position contributes to the represented number.
Positional notation Created 2026-09-29 Updated 2026-10-14
In positional notation, a numeral digit contributes its value multiplied by a weight determined by its position. Fix an integer radix . A finite string of numeral digits , with , represents the nonnegative integer
The rightmost position has weight ; each move left multiplies the weight by . This weight is the place value. For a nonzero integer, the canonical string has . Zero is written with the single numeral digit . Leading zeros are permitted in a fixed-width display but omitted in the canonical form: . A negative integer is written with a separate minus sign and the positional notation for its absolute value; the minus sign is not a numeral digit.[ref]
For example,
The zero is essential inside this string: , not . It records that the tens position contributes nothing while keeping the hundreds and units in their proper positions. The same integer has binary representation
Figure 1.
One integer, two encodings:
. Each numeral digit is multiplied by its place value. Decimal uses the weights ; binary uses . Zero digits preserve positions without contributing to the total. Both rows sum to . Details.
Repeated Euclidean division constructs the representation exactly. Set . At each step write
Keep the remainder and continue with the integer quotient . A positive quotient strictly decreases, so eventually it is zero. Substituting the successive equations back into the first gives : the numeral digits are obtained from right to left. The remainder modulo uniquely fixes , and then the quotient uniquely fixes the remaining string by the same reasoning. This proves existence and uniqueness once leading zeros are excluded. The needed unique quotient and remainder are precisely the conclusion of the Euclidean division theorem.[ref]
This finite expansion concerns nonnegative integers. Extending positional notation to fractional positions uses weights to the right of a point; an arbitrary real number need not have a finite digit string. In particular, the decimal representation represents , while the base-two string represents . The radix is part of the interpretation.
The benefit is compact arithmetic: positions can encode every nonnegative integer below . To see the upper endpoint, fill all positions with ; the finite geometric series gives . Carrying in addition exchanges units of one place value for one unit of the next. Thus a short string stores a large count and also supplies an algorithm for computing with it.
Radix 2026-10-14
The radix is the base of positional notation. In the ordinary integer-base case it is an integer , and successive place values differ by a factor of .
Radix sort key encoding 2026-10-18
An encoding for radix sort must make the intended total order of sort keys agree with the lexicographic order of its fixed-width numerical digit tuples. The positional notation for bounded nonnegative integers has this property. At the most significant differing position , a one-unit numerical digit difference contributes , while all lower positions together contribute at most
This geometric series shows why lower numerical digits cannot reverse that comparison. Leading zero padding works here because it preserves place values and the represented integer.
For signed integers in a known integer interval , encode and choose with . This order-preserving function is also injective: exactly when . For , the four-bit encodings of are after adding eight. Restore the original signed sort keys when displaying the complete sorting records; the encoding need not replace their data. Sorting the unsigned values of raw two's complement bit patterns would put nonnegative integers before negative ones, so their representation alone is not this ordered encoding.
For variable-length strings, first specify the alphabet order and whether a proper prefix precedes its extensions. As an original construction, use , let every string have length at most three, encode as one and as two, and append zeros to width three. Zero is reserved for an end marker strictly below every real symbol. The strings encode as in radix three, which preserves their lexicographic order. A differing real symbol decides the comparison; at a prefix boundary, the shorter string's zero comes before the extension's one or two. Left padding would instead encode as and as , reversing . Padding raw bytes with zero also fails if zero is an allowed data symbol: distinct strings can then receive the same encoding. A reserved end marker and an explicit symbol ordering are essential; byte order alone does not establish a desired human text order.
Figure 1.
Stable ties preserve lower digits; suitable encodings preserve the intended order
. Original counterexample above: reversing a tens tie destroys the units order and a later stable hundreds pass cannot repair it. Below: signed integer offsets and a reserved end marker for bounded strings produce increasing fixed-width encodings. All entries are exact constructed examples. Details.
Repunit 2026-10-20
A repdigit whose digits are all 1 in a specified positional notation of base . Its value is the geometric series . In base ten, appending one digit gives , so its remainder modulo can be computed by a recurrence relation without constructing the full integer.
Simply normal number 2026-10-14
A real number is simply normal in base if each individual digit in its positional notation has limiting digit block frequency . This is the length-one part of the definition of a normal number. It places no equal-frequency requirement on longer words.
For example, is a simply normal number in base two: each binary digit has frequency . But and never occur, and and each have frequency . Thus is not a normal number in base two. Even a sequence that looks more complicated, such as the deterministic Thue–Morse sequence, must be tested against the actual digit block frequency definition; visual complexity is no substitute for it.
The decimal representation makes the same point in base ten. Every digit has frequency , yet the only adjacent pairs are
Each has limiting digit block frequency ; the other ninety pairs have frequency zero. A normal number in base ten requires for every one of the hundred pairs. This rational number is a simply normal number in base ten, but it is not a normal number in that base.
Truncatable prime 2026-10-20
A prime number that remains prime after successively deleting digits from a specified end of its positional notation. Left truncation, right truncation, and requiring both are distinct conditions. For example, is truncatable from both ends: and consist entirely of prime numbers.