考虑一个问题

$$1 \leq n \leq 1e7,求\sum_{1 \leq i< j \leq n}(a_{i}b_{j}-a_{j}b_{i})^{2}(mod\quad1e9+7)$$

结论——拉格朗日恒等式

\[(\sum_{i=1}^{n}a_{i}^{2})(\sum_{i=1}^{n}b_{i}^{2})=(\sum_{i=1}^{n}a_{i}b_{i})^{2}+\sum_{1 \leq i< j \leq n}(a_{i}b_{j}-a_{j}b_{i})^{2} \]

拉格朗日恒等式的证明
法1 directly
证明:

\[左边=\sum_{i=1}^{n}a_{i}^{2}b_{i}^{2}+\sum_{1 \leq i< j \leq n}a_{i}^{2}b_{j}^{2}+\sum_{1 \leq i< j \leq n}a_{j}^{2}b_{i}^{2} \]

\[右边=\sum_{i=1}^{n}a_{i}^{2}b_{i}^{2}+2\sum_{1 \leq i< j \leq n}a_{i}b_{j}a_{j}b_{i}+\sum_{1 \leq i< j \leq n}a_{i}^{2}b_{j}^{2}+\sum_{1 \leq i< j \leq n}a_{j}^{2}b_{i}^{2}-2\sum_{1 \leq i< j \leq n}a_{i}b_{j}a_{j}b_{i} \]

左边=右边
证毕#

法2 数学归纳法
证明:

\[1^{\circ}\quad当i=1时,左边=a_{1}^{2}b_{1}^{2}=右边,满足原式 \]

\[2^{\circ}\quad假设当i=n-1时成立,则有(\sum_{i=1}^{n-1}a_{i}^{2})(\sum_{i=1}^{n-1}b_{i}^{2})=(\sum_{i=1}^{n-1}a_{i}b_{i})^{2}+\sum_{1 \leq i< j \leq n-1}(a_{i}b_{j}-a_{j}b_{i})^{2} \]

\[3^{\circ}\quad当i=n时,(\sum_{i=1}^{n}a_{i}^{2})(\sum_{i=1}^{n}b_{i}^{2})=(\sum_{i=1}^{n-1}a_{i}^{2})(\sum_{i=1}^{n-1}b_{i}^{2})+a_{n}^{2}+b_{n}^{2}+\sum_{i=1}^{n-1}a_{i}^{2}b_{n}^{2}+\sum_{i=1}^{n-1}b_{i}^{2}a_{n}^{2} \]

\[(\sum_{i=1}^{n}a_{i}b_{i})^{2}+\sum_{1 \leq i< j \leq n}(a_{i}b_{j}-a_{j}b_{i})^{2}=(\sum_{i=1}^{n-1}a_{i}b_{i})^{2}+2a_{n}b_{n}\sum_{i=1}^{n-1}a_{i}b_{i}+a_{n}^{2}+b_{n}^{2}+\sum_{1 \leq i< j \leq n-1}(a_{i}b_{j}-a_{j}b_{i})^{2}-2a_{n}b_{n}\sum_{i=1}^{n-1}a_{i}b_{i} \]

\[可得(\sum_{i=1}^{n}a_{i}^{2})(\sum_{i=1}^{n}b_{i}^{2})=(\sum_{i=1}^{n}a_{i}b_{i})^{2}+\sum_{1 \leq i< j \leq n}(a_{i}b_{j}-a_{j}b_{i})^{2} \]

证毕#