Modular multiply

@see protectedSlidingWindow()
@access private
@param Array $x
@param Array $y
@param Array $n
@param Integer $mode
@return Array
329568
public function protectedMultiplyReduce($x, $y, $n, $mode)
    {
        if ($mode == MATH_BIGINTEGER_MONTGOMERY) {
            return $this->protectedMontgomeryMultiply($x, $y, $n);
        }
        $temp = $this->protectedMultiply($x, false, $y, false);
        return $this->protectedReduce($temp[MATH_BIGINTEGER_VALUE], $n, $mode);
    }
1219640
public function protectedReduce($x, $n, $mode)
    {
        switch ($mode) {
            case MATH_BIGINTEGER_MONTGOMERY:
                return $this->protectedMontgomery($x, $n);
            case MATH_BIGINTEGER_BARRETT:
                return $this->protectedBarrett($x, $n);
            case MATH_BIGINTEGER_POWEROF2:
                $lhs = new BigInteger();
                $lhs->value = $x;
                $rhs = new BigInteger();
                $rhs->value = $n;
                return $x->protectedMod2($n);
            case MATH_BIGINTEGER_CLASSIC:
                $lhs = new BigInteger();
                $lhs->value = $x;
                $rhs = new BigInteger();
                $rhs->value = $n;
                list ($temp) = $lhs->divide($rhs);
                return $temp->value;
            case MATH_BIGINTEGER_NONE:
                return $x;
            default:
                // an invalid $mode was provided
        }
    }
719029
public static function getMode(string $mode): array
    {
        $options = [
            "shuffle"   =>  false,
            "repeat"    =>  false,
        ];

        if (in_array($mode, ["REPEAT_ALL", "SHUFFLE"])) {
            $options["repeat"] = true;
        }
        if (in_array($mode, ["SHUFFLE_NOREPEAT", "SHUFFLE"])) {
            $options["shuffle"] = true;
        }

        return $options;
    }
444361
public static void plus(double[] y, double[] x) {
        if (x.length != y.length) {
            throw new IllegalArgumentException(String.format("Arrays have different length: x[%d], y[%d]", x.length, y.length));
        }

        for (int i = 0; i < x.length; i++) {
            y[i] += x[i];
        }
    }
657150
private function _mult(string $X, string $Y): string
    {
        $x = GCM::strToGMP($X);
        $Z = GCM::strToGMP(GCM::ZB_128);
        $V = GCM::strToGMP($Y);
        $R = GCM::strToGMP(self::R);
        for ($i = 0; $i < 128; ++$i) {
            // if bit at X[i] is set
            if (gmp_testbit($x, 127 - $i)) {
                $Z ^= $V;
            }
            // if LSB(Vi) = 0
            if (!gmp_testbit($V, 0)) {
                $V >>= 1;
            } else {
                $V = ($V >> 1) ^ $R;
            }
        }
        return GCM::gmpToStr($Z, 16);
    }
930144
public static double Y(int n, double x) {
        double by, bym, byp, tox;

        if (n == 0) return Y0(x);
        if (n == 1) return Y(x);

        tox = 2.0 / x;
        by = Y(x);
        bym = Y0(x);
        for (int j = 1; j < n; j++) {
            byp = j * tox * by - bym;
            bym = by;
            by = byp;
        }
        return by;
    }
947777
private function modNn(int $x) : int
    {
        while ($x >= $this->blockSize) {
            $x -= $this->blockSize;
            $x = ($x >> $this->symbolSize) + ($x & $this->blockSize);
        }

        return $x;
    }
491891
public static function mul(array $m1, array $m2): array
    {
        $res = [];
        foreach ($m1 as $i => $val) {
            $res[] = $val * $m2[$i];
        }

        return $res;
    }
1307881
function _prepareReduce($x, $n, $mode)
    {
        if ($mode == self::MONTGOMERY) {
            return $this->_prepMontgomery($x, $n);
        }
        return $this->_reduce($x, $n, $mode);
    }
758728
public function add($x = 0, $y = 0) {
		$this->width += $x;
		$this->height += $y;
		return $this;
	}
1078870
function setLadderMode($mode, $multicall = false)
    {
        if ($mode !== 0 && $mode !== 1) {
            throw new InvalidArgumentException('mode = ' . print_r($mode, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($mode), $multicall);
    }
1265804
public function rectangle($x, $y, $width, $height, $context, $x, $y, $width, $height)
    {
    }
575605
public static function pearson(array $x, array $y): float
    {
        if (count($x) !== count($y)) {
            throw new InvalidArgumentException('Size of given arrays does not match');
        }

        $count = count($x);
        $meanX = Mean::arithmetic($x);
        $meanY = Mean::arithmetic($y);

        $axb = 0;
        $a2 = 0;
        $b2 = 0;

        for ($i = 0; $i < $count; ++$i) {
            $a = $x[$i] - $meanX;
            $b = $y[$i] - $meanY;
            $axb += ($a * $b);
            $a2 += $a ** 2;
            $b2 += $b ** 2;
        }

        return $axb / ($a2 * $b2) ** .5;
    }
974402
public static function mul($n1, $n2, $round = false)
    {
        $product = bcmul($n1, $n2, self::$scale);

        return $round ? self::round($product) : (float)$product;
    }
1201143
function add(x, y) {
	var z = [];
	var n = Math.max(x.length, y.length);
	var carry = 0;
	var i = 0;
	while (i < n || carry) {
		var xi = i < x.length ? x[i] : 0;
		var yi = i < y.length ? y[i] : 0;
		var zi = carry + xi + yi;
		z.push(zi % 10);
		carry = Math.floor(zi / 10);
		i++;
	}
	return z;
}
1033279
public static function multiply($a, $b)
    {
        if (function_exists('gmp_mul')) {
            return gmp_mul($a, $b);
        }

        return bcmul($a, $b, 0);
    }
816902
public function multiply($v) {
		$components = array();
		if(is_object($v)) {
			if(!($v instanceof Vector)) {
				throw new Exception('Unspupported data structure');
			}
			if($this->dimension != $v->getDimensions()) {
				throw new Exception("Both vectors must have the same size");
			}
			$otherComponents = $v->toArray();
			foreach($this->components as $i => $component) {
				$components[] = $component * $otherComponents[$i];
			}
		} else {
			foreach($this->components as $i => $component) {
				$components[] = $component * $v;
			}
		}
		$this->components = $components;
		return $this;
	}