Skip to content

Commit

Permalink
Go over new builtins up to PolyLog
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Jan 21, 2025
1 parent c874aa9 commit 679def7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
25 changes: 18 additions & 7 deletions mathics/builtin/atomic/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,26 +301,37 @@ class NumberDigit(Builtin):
https://reference.wolfram.com/language/ref/NumberDigit.html</url>
<dl>
<dt>'NumberDigit[$x$, $n$]'
<dd>returns the digit coefficient of 10^$n$ for the real-valued number $x$.
<dt>'NumberDigit[$x$, $n$, $b$]'
<dd>returns the coefficient of $b^n$ in the base-$b$ representation of $x$.
<dd>returns the coefficient of $b$^$n$ in the base-$b$ representation of $x$.
</dl>
>> NumberDigit[123456, 2]
= 4
>> NumberDigit[12.3456, -1]
Get the 10^2 digit of a 210.345:
>> NumberDigit[210.345, 2]
= 2
Get the 10^-1 digit of a 210.345:
>> NumberDigit[210.345, -1]
= 3
>> BaseForm[N[Pi], 2]
= 11.00100100001111110_2
Get the 2^0 bit of the Pi:
= 1
"""

attributes = A_PROTECTED | A_READ_PROTECTED

summary_text = "digits of a real number"

rules = {
"NumberDigit[x_, n_Integer]": "NumberDigit[x, n, 10]",
"NumberDigit[x_, n_Integer, b_Integer]": "RealDigits[x, b, 1, n][[1]][[1]]",
}

summary_text = "get digits of a real number"


class RealDigits(Builtin):
"""
Expand Down Expand Up @@ -776,7 +787,7 @@ class Precision(Builtin):

summary_text = "find the precision of a number"

def eval(self, z, evaluation):
def eval(self, z, evaluation: Evaluation):
"""Precision[z_]"""
if isinstance(z, MachineReal):
return SymbolMachinePrecision
Expand Down
24 changes: 20 additions & 4 deletions mathics/builtin/intfns/combinatorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,39 @@ class PolygonalNumber(Builtin):
:Polygonal number: https://en.wikipedia.org/wiki/Polygonal_number</url> (<url>
:WMA: https://reference.wolfram.com/language/ref/PolygonalNumber.html</url>)
<dl>
<dt>'PolygonalNumber[$n$]'
<dd>gives the $n$th triangular number.
<dt>'PolygonalNumber[$r$, $n$]'
<dd>gives the $n$th $r$-gonal number.
</dl>
>> Table[PolygonalNumber[n], {n, 10}]
= {1, 3, 6, 10, 15, 21, 28, 36, 45, 55}
>> Table[PolygonalNumber[r, 10], {r, 3, 10}]
= {55, 100, 145, 190, 235, 280, 325, 370}
The sum of two consecutive Polygonal numbers is the square of the larger number:
>> Table[PolygonalNumber[n-1] + PolygonalNumber[n], {n, 10}]
= {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}
'PolygonalNumber'[$r$, $n$] can be interpreted as the number of points arranged in the form of $n$-1 polygons of $r$ sides.
List the tenth $r-gonal number of regular polygons from 3 to 8:
>> Table[PolygonalNumber[r, 10], {r, 3, 8}]
= {55, 100, 145, 190, 235, 280}
See also <url>
:Binomial:
doc/reference-of-built-in-symbols/integer-functions/combinatorial-functions/binomial/</url>, and <url>
:RegularPolygon:
doc/reference-of-built-in-symbols/drawing-graphics/regularpolygon/</url>.
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED
summary_text = "polygonal number"

rules = {
"PolygonalNumber[n_Integer]": "PolygonalNumber[3, n]",
"PolygonalNumber[r_Integer, n_Integer]": "(1/2) n (n (r - 2) - r + 4)",
}
summary_text = "get polygonal number"


class RogersTanimotoDissimilarity(_BooleanDissimilarity):
Expand Down

0 comments on commit 679def7

Please sign in to comment.