|
17 | 17 | from mathics.core.atoms import Integer |
18 | 18 | from mathics.core.attributes import ( |
19 | 19 | A_LISTABLE, |
| 20 | + A_N_HOLD_FIRST, |
20 | 21 | A_NUMERIC_FUNCTION, |
21 | 22 | A_ORDERLESS, |
22 | 23 | A_PROTECTED, |
23 | 24 | A_READ_PROTECTED, |
24 | 25 | ) |
25 | 26 | from mathics.core.builtin import Builtin, MPMathFunction, SympyFunction |
| 27 | +from mathics.core.evaluation import Evaluation |
26 | 28 | from mathics.core.expression import Expression |
27 | 29 | from mathics.core.list import ListExpression |
28 | 30 | from mathics.core.symbols import ( |
|
39 | 41 | SymbolSubsets = Symbol("Subsets") |
40 | 42 |
|
41 | 43 |
|
| 44 | +class BellB(SympyFunction): |
| 45 | + """ |
| 46 | + <url> |
| 47 | + :Bell number: https://en.wikipedia.org/wiki/Bell_number</url> (<url> |
| 48 | + :SymPy: https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.bell</url>, <url> |
| 49 | + :WMA: https://reference.wolfram.com/language/ref/BellB.html</url>) |
| 50 | + <dl> |
| 51 | + <dt>'BellB[$n$]' |
| 52 | + <dd>Bell number $B$_$n$. |
| 53 | +
|
| 54 | + <dt>'BellB[$n$, $x$]' |
| 55 | + <dd>Bell polynomial $B$_$n$($x$). |
| 56 | + </dl> |
| 57 | +
|
| 58 | + >> BellB[10] |
| 59 | + = 115975 |
| 60 | +
|
| 61 | + >> BellB[5, x] |
| 62 | + = x + 15 x ^ 2 + 25 x ^ 3 + 10 x ^ 4 + x ^ 5 |
| 63 | + """ |
| 64 | + |
| 65 | + attributes = A_LISTABLE | A_N_HOLD_FIRST | A_PROTECTED | A_READ_PROTECTED |
| 66 | + summary_text = "Bell numbers" |
| 67 | + sympy_name = "bell" |
| 68 | + |
| 69 | + def eval(self, z, evaluation: Evaluation): |
| 70 | + "%(name)s[z__]" |
| 71 | + return super().eval(z, evaluation) |
| 72 | + |
| 73 | + |
42 | 74 | class _BooleanDissimilarity(Builtin): |
43 | 75 | @staticmethod |
44 | 76 | def _to_bool_vector(u): |
@@ -184,6 +216,36 @@ def _compute(self, n, c_ff, c_ft, c_tf, c_tt): |
184 | 216 | ) |
185 | 217 |
|
186 | 218 |
|
| 219 | +class EulerE(SympyFunction): |
| 220 | + """ |
| 221 | + <url> |
| 222 | + :Euler numbers: https://en.wikipedia.org/wiki/Euler_numbers</url> (<url> |
| 223 | + :SymPy: https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.euler</url>, <url> |
| 224 | + :WMA: https://reference.wolfram.com/language/ref/EulerE.html</url>) |
| 225 | + <dl> |
| 226 | + <dt>'EulerE[$n$]' |
| 227 | + <dd>Euler number $E$_$n$. |
| 228 | +
|
| 229 | + <dt>'EulerE[$n$, $x$]' |
| 230 | + <dd>Euler polynomial $E$_$n$($x$). |
| 231 | + </dl> |
| 232 | +
|
| 233 | + >> Table[EulerE[k], {k, 0, 10}] |
| 234 | + = {1, 0, -1, 0, 5, 0, -61, 0, 1385, 0, -50521} |
| 235 | +
|
| 236 | + >> EulerE[5, z] |
| 237 | + = -1 / 2 + 5 z ^ 2 / 2 - 5 z ^ 4 / 2 + z ^ 5 |
| 238 | + """ |
| 239 | + |
| 240 | + attributes = A_LISTABLE | A_PROTECTED |
| 241 | + summary_text = "Euler numbers" |
| 242 | + sympy_name = "euler" |
| 243 | + |
| 244 | + def eval(self, z, evaluation: Evaluation): |
| 245 | + "%(name)s[z__]" |
| 246 | + return super().eval(z, evaluation) |
| 247 | + |
| 248 | + |
187 | 249 | class JaccardDissimilarity(_BooleanDissimilarity): |
188 | 250 | """ |
189 | 251 | <url> |
@@ -214,6 +276,44 @@ def _compute(self, n, c_ff, c_ft, c_tf, c_tt): |
214 | 276 | ) |
215 | 277 |
|
216 | 278 |
|
| 279 | +class LucasL(SympyFunction): |
| 280 | + """ |
| 281 | + <url> |
| 282 | + :Lucas Number: |
| 283 | + https://en.wikipedia.org/wiki/Lucas_number</url> (<url> |
| 284 | + :SymPy: |
| 285 | + https://docs.sympy.org/latest/modules/functions/combinatorial.html#sympy.functions.combinatorial.numbers.lucas</url>, \ |
| 286 | + <url> |
| 287 | + :WMA: |
| 288 | + https://reference.wolfram.com/language/ref/LucasL.html</url>) |
| 289 | +
|
| 290 | + <dl> |
| 291 | + <dt>'LucasL[$n$]' |
| 292 | + <dd>gives the $n$th Lucas number. |
| 293 | + </dl> |
| 294 | +
|
| 295 | + A list of the first five Lucas numbers: |
| 296 | + >> Table[LucasL[n], {n, 1, 5}] |
| 297 | + = {1, 3, 4, 7, 11} |
| 298 | + >> Series[LucasL[1/2, x], {x, 0, 5}] |
| 299 | + = 1 + 1 / 4 x + 1 / 32 x ^ 2 + (-1 / 128) x ^ 3 + (-5 / 2048) x ^ 4 + 7 / 8192 x ^ 5 + O[x] ^ 6 |
| 300 | + """ |
| 301 | + |
| 302 | + attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED |
| 303 | + |
| 304 | + summary_text = "lucas number" |
| 305 | + sympy_name = "lucas" |
| 306 | + |
| 307 | + rules = { |
| 308 | + "LucasL[n_, 1]": "LucasL[n]", |
| 309 | + "LucasL[n_, x_]": "(x/2 + Sqrt[1 + x^2 / 4])^n + Cos[n Pi] / (x/2 + Sqrt[1 + x^2 / 4])^n // Simplify", |
| 310 | + } |
| 311 | + |
| 312 | + def eval_integer(self, n: Integer, evaluation): |
| 313 | + "LucasL[n_Integer]" |
| 314 | + return self.eval(n, evaluation) |
| 315 | + |
| 316 | + |
217 | 317 | class MatchingDissimilarity(_BooleanDissimilarity): |
218 | 318 | """ |
219 | 319 | <url>:WMA link:https://reference.wolfram.com/language/ref/MatchingDissimilarity.html</url> |
@@ -276,6 +376,31 @@ def eval(self, values, evaluation): |
276 | 376 | return Expression(SymbolTimes, *elements) |
277 | 377 |
|
278 | 378 |
|
| 379 | +class PolygonalNumber(Builtin): |
| 380 | + """ |
| 381 | + <url> |
| 382 | + :Polygonal number: https://en.wikipedia.org/wiki/Polygonal_number</url> (<url> |
| 383 | + :WMA: https://reference.wolfram.com/language/ref/PolygonalNumber.html</url>) |
| 384 | + <dl> |
| 385 | + <dt>'PolygonalNumber[$r$, $n$]' |
| 386 | + <dd>gives the $n$th $r$-gonal number. |
| 387 | + </dl> |
| 388 | +
|
| 389 | + >> Table[PolygonalNumber[n], {n, 10}] |
| 390 | + = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55} |
| 391 | + >> Table[PolygonalNumber[r, 10], {r, 3, 10}] |
| 392 | + = {55, 100, 145, 190, 235, 280, 325, 370} |
| 393 | + """ |
| 394 | + |
| 395 | + attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED | A_READ_PROTECTED |
| 396 | + summary_text = "polygonal number" |
| 397 | + |
| 398 | + rules = { |
| 399 | + "PolygonalNumber[n_Integer]": "PolygonalNumber[3, n]", |
| 400 | + "PolygonalNumber[r_Integer, n_Integer]": "(1/2) n (n (r - 2) - r + 4)", |
| 401 | + } |
| 402 | + |
| 403 | + |
279 | 404 | class RogersTanimotoDissimilarity(_BooleanDissimilarity): |
280 | 405 | """ |
281 | 406 | <url> |
|
0 commit comments