Operator Square

Let the operator \square be defined for all positive integers the following way:

  • 1 1 = 1 1 \square 1=1 .
  • For all positive integers n > 1 n>1 , n 1 = ( n 1 ) 1 + n n \square 1=(n-1) \square 1+n .
  • For all positive integers n > 1 n>1 , 1 n = 1 ( n 1 ) + n 1 \square {n}=1 \square (n-1)+n .
  • For all positive integers a > 1 a>1 and b > 1 b>1 , a b = a ( b 1 ) + ( a 1 ) b a\square{b}=a\square(b-1)+(a-1)\square{b} .

Evaluate 5 5 5\square5 .


The answer is 350.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Chung Kevin
Nov 17, 2016

Set up the summation on a grid, to ensure that we get the proper numbers.

The first rule tells us the first horizontal row.
The second rule tells us the first vertical row.
The third rule tells us that each cell is obtained by summing up the cell above it and the cell to the left.

Hence, we get

Awesome! Hands down, the neatest solution to the problem!

Sidharth Soundararajan - 4 years, 6 months ago

Nice! Clear and simple, and easy to understand.

Tarmo Taipale - 4 years, 7 months ago

Log in to reply

Thanks. I looked at your solution, and that's what you were saying. I think this way makes it clearer for others to understand how to approach the problem.

Chung Kevin - 4 years, 7 months ago
Calvin Lin Staff
Nov 18, 2016

Read Kevin Chung's solution to understand how to solve this particular problem.
The general solution to the recurrence relation is a b = ( a + b a ) ( a + b 2 a 1 ) a \square b = { a + b \choose a } - { a + b - 2 \choose a-1 } , which we can prove by induction and checking all the 1 n , n 1 1 \square n, n \square 1 base cases. However, this would make the formula seem like magic.
This solution explains how pascal's triangle can be applied to solve this recurrence relation problem type and obtain the formula.

Consider the following operator \oplus .

  • a b = 0 a \oplus b = 0 if a < 0 a < 0 or b < 0 b < 0
  • Seed: 0 0 = 1 0 \oplus 0 = {\color{#D61F06}1}
  • a b = a ( b 1 ) + ( a 1 ) b a \oplus b = a \oplus (b-1) + (a-1) \oplus b

By setting it up in a triangle-form, we get the following:

1 0 + 1 = 1 1 + 0 = 1 0 + 1 = 1 1 + 1 = 2 1 + 0 = 1 0 + 1 = 1 1 + 2 = 3 2 + 1 = 3 1 + 0 = 1 \begin{array} { cccccccccccc} & & & & & {\color{#D61F06}1} & & & & & \\ & & & & 0+1=1 & & 1+0=1 & & & & \\ &&& 0+1=1 && 1+1=2 &&1+0=1 &&&\\ && 0+1=1 && 1+2=3 && 2+1=3 && 1+0=1 && \\ \end{array}

Thus, we see that the 1 \color{#D61F06} 1 helps us to generate the Pascal's triangle, and we obtain that each term is of the form ( a + b a ) { a + b \choose a } .


How do we adapt it to the scenario in the question? The trick is to find suitable places seed 1 \color{#D61F06} 1 that would lead us towards the desired result. It's not currently obvious what we could do, so let's analyze the given scenario further:

1 2 2 3 ? 3 4 ? ? 4 5 ? ? ? 5 6 ? ? ? ? 6 \begin{array} { ll llllllllll} & & & & & 1 & & & & & \\ & & & & 2 & & 2 & & & & \\ &&& 3 && ? && 3 &&&\\ && 4 && ? && ? && 4 && \\ & 5 && ? && ? && ? && 5 \\ 6 && ? && ? && ? && ? && 6 \\ \end{array}

The issue here is that the sides of the triangle are not 1, and so we cannot find the 1 \color{#D61F06} 1 to seed the pattern. However, notice that the sides are identical to the 2nd row of Pascal's triangle, so that suggests that we could backtrack to find our 1 \color{#D61F06}1 . Let's work with the left side first.

1 1 1 1 2 2 1 3 ? 3 1 4 ? ? 4 \begin{array} { ll llllllllll} & & & & {\color{#D61F06}1} & & & & & \\ & & & {\color{#3D99F6}1} && 1 & & & & & \\ & & {\color{#3D99F6}1}& & 2 & & 2 & & & & \\ &{\color{#3D99F6}1}&& 3 && ? && 3 &&&\\ {\color{#3D99F6}1}&& 4 && ? && ? && 4 && \\ \end{array}

This looks great! We've found a potential seeding point. Now, let's observe what happens if we tried to do the same on the right.

1 1 1 1 1 1 2 2 1 1 3 ? 3 1 1 4 ? ? 4 1 \begin{array} { ll llllllllll} & & & & {\color{#D61F06}1} & & {\color{#D61F06}1} & & & \\ & & & {\color{#3D99F6}1} && {\color{#69047E}1} & & {\color{#3D99F6}1}& & & \\ & & {\color{#3D99F6}1}& & 2 & & 2 & & {\color{#3D99F6}1}& & \\ &{\color{#3D99F6}1}&& 3 && ? && 3 &&{\color{#3D99F6}1}&\\ {\color{#3D99F6}1}&& 4 && ? && ? && 4 && {\color{#3D99F6}1} \\ \end{array}

As you can see, if we tried to duplicate the same naively, we end up with the 1 { \color{#69047E} 1 } having an incorrect value. It should have been 1 + 1 = 2 1 + 1 = 2 , but instead we have it as 1 (and that affects all the subsequent values). How can we fix this? Well, let's add a seed of 1 -1 at that spot!

With the following seed:

1 1 1 \begin{array} { ll llllllllll} & & & & {\color{#D61F06}1} & & {\color{#D61F06}1} & & & \\ & & & && {\color{#D61F06}-1} & & & & & \\ \end{array}

We will obtain:

1 1 0 + 1 = 1 1 + 1 + ( 1 ) = 1 1 + 0 = 1 0 + 1 = 1 1 + 1 = 2 1 + 1 = 2 1 + 0 = 1 0 + 1 = 1 1 + 2 = 3 2 + 2 = 4 2 + 1 = 3 1 + 0 = 1 0 + 1 = 1 1 + 3 = 4 3 + 4 = 7 4 + 3 = 7 3 + 1 = 4 1 + 0 = 1 \begin{array} {cccccccccccc} &&&& {\color{#D61F06}1} && {\color{#D61F06}1} && \\ & & & 0+1=1 && 1+1+ {\color{#D61F06}(-1)} =1 & & 1+0=1 & & & \\ & & 0+1=1& & 1+1=2 & & 1+1=2 & & 1+0=1& & \\ &0+1=1&& 1+2=3 && 2+2=4 && 2+1=3 &&1+0=1&\\ 0+1=1&& 1+3=4 && 3+4=7 && 4+3=7 && 3+1=4 && 1+0=1\\ \end{array}

Let the 1 \color{#D61F06} -1 seed be in position ( 1 , 1 ) (1,1) , since that is what the \square operator desires.
Consider the contribution of these seeds to the entry in ( a , b ) (a,b) .

The 1 \color{#D61F06} 1 seed in position ( 1 , 0 ) (1, 0) will contribute 1 × ( ( a 1 ) + b ( a 1 ) ) 1 \times { (a-1) + b \choose (a-1) } .
The 1 \color{#D61F06} 1 seed in position ( 0 , 1 ) (0,1) will contibute 1 × ( a + ( b 1 ) ( b 1 ) ) 1 \times { a + (b-1) \choose (b-1) } .
The 1 \color{#D61F06} -1 seed in position ( 1 , 1 ) (1,1) will contribute 1 × ( ( a 1 ) + ( b 1 ) ( a 1 ) ) -1 \times { (a-1) + (b-1) \choose (a-1) } .
Hence, a b = ( a + b 1 a 1 ) + ( a + b 1 b 1 ) ( a + b 2 a 1 ) a \square b = { a + b - 1 \choose a - 1 } + { a + b -1 \choose b-1 } - { a + b - 2 \choose a-1 } .


Note: We could have used a different seed of

1 0 0 1 \begin{array} { ll llllllllll} & & & & & {\color{#D61F06}1} & & & & & \\ & & & & {\color{#D61F06}0} & & {\color{#D61F06}0} & & & \\ & & & && {\color{#D61F06}-1} & & & & & \\ \end{array}

which leads to the equivalent (but nicer looking) formula ( a + b a ) ( a + b 2 a 1 ) { a + b \choose a } - { a + b - 2 \choose a-1 } .

Give this idea a try and see what you get. For example, how can we solve:

  • 0 n = n 2 0 \otimes n = n^2
  • n 0 = n n \otimes 0 = n
  • a b = a ( b 1 ) + ( a 1 ) b a \otimes b = a \otimes (b-1) + (a-1) \otimes b

Now I've got some idea. Looking at it now, it should have been obvious I should have compared the values with Pascal triangle.

Tarmo Taipale - 4 years, 7 months ago
Tarmo Taipale
Nov 14, 2016

In Rectangular Grid Walk, the number of ways an object can run through an a × b a\times{b} grid going only two directions is ( a + b b ) \displaystyle {a+b \choose b} .

As the definition says a b = a ( b 1 ) + ( a 1 ) b a\square{b}=a\square(b-1)+(a-1)\square{b} (when a,b >1) we can think of a 5 × 5 5\times5 rectangular grid:

When we "shatter" the original 5 5 5\square5 step by step with the previous rule, and the other two rules: n 1 = ( n 1 ) 1 + n n\square1=(n-1)\square1+n and 1 n = 1 n 1 + n 1\square{n}=1\square{n-1}+n we see that 5 1 5\square1 , 4 1 4\square1 , 3 1 3\square1 , 2 1 2\square1 , 1 5 1\square5 , 1 4 1\square4 , 1 3 1\square3 , 1 2 1\square2 and 1 1 1\square1 appear during the process as many times as there are possible ways to reach the dot representing them in the rectangular grid above. When this process is continued, each n 1 n\square1 and 1 n 1\square{n} produces the number n n in the final result as they are "shattered" by the rules n 1 = ( n 1 ) 1 + n n\square1=(n-1)\square1+n and 1 n = 1 n 1 + n 1\square{n}=1\square{n-1}+n . Eventually we get these " n n :s" with each value of n n and a number of 1 1 1\square1 :s, and there was the definition 1 1 = 1 1\square1=1 .

For each positive integer m m and n n , the rectangular grid presenting m n m\square{n} has the measures m × n m\times{n} in the amount of dots. In general, for each positive integer a a when 1 < a ( m 2 ) 1<a\leq(m-2) , ( m a ) 1 (m-a)\square1 appears ( n 1 + a a ) \displaystyle{n-1+a \choose a} times during the process, and for each positive integer b b when 1 < b ( n 2 ) 1<b\leq(n-2) , ( n b ) 1 (n-b)\square1 appears ( m 1 + b b ) \displaystyle{m-1+b \choose b} times. Each ( m a ) 1 (m-a)\square1 produces an m a m-a and each ( n b ) 1 (n-b)\square1 produces an n b n-b in the final result, so the previous values are multiplied with them and then summed together. Additionally, 1 1 1\square1 is produced ( m + n 2 n 1 ) \displaystyle{m+n-2 \choose n-1} times.

For example, there is one way to produce m 1 m\square1 with using the rules above, and ( n 1 ) \displaystyle {n \choose 1} ways to produce ( m 1 ) 1 (m-1)\square{1} , judging by the formula for rectangular grid walk presented above in the start. Each m 1 m\square1 produces an m m when "shattering", and each ( m 1 ) 1 (m-1)\square1 produces an m 1 m-1 when "shattering".

This means m n = k = 0 m 2 ( ( m k ) ( n 1 + k k ) ) + k = 0 n 2 ( ( n k ) ( m 1 + k k ) ) + ( m + n 2 n 1 ) m\square{n}=\sum_{k=0}^{m-2}((m-k)\displaystyle {n-1+k \choose k})+\sum_{k=0}^{n-2}((n-k)\displaystyle {m-1+k \choose k})+\displaystyle {m+n-2 \choose n-1}

We get

5 5 = 2 ( 1 × 5 + 5 × 4 + ( 6 2 ) × 3 + ( 7 3 ) × 2 ) + ( 8 4 ) × 1 = 2 ( 5 + 20 + 45 + 70 ) + 70 = 2 × 140 + 70 = 350 5\square5=2(1\times5+5\times4+\displaystyle {6 \choose 2}\times 3+\displaystyle {7 \choose 3}\times 2)+\displaystyle {8 \choose 4}\times 1=2(5+20+45+70)+70=2\times140+70=\boxed{350} .

I find it hard to understand what you're trying to express. I understand what you're doing, but maybe showing how to calculate the value directly (similar to the case of tabulating the number of ways to reach ( 5 , 5 ) (5,5) would make the solution easier to comprehend.

Do you know what the general formula for a b a \square b is?

Calvin Lin Staff - 4 years, 7 months ago

Log in to reply

Now I've added the general way of evaluating m n m\square{n} , and I've tried to make the solution a bit more clear.

Tarmo Taipale - 4 years, 7 months ago

Log in to reply

There is a nicer format for the answer, ( a + b a ) ( a + b 2 a 1 ) { a + b \choose a } - { a + b - 2 \choose a-1 } . (Edit: I had the wrong formula previously)

Do you see how to arrive at this formula from the problem / setup?

(Of course, we can prove it by induction, but that requires somehow guessing the pattern, which isn't too obvious).

Calvin Lin Staff - 4 years, 7 months ago

Log in to reply

@Calvin Lin I haven't really managed to see the way to get that simpler formula.

Tarmo Taipale - 4 years, 7 months ago

Here is a straightforward way to run Chung Kevin's idea using Haskell:

1
2
3
4
5
f :: Int -> Int -> Int
f 1 1 = 1
f n 1 = n + f (n-1) 1
f 1 n = n + f 1 (n-1)
f n m = f n (m-1) + f (n-1) m 

Then, f 5 5 gives the desired result.

that's my type of solution! did the same!

Kunal Gupta - 4 years, 6 months ago

Log in to reply

Please tell me you used haskell too!

Agnishom Chattopadhyay - 4 years, 6 months ago

Log in to reply

Nopes! haven't learned it yet! i used c++11

Kunal Gupta - 4 years, 6 months ago

Log in to reply

@Kunal Gupta That's cool too!

Agnishom Chattopadhyay - 4 years, 6 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...