def hensel_lift_zp(g0, f0, char, height)
437561
def hensel_lift_zp(g0, f0, char, height, where)
      # self in MPolynomial/int
      # g0 in Polyomial/Zp, candidate of factor of f0
      # f0 in Polyomial/Zp, one variable reduction of self

      #    fk = _hensel_lift(g0, f0, char, height) {|ha, ary, cofacts|
      fk = _hensel_lift(g0, f0, char, height, where) do |ha, ary, cofacts|
        decompose_on_cofactors_modp(ha, ary, cofacts)
      end

      r = self - fk[0] * fk[1]
      return fk if r.zero?

      nil
    end
563699
def fap_davies(Z, fmax, t, y, dy, normalization='standard'):
    
    N = len(t)
    fap_s = fap_single(Z, N, normalization=normalization)
    tau = tau_davies(Z, fmax, t, y, dy, normalization=normalization)
    return fap_s + tau
480222
def drange(v0, v1, d):
    """"""
    assert v0 < v1
    return xrange(int(v0)//d, int(v1+d)//d)
966690
def _vminFindStart(v,E,Lz,I3V,delta,u0,cosh2u0,sinh2u0,
                                potu0pi2,pot):
    
    vtry= 0.9*v
    while _JzStaeckelIntegrandSquared(vtry,
                                      E,Lz,I3V,delta,u0,cosh2u0,sinh2u0,
                                      potu0pi2,pot) >= 0. \
                                      and vtry > 0.000000001:
        vtry*= 0.9
    if vtry < 0.000000001: return 0.   
    return vtry
1093634
private static int[] hslToRgb(float h, float s, float l) {
        
        int[] ret = new int[3];
        
        float m2 = (l <= 0.5f) ? l * (s + 1) : l + s - l * s; 
        float m1 = l * 2 - m2;
        ret[0] = Math.round(hueToRgb(m1, m2, h + 1.0f/3.0f) * MAX_VALUE);
        ret[1] = Math.round(hueToRgb(m1, m2, h) * MAX_VALUE);
        ret[2] = Math.round(hueToRgb(m1, m2, h - 1.0f/3.0f) * MAX_VALUE);
        return ret;
    }
476374
def zcr(data):
    """"""
    data = np.mean(data, axis=1)

    count = len(data)
    countZ = np.sum(np.abs(np.diff(np.sign(data)))) / 2
    return (np.float64(countZ) / np.float64(count - 1.0))
313995
function hsl2rgb(h, s, l) {
		// HSL 0 to 1 => RGB results from 0 to 255
		var r, g, b, var_1, var_2;

		if (s === 0) {
			r = l * 255;
			g = l * 255;
			b = l * 255;
		} else {
			var_2 = (l < 0.5) ? l * (1 + s) : ((l + s) - (s * l));
			var_1 = 2 * l - var_2;

			r = 255 * h2rgb(var_1, var_2, h + (1 / 3));
			g = 255 * h2rgb(var_1, var_2, h);
			b = 255 * h2rgb(var_1, var_2, h - (1 / 3));
		}

		return [r, g, b];
	}
1149227
function nelderMead(f, x0, parameters) {
        parameters = parameters || {};

        var maxIterations = parameters.maxIterations || x0.length * 200,
            nonZeroDelta = parameters.nonZeroDelta || 1.05,
            zeroDelta = parameters.zeroDelta || 0.001,
            minErrorDelta = parameters.minErrorDelta || 1e-6,
            minTolerance = parameters.minErrorDelta || 1e-5,
            rho = parameters.rho !== undefined ? parameters.rho : 1,
            chi = parameters.chi !== undefined ? parameters.chi : 2,
            psi = parameters.psi !== undefined ? parameters.psi : -0.5,
            sigma = parameters.sigma !== undefined ? parameters.sigma : 0.5,
            maxDiff;

        // initialize simplex.
        var N = x0.length,
            simplex = new Array(N + 1);
        simplex[0] = x0;
        simplex[0].fx = f(x0);
        simplex[0].id = 0;
        for (var i = 0; i < N; ++i) {
            var point = x0.slice();
            point[i] = point[i] ? point[i] * nonZeroDelta : zeroDelta;
            simplex[i + 1] = point;
            simplex[i + 1].fx = f(point);
            simplex[i + 1].id = i + 1;
        }

        function updateSimplex(value) {
            for (var i = 0; i < value.length; i++) {
                simplex[N][i] = value[i];
            }
            simplex[N].fx = value.fx;
        }

        var sortOrder = function sortOrder(a, b) {
            return a.fx - b.fx;
        };

        var centroid = x0.slice(),
            reflected = x0.slice(),
            contracted = x0.slice(),
            expanded = x0.slice();

        for (var iteration = 0; iteration < maxIterations; ++iteration) {
            simplex.sort(sortOrder);

            if (parameters.history) {
                // copy the simplex (since later iterations will mutate) and
                // sort it to have a consistent order between iterations
                var sortedSimplex = simplex.map(function (x) {
                    var state = x.slice();
                    state.fx = x.fx;
                    state.id = x.id;
                    return state;
                });
                sortedSimplex.sort(function (a, b) {
                    return a.id - b.id;
                });

                parameters.history.push({ x: simplex[0].slice(),
                    fx: simplex[0].fx,
                    simplex: sortedSimplex });
            }

            maxDiff = 0;
            for (i = 0; i < N; ++i) {
                maxDiff = Math.max(maxDiff, Math.abs(simplex[0][i] - simplex[1][i]));
            }

            if (Math.abs(simplex[0].fx - simplex[N].fx) < minErrorDelta && maxDiff < minTolerance) {
                break;
            }

            // compute the centroid of all but the worst point in the simplex
            for (i = 0; i < N; ++i) {
                centroid[i] = 0;
                for (var j = 0; j < N; ++j) {
                    centroid[i] += simplex[j][i];
                }
                centroid[i] /= N;
            }

            // reflect the worst point past the centroid  and compute loss at reflected
            // point
            var worst = simplex[N];
            weightedSum(reflected, 1 + rho, centroid, -rho, worst);
            reflected.fx = f(reflected);

            // if the reflected point is the best seen, then possibly expand
            if (reflected.fx < simplex[0].fx) {
                weightedSum(expanded, 1 + chi, centroid, -chi, worst);
                expanded.fx = f(expanded);
                if (expanded.fx < reflected.fx) {
                    updateSimplex(expanded);
                } else {
                    updateSimplex(reflected);
                }
            }

            // if the reflected point is worse than the second worst, we need to
            // contract
            else if (reflected.fx >= simplex[N - 1].fx) {
                    var shouldReduce = false;

                    if (reflected.fx > worst.fx) {
                        // do an inside contraction
                        weightedSum(contracted, 1 + psi, centroid, -psi, worst);
                        contracted.fx = f(contracted);
                        if (contracted.fx < worst.fx) {
                            updateSimplex(contracted);
                        } else {
                            shouldReduce = true;
                        }
                    } else {
                        // do an outside contraction
                        weightedSum(contracted, 1 - psi * rho, centroid, psi * rho, worst);
                        contracted.fx = f(contracted);
                        if (contracted.fx < reflected.fx) {
                            updateSimplex(contracted);
                        } else {
                            shouldReduce = true;
                        }
                    }

                    if (shouldReduce) {
                        // if we don't contract here, we're done
                        if (sigma >= 1) break;

                        // do a reduction
                        for (i = 1; i < simplex.length; ++i) {
                            weightedSum(simplex[i], 1 - sigma, simplex[0], sigma, simplex[i]);
                            simplex[i].fx = f(simplex[i]);
                        }
                    }
                } else {
                    updateSimplex(reflected);
                }
        }

        simplex.sort(sortOrder);
        return { fx: simplex[0].fx,
            x: simplex[0] };
    }
949968
def get_prinz_pot(nstep, x0=0., nskip=1, dt=0.01, kT=10.0, mass=1.0, damping=1.0):
    """
    pw = PrinzModel(dt, kT, mass=mass, damping=damping)
    return pw.sample(x0, nstep, nskip=nskip)
1258258
private static function _hue2rgb( $m1, $m2, $h )
	{
		$h = ( $h < 0 ) ? $h + 1 : ( ( $h > 1 ) ? $h - 1 : $h );
		if ( $h * 6 < 1 ) return $m1 + ( $m2 - $m1 ) * $h * 6;
		if ( $h * 2 < 1 ) return $m2;
		if ( $h * 3 < 2 ) return $m1 + ( $m2 - $m1 ) * ( 0.66666 - $h ) * 6;
		return $m1;
	}
1327164
public static int fromHSL(float h, float s, float l, int a) {
        int r, g, b;

        if (s == 0) {
            r = g = b = (int) (l * MAX);
        } else {
            float v1, v2;
            float hue = h / 360f;

            v2 = (l < 0.5) ? (l * (1 + s)) : ((l + s) - (l * s));
            v1 = 2 * l - v2;

            r = (int) (MAX * HueToRGB(v1, v2, hue + (1.0f / 3)));
            g = (int) (MAX * HueToRGB(v1, v2, hue));
            b = (int) (MAX * HueToRGB(v1, v2, hue - (1.0f / 3)));
        }

        return getARGB(r, g, b, a);
    }
697167
private static int isTashkeelOnTatweelChar(char ch){
        if (ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75 && ch != SHADDA_TATWEEL_CHAR)
        {
            return tashkeelMedial [ch - 0xFE70];
        } else if( (ch >= 0xfcf2 && ch <= 0xfcf4) || (ch == SHADDA_TATWEEL_CHAR)) {
            return 2;
        } else {
            return 0;
        }
    }
1141866
def gammalnStirling(z):
    
    return (0.5 * (np.log(2. * np.pi) - np.log(z))) \
           + (z * (np.log(z + (1. / ((12. * z) - (1. / (10. * z))))) - 1.))
1199976
function compress(data) {
    var HLOG = 16;
    var HSIZE = (1 << HLOG);
    var LZF_MAX_OFF = (1 << 13);
    var LZF_MAX_REF = ((1 << 8) + (1 << 3));
    var LZF_MAX_LIT = (1 <<  5);

    function FRST(data, p) {
        return (((data[p]) << 8) | data[p+1]);
    }

    function NEXT(v, data, p) {
        return (((v) << 8) | data[p+2]);
    }

    function IDX(h) {
        return (((h * 0x1e35a7bd) >> (32 - HLOG - 8)) & (HSIZE - 1));
    }

    var input = new Uint8Array(data);
    var output = [];
    var htab = new Uint32Array(HSIZE);

    var in_end = input.length, ip = 0, hval = FRST(input, ip);
    var op = 1, lit = 0; /* start run */

    while (ip < in_end - 2) {
        hval = NEXT(hval, data, ip);
        var hslot = IDX(hval);
        var ref = htab[hslot];
        htab[hslot] = ip;

        var off;

        if (ref < ip /* the next test will actually take care of this, but this is faster */
            && (off = ip - ref - 1) < LZF_MAX_OFF
            && ref > 0
            && input[ref + 2] == input[ip + 2]
            && input[ref + 1] == input[ip + 1]
            && input[ref] == input[ip]
        ) {
            /* match found at *ref++ */
            var len = 2;
            var maxlen = in_end - ip - len;
            maxlen = maxlen > LZF_MAX_REF ? LZF_MAX_REF : maxlen;

            output[op - lit - 1] = (lit - 1) & 255; /* stop run */
            if (lit == 0) {
                op -= 1; /* undo run if length is zero */
            }

            do {
                len++;
            }
            while (len < maxlen && input[ref + len] == input[ip + len]);

            len -= 2; /* len is now #octets - 1 */
            ip++;

            if (len < 7) {
                output[op++] = ((off >> 8) + (len << 5)) & 255;
            } else {
                output[op++] = ((off >> 8) + (7 << 5)) & 255;
                output[op++] = (len - 7) & 255;
            }

            output[op++] = off & 255;

            lit = 0; op++; /* start run */

            ip += len + 1;

            if (ip >= in_end - 2) {
                break;
            }

            --ip;
            --ip;
            hval = FRST(input, ip);

            hval = NEXT(hval, input, ip);
            htab[IDX(hval)] = ip++;

            hval = NEXT(hval, input, ip);
            htab[IDX(hval)] = ip++;
        } else {
            lit++;
            output[op++] = input[ip++];

            if (lit == LZF_MAX_LIT) {
                output[op - lit - 1] = (lit - 1) & 255; /* stop run */
                lit = 0; op++; /* start run */
            }
        }
    }

    while (ip < in_end) {
        lit++;
        output[op++] = input[ip++];

        if (lit == LZF_MAX_LIT) {
            output[op - lit - 1] = (lit - 1) & 255; /* stop run */
            lit = 0; op++; /* start run */
        }
    }

    if (lit != 0) {
        output[op - lit - 1] = (lit - 1) & 255; /* stop run */
    }

    // Return a Buffer if it exists (say in node), otherwise just
    // use a normal Uint8Array.
    if (typeof Buffer !== 'undefined') {
        return new Buffer(output);
    } else {
        var res = new Uint8Array(output.length);
        res.set(output);
        return res;
    }
}
222359
def mpixel(self, z, n=0):
        """"""
        z = z * z + self.c
        if (abs(z) > 2.0):
            return self.color(n)
        n += 1
        if (n > self.max_iter):
            return None
        return self.mpixel(z, n)
349417
def pad_z(pts, value=0.0):
    """"""
    pts = np.asarray(pts)
    if pts.shape[-1] < 3:
        if len(pts.shape) < 2:
            return np.asarray((pts[0], pts[1], value), dtype=pts.dtype)
        pad_col = np.full(len(pts), value, dtype=pts.dtype)
        pts = np.asarray((pts.T[0], pts.T[1], pad_col)).T
    return pts
898140
function blackHeight(x, z) {
    if (x === z) {
        return 0;
    }
    else {
        var hL = blackHeight(x.l, z);
        if (hL >= 0) {
            var hR = blackHeight(x.r, z);
            if (hR >= 0) {
                if (hR === hR) {
                    return x.flag ? hL : hL + 1;
                }
            }
        }
        return -1;
    }
}