Confirming the existence of a function related to a matrix

Is it possible to get an answer to the following question in Mathematica?

Let MM be a nn by nn matrix, is there a function m:N×N→Zm:\mathbb{N}\times \mathbb{N}\rightarrow \mathbb{Z} such that mij=mjim_{ij}=m_{ji} and mij=mi+2,j+2m_{ij}=m_{i+2,j+2} for all ii and jj.

I am new to Mathematica and interested whether such existential, abstract expressions can be solved in Mathematica.




If the dimension n is specified one can use FindInstance to solve for the m_i,j.
– Daniel Lichtblau
Feb 26 ’13 at 20:41



Sorry maybe it was not clear. I will enter the matrix M, so yes it’ll be specified.
– Nonlinear
Feb 26 ’13 at 20:46



Now I’m confused. I was assuming the m_i,j are entries of your M. Is that not the case? (In particular, is your M a numeric matrix?) If so then I’m not clear as to what is the question.
– Daniel Lichtblau
Feb 26 ’13 at 20:49



Wait… you changed your question. I thought the mijm_{ij} were entries in your matrix. Is that not the case? What relation does MM have with ff?
– R. M.♦
Feb 26 ’13 at 20:56



So now it’s no longer i+2,j+2i+2,j+2, but all possible i,j,k,li,j,k,l? You should formulate your problem correctly before posting instead of changing it every 5 minutes… else it is a waste of everyone’s time.
– R. M.♦
Feb 26 ’13 at 21:28


1 Answer


The good thing about programming with Mathematica is that you can move from conceptual problems like the one described to getting a solution pretty easily. Since you’re new to Mathematica, let’s walk this through step by step:

1. Let MM be an n×nn\times n matrix

This one’s easy:

ℳ[n_Integer] := Array[m, {n, n}]
ℳ[5] // MatrixForm

2. A function m: N×N→Zm:\ \mathbb{N}\times\mathbb{N}\to \mathbb{Z} such that mij=mjim_{ij}=m_{ji}

In other words, we don’t care about the order i,ji,j or j,ij,i — we can achieve this simply by making m have the attribute Orderless.

SetAttributes[m, Orderless]
ℳ[5] // MatrixForm

Compare this output with the one above.

3. A function m: N×N→Zm:\ \mathbb{N}\times\mathbb{N}\to \mathbb{Z} such that mij=mi+2,j+2m_{ij}=m_{i+2,j+2}

Here, we can use RSolve to solve for the relation m[i,j] == m[i+2,j+2]:

RSolve[m[i, j] == m[2 + i, 2 + j], m[i, j], {i, j}]
(* {{m[i, j] -> C[1][-2 i + 2 j] + (-1)^i C[2][-2 i + 2 j]}} *)

What this solution says is that mm can be a function of the form

m:(i,j)↦C1(i,j)+(−1)iC2(i,j)m: (i,j)\mapsto C_1(i,j) +(-1)^iC_2(i,j)

where the CiC_i are constant functions (C denotes a constant in Mathematica).

Now putting all of these together, we can do:

Block[{m, p, q},
SetAttributes[m, Orderless];
m[i_, j_] := p + (-1)^i q;
] // MatrixForm

where p and q are constants you can choose.



Why do you define m as p + (-1)^i q instead of p[j – i] + (-1)^i q[j – i]?
– ssch
Feb 26 ’13 at 21:00



@ssch It’s a constant function
– R. M.♦
Feb 26 ’13 at 21:00



ah right, never seen C[i][x] in a result before. Nice solution!
– ssch
Feb 26 ’13 at 21:11