# Lookup argument for folding **Example** Assume in lookup arguments, we have two columns $(A,S)$, and try to lookup $A_i\in S$. Firstly, we cannot directly fold two such instances, e.g. with random factor $r=1$: $$A_1=[1,1,2,3], S_1=[1,2,3,4,5]\\ A_2=[1,1,1,2], S_2=[1,2,3,4,5]\\ A_1+A_2=[2,2,3,5], S_1+S_2=[2,4,6,8,10]$$ Obviously $(A_1+A_2, S_1+S_2)$ will not work. And since the lookup is arbitrary, we probably will not have any explicit formula to make the folding of $(A,S)$ work. **Attempt 1** Assume we want to calcualte a function $F: X\rightarrow Y$. Instead of writing circuit for $F$, we do lookup argument that $(x,F(x))\in S$. Here $S=\{(x,F(x))|x\in X\}$. **Encoding**: we use encoder $enc$ to encode $(x,F(x))$ to be a field element, i.e. $$A(x):=enc[x,F(x)]\in\mathbb{F}_q$$ Now the table is $T=\{enc[x,F(x)]|x\in X\}$. When we do lookup of row $x$ across two columns $(x,F(x))$, we first encode as $A(x)=enc(x,F(x))$ and prove $A(x)\in S$. In the following, we will only consider the case that $X$ is closed under linear combination, i.e. $\forall x_1,x_2\in X$, we have $x_1+rx_2\in X$. In this case, we say the table $T$ is closed. Assume we have two instances: $(A, S)$, $(B, S)$, where $A_i=enc[x_A[i],F(x_A[i])]$, $B_i=enc[x_B[i],F(x_B[i])]$. We define folded instances of $A$ and $B$ as: $$C_i:=enc[x_A[i]+rx_B[i],F(x_A[i]+rx_B[i])]$$ Notice that table $S$ is closed by our assumption, we have $C_i\in S$. The folding prover needs to recalculate the new value $F(x_A[i]+rx_B[i])$. During in folding, the prover will first fold input value $x=x_1+r\cdot x_2$, then calculate $F(x)$ and fill it into corresponding advice column. There are $3$ kinds of columns, one type is for folding (like Sangria and Nova); one type is advice column calculated by applying $F$ on folded lookup key (it seems we can prove the soundness for this type); one type is fixed table column (i.e. will not change during folding). However, even this approach work, this is only suitable for hash, bit operation but not for range check (range check table is not closed). **Attempt 2** We can try to fold two instances such that the polynomial constraints below are still satisfied: $$Z(\omega X)\cdot (A'(X)+\beta)\cdot(S'(X)+\gamma)-Z(x)\cdot(A(x)+\beta)\cdot(S(X)+\gamma)=0\\ (A'(X)-S'(X))\cdot (A'(X)-A'(\omega^{-1}X))=0\\ $$ As example, let's fold the second relation. First rewrite it as: $$G=A'\cdot A'+A'\cdot A'^{\omega}-S'\cdot A'-S'A'^{\omega}=0$$ Take two instances $U_1=(A_1,A'_1,S'_1)$, $U_2=(A_2,A'_2,S'_2)$. $$A=A_1+rA_2, A'=A'_1+rA'_2, S'=S'_1+S'_2\\ G=G_1+r^2\cdot G_2+r\cdot(2A'_1A'_2+A'_1A'^{\omega}_2+A'^{\omega}_1A'_2\\ -S'_1A'_2-S'_2A'_1-S'_1A'^{\omega}_2-S'_2A'^{\omega}_1)\\ =G_1+r^2\cdot G_2 + r\cdot T$$ Thus, we need modify the second relation as $$P:=A'\cdot A'+A'\cdot A'^{\omega}-S'\cdot A'-S'A'^{\omega}+E$$ Then the folding will stay the same format. i.e. $$Fold(U_1,U_2)=G+E=(G_1+r^2G_2)+(E_1+r^2E_2+rT)$$