# Fully polynomial-time approximation scheme

A fully polynomial-time approximation scheme (FPTAS) is an algorithm for finding approximate solutions to function problems, especially optimization problems. An FPTAS takes as input an instance of the problem and a parameter ε > 0. It returns as output a value which is at least $1-\varepsilon$ times the correct value, and at most $1+\varepsilon$ times the correct value.
In the context of optimization problems, the correct value is understood to be the value of the optimal solution, and it is often implied that an FPTAS should produce a valid solution (and not just the value of the solution). Returning a value and finding a solution with that value are equivalent assuming that the problem possesses self reducibility.
Importantly, the run-time of an FPTAS is polynomial in the problem size and in 1/ε. This is in contrast to a general polynomial-time approximation scheme (PTAS). The run-time of a general PTAS is polynomial in the problem size for each specific ε, but might be exponential in 1/ε.
The term FPTAS may also be used to refer to the class of problems that have an FPTAS. FPTAS is a subset of PTAS, and unless P = NP, it is a strict subset.

## Relation to other complexity classes

All problems in FPTAS are fixed-parameter tractable with respect to the standard parameterization.
Any strongly NP-hard optimization problem with a polynomially bounded objective function cannot have an FPTAS unless P=NP. However, the converse fails: e.g. if P does not equal NP, knapsack with two constraints is not strongly NP-hard, but has no FPTAS even when the optimal objective is polynomially bounded.

## Converting a dynamic program to an FPTAS

Woeginger presented a general scheme for converting a certain class of dynamic programs to an FPTAS.

### Input

The scheme handles optimization problems in which the input is defined as follows:
* The input is made of n vectors, x$_1$,...,x$_n$.
* Each input vector is made of some $a$ non-negative integers, where $a$ may depend on the input.
* All components of the input vectors are encoded in binary. So the size of the problem is O(n+log(X)), where X is the sum of all components in all vectors.

### Extremely-simple dynamic program

It is assumed that the problem has a dynamic-programming (DP) algorithm using states. Each state is a vector made of some $b$ non-negative integers, where $b$ is independent of the input. The DP works in n steps. At each step i, it processes the input x$_i$, and constructs a set of states S$_i$. Each state encodes a partial solution to the problem, using inputs x$_1$,...,x$_i$. The components of the DP are:
* A set S$_0$ of initial states.
* A set F of transition functions. Each function f in F maps a pair (state,input) to a new state.
* An objective function g, mapping a state to its value.
The algorithm of the DP is:
* Let S$_0$ := the set of initial states.
* For k = 1 to n do:
** Let S$_k$ := {f(s,x$_k$) | f in F, s in S$_k$$_{−1}$}
* Output min/max {g(s) | s in S$_n$}.
The run-time of the DP is linear in the number of possible states. In general, this number can be exponential in the size of the input problem: it can be in O(n V$^b$), where V is the largest integer than can appear in a state. If V is in O(X), then the run-time is in O(n X$^b$), which is only pseudo-polynomial time, since it is exponential in the problem size which is in O(log X).
The way to make it polynomial is to trim the state-space: instead of keeping all possible states in each step, keep only a subset of the states; remove states that are "sufficiently close" to other states. Under certain conditions, this trimming can be done in a way that does not change the objective value by too much.
To formalize this, we assume that the problem at hand has a non-negative integer vector d = (d$_1$,...,d$_b$), called the degree vector of the problem. For every real number r>1, we say that two state-vectors s$_1$,s$_2$ are (d,r)-close if, for each coordinate j in 1,...,b: $r^{-d_{j}}\cdot s_{1,j}\leq s_{2,j}\leq r^{d_{j}}\cdot s_{1,j}$ (in particular, if d$_j$=0 for some j, then $s_{1,j}=s_{2,j}$).
A problem is called extremely-benevolent if it satisfies the following three conditions:
* Proximity is preserved by the transition functions: For any r>1, for any transition function f in F, for any input-vector x, and for any two state-vectors s$_1$,s$_2$, the following holds: if s$_1$ is (d,r)-close to s$_2$, then f(s$_1$,x) is (d,r)-close to f(s$_2$,x).
** A sufficient condition for this can be checked as follows. For every function f(s,x) in F, and for every coordinate j in 1,...,b, denote by f$_j$(s,x) the j-th coordinate of f. This f$_j$ can be seen as an integer function in b+a variables. Suppose that every such f$_j$ is a polynomial with non-negative coefficients. Convert it to a polynomial of a single variable z, by substituting s=(z$^{d1}$,...,z$^{db}$) and x=(1,...,1). If the degree of the resulting polynomial in z is at most d$_j$, then condition 1 is satisfied.
* Proximity is preserved by the value function: There exists an integer G ≥ 0 (which is a function of the value function g and the degree vector d), such that for any r>1, and for any two state-vectors s$_1$,s$_2$, the following holds: if s$_1$ is (d,r)-close to s$_2$, then: g(s$_1$) ≤ r$^G$ · g(s$_2$) (in minimization problems); g(s$_1$) ≥ r$^{(-G)}$ · g(s$_2$) (in maximization problems).
** A sufficient condition for this is that the function g is a polynomial function (of b variables) with non-negative coefficients.
* Technical conditions:
** All transition functions f in F and the value function g can be evaluated in polytime.
** The number |F| of transition functions is polynomial in n and log(X).
** The set S$_0$ of initial states can be computed in time polynomial in n and log(X).
** Let V$_j$ be the set of all values that can appear in coordinate j in a state. Then, the ln of every value in V$_j$ is at most a polynomial P$_1$(n,log(X)).
** If d$_j$=0, the cardinality of V$_j$ is at most a polynomial P$_2$(n,log(X)).
For every extremely-benevolent problem, the dynamic program can be converted into an FPTAS. Define:
* $\epsilon$ := the required approximation ratio.
* $r:=1+{\frac {\epsilon }{2Gn}}$, where G is the constant from condition 2. Note that ${\frac {1}{\ln {r}}}\leq 1+{\frac {2Gn}{\epsilon }}$.
* $L:=\left\lceil {\frac {P_{1}(n,\log(X))}{\ln(r)}}\right\rceil$, where P$_1$ is the polynomial from condition 3 (an upper bound on the ln of every value that can appear in a state vector). Note that $L\leq \left\lceil \left(1+{\frac {2Gn}{\epsilon }}\right)P_{1}(n,\log {X})\right\rceil$, so it is polynomial in the size of the input and in $1/\epsilon$. Also, $r^{L}=e^{\ln {r}}\cdot L\geq e^{P_{1}(n,\log {x})}$, so by definition of P$_1$, every integer that can appear in a state-vector is in the range [0,r$^L$].
* Partition the range [0,r$^L$] into L+1 r-intervals: $I_{0}=[0];I_{1}=[1,r);I_{2}=[r,r^{2});\ldots ;I_{L}=[r^{L-1},r^{L}]$.
* Partition the state space into r-boxes: each coordinate k with degree d$_k$ ≥ 1 is partitioned into the L+1 intervals above; each coordinate with d$_k$ = 0 is partitioned into P$_2$(n,log(X)) singleton intervals - an interval for each possible value of coordinate k (where P$_2$ is the polynomial from condition 3 above).
** Note that every possible state is contained in exactly one r-box; if two states are in the same r-box, then they are (d,r)-close.
* $R:=(L+1+P_{2}(n,\log {X}))^{b}$.
** Note that the number of r-boxes is at most R. Since b is a fixed constant, this R is polynomial in the size of the input and in $1/\epsilon$.
The FPTAS runs similarly to the DP, but in each step, it trims the state set into a smaller set T$_k$, that contains exactly one state in each r-box. The algorithm of the FPTAS is:
* Let T$_0$ := S$_0$ = the set of initial states.
* For k = 1 to n do:
** Let U$_k$ := {f(s,x$_k$) | f in F, s in T$_k$$_{−1}$}
** Let T$_k$ := a trimmed copy of U$_k$: for each r-box that contains one or more states of U$_k$, keep exactly one state in T$_k$.
* Output min/max {g(s) | s in T$_n$}.
The run-time of the FPTAS is polynomial in the total number of possible states in each T$_i$, which is at most the total number of r-boxes, which is at most R, which is polynomial in n, log(X), and $1/\epsilon$.
Note that, for each state s$_u$ in U$_k$, its subset T$_k$ contains at least one state s$_t$ that is (d,r)-close to s$_u$. Also, each U$_k$ is a subset of the S$_k$ in the original (untrimmed) DP. The main lemma for proving the correctness of the FPTAS is:$^{:Lem.3.3}$
   For every step k in 0,...,n, for every state s$_s$ in S$_k$, there is a state s$_t$ in T$_k$ that is (d,r$^k$)-close to s$_s$.
The proof is by induction on k. For k=0 we have T$_k$=S$_k$; every state is (d,1)-close to itself. Suppose the lemma holds for k-1. For every state s$_s$ in S$_k$, let s$_{s-}$ be one of its predecessors in S$_{k-1}$, so that f(s$_s$$_−$,x)=s$_s$. By the induction assumption, there is a state s$_{t-}$ in T$_{k-1}$, that is (d,r$^{k-1}$)-close to s$_s$$_−$. Since proximity is preserved by transitions (Condition 1 above), f(s$_t$$_−$,x) is (d,r$^{k-1}$)-close to f(s$_s$$_−$,x)=s$_s$. This f(s$_t$$_−$,x) is in U$_k$. After the trimming, there is a state s$_t$ in T$_k$ that is (d,r)-close to f(s$_{t-}$,x). This s$_t$ is (d,r$^k$)-close to s$_s$.
Consider now the state s$^*$ in S$_n$, which corresponds to the optimal solution (that is, g(s*)=OPT). By the lemma above, there is a state t* in T$_n$, which is (d,r$^n$)-close to s$^*$. Since proximity is preserved by the value function, g(t*) ≥ r$^{(-Gn)}$ · g(s*) for a maximization problem. By definition of r, $r^{-Gn}\geq (1-\epsilon )$. So $g(t^{*})\geq (1-\epsilon )\cdot OPT$. A similar argument works for a minimization problem.

#### Examples

Here are some examples of extremely-benevolent problems, that have an FPTAS by the above theorem.
1. Multiway number partitioning (equivalently, Identical-machines scheduling) with the goal of minimizing the largest sum is extremely-benevolent. Here, we have a = 1 (the inputs are integers) and b = the number of bins (which is considered fixed). Each state is a vector of b integers representing the sums of the b bins. There are b functions: each function j represents inserting the next input into bin j. The function g(s) picks the largest element of s. S$_0$ = {(0,...,0)}. The conditions for extreme-benevolence are satisfied with degree-vector d=(1,...,1) and G=1. The result extends to Uniform-machines scheduling and Unrelated-machines scheduling whenever the number of machines is fixed (this is required because R - the number of r-boxes - is exponential in b). Denoted Pm||$\max C_{j}$ or Qm||$\max C_{j}$ or Rm||$\max C_{j}$.
* Note: consider the special case b=2, where the goal is to minimize the square of the difference between the two part sums. The same DP can be used, but this time with value function g(s) = (s$_1$-s$_2$)$^2$. Now, condition 2 is violated: the states (s$_1$,s$_1$) and (s$_1$,s$_2$) may be (d,r)-close, but g(s$_1$,s$_1$) = 0 while g(s$_1$,s$_2$) > 0. so the above theorem cannot be applied. Indeed, the problem does not have an FPTAS unless P=NP, since an FPTAS could be used to decide in polytime whether the optimal value is 0.
2. Sum of cubed job completion time on any fixed number of identical or uniform machines - the latter denoted by Qm||$\sum C_{j}^{3}$ - is ex-benevolent with a=1, b=3, d=(1,1,3). It can be extended to any fixed power of the completion time.
3. Sum of weighted completion time on any fixed number of identical or uniform machines - the latter denoted by Qm||$\sum w_{j}C_{j}$.
4. Sum of completion time on any fixed number of identical or uniform machines, with time-dependent processing times: Qm|time-dep|$\sum C_{j}$. This holds even for weighted sum of completion time.
5. Weighted earliness-tardiness about a common due-date on any fixed number of machines: m||$\sum w_{j}|C_{j}|$.

### Simple dynamic program

Simple dynamic programs add to the above formulation the following components:
* A set H of filtering functions, of the same cardinality as F. Each function h$_i$ in H maps a pair (state,input) to a Boolean value. The value should be "true" if and only if activating the transition f$_i$ on this pair would lead to a valid state.
* A dominance relation, which is a partial order on states (no indifferences, not all pairs are comparable), and a quasi-dominance relation which is a total preorder on states (indifferences allowed, all pairs are comparable).
The original DP is modified as follows:
* Let S$_0$ := the set of initial states.
* For k = 1 to n do:
** Let S$_k$ := {f$_j$(s,x$_k$) | f$_j$ in F, s in S$_k$$_{−1}$, h$_j$(s,x$_k$)=True }, where h$_j$ is the filter function corresponding to the transition function f$_j$.
* Output min/max {g(s) | s in S$_n$}.
A problem is called benevolent if it satisfies the following conditions (which extend conditions 1, 2, 3 above):
* Proximity is preserved by the transition functions: For any r>1, for any transition function f in F, for any input-vector x, and for any two state-vectors s$_1$,s$_2$, the following holds:
** if s$_1$ is (d,r)-close to s$_2$, and s$_1$ quasi-dominates s$_2$, then either (a) f(s$_1$,x) is (d,r)-close to f(s$_2$,x), and f(s$_1$,x) quasi-dominates f(s$_2$,x), or (b) f(s$_1$,x) dominates f(s$_2$,x).
** if s$_1$ dominates s$_2$, then f(s$_1$,x) dominates f(s$_2$,x).
* Proximity is preserved by the value function: There exists an integer G ≥ 0 (a function of the value function g and the degree vector d), such that for any r>1, and for any two state-vectors s$_1$,s$_2$, the following holds:
** if s$_1$ is (d,r)-close to s$_2$, and s$_1$ quasi-dominates s$_2$, then: g(s$_1$) ≤ r$^G$ · g(s$_2$) (in minimization problems); g(s$_1$) ≥ r$^{(-G)}$ · g(s$_2$) (in maximization problems).
** if s$_1$ dominates s$_2$, then g(s$_1$) ≤ g(s$_2$) (in minimization problems); g(s$_1$) ≥ g(s$_2$) (in maximization problems).
* Technical conditions (in addition to the above):
** The quasi-dominance relation can be decided in polynomial time.
* Conditions on the filter functions: For any r>1, for any filter function h in H, for any input-vector x, and for any two state-vectors s$_1$,s$_2$, the following holds:
** if s$_1$ is (d,r)-close to s$_2$, and s$_1$ quasi-dominates s$_2$, then h(s$_1$,x) ≥ h(s$_2$,x).
** if s$_1$ dominates s$_2$, then h(s$_1$,x) ≥ h(s$_2$,x).
For every benevolent problem, the dynamic program can be converted into an FPTAS similarly to the one above, with two changes (boldfaced):
* Let T$_0$ := S$_0$ = the set of initial states.
* For k = 1 to n do:
** Let U$_k$ := {f$_j$(s,x$_k$) | f$_j$ in F, s in T$_k$$_{−1}$, h$_j$(s,x$_k$)=True }, where h$_j$ is the filter function corresponding to the transition function f$_j$.
** Let T$_k$ := a trimmed copy of U$_k$: for each r-box that contains one or more states of U$_k$, choose a single element that quasi-dominates all other elements in U$_k$, and insert it into T$_k$.
* Output min/max {g(s) | s in T$_n$}.

#### Examples

Here are some examples of benevolent problems, that have an FPTAS by the above theorem.
1. The 0-1 knapsack problem is benevolent. Here, we have a=2: each input is a 2-vector (weight, value). There is a DP with b=2: each state encodes (current weight, current value). There are two transition functions: f$_1$ corresponds to adding the next input item, and f$_2$ corresponds to not adding it. The corresponding filter functions are: h$_1$ verifies that the weight with the next input item is at most the knapsack capacity; h$_2$ always returns True. The value function g(s) returns s$_2$. The initial state-set is {(0,0)}. The degree vector is (1,1). The dominance relation is trivial. The quasi-dominance relation compares only the weight coordinate: s quasi-dominates t iff s$_1$ ≤ t$_1$. The implication of this is that, if state t has a higher weight than state s, then the transition functions are allowed to not preserve the proximity between t and s (it is possible, for example, that s has a successor and t does not have a corresponding successor). A similar algorithm was presented earlier by Ibarra and Kim. The run-time of this FPTAS can be improved to $O(n\log {1/\epsilon }+1/\epsilon ^{4})$ operations on integers. The exponent was later improved to 2.5.
* Note: consider In the 2-weighted knapsack problem, where each item has two weights and a value, and the goal is to maximize the value such that the sum of squares of the total weights is at most the knapsack capacity: $\left(\sum _{k\in K}w_{1,k}\right)^{2}+\left(\sum _{k\in K}w_{2,k}\right)^{2}\leq W$. We could solve it using a similar DP, where each state is (current weight 1, current weight 2, value). The quasi-dominance relation should be modified to: s quasi-dominates t iff (s$_1$$^2$ + s$_2$$^2$) ≤ (t$_1$$^2$ + t$_2$$^2$). But it violates Condition 1 above: quasi-dominance is not preserved by transition functions [for example, the state (2,2,..) quasi-dominates (1,3,..); but after adding the input (2,0,..) to both states, the result (4,2,..) does not quasi-dominate (3,3,..)]. So the theorem cannot be used. Indeed, this problem does not have an FPTAS unless P=NP. The same is true for the two-dimensional knapsack problem. The same is true for the multiple subset sum problem: the quasi-dominance relation should be: s quasi-dominates t iff max(s$_{1,}$s$_2$) ≤ max(t$_{1,}$t$_2$), but it is not preserved by transitions, by the same example as above.
2. Minimizing the weighted number of tardy jobs, or maximizing the weighted number of early jobs, on a single machine; denoted 1||$\sum w_{j}U_{j}$.
3. Batch scheduling for minimizing the weighted number of tardy jobs: 1|batch|$\sum w_{j}U_{j}$.
4. Makespan of deteriorating jobs on a single machine: 1|deteriorate|$\max C_{j}$.
5. Total late work on a single machine: 1||$\sum V_{j}$.
6. Total weighted late work on a single machine: 1||$\sum w_{j}V_{j}$.

### Non-examples

Despite the generality of the above result, there are cases in which it cannot be used.
1. In the total tardiness problem 1||$\sum T_{j}$, the dynamic programming formulation of Lawler requires to update all states in the old state space some B times, where B is of the order of X (the maximum input size). The same is true for a DP for economic lot-sizing. In these cases, the number of transition functions in F is B, which is exponential in the log(X), so the second technical condition is violated. The state-trimming technique is not useful, but another technique - input-rounding - has been used to design an FPTAS.
2. In the variance minimization problem 1||$CTV$, the objective function is $g(s)=s_{5}-(s_{4}-s_{3})^{2}/n$, which violates Condition 2, so the theorem cannot be used. But different techniques have been used to design an FPTAS.

## FPTAS for approximating real numbers

A different kind of problem in which FPTAS may be useful is finding rational numbers that approximate some real numbers. For example, consider the infinite series $\sum _{i=1}^{\infty }{\frac {1}{i^{3}}}$. The sum is an irrational number. To approximate it by a rational number, we can compute the sum of the first k elements, for some finite k. One can show that the error in approximation is about ${\frac {1}{2k^{2}}}$. Therefore, to get an error of ε, we need about ${\sqrt {\frac {1}{2\epsilon }}}$ elements, so this is an FPTAS. Note that this particular sum can be represented by another sum in which only O(log(ε)) elements are needed, so the sum can actually be approximated in polynomial time in the encoding length of ε.$^{:35,Sec.1}$

## Some other problems that have an FPTAS

* The knapsack problem, as well as some of its variants:
** 0-1 knapsack problem.
** Unbounded knapsack problem.
** Multi-dimensional knapsack problem with Delta-modular constraints.
** Multi-objective 0-1 knapsack problem.
** Parametric knapsack problem.
** Symmetric quadratic knapsack problem.
* Count-subset-sum (#SubsetSum) - finding the number of distinct subsets with a sum of at most C.
* Restricted shortest path: finding a minimum-cost path between two nodes in a graph, subject to a delay constraint.
* Shortest paths and non-linear objectives.
* Counting edge-covers.
* Vector subset search problem where the dimension is fixed.