# Singular value threshold projector

In this example, We introduce the implementation of singular value threshold projector.

### What is singular value threshold projector

Singular value threshold projectors project out singular vectors with singular values below/above a certain threshold. 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$$. For $$S\subset R$$ let $$\Sigma\_S$$ be the matrix obtained from $$\Sigma$$ by replacing all diagonal entries $$\Sigma\_{ii}\in S$$ by 1 and all diagonal entries $$\Sigma\_{ii}\notin S$$ by 0. We define $$\Pi\_S:=\Pi V\Sigma\_S V^{\dagger}\Pi$$ and similarly $$\tilde{\Pi}\_S:=\tilde{\Pi} W\Sigma\_S W^{\dagger}\tilde{\Pi}$$. For example, set $$S=\[0,\delta]$$ and $$\Pi\_S$$ projects out right singular vectors with singular value at most $$\delta$$. These threshold projectors play a major role in quantum algorithms.

### The equivalent problem in function approximation

As an example, we implement $$\Pi\_{\[0,0.5]}$$. We need to implement singular value transformation of $$A$$ for the following rectangle function. We call a subroutine to find the best even polynomial approximating $$f(x)$$ on the interval $$D\_{\delta}=\[0, 0.5-\delta]\cup \[0.5+\delta,1].$$ We solve the problem by convex optimization. Here are the parameters set for the subroutine.&#x20;

### Set up parameters

```matlab
opts.intervals=[0,0.5-delta,0.5+delta,1];
opts.objnorm = Inf;
opts.epsil = 0.1;
opts.npts = 500;
opts.isplot= true;
% scaling factor for the infinity norm
opts.fscale = 0.9;
opts.maxiter = 100;
opts.criteria = 1e-12;
opts.useReal = false;
opts.targetPre = true;
opts.method = 'Newton';
```

### Solving polynomial approximation

```matlab
targ = @(x) rectangularPulse(-0.5,0.5,x);
% Compute its Chebyshev coefficients. 
parity = 0;
deg = 250;
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="/files/kDbtPucOtzvLFdNynAke" alt=""><figcaption><p>Polynomial approximation of the target function</p></figcaption></figure>

<figure><img src="/files/hicye63IIhg8g7k7Yynu" alt=""><figcaption><p>Polynomial approximation error</p></figcaption></figure>

### Solving phase factors by running the solver

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

### Verifying the solution

```matlab
xlist1 = linspace(0,0.5-delta,500)';
xlist2 = linspace(0.5+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,'singular_value_threshold_projectors_error.png','-dpng','-r500');
```

<figure><img src="/files/pwT5fKmf6VQyBiOeiEjH" alt=""><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.5514e-08
max of solution = 0.9
iter          err
   1  +4.8369e-01 
   2  +1.9791e-01 
   3  +2.7179e-02 
   4  +3.0099e-04 
   5  +3.2263e-08 
Stop criteria satisfied.
The residual error is
   3.3529e-14
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qsppack.gitbook.io/qsppack/examples/singular-value-threshold-projector.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
