public static Surrogate logicalType(Stella_Object self) {
    { Surrogate testValue000 = Stella_Object.safePrimaryType(self);

      if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_DESCRIPTION)) {
        { Description self000 = ((Description)(self));

          if (Logic.monadicP(self000) &&
              ((BooleanWrapper)(KeyValueList.dynamicSlotValue(self000.dynamicSlots, Logic.SYM_LOGIC_IOTAp, Stella.FALSE_WRAPPER))).wrapperValue) {
            return (((PatternVariable)((self000.ioVariables.theArray)[0])).skolemType);
          }
          else if (Logic.monadicP(self000) &&
              (self000.ioVariables.nonEmptyP() &&
               ((((PatternVariable)((self000.ioVariables.theArray)[0])).skolemType != null) &&
                NamedDescription.classDescriptionP(Logic.surrogateToDescription(((PatternVariable)((self000.ioVariables.theArray)[0])).skolemType))))) {
            return (Logic.SGT_PL_KERNEL_KB_CONCEPT);
          }
          else {
            return (Logic.SGT_PL_KERNEL_KB_RELATION);
          }
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_PATTERN_VARIABLE)) {
        { PatternVariable self000 = ((PatternVariable)(self));

          { Surrogate type = self000.skolemType;

            if ((type != null) &&
                (!(type == Logic.SGT_STELLA_THING))) {
              return (type);
            }
          }
          { Proposition p = null;
            Iterator iter000 = Logic.unfilteredDependentIsaPropositions(self000).allocateIterator();

            while (iter000.nextP()) {
              p = ((Proposition)(iter000.value));
              if ((p.kind == Logic.KWD_ISA) &&
                  BooleanWrapper.coerceWrappedBooleanToBoolean(p.variableTypeP())) {
                return (((Surrogate)(p.operator)));
              }
            }
          }
          return (Logic.SGT_STELLA_THING);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_SKOLEM)) {
        { Skolem self000 = ((Skolem)(self));

          if (self000.skolemType != null) {
            return (self000.skolemType);
          }
          else {
            return (Logic.SGT_STELLA_THING);
          }
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
        { LogicObject self000 = ((LogicObject)(self));

          return (Logic.SGT_STELLA_THING);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_PROPOSITION)) {
        { Proposition self000 = ((Proposition)(self));

          return (Logic.SGT_LOGIC_PROPOSITION);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_LITERAL_WRAPPER)) {
        { LiteralWrapper self000 = ((LiteralWrapper)(self));

          return (Wrapper.wrapperValueType(self000));
        }
      }
      else if (Surrogate.subtypeOfSurrogateP(testValue000)) {
        { Surrogate self000 = ((Surrogate)(self));

          if ((self000.surrogateValue != null) &&
              (!(self000.surrogateValue == Logic.BOTTOM))) {
            return (Logic.logicalType(self000.surrogateValue));
          }
          else {
            return (Logic.SGT_STELLA_THING);
          }
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_SET)) {
        { Set self000 = ((Set)(self));

          return (Logic.SGT_PL_KERNEL_KB_SET);
        }
      }
      else if (Surrogate.subtypeOfClassP(testValue000)) {
        { Stella_Class self000 = ((Stella_Class)(self));

          return (Logic.SGT_PL_KERNEL_KB_CONCEPT);
        }
      }
      else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_SLOT)) {
        { Slot self000 = ((Slot)(self));

          if (Logic.booleanTypeP(self000.slotBaseType)) {
            return (Logic.SGT_PL_KERNEL_KB_RELATION);
          }
          else {
            return (Logic.SGT_PL_KERNEL_KB_FUNCTION);
          }
        }
      }
      else {
        return (self.primaryType());
      }
    }
  }