public static PatternVariable copyVariable(PatternVariable self, KeyValueMap mapping) {
    { PatternVariable copy = ((PatternVariable)(mapping.lookup(self)));

      if (copy != null) {
        return (copy);
      }
      copy = Logic.createVariable(self.skolemType, self.skolemName, false);
      if ((((Keyword)(Logic.$PRINTMODE$.get())) == Logic.KWD_REALISTIC) ||
          (((Keyword)(Logic.$PRINTMODE$.get())) == Logic.KWD_FLAT)) {
        copy.skolemName = self.skolemName;
      }
      else {
        { String copyname = "?CP_" + Native.string_subsequence(self.skolemName.symbolName, 1, Stella.NULL_INTEGER);

          copy.skolemName = Symbol.internSymbol(copyname);
        }
      }
      copy.skolemType = self.skolemType;
      if (((Stella_Object)(Stella_Object.accessInContext(self.variableValue, self.homeContext, false))) != null) {
        { PatternVariable object000 = copy;
          Stella_Object value000 = ((Stella_Object)(Stella_Object.accessInContext(self.variableValue, self.homeContext, false)));
          Stella_Object oldValue002 = object000.variableValue;
          Stella_Object newValue000 = Stella_Object.updateInContext(oldValue002, value000, object000.homeContext, false);

          if (!((oldValue002 != null) &&
              (oldValue002.primaryType() == Logic.SGT_STELLA_CS_VALUE))) {
            object000.variableValue = newValue000;
          }
        }
      }
      mapping.insertAt(self, copy);
      return (copy);
    }
  }