public static Description selectOptimalQueryPattern(Description description, BooleanVector booleanvector, ControlFrame parentframe) {
    { Description pattern = null;
      KeyValueList querypatterns = description.queryPatterns;

      if (querypatterns != null) {
        pattern = ((Description)(querypatterns.lookup(booleanvector)));
      }
      if (Stella_Object.traceKeywordP(Logic.KWD_OPTIMIZER)) {
        pattern = null;
      }
      if (pattern != null) {
        return (pattern);
      }
      if (querypatterns == null) {
        description.queryPatterns = KeyValueList.newKeyValueList();
      }
      { Object old$Boundtooffsetcounter$000 = Logic.$BOUNDTOOFFSETCOUNTER$.get();

        try {
          Native.setIntSpecial(Logic.$BOUNDTOOFFSETCOUNTER$, 0);
          pattern = Description.copyDescription(description, null, true);

        } finally {
          Logic.$BOUNDTOOFFSETCOUNTER$.set(old$Boundtooffsetcounter$000);
        }
      }
      description.queryPatterns.insertAt(booleanvector, pattern);
      if (!((!((!(Logic.$QUERY_OPTIMIZATION_STRATEGY$ == Logic.KWD_NONE)) &&
          (!((Logic.$QUERY_OPTIMIZATION_STRATEGY$ == Logic.KWD_DYNAMIC) ||
          (Logic.$QUERY_OPTIMIZATION_STRATEGY$ == Logic.KWD_DYNAMIC_WITH_CLUSTERING))))) ||
          (((BooleanWrapper)(KeyValueList.dynamicSlotValue(description.dynamicSlots, Logic.SYM_LOGIC_DONT_OPTIMIZEp, Stella.FALSE_WRAPPER))).wrapperValue ||
           (Proposition.containsOperatorP(description.proposition, Logic.SGT_PL_KERNEL_KB_CUT) ||
            Proposition.containsOperatorP(description.proposition, Logic.SGT_PL_KERNEL_KB_BOUND_VARIABLES))))) {
        Description.optimizeQuery(pattern, booleanvector, parentframe);
      }
      Description.simplifyDescription(pattern, true);
      return (pattern);
    }
  }