14
1
Many important topics in abstract algebra involve a binary function acting on a set. A number of properties of such functions have been defined in the investigation of such topics.
Your challenge will be to determine whether a given binary function on a given domain possesses five of these properties.
Properties
A binary function is closed if every possible output is in the domain.
A binary function is associative if the order in which the function is applied to a series of inputs doesn't affect the result. That is, $
is associative if (a $ b) $ c
always equals a $ (b $ c)
. Note that since the value (a $ b)
is used as an input, associative functions must be closed.
A binary function is commutative if swapping the order of the inputs doesn't change the result. In other words, if a $ b
always equals b $ a
.
A binary function has an identity element if there exists some element e
in the domain such that a $ e = a = e $ a
for all a
in the domain.
A binary function is idempotent if applying it to two identical inputs gives that number as the output. In other words, if a $ a = a
for all a
in the domain.
Input
You will be given a function in the form of a matrix, and the domain of the function will be the numbers 0 ... n-1
, where n
is the side length of the matrix.
The value (a $ b)
is encoded in the matrix as the a
th row's b
th element. If the input matrix is Q
, then a $ b
= Q[a][b]
For example, the exponentiation function (**
in Python) on the domain [0, 1, 2]
is encoded as:
[[1, 0, 0]
[1, 1, 1]
[1, 2, 4]]
The left and right domains are the same, so the matrix will always be square.
You may use any convenient matrix format as input, such as a list of lists, a single list in row- or column- major order, your language's native matrix object, etc. However, you may not take a function directly as input.
For simplicity, the matrix entries will all be integers. You may assume that they fit in your language's native integer type.
Output
You may indicate which of the above properties hold in any format you choose, including a list of booleans, a string with a different character for each property, etc. However, there must be a distinct, unique output for each of the 24 possible subsets of the properties. This output must be easily human-readable.
Examples
The maximum function on domain n=4:
[[0, 1, 2, 3]
[1, 1, 2, 3]
[2, 2, 2, 3]
[3, 3, 3, 3]]
This function has the properties of closure, associativity, commutativity, identity and idempotence.
The exponentiation function on domain n=3:
[[1, 0, 0]
[1, 1, 1]
[1, 2, 4]]
This function has none of the above properties.
The addition function on domain n=3:
[[0, 1, 2]
[1, 2, 3]
[2, 3, 4]]
This function has the properties of commutativity and identity.
The K combinator on domain n=3:
[[0, 0, 0]
[1, 1, 1]
[2, 2, 2]]
This function has the properties of closure, associativity and idempotence.
The absolute difference function on domain n=3:
[[0, 1, 2]
[1, 0, 1]
[2, 1, 0]]
This function has the properties of closure, commutativity and identity.
The average function, rounding towards even, on domain n=3:
[[0, 0, 1]
[0, 1, 2]
[1, 2, 2]]
This function has the properties of closure, commutativity, identity and idempotence.
The equality function on domain n=3:
[[1, 0, 0]
[0, 1, 0]
[0, 0, 1]]
This function has the properties of closure and commutativity.
Challenge
This is code golf. Standard loopholes apply. Least bytes wins.
How about
c=all(l>)
? – xnor – 2015-12-24T07:28:26.550Also,
[i%i|i<-b]==b
. – xnor – 2015-12-24T07:34:04.233Very readable for code-golf - nice! – isaacg – 2015-12-24T09:26:41.187