public static int countBacklinksOnRelation(Stella_Object self, Keyword kind, Surrogate relation) {
    { BacklinksIndex index = Logic.getBacklinksIndex(self);
      Cons equivalents = (Stella_Object.isaP(self, Logic.SGT_LOGIC_LOGIC_OBJECT) ? ((LogicObject)(self)).variableValueInverse() : Stella.NIL);
      int count = 0;

      if (index == null) {
        return (Stella.NULL_INTEGER);
      }
      count = Logic.selectPropositions(Cons.cons(Logic.KWD_RELATION, Cons.cons(((Stella.NIL == null) ? Stella.NIL : Stella.NIL), Cons.cons(relation, Cons.cons(self, Stella.NIL))))).estimatedLength();
      if ((count == 0) &&
          (!(NamedDescription.allDirectSubrelations(Logic.surrogateToDescription(relation), false) == Stella.NIL))) {
        count = 1;
      }
      { Stella_Object equiv = null;
        Cons iter000 = equivalents;

        for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
          equiv = iter000.value;
          count = count + Logic.countBacklinksOnRelation(equiv, kind, relation);
        }
      }
      return (count);
    }
  }