DigitSum
The sum of the digits of n in the given base (default 10).
✓ checked against that system · ! checked, with disagreements (hover a chip)Wikipedia
Digit sumMathWorldDigitSumWikidataQ1363568Wolfram LanguageDigitSum✓Rosetta CodeSum digits of an integerDigitSum(n)sum of the digits of , base 10.SageMath
sum(Integer(abs(n)).digits(10))SymPysum(digits(abs(n))[1:])DigitSum(n, base)sum of the digits of in the given base.SageMath
sum(Integer(abs(n)).digits(base))SymPysum(digits(abs(n), base)[1:])DigitSum(n, base, k)sum of just the first digits (most significant first); a negative sums the last instead (least significant first).Typed signatures
| Type | Package | Applies |
|---|---|---|
(integer, integer?) -> integer | compute-engine | always |
(integer, integer?, integer?) -> integer | numeralsreplaces compute-engine | always |
Details
- Equivalent to summing IntegerDigits(n, base).
- In base 2, the digit sum is the number of set bits (population count).
- in base 10 -- the basis of the classic divisibility-by-9 check and digital root.
- The sign of n is discarded before summing.
Plot
Examples
3 more kept as data, checked against the oraclesScope #
Properties #
Digit sum ≡ n (mod 9): the basis of the classic divisibility-by-9 check and the digital root
live ↗InOut
About
| Examples | 30 |
|---|---|
| Checked against | Wolfram Language 30 agreeSageMath 21 agreeSymPy 21 agreemathlib4 18 agree11 error |
| Crosswalk | WikipediaMathWorldWikidataWolfram LanguageSageMath ×2SymPy ×2Rosetta Code |
Implementation
mapped
sagepackages/oracle/src/mappings.tsmapped
sagepackages/oracle/src/mappings.tsmapped
sympypackages/oracle/src/mappings.tsmapped
sympypackages/oracle/src/mappings.tsmapped
mathlib4packages/oracle/src/mappings.tsThe sum of Nat.digits; natural n only, so a negative n (whose sign ours discards) is a domain error.
mapped
mathlib4packages/oracle/src/mappings.tsAs the one-argument row, in an integer base.
mapped
mathlib4packages/oracle/src/mappings.tsThe first k digits, most significant first; k past the digit count is the plain sum. A negative k (the last |k| digits) is a domain error, as is a negative n.
See also: DigitCount