---
# System prepended metadata

title: Fold with high degree
tags: [Folding]

---

# Fold with high degree
For $X \in H$, $k_i(X)$ is a constant, representing the circuit. $a(X), b(X), c(X), \dots$ represents the witness.

## degree-2(NOVA)
$$k_1(X) \cdot a(X) \cdot b(X) + k_2(X) \cdot c(X) + k_3(X) = 0$$


Relaxed, $u$ is different in different instances:

$$k_1(X) \cdot a(X) \cdot b(X) + u \cdot k_2(X) \cdot c(X) + u^2 \cdot k_3(X) = E(X)$$

Now fold the two instances into one: 
- $I_1 = (a_1(X), b_1(X), c_1(X), u_1, E_1(X))$ which satisfies: $k_1(X) \cdot a_1(X) \cdot b_1(X) + u_1 \cdot k_2(X) \cdot c_1(X) + u_1^2 \cdot k_3(X) = E_1(X)$
- $I_2 = (a_2(X), b_2(X), c_2(X), u_2, E_2(X))$ which satisfies: $k_1(X) \cdot a_2(X) \cdot b_2(X) + u_2 \cdot k_2(X) \cdot c_2(X) + u_2^2 \cdot k_3(X) = E_2(X)$


choose a random $r$:
- $a_3(X) = a_1(X) + r \cdot a_2(X)$
- $b_3(X) = b_1(X) + r \cdot b_2(X)$
- $c_3(X) = c_1(X) + r \cdot c_2(X)$
- $u_3 = u_1 + r \cdot u_2$
- $E_3(X) = E_1(X) + r \cdot T(X) + r^2 E_2(X)$
- $T(X) = k_1(X) \cdot a_2(X) \cdot b_1(X) + k_1(X) \cdot a_1(X) \cdot b_2(X) + u_1 \cdot k_2(X) \cdot c_2(X) + u_2 \cdot k_2(X) \cdot c_1(X) + 2 \cdot u_1 \cdot u_2 \cdot k_3(X)$

Folding result:
$$k_1(X) \cdot a_3(X) \cdot b_3(X) + u_3 \cdot k_2(X) \cdot c_3(X) + u_3^2 \cdot k_3(X) = E_3(X)$$

## degree-3
$$k_1(X) \cdot a(X) \cdot b(X) \cdot c(X) + k_2(X) \cdot d(X) \cdot e(X) + k_3(X) \cdot f(X) + k_4(X) = 0$$

Relaxed, $u$ is different in different instances:

$$k_1(X) \cdot a(X) \cdot b(X) \cdot c(X) + u \cdot k_2(X) \cdot d(X) \cdot e(X) + u^2 \cdot k_3(X) \cdot f(X) + u^3 \cdot k_4(X) = E(X)$$

Now fold the two instances into one: 
- $I_1 = (a_1(X), b_1(X), c_1(X), d_1(X), e_1(X), f_1(X), u_1, E_1(x))$ which satisfies: $k_1(X) \cdot a_1(X) \cdot b_1(X) \cdot c_1(X) + u_1 \cdot k_2(X) \cdot d_1(X) \cdot e_1(X) + u_1^2 \cdot k_3(X) \cdot f_1(X) + u_1^3 \cdot k_4(X) = E_1(X)$
- $I_2 = (a_2(X), b_2(X), c_2(X), d_2(X), e_2(X), f_2(X), u_2, E_2(X))$ which satisfies: $k_1(X) \cdot a_2(X) \cdot b_2(X) \cdot c_2(X) + u_2 \cdot k_2(X) \cdot d_2(X) \cdot e_2(X) + u_2^2 \cdot k_3(X) \cdot f_2(X) + u_2^3 \cdot k_4(X) = E_2(X)$


choose a random $r$:
- $a_3(X) = a_1(X) + r \cdot a_2(X)$
- $b_3(X) = b_1(X) + r \cdot b_2(X)$
- $c_3(X) = c_1(X) + r \cdot c_2(X)$
- $d_3(X) = d_1(X) + r \cdot d_2(X)$
- $e_3(X) = e_1(X) + r \cdot e_2(X)$
- $f_3(X) = f_1(X) + r \cdot f_2(X)$
- $u_3 = u_1 + r \cdot u_2$
- $E_3(X) = E_1(X) + r \cdot T_1(X) + r^2 \cdot T_2(X) + r^3 \cdot E_2(X)$
- $T_1(X) = k_1(X) \cdot a_2(X)\cdot b_1(X)\cdot c_1(X) + k_1(X) \cdot a_1(X)\cdot b_2(X)\cdot c_1(X)+ k_1(X) \cdot a_1(X)\cdot b_1(X)\cdot c_2(X) + u_1 \cdot k_2(X) \cdot d_2(X)\cdot e_1(X) + u_1\cdot k_2(X) \cdot d_1(X)\cdot e_2(X) + u_1^2 \cdot k_3(X) \cdot f_2(X) + u_2\cdot k_2(X) \cdot d_1(X)\cdot e_1(X)+ 2\cdot u_1 \cdot u_2 \cdot k_3(X) \cdot f_1(X) + 3\cdot u_1^2\cdot u_2 \cdot k_4(X)$
- $T_2(X) = k_1(X) \cdot a_2(X)\cdot b_2(X)\cdot c_1(X) + k_1(X) \cdot a_2(X)\cdot b_1(X)\cdot c_2(X) + u_1\cdot k_2(X) \cdot d_2(X) \cdot e_2(X) + u_2 \cdot k_2(X) \cdot d_2(X)\cdot e_1(X)+ k_1(X) \cdot a_1(X)\cdot b_2(X)\cdot c_2(X) + u_2 \cdot k_2(X) \cdot d_1(X) \cdot e_2(X) + 2 \cdot u_1\cdot u_2 \cdot k_3(X) \cdot f_2(X) + u_2^2 \cdot k_3(X) \cdot f_1(X) + 3 \cdot u_1\cdot u_2^2 \cdot k_4(X)$

Folding result:
$$k_1(X) \cdot a_3(X) \cdot b_3(X) \cdot c_3(X) + u_3 \cdot k_2(X) \cdot d_3(X) \cdot e_3(X) + u_3^2 \cdot k_3(X) \cdot f_3(X) + u_3^3 \cdot K_4(X)= E_3(X)$$

## degree-4
$$k_1(X) \cdot a(X) \cdot b(X) \cdot c(X) \cdot d(X) + k_2(X) \cdot e(X) \cdot f(X) \cdot g(X) + k_3(X) \cdot h(X) \cdot i(X) + k_4(X) \cdot j(X) + k_5(X) = 0$$

Relaxed, $u$ is different in different instances:

$$k_1(X) \cdot a(X) \cdot b(X) \cdot c(X) \cdot d(X) + u \cdot k_2(X) \cdot e(X) \cdot f(X) \cdot g(X) + u^2 \cdot k_3(X) \cdot h(X) \cdot i(X) + u^3 \cdot k_4(X) \cdot j(X) + u^4 \cdot k_5(X) = E(X)$$

Now fold the two instances into one: 
- $I_1 = (a_1(X), b_1(X), c_1(X), d_1(X), e_1(X), f_1(X), g_1(X), h_1(X), i_1(X), j_1(X), u_1, E_1(x))$ which satisfies: $k_1(X) \cdot a_1(X) \cdot b_1(X) \cdot c_1(X) \cdot d_1(X) + u_1 \cdot k_2(X) \cdot e_1(X) \cdot f_1(X) \cdot g_1(X) + u_1^2 \cdot k_3(X) \cdot h_1(X) \cdot i_1(X) + u_1^3 \cdot k_4(X) \cdot j_1(X) + u^4 \cdot k_5(X) = E_1(X)$
- $I_2 = (a_2(X), b_2(X), c_2(X), d_2(X), e_2(X), f_2(X), g_2(X), h_2(X), i_2(X), j_2(X), u_2, E_2(X))$ which satisfies: $k_1(X) \cdot a_2(X) \cdot b_2(X) \cdot c_2(X) \cdot d_2(X) + u_2 \cdot k_2(X) \cdot e_2(X) \cdot f_2(X) \cdot g_2(X) + u_2^2 \cdot k_3(X) \cdot h_2(X) \cdot i_2(X) + u_2^3 \cdot k_4(X) \cdot j_2(X) + u_2^4 \cdot k_5(X) = E_2(X)$

choose a random $r$:
- $a_3(X) = a_1(X) + r \cdot a_2(X)$
- $b_3(X) = b_1(X) + r \cdot b_2(X)$
- $c_3(X) = c_1(X) + r \cdot c_2(X)$
- $d_3(X) = d_1(X) + r \cdot d_2(X)$
- $e_3(X) = e_1(X) + r \cdot e_2(X)$
- $f_3(X) = f_1(X) + r \cdot f_2(X)$
- $g_3(X) = g_1(X) + r \cdot g_2(X)$
- $h_3(X) = h_1(X) + r \cdot h_2(X)$
- $i_3(X) = i_1(X) + r \cdot i_2(X)$
- $j_3(X) = j_1(X) + r \cdot j_2(X)$
- $u_3 = u_1 + r \cdot u_2$
- $E_3(X) = E_1(X) + r \cdot T_1(X) + r^2 \cdot T_2(X) + r^3 T_3(X) + r^4 \cdot E_2(X)$
$$\begin{align*}T_1(X) = & k_1(X)a_2(X)b_1(X)c_1(X)d_1(X) + k_1(X)a_1(X)b_2(X)c_1(X)d_1(X) + k_1(X)a_1(X)b_1(X)c_2(X)d_1(X) + k_1(X)a_1(X)b_1(X)c_1(X)d_2(X) + u_1k_2(X)e_2(X)f_1(X)g_1(X) + \\ & u_1k_2(X)e_1(X)f_2(X)g_1(X) + u_1k_2(X)e_1(X)f_1(X)g_2(X) + u_1^2k_3(X)h_2(X)i_1(X) + u_1^2k_3(X)h_1(X)i_2(X) + u_1^3k_4(X)j_2(X) + \\ & u_2k_2(X)e_1(X)f_1(X)g_1(X) + 2u_1u_2k_3(X)h_1(X)i_1(X) + 3u_1^2u_2k_4(X)j_1(X) + 4u_1^3u_2k_5(X) \end{align*}$$
$$\begin{align*}T_2(X) = & k_1(X)a_2(X)b_2(X)c_1(X)d_1(X) + k_1(X)a_2(X)b_1(X)c_2(X)d_1(X) + k_1(X)a_1(X)b_2(X)c_2(X)d_1(X) + k_1(X)a_2(X)b_1(X)c_1(X)d_2(X) + k_1(X)a_1(X)b_2(X)c_1(X)d_2(X) + \\ & k_1(X)a_1(X)b_1(X)c_2(X)d_2(X) + u_1k_2(X)e_2(X)f_2(X)g_1(X) + u_1k_2(X)e_2(X)f_1(X)g_2(X) + u_1k_2(X)e_1(X)f_2(X)g_2(X) + u_1^2k_3(X)h_2(X)i_2(X) + \\ & u_2(X)k_2(X)e_2(X)f_1(X)g_1(X) + u_2k_2(X)e_1(X)f_2(X)g_1(X) + u_2k_2(X)e_1(X)f_1(X)g_2(X) + 2u_1u_2k_3(X)h_2(X)i_1(X) + 2u_1u_2k_3(X)h_1(X)i_2(X) + \\ & 3u_1^2u_2k_4(X)j_2(X) + u_2^2k_3(X)h_1(X)i_1(X)+ 3u_1u_2^2k_4(X)j_1(X) + 6u_1^2u_2^2k_5(X) \end{align*}$$
$$\begin{align*}T_3(X) = & k_1(X)a_2(X)b_2(X)c_2(X)d_1(X) + k_1(X)a_2(X)b_2(X)c_1(X)d_2(X) + k_1(X)a_2(X)b_1(X)c_2(X)d_2(X) + k_1(X)a_1(X)b_2(X)c_2(X)d_2(X) + u_1k_2(X)e_2(X)f_2(X)g_2(X) + \\ & u_2k_2(X)e_2(X)f_2(X)g_1(X) + u_2k_2(X)e_2(X)f_1(X)g_2(X) + u_2k_2(X)e_1(X)f_2(X)g_2(X) + 2u_1u_2k_3(X)h_2(X)i_2(X) + u_2^2k_3(X)h_2(X)i_1(X) + \\ & u_2^2k_3(X)h_1(X)i_2(X) + 3u_1u_2^2j_2(X)k_4(X) + u_2^3k_4(X)j_1(X) + 4u_1u_2^3k_5(X)\end{align*}$$

Folding result:
$$k_1(X) \cdot a_3(X) \cdot b_3(X) \cdot c_3(X) \cdot d_3(X) + u_3 \cdot k_2(X) \cdot e_3(X) \cdot f_3(X) \cdot g_3(X) + u_3^2 \cdot k_3(X) \cdot h_3(X) \cdot i_3(X) + u_3^3 \cdot k_4(X) \cdot j_3(X) + u_3^4 \cdot k_5(X) = E_3(X)$$

## jellyfish
```rs
    /// qo * wo = pub_input + q_c +
    ///           q_mul0 * w0 * w1 + q_mul1 * w2 * w3 +
    ///           q_lc0 * w0 + q_lc1 * w1 + q_lc2 * w2 + q_lc3 * w3 +
    ///           q_hash0 * w0^5 + q_hash1 * w1^5 + q_hash2 * w2^5 + q_hash3 * w3^5 +
    ///           q_ecc * w0 * w1 * w2 * w3 * wo
```
Because the `pub_input` always is `zero` when check normal gates, so it needn't be relaxed:
$$\begin{align*} & q_{ecc}(X) \cdot w_0(X) \cdot w_1(X) \cdot w_2(X) \cdot w_3(X) \cdot w_o(X) + \\ & q_{mul0}(X)\cdot w_0(X) \cdot w_1(X) + q_{mul1}(X) \cdot w_2(X) \cdot w_3(X) + \\ & q_{lc0}(X)\cdot w_0(X) + q_{lc1}(X) \cdot w_1(X) + q_{lc2}(X) \cdot w_2(X) + q_{lc3}(X) \cdot w_3(X) + \\ & q_{hash0}(X) \cdot w_0^5(X) + q_{hash1}(X) \cdot w_1^5(X) + q_{hash2}(X) \cdot w_2^5(X) + q_{hash3}(X)\cdot w_3^5(X) + \\ & q_c(X) - q_o(X) \cdot w_o(X) = 0\end{align*}$$

the degree is 5.

Relaxed, $u$ is different in different instances:

$$\begin{align*} & q_{ecc}(X) \cdot w_0(X) \cdot w_1(X) \cdot w_2(X) \cdot w_3(X) \cdot w_o(X) + \\ & 
u^3 \cdot q_{mul0}(X)\cdot w_0(X) \cdot w_1(X) + u^3 \cdot q_{mul1}(X) \cdot w_2(X) \cdot w_3(X) + \\ & 
u^4 \cdot q_{lc0}(X)\cdot w_0(X) + u^4 \cdot q_{lc1}(X) \cdot w_1(X) +  u^4 \cdot q_{lc2}(X) \cdot w_2(X) + u^4 \cdot q_{lc3}(X) \cdot w_3(X) + \\ & 
q_{hash0}(X) \cdot w_0^5(X) +  q_{hash1}(X) \cdot w_1^5(X) + q_{hash2}(X) \cdot w_2^5(X) + q_{hash3}(X)\cdot w_3^5(X) + \\ & 
u^5 \cdot q_c(X) - u^4 \cdot q_o(X) \cdot w_o(X) = E(X)\end{align*}$$

Now fold the two instances into one: 
- $I_1 = (w_{01}(X), w_{11}(X), w_{21}(X), w_{31}(X), w_{o1}(X), u_1, E_1(X))$ which satisfies: $\begin{align*} & q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + \\ & 
u_1^3 \cdot q_{mul0}(X)\cdot w_{01}(X) \cdot w_{11}(X) + u_1^3 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{31}(X) + \\ & 
u_1^4 \cdot q_{lc0}(X)\cdot w_{01}(X) + u_1^4 \cdot q_{lc1}(X) \cdot w_{11}(X) +  u_1^4 \cdot q_{lc2}(X) \cdot w_{21}(X) + u_1^4 \cdot q_{lc3}(X) \cdot w_{31}(X) + \\ & 
q_{hash0}(X) \cdot w_{01}^5(X) + q_{hash1}(X) \cdot w_{11}^5(X) + q_{hash2}(X) \cdot w_{21}^5(X) + q_{hash3}(X) \cdot w_{31}^5(X) + \\ & 
u_1^5 \cdot q_c(X) - u_1^4 \cdot q_o(X) \cdot w_{o1}(X) = E_1(X)\end{align*}$
- $I_2 = (w_{02}(X), w_{12}(X), w_{22}(X), w_{32}(X), w_{o2}(X), u_2, E_2(X))$ which satisfies: $\begin{align*} & q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o2}(X) + \\ & 
u_2^3 \cdot q_{mul0}(X)\cdot w_{02}(X) \cdot w_{12}(X) + u_2^3 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{32}(X) + \\ & 
u_2^4 \cdot q_{lc0}(X)\cdot w_{02}(X) + u_2^4 \cdot q_{lc1}(X) \cdot w_{12}(X) +  u_2^4 \cdot q_{lc2}(X) \cdot w_{22}(X) + u_2^4 \cdot q_{lc3}(X) \cdot w_{32}(X) + \\ & 
q_{hash0}(X) \cdot w_{02}^5(X) + q_{hash1}(X) \cdot w_{12}^5(X) + q_{hash2}(X) \cdot w_{22}^5(X) + q_{hash3}(X) \cdot w_{32}^5(X) + \\ & 
u_2^5 \cdot q_c(X) - u_2^4 \cdot q_o(X) \cdot w_{o2}(X) = E_2(X)\end{align*}$

choose a random $r$:
- $w_{03}(X) = w_{01}(X) + r \cdot w_{02}(X)$
- $w_{13}(X) = w_{11}(X) + r \cdot w_{12}(X)$
- $w_{23}(X) = w_{21}(X) + r \cdot w_{22}(X)$
- $w_{33}(X) = w_{31}(X) + r \cdot w_{32}(X)$
- $w_{o3}(X) = w_{o1}(X) + r \cdot w_{o2}(X)$
- $u_3 = u_1 + r \cdot u_2$
- $E_3(X) = E_1(X) + r \cdot T_1(X) + r^2 \cdot T_2(X) + r^3 \cdot T_3(X) + r^4 \cdot T_4(X) + r^5 \cdot E_2(X)$

$$\begin{align*}T_1(X) = & 5 \cdot u_1^4 \cdot u_2 \cdot q_c(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc0}(X) \cdot w_{01}(X) + u_1^4 \cdot q_{lc0}(X) \cdot w_{02}(X) + \\ & 
5 \cdot q_{hash0}(X) \cdot w_{01}^4(X) \cdot w_{02}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc1}(X) \cdot w_{11}(X) + 3 \cdot u_1^2 \cdot u_2 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{11}(X) + \\ &
u_1^3 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{11}(X) + u_1^4 \cdot q_{lc1}(X) \cdot w_{12}(X) + u_1^3 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{12}(X) + 5 \cdot q_{hash1}(X) \cdot w_{11}^4(X) \cdot w_{12}(X) + \\ & 
4 \cdot u_1^3 \cdot u_2 \cdot q_{lc2}(X) \cdot w_{21}(X) + u_1^4 \cdot q_{lc2}(X) \cdot w_{22}(X) + 5 \cdot q_{hash2}(X) \cdot w_{21}^4(X) \cdot w_{22}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc3}(X) \cdot w_{31}(X) + \\ &
3 \cdot u_1^2 \cdot u_2 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{31}(X) + u_1^3 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{31}(X) + u_1^4 \cdot q_{lc3}(X) \cdot w_{32}(X) + u_1^3 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{32}(X) + \\ &
5 \cdot q_{hash3}(X) \cdot w_{31}^4(X) \cdot w_{32}(X) - 4 \cdot u_1^3 \cdot u_2 \cdot q_o(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o1}(X) - u_1^4 \cdot q_o(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o2}(X) \end{align*}$$

$$\begin{align*}T_2(X) = & 10 \cdot u_1^3 \cdot u_2^2 \cdot q_c(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc0}(X) \cdot w_{01}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc0}(X) \cdot w_{02}(X) + \\ &
10 \cdot q_{hash0}(X) \cdot w_{01}^3(X) \cdot w_{02}^2(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc1}(X) \cdot w_{11}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{11}(X) + \\ &
3 \cdot u_1^2 \cdot u_2 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{11}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc1}(X) \cdot w_{12}(X) + 3 \cdot u_1^2 \cdot u_2 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{12}(X) + \\ & 
u_1^3 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{12}(X) + 10 \cdot q_{hash1}(X) \cdot w_{11}^3(X) \cdot w_{12}^2(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc2}(X) \cdot w_{21}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc2}(X) \cdot w_{22}(X) + \\ &
10 \cdot q_{hash2}(X) \cdot w_{21}^3(X) \cdot w_{22}^2(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc3}(X) \cdot w_{31}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{31}(X) + \\ &
3 \cdot u_1^2 \cdot u_2 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{31}(X) + 4 \cdot u_1^3 \cdot u_2 \cdot q_{lc3}(X) \cdot w_{32}(X) + 3 \cdot u_1^2 \cdot u_2 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{32}(X) + \\ &
u_1^3 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{32}(X) + 10 \cdot q_{hash3}(X) \cdot w_{31}^3(X) \cdot w_{32}^2 - 6 \cdot u_1^2 \cdot u_2^2 \cdot q_o(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o1}(X) - 4 \cdot u_1^3 \cdot u_2 \cdot q_o(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o2}(X)\end{align*}$$

$$\begin{align*} T_3(X) = & 10 \cdot u_1^2 \cdot u_2^3 \cdot q_c(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc0}(X) \cdot w_{01}(X) + \\ & 
6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc0}(X) \cdot w_{02}(X) + 10 \cdot q_{hash0}(X) \cdot w_{01}^2(X) \cdot w_{02}^3(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc1}(X) \cdot w_{11}(X) + \\ &
u_2^3 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{11}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{11}(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc1}(X) \cdot w_{12}(X) + \\ &
3 \cdot u_1 \cdot u_2^2 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{12}(X) + 3 \cdot u_1^2 \cdot u_2 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{12}(X) + 10 \cdot q_{hash1}(X) \cdot w_{11}^2(X) \cdot w_{12}^3 + \\ & 
4 \cdot u_1 \cdot u_2^3 \cdot q_{lc2}(X) \cdot w_{21}(X) + 6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc2}(X) \cdot w_{22}(X) + 10 \cdot q_{hash2}(X) \cdot w_{21}^2(X) \cdot w_{22}^3 + \\ &
4 \cdot u_1 \cdot u_2^3 \cdot q_{lc3}(X) \cdot w_{31}(X) + u_2^3 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{31}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{31}(X) + \\ &
6 \cdot u_1^2 \cdot u_2^2 \cdot q_{lc3}(X) \cdot w_{32}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{32}(X) + 3 \cdot u_1^2 \cdot u_2 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{32}(X) + \\ &
10 \cdot q_{hash3}(X) \cdot w_{31}^2(X) \cdot w_{32}^3 - 4 \cdot u_1 \cdot u_2^3 \cdot q_o(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o1}(X) + \\ & 
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o1}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o1}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o1}(X) - 6 \cdot u_1^2 \cdot u_2^2 \cdot q_o(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{01}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o2}(X) \end{align*}$$

$$\begin{align*}T_4(X) = & 5 \cdot u_1 \cdot u_2^4 \cdot q_c(X) + u_2^4 \cdot q_{lc0}(X) \cdot w_{01}(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc0}(X) \cdot w_{02}(X) + \\ &
5 \cdot q_{hash0}(X) \cdot w_{01}(X) \cdot w_{02}^4(X) + u_2^4 \cdot q_{lc1}(X) \cdot w_{11}(X) + u_2^3 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{11}(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc1}(X) \cdot w_{12}(X) + \\ & 
u_2^3 \cdot q_{mul0}(X) \cdot w_{01}(X) \cdot w_{12}(X) + 3 \cdot u_1 \cdot u_2^2 \cdot q_{mul0}(X) \cdot w_{02}(X) \cdot w_{12}(X) + 5 \cdot q_{hash1}(X) \cdot w_{11}(X) \cdot w_{12}^4(X) + \\ &
u_2^4 \cdot q_{lc2}(X) \cdot w_{21}(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc2}(X) \cdot w_{22}(X) + 5 \cdot q_{hash2}(X) \cdot w_{21}(X) \cdot w_{22}^4(X) + u_2^4 \cdot q_{lc3}(X) \cdot w_{31}(X) + \\& 
u_2^3 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{31}(X) + 4 \cdot u_1 \cdot u_2^3 \cdot q_{lc3}(X) \cdot w_{32}(X) + u_2^3 \cdot q_{mul1}(X) \cdot w_{21}(X) \cdot w_{32}(X) + \\ &
3 \cdot u_1 \cdot u_2^2 \cdot q_{mul1}(X) \cdot w_{22}(X) \cdot w_{32}(X) + 5 \cdot q_{hash3}(X) \cdot w_{31}(X) \cdot w_{32}^4(X) - u_2^4 \cdot q_o(X) \cdot w_{o1}(X) + \\& 
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o1}(X) - 4 \cdot u_1 \cdot u_2^3 \cdot q_o(X) \cdot w_{o2}(X) + \\ &
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{31}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{02}(X) \cdot w_{12}(X) \cdot w_{21}(X) \cdot w_{32}(X) \cdot w_{o2}(X) + \\&
q_{ecc}(X) \cdot w_{02}(X) \cdot w_{11}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o2}(X) + q_{ecc}(X) \cdot w_{01}(X) \cdot w_{12}(X) \cdot w_{22}(X) \cdot w_{32}(X) \cdot w_{o2}(X) \end{align*}$$

Folding result:
$$\begin{align*} & q_{ecc}(X) \cdot w_{03}(X) \cdot w_{13}(X) \cdot w_{23}(X) \cdot w_{33}(X) \cdot w_{o3}(X) + \\ & u_3^3 \cdot q_{mul0}(X)\cdot w_{03}(X) \cdot w_{13}(X) + u_3^3 \cdot q_{mul1}(X) \cdot w_{23}(X) \cdot w_{33}(X) + \\ & u_3^4 \cdot q_{lc0}(X)\cdot w_{03}(X) + u_3^4 \cdot q_{lc1}(X) \cdot w_{13}(X) +  u_3^4 \cdot q_{lc2}(X) \cdot w_{23}(X) + u_3^4 \cdot q_{lc3}(X) \cdot w_{33}(X) + \\ & q_{hash0}(X) \cdot w_{03}^5(X) + q_{hash1}(X) \cdot w_{13}^5(X) + q_{hash2}(X) \cdot w_{23}^5(X) + q_{hash3}(X) \cdot w_{33}^5(X) + \\ & - u_3^4 \cdot q_o(X) \cdot w_{o3}(X) = E_3(X)\end{align*}$$



## reference
- https://hackmd.io/@70xfCGp1QViTYYJh3AMrQg/SkDf2nIzp
- https://github.com/EspressoSystems/jellyfish
- https://github.com/flyq/sage/blob/master/zkp/folding.sage#L125
- https://github.com/ZKMod-Lab/jellyfish/blob/test/relation/src/constraint_system.rs#L1397