---
title: Numerical tools
description: Work with integer bits, primes, factors, polynomials and numerical searches
skip_showdoc: true
---
Continue from [Rearranging and transforming arrays](rearranging-arrays.md).

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Bit operations

### [`ᵇ`](https://bpl.fast.ai//glyphs/superscript-b.html) (Bitwise)

In binary, the digit positions have values 1, 2, 4, and so on, counting from the right. The digits are 0 or 1, called bits. Six is binary `110` and three is `011`. Bitwise applies a Boolean function separately to each bit. [`∧`](https://bpl.fast.ai//glyphs/wedge.html) keeps a 1 only where both numbers have a 1, giving binary `010`, or two:

```bpl
6∧ᵇ3
```

```output
2ₓ
```

```bpl
6∨ᵇ3
```

```output
7ₓ
```

```bpl
6≠ᵇ3
```

```output
5ₓ
```

## Mathematical tools

### [`⍭`](https://bpl.fast.ai//glyphs/stile-tilde.html) (Primes)

A prime is an integer greater than 1 divisible only by itself and 1. `⍭n` gives the prime with `n` primes before it. `⍭0` is the prime 2:

```bpl
⍭ι8ₓ
```

```output
[2 3 5 7 11 13 17 19]ₓ
```

On a prime, `⍭⁻` gives its position. It counts the primes strictly below its argument, including when the argument is not itself prime:

```bpl
⍭⁻11
⍭⁻10
```

```output
4ₓ
4ₓ
```

With a left argument, [`⍭`](https://bpl.fast.ai//glyphs/stile-tilde.html) performs another prime operation. With code 1 it tests whether a number is prime, and with code 2 it gives the next prime:

```bpl
1⍭1 2 3 4 5 6
```

```output
$f $t $t $f $t $f
```

```bpl
2⍭10 11 12
```

```output
[11 13 13]ₓ
```

### [`⨸`](https://bpl.fast.ai//glyphs/circle-divide.html) (Factors)

A number's prime factors are primes whose product is that number. Factors gives them in ascending order, with repetitions. Multiplying them recovers the number:

```bpl
⨸360ₓ
```

```output
[2 2 2 3 3 5]ₓ
```

```bpl
×/⨸360ₓ
```

```output
360ₓ
```

Factors' inverse, `⨸⁻`, multiplies a list of factors back into the number.

```bpl
⨸⁻[2 2 2 3 3 5]ₓ
```

```output
360ₓ
```

An exponent counts the copies of one prime factor in the product. With a left argument of `¯∞`, Factors gives a table of distinct prime factors above their exponents:

```bpl
¯∞⨸360ₓ
```

```output
[2 3 5
 3 2 1]ₓ
```

### [`⌻`](https://bpl.fast.ai//glyphs/quad-jot.html) (Polynomials)

A polynomial is a sum of multiples of nonnegative integer powers of a variable, such as 1 \+ 2x \+ 3x². The multipliers `1 2 3` are its coefficients, starting with the constant term: the part without x. Binding these coefficients as the left argument of [`⌻`](https://bpl.fast.ai//glyphs/quad-jot.html) makes a polynomial function:

```bpl
p←[1 2 3]⌻
p[0 1 2]
```

```output
1 6 17
```

[`∂`](https://bpl.fast.ai//glyphs/partial.html) applies to this function too:

```bpl
p∂2
```

```output
14
```

A root is an input where the polynomial is zero. With one argument, [`⌻`](https://bpl.fast.ai//glyphs/quad-jot.html) gives the coefficient of the highest power and the approximate roots. For 2 − 3x \+ x², that coefficient is 1 and the roots are 1 and 2:

```bpl
⌻2 ¯3 1
```

```output
[1 [1ⱼ0 2ⱼ¯0]]
```

The inverse, `⌻⁻`, rebuilds the coefficients from the highest-power coefficient and roots.

```bpl
⌻⁻[1 [1 2]]
```

```output
2 ¯3 1
```

### [`⇄`](https://bpl.fast.ai//glyphs/right-left-arrows.html) (Optimize)

Optimize searches for the point where a function is least, starting from the right argument. The squared distance from 2 is least at 2:

```bpl
cost←{(ω-2)²}
cost⇄10
```

```output
2
```

With `"solve":$t` as the left argument, [`⇄`](https://bpl.fast.ai//glyphs/right-left-arrows.html) instead searches for a zero. This finds the positive square root of 2, starting from 1:

```bpl
["solve":$t] {ω²-2}⇄ 1
```

```output
1.414213562
```

[Previous: Rearranging and transforming arrays](rearranging-arrays.md) · [Study guide](../glyphs-study.md)
