lengthDistance method Null safety

double lengthDistance(
  1. Term other
)

Returns a normalized measure of difference between this Term and other on a log (base 2) scale:

  • returns 0.0 if other and this are the same length;
  • returns 0.0 if both this and other are empty;
  • returns 999.0 if this or other is empty, but not both;
  • returns 1.0 if other is twice as long, or half as long as this;

abs(log2(other.length/this.length)

Implementation

double lengthDistance(Term other) => isEmpty
    ? other.isEmpty
        ? 0
        : 999
    : other.isEmpty
        ? 999
        : (log(other.length / length) / log(2)).abs();