Construct VAR equation system (optionally with RLS constraint).
508783
def _construct_var_eqns(data, p, delta=None):
        
        t, m, l = np.shape(data)
        n = (l - p) * t  # number of linear relations
        rows = n if delta is None else n + m * p

        # Construct matrix x (predictor variables)
        x = np.zeros((rows, m * p))
        for i in range(m):
            for k in range(1, p + 1):
                x[:n, i * p + k - 1] = np.reshape(data[:, i, p - k:-k].T, n)
        if delta is not None:
            np.fill_diagonal(x[n:, :], delta)

        # Construct vectors yi (response variables for each channel i)
        y = np.zeros((rows, m))
        for i in range(m):
            y[:n, i] = np.reshape(data[:, i, p:].T, n)

        return x, y
70525
private static Variable[] litsAsVars(final Literal[] lits) {
    final Variable[] vars = new Variable[lits.length];
    for (int i = 0; i < vars.length; i++)
      vars[i] = lits[i].variable();
    return vars;
  }
490540
def add_variables(vars)
      # Allocate space for the new variables
      ret = LPSolve.resize_lp(@ptr, @constraints.length,
                              @variables.length + vars.length)
      fail if ret != 1

      # Store all the variables in the model
      vars.each { |var| store_variable var }
    end
342263
void buildALK(final EncodingResult result, final Variable[] vars, int rhs) {
    final LNGVector<Variable> cardinalityOutvars = this.initializeConstraint(result, vars);
    this.incData = new CCIncrementalData(result, CCConfig.ALK_ENCODER.TOTALIZER, rhs, vars.length, cardinalityOutvars);
    this.toCNF(cardinalityOutvars, rhs, Bound.LOWER);
    assert this.cardinalityInvars.size() == 0;
    for (int i = 0; i < rhs; i++)
      this.result.addClause(cardinalityOutvars.get(i));
  }
1337003
def relax_AX(self):
        """"""

        self.AXnr = self.cnst_A(self.X, self.Xf)
        if self.rlx == 1.0:
            self.AX = self.AXnr
        else:
            alpha = self.rlx
            self.AX = alpha*self.AXnr + (1-alpha)*self.block_cat(
                self.var_y0() + self.S, self.var_y1())
1180127
function(eqns, var_array) {
        //check if a var_array was specified
        //nerdamer.clearVars();// this deleted ALL variables: not what we want
        //parse all the equations to LHS. Remember that they come in as strings
        for(var i=0; i<eqns.length; i++) 
            eqns[i] = toLHS(eqns[i]);
        
        var l = eqns.length,
            m = new core.Matrix(),
            c = new core.Matrix(),
            expand_result = false,
            vars;
        
        if(typeof var_array === 'undefined') {
            //check to make sure that all the equations are linear
            if(!_A.allLinear(eqns)) 
                core.err('System must contain all linear equations!');
            vars = variables(eqns[0]);

            //get all variables
            for(var i=1; i<l; i++) 
                vars = vars.concat(variables(eqns[i])); 
            //remove duplicates
            vars = core.Utils.arrayUnique(vars).sort();
            
            // deletes only the variables of the linear equations in the nerdamer namespace
            for (var i=0;i<vars.length;i++){
                nerdamer.setVar(vars[i],"delete");
            }
            // populate the matrix
            for(var i=0; i<l; i++) {
                var e = eqns[i]; //store the expression
                for(var j=0; j<l; j++) {     
                    var variable = e.symbols[vars[j]];
                    m.set(i, j, variable ? variable.multiplier : 0);
                }
                var num = e.symbols['#']; 
                c.set(i, 0, new Symbol(num ? -num.multiplier : 0));
            }
        }
        else {
            /**
             * The idea is that we loop through each equation and then expand it. Afterwards we loop
             * through each term and see if and check to see if it matches one of the variables.
             * When a match is found we mark it. No other match should be found for that term. If it
             * is we stop since it's not linear.
             */               
            vars = var_array;
            expand_result = true;
            for(i=0; i<l; i++) {
                //prefill
                c.set(i, 0, new Symbol(0));
                var e = _.expand(eqns[i]).collectSymbols(); //expand and store
                //go trough each of the variables
                for(var j=0; j<var_array.length; j++) {
                    m.set(i, j, new Symbol(0));
                    var v = var_array[j];
                    //go through the terms and sort the variables
                    for(var k=0; k<e.length; k++) {
                        var term = e[k],
                            check = false;
                        for(var z=0; z<var_array.length; z++) {
                            //check to see if terms contain multiple variables
                            if(term.contains(var_array[z])) {
                                if(check)
                                    core.err('Multiple variables found for term '+term);
                                check = true;
                            }   
                        }
                        //we made sure that every term contains one variable so it's safe to assume that if the
                        //variable is found then the remainder is the coefficient.
                        if(term.contains(v)) {
                            var tparts = explode(remove(e, k), v);
                            m.set(i, j, _.add(m.get(i, j), tparts[0]));
                        }
                    }
                }
                //all the remaining terms go to the c matrix
                for(k=0; k<e.length; k++) {
                    c.set(i, 0, _.add(c.get(i, 0), e[k]));
                }
            }
            //consider case (a+b)*I+u
        }
            
        // Use M^-1*c to solve system
        m = m.invert();
        var result = m.multiply(c);
        //correct the sign as per issue #410
        if(core.Utils.isArray(var_array))
            result.each(function(x) {
                return x.negate();
            });
        var solutions = core.Settings.SOLUTIONS_AS_OBJECT ? {} : [];
        result.each(function(e, idx) { 
            var solution = (expand_result ? _.expand(e) : e).valueOf();
            var variable = vars[idx];
            if(core.Settings.SOLUTIONS_AS_OBJECT) {
                solutions[variable] = solution;
            }
            else
                solutions.push([variable, solution]); 
        });
        //done
        return solutions;
    }
506778
def incr(**vars):
    
    for k, v in vars:
        current_context.vars.setdefault(k, 0)
        current_context[k] += v
1019346
void buildEXK(final EncodingResult result, final Variable[] vars, int rhs) {
    final LNGVector<Variable> cardinalityOutvars = this.initializeConstraint(result, vars);
    this.toCNF(cardinalityOutvars, rhs, Bound.BOTH);
    assert this.cardinalityInvars.size() == 0;
    for (int i = 0; i < rhs; i++)
      this.result.addClause(cardinalityOutvars.get(i));
    for (int i = rhs; i < cardinalityOutvars.size(); i++)
      this.result.addClause(cardinalityOutvars.get(i).negate());
  }
1287251
def _run_opf(self, P, q, AA, ll, uu, xmin, xmax, x0, opt):
        
        AAcvx = tocvx(AA)
        nx = x0.shape[0] # number of variables
        # add var limits to linear constraints
        eyex = spmatrix(1.0, range(nx), range(nx))
        A = sparse([eyex, AAcvx])
        l = matrix([-xmin, ll])
        u = matrix([ xmax, uu])

        Ae, be, Ai, bi = split_linear_constraints(A, l, u)


        if len(P.V) > 0:
            cvx_sol = solvers.qp(P, q, Ai, bi, Ae, be, self.solver, {"x": x0})
        else:
            cvx_sol = solvers.lp(q, Ai, bi, Ae, be, self.solver, {"x": x0})

        return cvx_sol
768616
def evaluate_condition(condition, vars):
    ''''''
    if condition is None:
        return True
    v = evaluate_expression(condition, vars)
    if v is None:
        return False
    return v
372625
def flux_r(q_vars: List[fl.Var], i: int, j: int):
    """"""
    return fl.sqrt(flux_r2(q_vars, i, j))
374407
def bound_variables(xmrs):
    """"""
    bvs = set(
        ep.intrinsic_variable for ep in xmrs.eps()
        if ep.is_quantifier() and ep.intrinsic_variable is not None
    )
    return sorted(bvs, key=var_id)
267919
def solve_sort(expr, vars):
    """"""
    lhs_values = repeated.getvalues(__solve_for_repeated(expr.lhs, vars)[0])

    sort_expression = expr.rhs

    def _key_func(x):
        return solve(sort_expression, __nest_scope(expr.lhs, vars, x)).value

    results = ordered.ordered(lhs_values, key_func=_key_func)

    return Result(repeated.meld(*results), ())
242165
def solve_select(expr, vars):
    
    data, _ = __solve_for_repeated(expr.lhs, vars)
    key = solve(expr.rhs, vars).value

    try:
        results = [associative.select(d, key) for d in repeated.getvalues(data)]
    except (KeyError, AttributeError):
        # Raise a better exception for accessing a non-existent key.
        raise errors.EfilterKeyError(root=expr, key=key, query=expr.source)
    except (TypeError, ValueError):
        # Raise a better exception for what is probably a null pointer error.
        if vars.locals is None:
            raise errors.EfilterNoneError(
                root=expr, query=expr.source,
                message="Cannot select key %r from a null." % key)
        else:
            raise
    except NotImplementedError:
        raise errors.EfilterError(
            root=expr, query=expr.source,
            message="Cannot select keys from a non-associative value.")

    return Result(repeated.meld(*results), ())
1048219
def store_variable(var)
      # Update the variable to track the index in the model
      index = @var_count + 1
      var.model = self
      var.index = index
      var.freeze
      @var_count += 1

      ret = LPSolve.add_columnex @ptr, 0, nil, nil
      fail if ret != 1

      # Set variable properties
      set_variable_type index, var.type

      ret = LPSolve.set_col_name(@ptr, index, var.name)
      fail if ret != 1

      ret = LPSolve.set_obj(@ptr, index, var.coefficient)
      fail if ret != 1

      set_variable_bounds index, var.lower_bound, var.upper_bound

      @variables << var
    end
15357
def solve_tuple(expr, vars):
    """"""
    result = tuple(solve(x, vars).value for x in expr.children)
    return Result(result, ())
535258
private LNGVector<Variable> initializeConstraint(final EncodingResult result, final Variable[] vars) {
    result.reset();
    this.result = result;
    this.cardinalityInvars = new LNGVector<>(vars.length);
    final LNGVector<Variable> cardinalityOutvars = new LNGVector<>(vars.length);
    for (final Variable var : vars) {
      this.cardinalityInvars.push(var);
      cardinalityOutvars.push(this.result.newVariable());
    }
    return cardinalityOutvars;
  }