# HP Calculator Wiki

### Site Tools

prime:programming:cas-integer_commands

### CAS-Integer Commands

This section will cover the Integer commands of the HP Prime. Unless noted, the commands are practically useful only in CAS Mode and in CAS programs.

Examples given in this section is with the CAS Simplify setting set to Maximum. The “Include complex results in variables” option is turned off.

#### idivis

Returns a sequence (vector) of an integer's divisors.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

idivis(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.idivis(integer)

Home Mode - RPN Entry:

1: integer CAS.idivis(1) press Enter

Examples:

CAS Mode
idivis(36) returns [1 2 4 3 6 12 9 18 36]

Access: Toolbox, CAS, 5. Integers, 1. idivis

#### ifactor

Returns the prime factorization of an integer. The output is a textbook representation of an integer's factorization.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

ifactor(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.ifactor(integer)

Home Mode - RPN Entry:

1: integer CAS.ifactor(1) press Enter

Examples:

CAS Mode
ifactor(36) returns 2^2*3^2

Access: Toolbox, CAS, 5. Integers, 2. ifactor

Note: Be careful because the commands ifactor and ifactors do different things (one little “s”).

#### ifactor

Returns the prime factorization of an integer. The output is a sequence of pairs: prime divisor followed by its multiplicity.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

ifactors(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.ifactors(integer)

Home Mode - RPN Entry:

1: integer CAS.ifactors(1) press Enter

Examples:

CAS Mode
ifactors(36) returns [2 2 3 2]

Access: Toolbox, CAS, 5. Integers, 3. ifactors

Note: Be careful because the commands ifactor and ifactors do different things (one little “s”).

#### gcd

Greatest common divisor of two polynomials or integers.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

Greatest Common Divisor of Polynomials:
gcd(polynomial, polynomial)

Greatest Common Divisor of Integers:
gcd(integer, integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.gcd(integer, integer)

Home Mode - RPN Entry:

2: integer
1: integer
CAS.gcd(2)

Examples:

CAS Mode

Polynomials:
gcd(2x^2+4x, 4x) returns 2x

gcd(2x^3+2, 3x^5+3) returns x+1

Integers:
gcd(175, 225) returns 25

Access: Toolbox, CAS, 6. Polynomial, 5. gcd OR
Toolbox, CAS, 5. Integers, 5. gcd

#### lcm

Least common multiple of two polynomials or integers.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

Least Common Multiple of Polynomials:
lcm(polynomial, polynomial)

Least Common Multiple of Integers:
lcm(integer, integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.lcm(integer, integer)

Home Mode - RPN Entry:

2: integer
1: integer
CAS.lcm(2)

Examples:

CAS Mode

Polynomials:
lcm(x+1, x^2-1) returns x^2-1

lcm(x^2+1, x^3-1) returns x^5+x^3-x^2-1

Integers:
lcm(175, 225) returns 1575

Access: Toolbox, CAS, 6. Polynomial, 6. lcm OR
Toolbox, CAS, 5. Integers, 6. lcm

### Prime Number Commands

#### isprime

Tests to see if an integer is a prime number. The number is prime if the integer's divisors are only itself and 1.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

isprime(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.isprime(integer)

Home Mode - RPN Entry:

1: integer CAS.isprime(1), press Enter

Output:

In CAS mode, isprime returns true and false.

In all other modes, CAS.isprime returns 1 (representing true) and 0 (representing false).

Examples:

CAS Mode

isprime(36) returns false

isprime(47) returns true

Home Mode

CAS.isprime(36) returns 0

CAS.isprime(47) returns 1

Access: Toolbox, CAS, 5. Integer, 6. Prime, 1. isprime

#### ithprime

Returns the nth prime number. Example, ithprime(25) returns the 25th prime number, which is 97. The sequence of primes is: 2, 3, 5, 7, etc.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

ithprime(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.ithprime(integer)

Home Mode - RPN Entry:

1: integer CAS.ithprime(1), press Enter

Note: If the argument for ithprime is not an integer, it returns an “Error: Bad Argument Type” .

Examples:

CAS Mode

ithprime(25) returns 97.

ithprime(36) returns 149.

Access: Toolbox, CAS, 5. Integer, 6. Prime, 2. ithprime

#### nextprime

Returns the next prime number greater than n.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

nextprime(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.nextprime(integer)

Home Mode - RPN Entry:

1: integer CAS.nextprime(1), press Enter

Note: If the argument for nextprime is not an integer, it returns an “Error: Bad Argument Type” .

Examples:

CAS Mode

nextprime(33) returns 37

nextprime(37) returns 41

Access: Toolbox, CAS, 5. Integer, 6. Prime, 3. nextprime

#### prevprime

Returns the next prime number less than n.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

prevprime(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.prevprime(integer)

Home Mode - RPN Entry:

1: integer CAS.prevprime(1), press Enter

Note: If the argument for prevprime is not an integer, it returns an “Error: Bad Argument Type” .

Examples:

CAS Mode

prevprime(33) returns 31

prevprime(31) returns 29

Access: Toolbox, CAS, 5. Integer, 6. Prime, 5. prevprime

#### euler

Euler's phi function, also known as the totient function. Φ(n). The function returns the number of positive integers less than or equal to n which are coprime to n. An integer is coprime to n if their greatest common divisor (gcd) is 1.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

euler(integer)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.euler(integer)

Home Mode - RPN Entry:

1: integer CAS.euler(1), press Enter

Note: If the argument for euler is not an integer, it returns an “Error: Bad Argument Type” .

Examples:

CAS Mode

euler(25) returns 20

euler(36) returns 12

Access: Toolbox, CAS, 5. Integer, 6. Prime, 5. euler

### Integer Divsion Commands

#### iquo

Returns the quotient portion of the division m ÷ n, where m and n are integers.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

iquo(dividend or numerator, divisor or denominator)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.iquo(dividend or numerator, divisor or denominator)

Home Mode - RPN Entry:

2: dividend or numerator 1: divisor or denominator CAS.iquo(2), press Enter

Examples:

CAS Mode

iquo(96, 85) returns 1

iquo(96, 6) returns 16

Access: Toolbox, CAS, 5. Integer, 7. Division, 1. iquo

#### irem

Returns the remainder portion of the division m ÷ n, where m and n are integers.

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

irem(dividend or numerator, divisor or denominator)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.irem(dividend or numerator, divisor or denominator)

Home Mode - RPN Entry:

2: dividend or numerator 1: divisor or denominator CAS.irem(2), press Enter

Examples:

CAS Mode

irem(96, 85) returns 11

irem(96, 6) returns 0

Access: Toolbox, CAS, 5. Integer, 7. Division, 2. irem

#### ichinrem

Integer Chinese Remainder Theorem for two equations. Takes two lists [a, p] and [b, q] and returns a list of two integers [r, n] such that x Ξ r mod n. In this case, x Ξ a mod p, x Ξ b mod q, and n Ξ p * q.

Source: HP Prime help screen for ichinrem

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

ichinrem([a,p],[b,q])

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.inchinrem([a,p],[b,q])

Home Mode - RPN Entry:

2: [a, p]
1: [b, q]
CAS.inchinrem(2), press Enter

Examples:

CAS Mode

ichinrem([2,7],[3,5]) returns [-12, 35] meaning:

Access: Toolbox, CAS, 5. Integer, 7. Division, 3. inchinrem

#### powmod

Power and modulo function. powmod takes three integers: a, n, and p and returns a^n mod p.

Source: HP Prime help screen for powmod

Syntax

Input:

CAS Mode
Program Editor - CAS Programs

powmod(a,n,p)

Home Mode- Algebraic or Textbook Entry:
Normal Program Editor

CAS.powmod(a,n,p)

Home Mode - RPN Entry:

3: a
2: n
1: p
CAS.powmod(3), press Enter

Examples:

CAS Mode

powmod(4,8,6) returns 4 (4^8 MOD 6)

powmod(8, 2,3) returns 1 (8^2 MOD 3)

Access: Toolbox, CAS, 5. Integer, 7. Division, 4. powmod