question about initMN
Closed this issue · 2 comments
MarisaKirisame commented
initMN :: Ring r ⇒ Int → r
initMN 0 = r₀
initMN 1 = r₁
initMN n | n < 0 = rneg (initMN (-n))
| odd n = two ⊗ initMN ((n - 2) div
2) ⊕ r₁
| otherwise = two ⊗ initMN ((n - 2) div
2)
where two = r₁ ⊕ r₁
this look strange to me... can you explain the otherwie case?
If I get it correctly,
initMN 4 = two ⊗ initMN ((4 - 2) div
2) = two ⊗ initMN 1 = two ⊗ r₁ = (r₁ ⊕ r₁) ⊗ r₁ = r₁ ⊕ r₁
Is there something wrong?
yallop commented
Indeed; this does look strange. I think n - 2
should just be n
in the odd
and otherwise
cases.
Then we have
initMN 4
= two ⊗ initMN (4 `div` 2)
= two ⊗ initMN 2
= two ⊗ (two ⊗ initMN (2 `div` 2))
= two ⊗ (two ⊗ initMN 1)
= two ⊗ (two ⊗ r₁)
= (r₁ ⊕ r₁) ⊗ ((r₁ ⊕ r₁) ⊗ r₁)