Need an advice on how to approach the following NP-hard problem:
Given a sequence tan(1),tan(2),...,tan(n) insert '+', '-', '*' to minimize the absolute value of difference of n and value of resulting expression. (5 ≤ n ≤ 365).
I know very little about approximation algorithms for NP-hard problems and I'd be happy if anon could give me a general idea how to approach this problem or what this problem can be reduced to or whether it is a generalization of some well-known NP-problem so I can google more efficiently.
>>9162277
I'd build a dynamic programming table from n=5 to n=365, tracking which operator gives the lowest absolute value up to that n.
>>9162292
Also this seems related to knapsack problems, but I don't know how I'd spell out the reduction mapping to which variant.
OP: Can you specify the problem statement in a bit more detail, please?
>>9162277
There's a few rules here.
The smallest possible value is 0.
Tangent ranges between -inf and +inf
Your domain can be converted to about
2 pi to 100 pi.
You can't use derivatives.
Based on this, you can use the periodic nature of tangent.
You want to add all the values in the first quadrant with those in the 4th. There's an offset of n. Whatever is left over from symmetry needs to be minimized.
From 5 to 365, most of the terms cancel so you are left with a much simpler problem.
>>9162292
>>9162293
Thanks, I'll give it a try.
>>9162302
I think I'll just give an example for the toy case of [math]n = 3[/math] (although I said [math]n \ge 5[/math]). For the sequence [math]tan(1),\
tan(2), \ tan(3)[/math] the desired result is [math]tan(1) - tan(2) + tan(3) = 0.599901 [/math]. In this case [math]0.599901[/math] is the closest you can get to [math]3[/math].
>>9162310
I assume these are radians.
What about tan(1) + tan(2) * tan(3) = 1.86887760364 ?