Modulo

Instance of: modular arithmetic

AKA:

Distinct from:

English: A modulo operation retrieves the remainder following euclidean division. Euclidean division is division with a remainder. The quotient is an integer count of the number of times the whole divisor can be placed in the dividend. The remainder is the dividend minus the quotient times the divisor.

Formalization:

\[ \]

Cites: Wikipedia ; Wikidata ; Wolfram

Code

Examples:

dividend=10
divisor=3
remainder= 10 %% 3
remainder
[1] 1

Examples:

dividend=10
divisor=3
remainder= 10 % 3
remainder
1

Examples:

import numpy as np
dividend=np.array(10)
divisor=np.array(3)
remainder= np.mod(10,3)
remainder
1

Examples:

import jax.numpy as jnp
dividend=jnp.array(10)
WARNING:jax._src.lib.xla_bridge:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
divisor=jnp.array(3)
remainder= jnp.mod(10,3)
remainder
DeviceArray(1, dtype=int32, weak_type=True)

library(DBI)
# Create an ephemeral in-memory RSQLite database
#con <- dbConnect(RSQLite::SQLite(), dbname = ":memory:")
#dbListTables(con)
#dbWriteTable(con, "mtcars", mtcars)
#dbListTables(con)

#Configuration failed because libpq was not found. Try installing:
#* deb: libpq-dev libssl-dev (Debian, Ubuntu, etc)
#install.packages('RPostgres')
#remotes::install_github("r-dbi/RPostgres")
#Took forever because my file permissions were broken
#pg_lsclusters
require(RPostgres)
Loading required package: RPostgres
# Connect to the default postgres database
#I had to follow these instructions and create both a username and database that matched my ubuntu name
#https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart
con <- dbConnect(RPostgres::Postgres())
SELECT MOD(10, 3);
1 records
mod
1
import torch
dividend = torch.tensor(10)
divisor = torch.tensor(3)
remainder=torch.remainder(dividend, divisor)
remainder
tensor(1)

0.0.1 Tensorflow

import tensorflow as tf
dividend = tf.constant(10)
divisor = tf.constant(3)
remainder=tf.math.floormod(dividend, divisor)
remainder
<tf.Tensor: shape=(), dtype=int32, numpy=1>