<p>Assuming that the $c_{a,b}$ values appears in a nicely ordered way, you can use <strong>Horner's rule</strong> to evaluate the polynomial in $O(n^2)$ arithmetic operations. As mentioned by <em>frogeyedpeas</em>, you can't expect beating $n^2$ because it is the size of the input.</p>

<p>Note that if you are interested by the number of bit operations then you need to multiply this by the elementary cost of multiplication (for numbers of the size considered in your problem).</p>

<p>It you want to beat the $n^2$ bound, you need the $c_{a,b}$ to be represented in a more compact/structured way.</p>

CC BY-SA 3.0
2013-09-07T17:41:47.503Z
2013-09-07T17:41:47.503Z
minar
<p>Assuming No Space Limitations:</p>

<p>To compute:</p>

<p>$$x^a \ \ mod \ \ n$$</p>

<p>Use modular exponentiation by squarings. Which takes roughly $O(ln(a))$</p>

<p>Be sure to store the values produced by the algorithm so that way later attempts to compute $x^a$ need not start from scratch and will be significantly faster than before (I have a feeling this is the type of detail you want heuristics on so I will try my best underneath)</p>

<p>The same process works for Y as well.</p>

<p>The total time becomes $O(n^2ln(n))$</p>

<p>Now for further detail:</p>

<p>If we 2D sort the elements $c_{a,b}$ based on the size of their coordinates we consume time:</p>

<p>$$O(nln(n)$$</p>

<p>At this point however if we begin to compute the values x^a and y^b we will be doing it step by incrementally and therefore the total computation time is:</p>

<p>$$nln(n)$$ but this being done at each step of the $n^2$ computations...</p>

<p>So the total time is:</p>

<p>$$O(n^2)$$</p>

<p>Cutting this down further I predict can be done via Quantum Computation.</p>

<p>sorry I believe I made a mistake:</p>

<p>The 2dimensional sort would take $n^2ln(n)$...</p>

<p>So the time complexity is:</p>

<p>$$O(n^2ln(n))$$</p>

<p>Sadly :(</p>

<p>Without bringing some kind of Quantum computation out the best you could ever do is $n^2$ as that's the time to just read the problem input. Manipulating it once it is read will likely be of similar complexity</p>

CC BY-SA 3.0
2013-08-28T01:44:17.893Z
2013-08-28T02:59:27.393Z
2013-08-28T02:59:27.393Z
Sidharth Ghoshal
<p>Given in this problem is a set of values $0 \le c_{a,b} &lt; n$, where $0 \le a &lt; n$ and $0 \le b &lt; n$.</p>

<p>The problem is to find the following sum as quickly as possible:</p>

<p>$$\sum_{a,b}{c_{a,b}x^a y^b} \bmod n$$</p>

<p>Here $x$ and $y$ are also assumed to be integers modulo $n$.</p>

<p>I'd like to know what the best method/approach is to solving this problem, and what kinds of worst-case behavior we can expect to get the sum.</p>

<p>Are there any similar problems whose solutions may help with this?</p>

<p><strong>SOME NAIVE IDEAS</strong></p>

<p>There are $n^2$ different constants and only $n$ different possible assignments for each $c_{a,b}$, so it seems that grouping some of the coefficients together is the best way to go.  However, beyond simple ideas, I'm not sure what will work best.  I'm hoping I can get some good suggestions.</p>

<p><strong>MOTIVATION</strong></p>

<p>My motivation for tackling this particular problem is that its solution may help improve the bounds of #3-SAT by some small degree.  However, the relation between the two is fairly complicated.</p>

CC BY-SA 3.0
2013-09-07T23:00:03.340Z
Note that this can also be written as the matrix form $X^\top C Y$, where $X$ and $Y$ are vectors of the form $[1, x, x^2, \ldots]$. This goes back to the comments about the structure of the C matrix. If there's something special there, then maybe you can take advantage of it.
Suresh Venkat
<ds.algorithms><worst-case>
How well can we do with this variable assignment problem?
Matt Groff
# How well can we do with this variable assignment problem?

(Asked by: username_0 on 2013-08-28)

Given in this problem is a set of values $0 \le c\_{a,b} < n$, where $0 \le a < n$ and $0 \le b < n$.

The problem is to find the following sum as quickly as possible:

$$\sum\_{a,b}{c\_{a,b}x^a y^b} \bmod n$$

Here $x$ and $y$ are also assumed to be integers modulo $n$.

I'd like to know what the best method/approach is to solving this problem, and what kinds of worst-case behavior we can expect to get the sum.

Are there any similar problems whose solutions may help with this?

**SOME NAIVE IDEAS**

There are $n^2$ different constants and only $n$ different possible assignments for each $c\_{a,b}$, so it seems that grouping some of the coefficients together is the best way to go. However, beyond simple ideas, I'm not sure what will work best. I'm hoping I can get some good suggestions.

**MOTIVATION**

My motivation for tackling this particular problem is that its solution may help improve the bounds of #3-SAT by some small degree. However, the relation between the two is fairly complicated.

**Tags:** ds.algorithms, worst-case

> **Comments:**
> **username_1**: Note that this can also be written as the matrix form $X^\top C Y$, where $X$ and $Y$ are vectors of the form $[1, x, x^2, \ldots]$. This goes back to the comments about the structure of the C matrix. If there's something special there, then maybe you can take advantage of it.  

---

## 2 answers

### Answer by username_2 on 2013-09-07. Score: 1

Assuming that the $c\_{a,b}$ values appears in a nicely ordered way, you can use **Horner's rule** to evaluate the polynomial in $O(n^2)$ arithmetic operations. As mentioned by *frogeyedpeas*, you can't expect beating $n^2$ because it is the size of the input.

Note that if you are interested by the number of bit operations then you need to multiply this by the elementary cost of multiplication (for numbers of the size considered in your problem).

It you want to beat the $n^2$ bound, you need the $c\_{a,b}$ to be represented in a more compact/structured way.


---

### Answer by username_3 on 2013-08-28. Score: 0

Assuming No Space Limitations:

To compute:

$$x^a \ \ mod \ \ n$$

Use modular exponentiation by squarings. Which takes roughly $O(ln(a))$

Be sure to store the values produced by the algorithm so that way later attempts to compute $x^a$ need not start from scratch and will be significantly faster than before (I have a feeling this is the type of detail you want heuristics on so I will try my best underneath)

The same process works for Y as well.

The total time becomes $O(n^2ln(n))$

Now for further detail:

If we 2D sort the elements $c\_{a,b}$ based on the size of their coordinates we consume time:

$$O(nln(n)$$

At this point however if we begin to compute the values x^a and y^b we will be doing it step by incrementally and therefore the total computation time is:

$$nln(n)$$ but this being done at each step of the $n^2$ computations...

So the total time is:

$$O(n^2)$$

Cutting this down further I predict can be done via Quantum Computation.

sorry I believe I made a mistake:

The 2dimensional sort would take $n^2ln(n)$...

So the time complexity is:

$$O(n^2ln(n))$$

Sadly :(

Without bringing some kind of Quantum computation out the best you could ever do is $n^2$ as that's the time to just read the problem input. Manipulating it once it is read will likely be of similar complexity


---

