Skip to content

Instantly share code, notes, and snippets.

@dannypsnl
Last active September 1, 2025 07:09
Show Gist options
  • Select an option

  • Save dannypsnl/df2949dd92805596de14240c37b181e0 to your computer and use it in GitHub Desktop.

Select an option

Save dannypsnl/df2949dd92805596de14240c37b181e0 to your computer and use it in GitHub Desktop.
Check given multiplication table form a grope structure or not

Grope

A grope is a set $G$ together with a binary operation $\circ$, in which the identity

$$ x \circ (y \circ x) = y $$

is satisfied for all $x, y \in G$.

The art of computer programming, Vol. 4B, p.132, problem 75.b

#lang racket
(require math/array)
(define ((make-mul table) x y)
(array-ref table (vector x y)))
(define (table-grope? table)
(define n '(0 1 2 3))
(define mul (make-mul table))
(for/and ([l (cartesian-product n n)])
(match-define (list x y) l)
(= (mul x (mul y x)) y)))
(table-grope? (array #[#[0 1 2 3]
#[1 0 3 2]
#[2 3 0 1]
#[3 2 1 0]]))
(table-grope? (array #[#[0 3 2 1]
#[3 2 1 0]
#[2 1 0 3]
#[1 0 3 2]]))
(table-grope? (array #[#[0 1 3 2]
#[1 0 2 3]
#[3 2 1 0]
#[2 3 0 1]]))
(table-grope? (array #[#[0 2 3 1]
#[3 1 0 2]
#[1 3 2 0]
#[2 0 1 3]]))
(table-grope? (array #[#[0 3 1 2]
#[2 1 3 0]
#[3 0 2 1]
#[1 2 0 3]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment