public static SequenceIndex helpSelectRelationPropositions(Cons pattern) {
    { Cons arguments = pattern.rest.rest;
      Stella_Object relation = arguments.value;
      Cons keys = arguments.rest;

      { Stella_Object value000 = null;

        { Stella_Object key = null;
          Cons iter000 = keys;

          loop000 : for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
            key = iter000.value;
            if ((key != null) &&
                Logic.instanceHasBacklinksP(key)) {
              value000 = key;
              break loop000;
            }
          }
        }
        { Stella_Object anchor = value000;
          Skolem functionSkolem = null;

          if (anchor == null) {
            { NamedDescription description = Logic.getDescription(relation);

              if (description != null) {
                return (NamedDescription.getDescriptionExtension(description, true));
              }
              else {
                return (Logic.NIL_NON_PAGING_INDEX);
              }
            }
          }
          { SequenceIndex index = Logic.unfilteredDependentPropositions(anchor, ((Surrogate)(relation)));
            Cons sequence = index.theSequence;
            Cons filteredsequence = Stella.NIL;
            Cons allkeyvalues = null;

            if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(index), Logic.SGT_LOGIC_PAGING_INDEX)) {
              { PagingIndex index000 = ((PagingIndex)(index));

                if ((index000.store != null) &&
                    (((Keyword)(index000.selectionPattern.value)) == Logic.KWD_RELATION)) {
                  index000.selectionPattern = pattern;
                  return (index000);
                }
              }
            }
            else {
            }
            if (sequence == Stella.NIL) {
              return (Logic.NIL_NON_PAGING_INDEX);
            }
            { Proposition prop = null;
              Cons iter001 = sequence;

              loop001 : for (;!(iter001 == Stella.NIL); iter001 = iter001.rest) {
                prop = ((Proposition)(iter001.value));
                if (!(Stella_Object.equalP(relation, prop.operator))) {
                  if (prop.kind == Logic.KWD_EQUIVALENT) {
                    functionSkolem = Proposition.getSkolemAndValueTerms(prop, new Object[1]);
                    if (functionSkolem != null) {
                      prop = functionSkolem.definingProposition;
                    }
                    if (!(Stella_Object.equalP(relation, prop.operator))) {
                      continue loop001;
                    }
                  }
                  else {
                    continue loop001;
                  }
                }
                if (allkeyvalues == null) {
                  allkeyvalues = Stella.NIL;
                  if (!(keys.rest == Stella.NIL)) {
                    { Stella_Object key = null;
                      Cons iter002 = keys;
                      Cons collect000 = null;

                      for (;!(iter002 == Stella.NIL); iter002 = iter002.rest) {
                        key = iter002.value;
                        if (collect000 == null) {
                          {
                            collect000 = Cons.cons(Logic.valueOf(key), Stella.NIL);
                            if (allkeyvalues == Stella.NIL) {
                              allkeyvalues = collect000;
                            }
                            else {
                              Cons.addConsToEndOfConsList(allkeyvalues, collect000);
                            }
                          }
                        }
                        else {
                          {
                            collect000.rest = Cons.cons(Logic.valueOf(key), Stella.NIL);
                            collect000 = collect000.rest;
                          }
                        }
                      }
                    }
                  }
                }
                if (!(allkeyvalues == Stella.NIL)) {
                  { Vector arguments000 = prop.arguments;

                    { boolean testValue000 = false;

                      testValue000 = arguments000 != null;
                      if (testValue000) {
                        { boolean alwaysP000 = true;

                          { Stella_Object key = null;
                            Cons iter003 = allkeyvalues;
                            Stella_Object arg = null;
                            Vector vector000 = arguments000;
                            int index001 = 0;
                            int length000 = vector000.length();

                            loop003 : for (;(!(iter003 == Stella.NIL)) &&
                                      (index001 < length000); iter003 = iter003.rest, index001 = index001 + 1) {
                              key = iter003.value;
                              arg = (vector000.theArray)[index001];
                              if (!((key == null) ||
                                  (Stella_Object.equalP(key, Logic.valueOf(arg)) ||
                                   (Stella_Object.isaP(key, Logic.SGT_LOGIC_PROPOSITION) &&
                                    (Stella_Object.isaP(Logic.valueOf(arg), Logic.SGT_LOGIC_PROPOSITION) &&
                                     Proposition.unifyPropositionsP(((Proposition)(key)), ((Proposition)(Logic.valueOf(arg))), KeyValueMap.newKeyValueMap())))))) {
                                alwaysP000 = false;
                                break loop003;
                              }
                            }
                          }
                          testValue000 = alwaysP000;
                        }
                      }
                      if (!(testValue000)) {
                        continue loop001;
                      }
                    }
                  }
                }
                if (!(Proposition.deletedPropositionP(prop))) {
                  filteredsequence = Cons.cons(prop, filteredsequence);
                }
              }
            }
            if (filteredsequence == Stella.NIL) {
              return (Logic.NIL_NON_PAGING_INDEX);
            }
            else {
              { NonPagingIndex self001 = NonPagingIndex.newNonPagingIndex();

                self001.theSequence = filteredsequence;
                { NonPagingIndex value001 = self001;

                  return (value001);
                }
              }
            }
          }
        }
      }
    }
  }