# HS.5.1 Polynomial Error

**URL:** <https://discuss.pennylane.ai/t/hs-5-1-polynomial-error/8693>\
**Category:** Codebook\
**Created:** [June 30, 2025, 7:29am UTC](https://discuss.pennylane.ai/t/hs-5-1-polynomial-error/8693 "2025-06-30T07:29:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adri](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@adri](https://discuss.pennylane.ai/u/adri)\
**Post date:** [June 30, 2025, 7:29am UTC](https://discuss.pennylane.ai/t/hs-5-1-polynomial-error/8693/1 "2025-06-30T07:29:23Z")

</div>

Hi everyone,

I’m trying to implement a QSP sequence that reproduces the polynomial for two iterations of Grover’s search:

P(x) = 16x^5 - 20x^3 + 5x

I’ve double-checked the encoding and signs, and everything seems consistent with the theory but I’m getting the following error when I run my code:

```auto
Error: Your polynomial isn't correct.

```

Here is the full code I`m usuing:

```Pyhton
target_poly = [0, 5, 0, -20, 0, 16] # Coefficients of the polynomial ordered from lowest to highest power

RZ_angles = qml.poly_to_angles(target_poly, "QSP") # Get the QSP angles from PennyLane

a_array = np.linspace(-1,1,200) # Array of 'a' values (overlaps) to evaluate the polynomial over

dev = qml.device("default.qubit", wires=1)

@qml.qnode(dev)

def qsp(): 
    """
    This quantum function implements a QSP sequence for Grovers search 
    and returns an array that contains the information to extract the polynomial

    """
    for k in range(len(RZ_angles) - 1, 0, -1):
        qml.RZ(-2*RZ_angles[k], wires=0)
        qml.RX(2 * np.arccos(a), wires=0)

    qml.RZ(-2*RZ_angles[0], wires=0)
        
    return qml.state()

P_a_QSP = []
for val in a_array:
    a = val  
    P_a_QSP.append(qsp()[0]) 
P_a_QSP = np.array(P_a_QSP)

```

Any idea what might be wrong?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![daniela.murcillo](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/daniela.murcillo/32/3612_2.png) [@daniela.murcillo](https://discuss.pennylane.ai/u/daniela.murcillo)\
**Post date:** [July 2, 2025, 6:37pm UTC](https://discuss.pennylane.ai/t/hs-5-1-polynomial-error/8693/2 "2025-07-02T18:37:16Z")

</div>

Hi!  
thank you for your question.  
Your answer is almost right. This is a matter of slicing the result of `qsp()` correctly.  
Try to print what the function output and see how you can extract an array of the polynomial (recall to select the real part). Taking a look at [this piece](https://docs.pennylane.ai/en/stable/code/api/pennylane.state.html) of documentation might be useful.  
Let me know if this works.
