# HS.5.2 polynomial

**URL:** <https://discuss.pennylane.ai/t/hs-5-2-polynomial/9393>\
**Category:** Codebook\
**Created:** [June 26, 2026, 10:52pm UTC](https://discuss.pennylane.ai/t/hs-5-2-polynomial/9393 "2026-06-26T22:52:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mchau](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mchau](https://discuss.pennylane.ai/u/mchau)\
**Post date:** [June 26, 2026, 10:52pm UTC](https://discuss.pennylane.ai/t/hs-5-2-polynomial/9393/1 "2026-06-26T22:52:11Z")

</div>

> **[Hamiltonian Simulation | Quantum Signal Processing | PennyLane Codebook](https://pennylane.ai/codebook/hamiltonian-simulation/QSP)**
>
> Perform polynomial transformations on an encoded scalar.

The exercise is from the link above. We need to use QSP to estimate the \text{erf} function. I tried to solve that **without** viewing the hint by estimating the Chebyshev series of erf. I run this externally and copy the coef to the exercise

```auto
from numpy.polynomial.chebyshev import chebfit
def integrand(t):
    return 2/np.sqrt(np.pi) * np.exp(-t**2)

y = []
x = np.arange(-1, 1, 0.005)
for i in x:
    I, _ = quad(integrand, 0, i)
    y.append(I)

# do the chebyshev fit
coef = chebfit(x, y, deg=7)

```

Now I click the hint, and see we use Taylor expansion. That worked, but aren’t we supposed to use Chebysev as HS.5.1 instead of Taylor?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [June 29, 2026, 8:43pm UTC](https://discuss.pennylane.ai/t/hs-5-2-polynomial/9393/2 "2026-06-29T20:43:33Z")

</div>

Hi @mchau , it’s great to see you back in the Forum!

It’s possible that more than one solution can give the right answer but we encourage you to use the method described in the Codercise. We will take a deeper look into this just to check that everything is working correctly but in the meantime I encourage you to try it out with the instructions from the exercise.

---

<div class="post-metadata">

**Author:** ![dren](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/dren/32/4183_2.png) [@dren](https://discuss.pennylane.ai/u/dren)\
**Post date:** [July 7, 2026, 4:20pm UTC](https://discuss.pennylane.ai/t/hs-5-2-polynomial/9393/3 "2026-07-07T16:20:55Z")

</div>

Hi @mchau, thanks for your excellent question!

There are a couple of things going on here. On one hand, the description for HS.5.2 does indeed suggest a “Taylor series expansion” of erf, which is indeed what we were looking for. I will elaborate in a moment.

On the other hand, HS.5.2 (and QSP generally) is ultimately agnostic to any polynomial basis you select so long as the final polynomial approximates erf. In principle, you could have used a Chebyshev polynomial with `qp.poly_to_angles` so long as you enforced definite parity (which the Taylor series for erf does automatically) and converted the Chebyshev polynomial coefficients to the monomial coefficients that `qp.poly_to_angles` expects. I.e., `numpy.polynomial.chebyshev.cheb2poly(coef)`, then enforce parity, then feed into `qp.poly_to_angles`.

To clarify, HS.5.1 uses a Chebyshev polynomial because that is what Grover’s algorithm naturally produces (You will find that RZ\_angles in HS.5.1 are all 0). However, HS.5.2 uses a Taylor series to approximate erf because it is a simple way of obtaining a definite parity polynomial.

I hope that helps!

Best wishes,

David
