* @param n
   * @return LogicObject
   */
  public static LogicObject getNthDomain(LogicObject relation, int n) {
    if (Logic.classP(relation)) {
      return (((n == 0) ? relation : null));
    }
    if (Surrogate.subtypeOfP(Stella_Object.safePrimaryType(relation), Logic.SGT_LOGIC_NAMED_DESCRIPTION)) {
      { NamedDescription relation000 = ((NamedDescription)(relation));

        if ((n >= 0) &&
            (n < relation000.ioVariableTypes.length())) {
          { Proposition domainprop = ((Proposition)(PLI.helpGetPropositions(((LogicObject)(PLI.SGT_PL_KERNEL_KB_NTH_DOMAIN.surrogateValue)), Cons.cons(relation000, Cons.cons(IntegerWrapper.wrapInteger(n), Cons.cons(null, Stella.NIL))), 1, null, null).value));

            if (domainprop != null) {
              return (((LogicObject)((domainprop.arguments.theArray)[(domainprop.arguments.length() - 1)])));
            }
          }
        }
      }
    }
    else {
    }
    return (null);
  }