// Sub returns the difference betweeen vectors u and v.
770583
func (u Vec) Sub(v Vec) Vec {
	return Vec{
		u.X - v.X,
		u.Y - v.Y,
	}
}
789719
func (s *Stats) Sub(other *Stats) Stats {
	if other == nil {
		return *s
	}
	var diff Stats
	diff.FreePageN = s.FreePageN
	diff.PendingPageN = s.PendingPageN
	diff.FreeAlloc = s.FreeAlloc
	diff.FreelistInuse = s.FreelistInuse
	diff.TxN = s.TxN - other.TxN
	diff.TxStats = s.TxStats.Sub(&other.TxStats)
	return diff
}
315079
func (m1 Mat4x2) Sub(m2 Mat4x2) Mat4x2 {
	return Mat4x2{m1[0] - m2[0], m1[1] - m2[1], m1[2] - m2[2], m1[3] - m2[3], m1[4] - m2[4], m1[5] - m2[5], m1[6] - m2[6], m1[7] - m2[7]}
}
1049690
func substitute(src, sub, repl string) string {
	idx := strings.Index(src, sub)
	for idx >= 0 {
		src = src[:idx] + repl + src[idx+len(sub):]
		idx = strings.Index(src, sub)
	}
	return src
}
877449
func (x Vector) Diff() Vector {
	n := len(x)

	if n < 2 {
		return Vector{NA}
	} else {
		d := make(Vector, n-1)

		i := 1
		for i < n {
			d[i-1] = x[i] - x[i-1]
			i++
		}
		return d
	}
}
609460
func (this *Context) Sub(s interface{}) *Context {
    isEmpty := this.Empty()

    switch t := s.(type) {
    case string:
        i, ok := this.Names[t]
        if !ok {
            panic("submatch not exist: " + t)
        }

        var result *Context
        if isEmpty {
            result = this.createEmptySub()
        } else {
            result = NewDoc(this.List[i])
            result.Parent = this
        }

        return result
    case int:
        if len(this.List) < t + 1 && !isEmpty {
            panic(fmt.Sprintf("submatch index not exist: %d", t))
        }

        var result *Context
        if isEmpty {
            result = this.createEmptySub()
        } else {
            result = NewDoc(this.List[t])
            result.Parent = this
        }

        return result
    default:
        panic(fmt.Sprintf("invalid sub index: %v", s))
    }
}
601269
func (vec *T) Sub(v *T) *T {
	vec[0] -= v[0]
	vec[1] -= v[1]
	return vec
}
384114
func Sub(a, b []float64) {
	b = b[:len(a)]
	for i, v := range a {
		a[i] = v - b[i]
	}
}
1052581
func (c RGBA) Sub(d RGBA) RGBA {
	return RGBA{
		R: c.R - d.R,
		G: c.G - d.G,
		B: c.B - d.B,
		A: c.A - d.A,
	}
}
700246
func (met *Metrics) SubF(name string, value float64) {
	rounded := math.Floor(value + 0.5)
	atomic.AddInt64(met.get(name), int64(-rounded))
}
694739
func substVar(s string, noMatch string, sep string) (string, string) {
	endPos := strings.Index(s, sep)
	if endPos == -1 {
		return noMatch, s
	}

	v, ok := lookupVar(s[:endPos])
	if !ok {
		return noMatch, s
	}

	return v, s[endPos+1:]
}
1194388
func SubU64x2(x, y U64x2) U64x2 {
	val := U64x2{}
	for i := 0; i < 2; i++ {
		val[i] = x[i] - y[i]
	}
	return val
}
955378
func (m *Matrix) SubMatrix(i, j, rows, cols int) *Matrix {
	return &Matrix{
		elements: m.elements[i*m.stride+j : i*m.stride+j+(rows-1)*m.stride+cols],
		stride:   m.stride,
		epsilon:  m.epsilon,
	}
}
203456
func Sub(a, b []float64) {
	if len(a) != len(b) {
		panic("vectors must be the same length")
	}
	subAsm(a, b)
}
370167
func Sub(z, x *big.Int, y uint64) *big.Int {
	zw := z.Bits()
	switch xw := x.Bits(); {
	default:
		zw = sub(zw, xw, big.Word(y))
	case y == 0:
		zw = set(zw, xw)
	case len(xw) == 0:
		panic("underflow")
	}
	return z.SetBits(zw)
}
862279
func (c Context) Sub(z, x, y *Big) *Big {
	if debug {
		x.validate()
		y.validate()
	}
	if z.invalidContext(c) {
		return z
	}

	if x.IsFinite() && y.IsFinite() {
		z.form = c.add(z, x, x.form, y, y.form^signbit)
		return c.round(z)
	}

	// NaN - NaN
	// NaN - y
	// x - NaN
	if z.checkNaNs(x, y, subtraction) {
		return z
	}

	if x.form&inf != 0 {
		if y.form&inf != 0 && (x.form&signbit == y.form&signbit) {
			// -Inf - -Inf
			// -Inf - -Inf
			return z.setNaN(InvalidOperation, qnan, subinfinf)
		}
		// ±Inf - y
		// -Inf - +Inf
		// +Inf - -Inf
		return z.Set(x)
	}
	// x - ±Inf
	return z.Neg(y)
}
1136925
func SliceSubsetOf(sub, main []string) (bool, []string) {
	var diff []string
	occurences := make(map[string]int, len(main))
	result := true
	for _, element := range main {
		occurences[element]++
	}
	for _, element := range sub {
		if count, ok := occurences[element]; !ok {
			// Element was not found in the main slice.
			result = false
			diff = append(diff, element)
		} else if count < 1 {
			// The element is in both slices, but the sub slice
			// has more duplicates.
			result = false
		} else {
			occurences[element]--
		}
	}
	return result, diff
}