private static String expandWasVariable(String formula, int varNumber, List<String> events) {
    	final Pattern p = Pattern.compile("variable\\((\\w+)\\)");
		final Matcher m = p.matcher(formula);
		final StringBuilder sb = new StringBuilder();
		int lastPos = 0;
		while (m.find()) {
			final String varName = m.group(1);
			final int varIndex = Integer.parseInt(varName.substring(1));
			sb.append(formula.substring(lastPos, m.start()));
			final List<String> expansion = new ArrayList<>();
			for (String event : events) {
				for (int j = 0; j < 1 << varNumber; j++) {
					char[] arr = new char[varNumber];
					for (int pos = 0; pos < varNumber; pos++) {
						arr[pos] = ((j >> pos) & 1) == 1 ? '1' : '0';
					}
					if (arr[varIndex] == '1') {
						expansion.add("event(" + event + String.valueOf(arr) + ")");
					}
				}
			}
			lastPos = m.end();
			String strToAppend = String.join(" || ", expansion);
			if (expansion.size() > 1) {
				strToAppend = "(" + strToAppend + ")";
			}
			sb.append(strToAppend);
		}
		sb.append(formula.substring(lastPos, formula.length()));
		return sb.toString();
	}