# Uniform singular value amplification

In this example, We introduce the implementation of uniform singular value amplification.

### What is uniform singular value amplification

Uniform singular value amplification uniformly amplifies the singular values of a matrix represented as a projected unitary. Suppose that we have access to a unitary $$U$$, its inverse $$U^\dagger$$ and the controlled reflection operators $$(2\Pi-I)$$, $$(2\tilde{\Pi}-I)$$. $$A:=\tilde{\Pi} U\Pi$$ is of our interest and has a singular value decomposition $$A=W\Sigma V$$.&#x20;

### The equivalent problem in function approximation

The goal of uniform singular value amplification is to implement the singular value transformation of $$A$$ for function $$f(x)$$. Here, $$f(x)$$ is linear function $$\lambda x$$ over some interval and takes value zero for other $$x$$.

For numerical demonstration, we consider target function to be

$$f(x)=x/a, \quad x\in\[0,a], \quad a=0.2.$$

To numerically find the best odd polynomial approximating $$f(x)$$, we use a subroutine which solves the problem using convex optimization. We first set the parameters of the subroutine.

For numerical demonstration, we scale the target function by a factor of $$0.9$$, to improve the numerical stability.

We call a subroutine to find the best odd polynomial approximating $$f(x)$$ on the interval $$D\_a = \[0, a]$$, where we solves the problem by convex optimization. Here are the parameters set for the subroutine.

```matlab
a = 0.2;
targ = @(x) x/a;

deg = 101;
parity = mod(deg, 2);
delta =0.01;
opts.intervals=[0,a];
opts.objnorm = Inf;
% opts.epsil is usually chosen such that target function 
% is bounded by 1-opts.epsil over D_delta 
opts.epsil = 0.01;
opts.npts = 500;
opts.fscale = 0.9;
opts.isplot=true;

coef_full=cvx_poly_coef(targ, deg, opts);
% The solver outputs all Chebyshev coefficients while we have to post-select 
% those of odd order due to the parity constraint.
coef = coef_full(1+parity:2:end);
```

<figure><img src="https://40428858-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FznDlSgNqsJLx79OHu47P%2Fuploads%2FteYBe8Icvv0H7AfW59uD%2Funiform_singular_value_amplification_polynomial.png?alt=media&#x26;token=c61cb6a3-d6ea-41d2-8615-84a71ca97038" alt="" width="563"><figcaption><p>Polynomial approximation of the target function</p></figcaption></figure>

<figure><img src="https://40428858-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FznDlSgNqsJLx79OHu47P%2Fuploads%2FRwfli3uROKRwNN2Hamcr%2Funiform_singular_value_amplification_polynomial_error.png?alt=media&#x26;token=306eecd6-f265-49a7-8ae5-56adcca7a7ad" alt="" width="563"><figcaption><p>Polynomial approximation error</p></figcaption></figure>

### Set up parameters

We use Newton method for solving phase factors. The parameters of the solver is initiated as follows.

```matlab
opts.maxiter = 100;
opts.criteria = 1e-12;
opts.useReal = true;
opts.targetPre = true;
opts.method = 'Newton';
```

### Solving phase factors by running the solver

```matlab
[phi_proc,out] = QSP_solver(coef,parity,opts);
```

### Verifying the solution

We verify the solved phase factors by computing the residual error in terms of $$l^{\infty}$$ norm.

```matlab
xlist1 = linspace(0,a-delta,500)';
xlist2 = linspace(a+delta,1,500)';
xlist = cat(1, xlist1,xlist2);
func = @(x) ChebyCoef2Func(x, coef, parity, true);
targ_value = targ(xlist);
func_value = func(xlist);
QSP_value = QSPGetEntry(xlist, phi_proc, out);
err= norm(QSP_value-func_value,Inf);
disp('The residual error is');
disp(err);

figure()
plot(xlist,QSP_value-func_value)
xlabel('$$x$$', 'Interpreter', 'latex')
ylabel('$$g(x,\Phi^*)-f_\mathrm{poly}(x)$$', 'Interpreter', 'latex')
print(gcf,'uniform_singular_value_amplification_error.png','-dpng','-r500');
```

<figure><img src="https://40428858-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FznDlSgNqsJLx79OHu47P%2Fuploads%2FpgFQkrngIM4DsNRypRf1%2Funiform_singular_value_amplification_error.png?alt=media&#x26;token=3c6f160d-9619-4555-a5aa-92d32839de98" alt="" width="563"><figcaption><p>The point-wise error of the solved phase factors.</p></figcaption></figure>

### Reference

1. Gilyén, A., Su, Y., Low, G. H., & Wiebe, N. (2019, June). Quantum singular value transformation and beyond: exponential improvements for quantum matrix arithmetics. In *Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing* (pp. 193-204).
2. Dong, Y., Meng, X., Whaley, K. B., & Lin, L. (2021). Efficient phase-factor evaluation in quantum signal processing. *Physical Review A*, *103*(4), 042419.

<details>

<summary>Output of the code</summary>

```
norm error = 6.22653e-06
max of solution = 0.992105
iter          err
   1  +7.4719e-01 
   2  +2.1185e-01 
   3  +4.7890e-02 
   4  +5.7683e-03 
   5  +1.5395e-04 
   6  +1.3721e-07 
Stop criteria satisfied.
The residual error is
   7.3552e-14
```

</details>
