Performs a simultaneous substitution on this formula given a single mapping from variable to formula.
@param variable the variable
@param formula  the formula
@return a new substituted formula
554838
public Formula substitute(final Variable variable, final Formula formula) {
        final Substitution subst = new Substitution();
        subst.addMapping(variable, formula);
        return this.substitute(subst);
    }
986445
def substitute(init, value, depth)
      if depth > VAR_SUBSTITUTION_MAX_DEPTH
        raise SystemStackError, "Maximal recursive depth (#{VAR_SUBSTITUTION_MAX_DEPTH})
          reached for resolving variable #{init}, reached #{value} before stopping."
      end
      original = value.clone
      value.gsub!(/(#(.*?)#)+?/) do
       # 1. Match pre-defined variable, or variable defined in appliance definition.
       next @appliance_config.variables[$2] if @appliance_config.variables.has_key?($2)
       # 2. Match from environment variables.
       next ENV[$2] unless ENV[$2].nil?
       # 3. No match, replace the original string.
       $1
      end
      substitute(init, value, depth+1) unless original == value
    end
887684
public void add(final Formula formula) {
        final Formula cnf = formula.cnf();
        switch (cnf.type()) {
            case TRUE:
                break;
            case FALSE:
            case LITERAL:
            case OR:
                this.addClause(generateClauseVector(cnf), null);
                break;
            case AND:
                for (final Formula op : cnf) {
                    this.addClause(generateClauseVector(op), null);
                }
                break;
            default:
                throw new IllegalStateException("Unexpected formula type in CNF: " + cnf.type());
        }
    }
1260323
@Override
    public IMolecularFormula add(IMolecularFormula formula) {
        for (IIsotope newIsotope : formula.isotopes()) {
            addIsotope(newIsotope, formula.getIsotopeCount(newIsotope));
        }
        if (formula.getCharge() != null) {
            if (charge != null)
                charge += formula.getCharge();
            else
                charge = formula.getCharge();
        }
        return this;
    }
583600
public JsStatement var(String variable)
	{
		JsStatement statement = new JsStatement();
		statements.add(statement);
		return statement.append(variable);
	}
765732
public Expression2 substitute(int index, String newConstantExpression) {
    return substitute(index, Expression2.constant(newConstantExpression));
  }
432043
public SDVariable addVariable(SDVariable variable) {
        Preconditions.checkState(variable.getSameDiff() == this, "Samediff instance must be the same.");

        if (variables.containsKey(variable.getVarName()) && !variables.get(variable.getVarName()).getVariable().equals(variable)) {
            throw new IllegalArgumentException("Variable already found with variable opName " + variable.getVarName());
        }

        Preconditions.checkState(variable.getSameDiff() == this, "Same diff instance for variable must be the same!");
        variables.put(variable.getVarName(), Variable.builder().name(variable.getVarName()).variable(variable).build());
        return variable;
    }
546656
public <T extends ImmutableTerm> ImmutableSubstitution<T> prioritizeRenaming(
            ImmutableSubstitution<T> substitution, ImmutableSet<Variable> priorityVariables) {

        ImmutableMultimap<Variable, Variable> renamingMultimap = substitution.getImmutableMap().entrySet().stream()
                .filter(e -> priorityVariables.contains(e.getKey())
                        && (e.getValue() instanceof Variable)
                        && (!priorityVariables.contains(e.getValue())))
                .collect(ImmutableCollectors.toMultimap(
                        e -> (Variable) e.getValue(),
                        Map.Entry::getKey));

        if (renamingMultimap.isEmpty())
            return substitution;

        ImmutableMap<Variable, Variable> renamingMap = renamingMultimap.asMap().entrySet().stream()
                .collect(ImmutableCollectors.toMap(
                        Map.Entry::getKey,
                        e -> e.getValue().iterator().next()));
        InjectiveVar2VarSubstitution renamingSubstitution = substitutionFactory.getInjectiveVar2VarSubstitution(renamingMap);

        // TODO: refactor
        return (ImmutableSubstitution<T>) renamingSubstitution.composeWith(substitution);
    }
671667
public static String substituteValueInExpression(String expression, String newValue)
   {
      ExpressionTemplate t = new ExpressionTemplate(expression);
      if (newValue != null && (getExpressionKey(t.getTemplate()) == null ||
            (t.isComplex()  && !newValue.equals(t.getValue()))))
         return newValue;

      String result = t.getSubstitution();
      if (!t.isComplex() && newValue != null)
      {
         int start = result.lastIndexOf(":$");
         start = result.indexOf(":", start + 1);
         int end = result.indexOf("}", start + 1);

         if (start < 0 || end < 0 || start == result.lastIndexOf("${:}") + 2)
            return result;

         result = result.substring(0, start + 1) + newValue +  result.substring(end);
      }
      return result;
   }
34895
Formula translateToFormula(final List<Variable> varOrder) {
    final FormulaFactory f = varOrder.get(0).factory();
    assert this.bits.length == varOrder.size();
    final List<Literal> operands = new ArrayList<>(varOrder.size());
    for (int i = 0; i < this.bits.length; i++)
      if (this.bits[i] != Tristate.UNDEF)
        operands.add(this.bits[i] == Tristate.TRUE ? varOrder.get(i) : varOrder.get(i).negate());
    return f.and(operands);
  }
331729
def substitute_variables(command, level, name, value, target=None, **kwargs):
    """"""
    rule = kwargs.get('rule', {})
    rule_value = rule.get('value', '') if rule else ''
    substitutes = {
        '${level}': str(level),
        '${target}': str(target),
        '${name}': '"' + str(name) + '"',
        '${value}': str(value),
        '${limit_value}': str(rule_value),
    }

    result = command
    for pattern, value in substitutes.items():
        result = result.replace(pattern, value)

    return result
963491
public static BinaryExpression newAssignmentExpression(Variable variable, Expression rhs) {
        VariableExpression lhs = new VariableExpression(variable);
        Token operator = Token.newPlaceholder(Types.ASSIGN);

        return new BinaryExpression(lhs, operator, rhs);
    }
262614
public Variable newVariable() {
    if (this.miniSat == null && this.cleaneLing == null)
      return this.f.newCCVariable();
    else if (this.miniSat != null) {
      final int index = this.miniSat.underlyingSolver().newVar(!this.miniSat.initialPhase(), true);
      final String name = FormulaFactory.CC_PREFIX + "MINISAT_" + index;
      this.miniSat.underlyingSolver().addName(name, index);
      return new EncodingAuxiliaryVariable(name, false);
    } else
      return new EncodingAuxiliaryVariable(this.cleaneLing.createNewVariableOnSolver(FormulaFactory.CC_PREFIX + "CLEANELING"), false);
  }
393743
def substitute(self, text, subvars={},
                   checkmissing=None):
        ''''''

        if checkmissing is None:
            checkmissing = self.checkmissing

        while True:
            idx = text.find(self.start_var_token)
            if idx == -1:
                return text
            endidx = text[idx:].find(self.end_var_token)
            if endidx == -1:
                raise MAVSubstituteError('missing end of variable: %s' % text[idx:idx+10])
            varname = text[idx+2:idx+endidx]
            fullvar = varname

            # allow default value after a :
            def_value = None
            colon = varname.find(':')
            if colon != -1:
                def_value = varname[colon+1:]
                varname = varname[:colon]

            if varname in subvars:
                value = subvars[varname]
            elif def_value is not None:
                value = def_value
            elif checkmissing:
                raise MAVSubstituteError("unknown variable in '%s%s%s'" % (
                    self.start_var_token, varname, self.end_var_token))
            else:
                return text[0:idx+endidx] + self.substitute(text[idx+endidx:], subvars, checkmissing=False)
            text = text.replace("%s%s%s" % (self.start_var_token, fullvar, self.end_var_token), str(value))
        return text
114846
public <X extends Exception> void replaceIf(final Try.TriPredicate<R, C, E, X> predicate, final E newValue) throws X {
        checkFrozen();

        if (rowLength() > 0 && columnLength() > 0) {
            this.init();

            final int rowLength = rowLength();
            int columnIndex = 0;
            R rowKey = null;
            C columnKey = null;
            E val = null;

            for (List<E> column : _columnList) {
                columnKey = _columnKeyIndexMap.getByValue(columnIndex);

                for (int rowIndex = 0; rowIndex < rowLength; rowIndex++) {
                    rowKey = _rowKeyIndexMap.getByValue(rowIndex);
                    val = column.get(rowIndex);

                    if (predicate.test(rowKey, columnKey, val)) {
                        column.set(rowIndex, newValue);
                    }
                }

                columnIndex++;
            }
        }
    }
1310122
@Override
	public RandomVariable sub(double value) {
		return apply(OperatorType.SUB, new RandomVariable[]{this, constructNewAADRandomVariable(value)});
	}
1270862
public void setComponent(String component, Variable ... vars) {
		for (Variable var : vars) {
			if (var.getComponent() != null && !var.getComponent().equals(component)) {
				components.get(var.getComponent()).remove(var);
			}
		}
		if (!components.containsKey(component)) components.put(component, new ArrayList<Variable>());
		for (Variable var : vars) components.get(component).add(var);
	}

	/**
	 * Create a batch of new {@link Variable}s for this {@link ConstraintSolver}.
	 * @param num The number of variables to create.
	 * @return A batch of new {@link Variable}s.
	 */
	public final Variable[] createVariables(int num) {
		return this.createVariables(num, null);
	}

	/**
	 * Create a batch of new {@link Variable}s for this {@link ConstraintSolver}.
	 * @param num The number of variables to create.
	 * @param component The component tag to associate to these new variables.
	 * @return A batch of new {@link Variable}s.
	 */
	public final Variable[] createVariables(int num, String component) {
		Variable[] ret = createVariablesSub(num, component);
		if (ret == null) return null;
		//need to add all to network so if sth goes wrong I can delete all of them concurrently
		for (Variable v : ret) this.theNetwork.addVariable(v);
		if (!skipPropagation && autoprop && checkDomainsInstantiated() && !noPropOnVarCreation) this.propagate();
		logger.finest("Created variables " + Arrays.toString(ret));
		return ret;
	}