@Override
  public void terminate(PointCollector collector) throws Exception {
    if (list2.isEmpty()) { // Exception: divided by zero
      throw new ArithmeticException("Divided by zero.");
    } else if (list2.size() > list1.size()) { // order of divisor is larger than dividend
      if (result.equalsIgnoreCase(QUOTINENT_RESULT)) { // quotient
        collector.putDouble(0, 0);
      } else { // residue
        for (int i = 0; i < list1.size(); i++) {
          collector.putDouble(i, list1.get(i));
        }
      }
    } else { // order of divisor is no larger than dividend
      double[] q = new double[list1.size() - list2.size() + 1];
      Double[] r = list1.toArray(new Double[0]);
      int m = list2.size() - 1;
      for (int i = q.length - 1; i >= 0; i--) {
        q[i] = r[i + m] / list2.get(m);
        r[i + m] = 0.0D;
        for (int j = 0; j < m; j++) {
          r[i + j] -= q[i] * list2.get(j);
        }
      }
      if (result.equalsIgnoreCase(QUOTINENT_RESULT)) { // quotient
        for (int i = 0; i < q.length; i++) {
          collector.putDouble(i, q[i]);
        }
      } else { // residue
        for (int i = 0; i < r.length; i++) {
          collector.putDouble(i, r[i]);
        }
      }
    }
  }
This function calculates deconvolution of two input series.
library-udf/src/main/java/org/apache/iotdb/library/frequency/UDTFDeconv.java