Question 0: Are any of these of interest in being included in the Number Theory or other shared folders?

Question 1: I know I can use

- Code: Select all
`"number" Tools.checkType`

in an RPL/RPL+ program, or

- Code: Select all
`Tools.checkType(x, "number")`

in a JavaScript function.

But can I use more than one test, to allow for both "numbers" and "bignum" as input for example?

Question 1A: I am attempting to document the TYPE and typeof results with various ND1 types, and they match up fairly well with the HP50G AUR TYPE results. I haven't been able to generate each type, though.

Here is my listing (50G TYPE followed by spaces, then ND1 typeof, then a space and a hyphen and a space, then the 50G name for the TYPE.

At the end are some other types and what the TYPE number returns. Some vectors return different TYPE numbers, as well.

TYPE typeof

50G ND1 - 50G name

---------------------------------------------------------------------

0 number - Real Number

1 complex number - Complex Number

2 string - String

3 - Real Array

4 vector - Complex Array

5 - List

6 expression or name - Global name

7 expression or name - Local Name

8 RPL program - Program

9 expression or name - Algebraic Object

10 binary number - Binary Integer

11 - Graphics Object

12 tagged - Tagged Object

13 - Unit Object

14 - XLIB Name

15 - Directory

16 - Library

17 - Backup Object

18 - Built-in Function

19 - Built-in Command

20 - System Binary

21 - Extended Real

22 - Extended Complex

23 - Linked Array

24 - Character

25 - Code Object

26 - Library Data

27 - Minifont

28 bignum - Real Integer

29 - Symbolic Vector/Matrix

30 - Font

31 - Extended Object

fraction 9

boolean 0

CF (continued fraction) -1

matrix

bigfloat -1

function (JS function) -1

Question 2: Some built-in functions return regular numbers up to a certain point, then return BigInts afterward. Can I program that? An example is the Catalan number; it should return an integer result, but for 14, it returns 2674440.00000001 (when it should be 2674440 exactly; 17 returns 129644789.999999 and should be rounded up. Larger inputs return numbers of the form 1.23e+59.

Essentially, I want to use BigNum calculations in JavaScript using the factorial function, but I get an "undefined function" instead.

About the programs:

I created the Anot, Aor, Aand and Axor commands to match the functionality of similar functions on the HP50G; you can use the AND, OR, NOT and XOR there on strings. Pretty fun.

Here are my updated programs:

'Factors' (from factors, which returns a set of factor/exponent pairs, creates an expanded list of prime factors, leaving original number on stack)

Input: number

Output: vector

- Code: Select all
`≪ RECT @dup factors toElements 2. / { } 1. ROT START DUP 1. 4. ROLL START PICK3 + NEXT NIP NIP NEXT≫`

'Derange' (returns number of derangements or subfactorial, where each item is in a different position from original.)

Input: number

- Code: Select all
`≪ abs int factorial e / 0 round≫`

'Collatz' (RPL + version)

Input: number

- Code: Select all
`≪ @dup IF isEven THEN 2 / ELSE 3 * ++ END≫`

'Ulam' (computes number of Collatz steps to reach 1)

Input: number

- Code: Select all
`≪ 0 OVER DO Collatz SWAP 1 + SWAP UNTIL DUP 1 SAME END DROP SWAP≫`

'UnitDivs' (number of unitary divisors: gcd(n,n/d) = 1)

Input: number

- Code: Select all
`≪ divs @dupdup reverse 2 ≪ gcd≫ DOLIST ≪ 1 ==≫ select≫`

'Digits' (vector of digits of number)

Input: number

- Code: Select all
`≪ split [isInt] filter≫`

'DblFact' (double factorial)

Input: number

- Code: Select all
`function (x) {`

var d = 1;

if (x < 2) return d;

var i = x;

while (i > 0) {

d = d * i;

i = i - 2;

}

return d;

}

'Diffs' (successive differences of a vector, one entry shorter than the input vector)

Input: vector

- Code: Select all
`≪ @dup tail 0 + - @dup size 1 - resize≫`

'ageme' (number of days since I was born)

- Code: Select all
`function () {`

var monthArray = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];

var today = new Date();

var bmo=today.getMonth();

var d2a = monthArray[bmo] + ' '

+ today.getDate() + ', '

+ today.getFullYear() ;

var s2 = Date.parse ( d2a );

var s1 = Date.parse ( "[color=#FF0000]Insert DOB here as Month, dd, yyyy[/color]" );

var dayDiff = Math.abs(Math.round((s2-s1)/86400000))

return dayDiff;

}

'cool' (cool things about input number)

Input: number

- Code: Select all
`≪ =n "Nxt" n nextPrime @tag "Prv" n prevPrime @tag "Divs" n ndivs @tag "Phi" n phi @tag "Rdcl" n radical @tag "sigma" n 1 sigma @tag "Hex" n toHex @tag "Oct" n toOct @tag "Ulam" n Ulam @drop @tag n Factors ≫`

'PartConj' (conjugate of a partition; reading a Ferrers diagram vertically instead of horizontally)

Input: vector

- Code: Select all
`≪ @dup =v [] =a 1 at 1 - 0 @swap FOR x v ≪ x > ≫ map total a @swap + =a NEXT a≫`

'Period' (not perfect - supposed to return the period of a repeating decimal fraction; works for primes and some composites but not all)

Input: number

- Code: Select all
`≪ =n n @dup 1 - 1 @swap FOR x 10 x n modpow @dup 0 IF == THEN @drop "=terminates" @tag BREAK END IF 1 == THEN x "=period" @tag BREAK END NEXT≫`

'Egypt' (gives vector of denominators of input proper fraction; the last entry is returned as a fraction)

Input: fraction

- Code: Select all
`≪ @dupdup [ ] =n inv @dup WHILE isInt NOT REPEAT 1 + int @dup n + =n inv - @dup inv @dup END n + @drop2nd reverse≫`

'UniqFactors' (unique prime factors of number)

Input: number

- Code: Select all
`≪ Factors removeDuplicates≫`

'toBinv' (convert integer to binary vector)

Input: number

- Code: Select all
`function (x) {`

var b = x.toString(2);

var a = split(b);

return a;

}

'SumBits' (compute the sum of binary bits in the number; leave original number on stack)

Input: number

- Code: Select all
`≪ @dup toBinv total≫`

'Anot' (NOT an ASCII string)

Input: string

- Code: Select all
`function (y) {`

y = calculator.unquote(y) ;

x = "" ;

for (i=0;i<y.length;i++) {

x += String.fromCharCode((~ y.charCodeAt(i)) & 255) ;

}

x = "\"" + x + "\"" ;

return x ;

}

'Axor' (XOR two ASCII strings)

Input: two strings

- Code: Select all
`function (y, z) {`

y = calculator.unquote(y) ;

z = calculator.unquote(z) ;

ly = y.length ;

lz = z.length ;

if (lz>ly) {

y += new Array(lz + 1).join(" ").slice(0,lz) ;

}

if (ly>lz) {

z += new Array(ly + 1).join(" ").slice(0,ly) ;

}

x = "" ;

for (i=0;i<y.length;i++) {

x += String.fromCharCode((y.charCodeAt(i) ^ z.charCodeAt(i)) & 255) ;

}

x = "\"" + x + "\"" ;

return x ;

}

'Aor' (OR two ASCII strings)

Input: two strings

- Code: Select all
`function (y, z) {`

y = calculator.unquote(y) ;

z = calculator.unquote(z) ;

ly = y.length ;

lz = z.length ;

if (lz>ly) {

y += new Array(lz + 1).join(" ").slice(0,lz) ;

}

if (ly>lz) {

z += new Array(ly + 1).join(" ").slice(0,ly) ;

}

x = "" ;

for (i=0;i<y.length;i++) {

x += String.fromCharCode((y.charCodeAt(i) | z.charCodeAt(i)) & 255) ;

}

x = "\"" + x + "\"" ;

return x ;

}

'Aand' (AND two ASCII strings)

Input: two strings

- Code: Select all
`function (y, z) {`

y = calculator.unquote(y) ;

z = calculator.unquote(z) ;

ly = y.length ;

lz = z.length ;

if (lz>ly) {

y += new Array(lz + 1).join(" ").slice(0,lz) ;

}

if (ly>lz) {

z += new Array(ly + 1).join(" ").slice(0,ly) ;

}

x = "" ;

for (i=0;i<y.length;i++) {

x += String.fromCharCode((y.charCodeAt(i) & z.charCodeAt(i)) & 255) ;

}

x = "\"" + x + "\"" ;

return x ;

}

'Lucas' (Lucas number from sequence 1,3,4,7,...)

Input: integer

- Code: Select all
`function (n) {`

Tools.checkType(n, "number") ;

var j=BigInteger.ONE ;

var k=BigInteger.THREE ;

if (n == 0) {

var x = BigInteger.ZERO ;

}

else if (n == 1) {

var x = j ;

}

else if (n == 2) {

var x = k ;

}

else

for (var i=2; i<n; i++) {

x = BigNum["+"](j, k) ;

j = k ;

k = x ;

}

return x ;

}

'Bell' (Bell number: number of non-empty sets)

Input: integer

- Code: Select all
`function (n) {`

var b = [];

var j, k, a ;

b[0] = 1 ;

b[1] = 1 ;

a = 1 ;

if (n>1) {

for (j=2; j<=n; j++) {

a = 0 ;

for (k=0; k<j; k++) {

a += (b[k]*calculator.functions.combinations(j-1,k)) ;

}

b[j] = a ;

}

a = b[n] ;

}

return a ;

}

'Catalan' (answers to many counting problems)

Input: integer

- Code: Select all
`function (n) {`

var c = ME.factorial(2 * n) / (ME.factorial(n + 1) * ME.factorial(n)) ;

return c ;

}

David Motto