# Codercise HS.1.3

**URL:** <https://discuss.pennylane.ai/t/codercise-hs-1-3/8732>\
**Category:** Codebook\
**Created:** [July 7, 2025, 6:04pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732 "2025-07-07T18:04:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyyoung](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/cyyoung/32/3821_2.png) [@cyyoung](https://discuss.pennylane.ai/u/cyyoung)\
**Post date:** [July 7, 2025, 6:04pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/1 "2025-07-07T18:04:33Z")

</div>

Hi. Im so stuck on this chapter.

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/a/ae6b87b8f17772ae0bc75038dec99827f74e944e.png)  
Could I get some help, I don’t know what im doing wrongly

Also, it seems there may be an error in the theory section under Higher-order Trotterization.

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/d/d88ac7b02e63035fb2b0088ea3285ca3d36ff7b1.png)  
for s\_2, it seems that k =1, but the given value for s\_2 takes k = 2. Should the formula for s\_2k be 1/(4-4^1/(2(2k)-1))?

---

<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 7, 2025, 8:08pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/2 "2025-07-07T20:08:43Z")

</div>

Hi! thanks for this question.  
I’m so glad you are working through the Codebook.  
I think you found a mistake, but the solution is rather s\_{2k}=1/(1-4^{1/(2k+1)}). I found the correct formula in a reference.  
I will fix this both in the theory and the Codercises. Your codercise solution will be almost correct, you just need to change `s_2k` to the correct value that we just discussed.  
Check back in a few days and things should be working properly.  
Thank you again for spotting these mistakes and reporting them.

---

<div class="post-metadata">

**Author:** ![cyyoung](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/cyyoung/32/3821_2.png) [@cyyoung](https://discuss.pennylane.ai/u/cyyoung)\
**Post date:** [July 7, 2025, 9:41pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/3 "2025-07-07T21:41:35Z")

</div>

I see. Thanks! I was losing my head over this.  
No worries, i really enjoy doing the exercises. Even though sometimes im losing my mind over the math, im really having a blast learning something this exciting

---

<div class="post-metadata">

**Author:** ![cyyoung](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/cyyoung/32/3821_2.png) [@cyyoung](https://discuss.pennylane.ai/u/cyyoung)\
**Post date:** [July 7, 2025, 11:04pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/4 "2025-07-07T23:04:59Z")

</div>

I think i see the issue the formula for s\_2k is 1/(4-4^(1/(2k+1))), but the k is for the 2k order, as in when k = 2, the order is 4, therefore the s used is 1/(4-4^(1/(2(k-1)+1))) which equals to 1/(4-4^(1/(2k-1))).  
This  
 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/8/89cd57694ee1ab54a5bcfaf5963d8c2aea7fceef.png)  
would be more accurate if we are to use the correct formula in the reference as you mentioned.  
For U\_2k, s\_2(k-1) = 1/(4-4^(1/(2(k-1)+1))) = 1/(4-4^(1/(2k-1))), which when k=2, s\_2 = 1/(4-4^(1/(3)))

---

<div class="post-metadata">

**Author:** ![eigenname](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/eigenname/32/3930_2.png) [@eigenname](https://discuss.pennylane.ai/u/eigenname)\
**Post date:** [August 7, 2025, 9:49pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/5 "2025-08-07T21:49:03Z")

</div>

I also found this module, let alone codercise challenging. Like @cyyoung, I had implemented

```python
s_2k = 1 / (4 - 4**(1 / (2*k - 1)))

```

but I’m still incorrect.. I’ve implemented the same lines of recursion as well.

---

<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:** [August 8, 2025, 7:17pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/6 "2025-08-08T19:17:18Z")

</div>

Hi!  
Thanks for the feedback. Is there anything in particular that you think we can improve to make it more understandable?

Regarding your question, the formula both in the theory and the codercise is `s_2k = 1 / (4 - 4**(1 / (2*k + 1)))`. There is a plus one and not minus one. This one should work, let me know.

---

<div class="post-metadata">

**Author:** ![eigenname](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/eigenname/32/3930_2.png) [@eigenname](https://discuss.pennylane.ai/u/eigenname)\
**Post date:** [August 8, 2025, 7:21pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/7 "2025-08-08T19:21:35Z")

</div>

Oh I see now.. I got confused between the discussions of s\_2k but needed to pay attention to whether it was + or - for the correct formula. The small details are killer!

Thank you Daniela!

---

<div class="post-metadata">

**Author:** ![petrus1732](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/petrus1732/32/4022_2.png) [@petrus1732](https://discuss.pennylane.ai/u/petrus1732)\
**Post date:** [September 4, 2025, 7:25pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/8 "2025-09-04T19:25:19Z")

</div>

Hi! I just finished the code excercise and I think the issue hasn’t been fixed yet! I think the source of confusion is that there are two equivalent ways the Suzuki recursion is sometimes written, depending on whether you define U\_{2k} from U\_{2(k-1)} or U\_{2(k+1)} from U\_{2k}.

- If the **order-2k formula** is defined recursively from the **order-2(k-1) formula**:

- But if you instead write the recursion as building U\_{2(k+2)} directly from U\_{2k}, then the coefficient takes the form

Both formulas are correct, but they are **shifted by the index convention** : one defines U\_{2k} from U\_{2(k-1)}, while the other defines U\_{2(k+2)} from U\_{2k}.

In the exercise code, the recursion function `U(..., k)` is meant to build U\_{2k} out of U\_{2(k-1)}. In that case, the correct coefficient should be

s = \frac{1}{4 - 4^{1/(2k-1)}},

not with 2k+1. Using 2k+1 corresponds to the other indexing convention (jumping by 2 each time), which doesn’t match how the code is structured. On the other hand, the formula of the theory part in the Codebook is still correct since the plus one form is for building U\_{2(k+2)} from U\_{2k}.

---

<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:** [September 5, 2025, 8:29pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/9 "2025-09-05T20:29:29Z")

</div>

Thanks for your input, @petrus1732 !!  
Let me take a careful look and get back to you.  
Just out of curiosity, was there a typo in your answer and you meant U\_{2(k+1)} instead of U\_{2(k+2)}? (in the second half).

---

<div class="post-metadata">

**Author:** ![petrus1732](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/petrus1732/32/4022_2.png) [@petrus1732](https://discuss.pennylane.ai/u/petrus1732)\
**Post date:** [September 6, 2025, 2:38am UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/10 "2025-09-06T02:38:33Z")

</div>

Yes, that’s a typo. Sorry for the confusion.

---

<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:** [September 9, 2025, 7:25pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/11 "2025-09-09T19:25:03Z")

</div>

Hi!  
I think I finally see what you are saying.  
The conventions got mixed up. The theory part is consistent and correct in itself. But the Codercise is built with the recursion of the `k-1` unitaries and the correct thing to do would be to keep `2k-1` in the `s` variable there. Ah! this is unfortunate.  
I will also change the statement of the codercise to be consistent with the implementation.

Thanks. I will get to it asap.

---

<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:** [September 9, 2025, 7:31pm UTC](https://discuss.pennylane.ai/t/codercise-hs-1-3/8732/12 "2025-09-09T19:31:36Z")

</div>

Hi! please see the latest discussion on this topic so things can be further clarified. Sorry about the confusion and thanks for participating in the forum.
