#136: Start working on database persistence

This commit is contained in:
TwinProduction
2021-07-12 00:56:30 -04:00
committed by Chris
parent e6335da94f
commit bd1eb7c61b
657 changed files with 2190821 additions and 82 deletions

13
vendor/modernc.org/mathutil/AUTHORS generated vendored Normal file
View File

@ -0,0 +1,13 @@
# This file lists authors for copyright purposes. This file is distinct from
# the CONTRIBUTORS files. See the latter for an explanation.
#
# Names should be added to this file as:
# Name or Organization <email address>
#
# The email address is not required for organizations.
#
# Please keep the list sorted.
CZ.NIC z.s.p.o. <kontakt@nic.cz>
Edward Betts <edward@4angle.com>
Jan Mercl <0xjnml@gmail.com>

14
vendor/modernc.org/mathutil/CONTRIBUTORS generated vendored Normal file
View File

@ -0,0 +1,14 @@
# This file lists people who contributed code to this repository. The AUTHORS
# file lists the copyright holders; this file lists people.
#
# Names should be added to this file like so:
# Name <email address>
#
# Please keep the list sorted.
Bodecker DellaMaria <bojdell@gmail.com>
Edward Betts <edward@4angle.com>
Faiz Abbasi <faizamodo@gmail.com>
Gary Burd <gary@beagledreams.com>
Jan Mercl <0xjnml@gmail.com>
Muhammad Surya <surya.asriadie@gmail.com>

27
vendor/modernc.org/mathutil/LICENSE generated vendored Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2014 The mathutil Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the names of the authors nor the names of the
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

56
vendor/modernc.org/mathutil/Makefile generated vendored Normal file
View File

@ -0,0 +1,56 @@
# Copyright (c) 2016 The mathutil Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
.PHONY: all clean cover cpu editor internalError later mem nuke todo edit
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
ngrep='TODOOK\|parser\.go\|scanner\.go\|.*_string\.go'
all: editor
go vet 2>&1 | grep -v $(ngrep) || true
golint 2>&1 | grep -v $(ngrep) || true
make todo
misspell *.go
unconvert || true
maligned || true
staticcheck || true
clean:
go clean
rm -f *~ *.test *.out
cover:
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
cpu: clean
go test -run @ -bench . -cpuprofile cpu.out
go tool pprof -lines *.test cpu.out
edit:
@ 1>/dev/null 2>/dev/null gvim -p Makefile *.go &
editor:
gofmt -l -s -w *.go
go test
go build
internalError:
egrep -ho '"internal error.*"' *.go | sort | cat -n
later:
@grep -n $(grep) LATER * || true
@grep -n $(grep) MAYBE * || true
mem: clean
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
go tool pprof -lines -web -alloc_space *.test mem.out
nuke: clean
go clean -i
todo:
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
@grep -nr $(grep) TODO * | grep -v $(ngrep) || true
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true

10
vendor/modernc.org/mathutil/README generated vendored Normal file
View File

@ -0,0 +1,10 @@
This is a goinstall-able mirror of modified code already published at:
http://git.nic.cz/redmine/projects/gornd/repository
Packages in this repository:
Install: $ go get modernc.org/mathutil
Godocs: http://godoc.org/modernc.org/mathutil
Install: $ go get modernc.org/mathutil/mersenne
Godocs: http://godoc.org/modernc.org/mathutil/mersenne

88
vendor/modernc.org/mathutil/binarylog.go generated vendored Normal file
View File

@ -0,0 +1,88 @@
// Copyright (c) 2016 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"math/big"
"github.com/remyoudompheng/bigfft"
)
type float struct {
n *big.Int
fracBits int
maxFracBits int
}
func newFloat(n *big.Int, fracBits, maxFracBits int) float {
f := float{n: n, fracBits: fracBits, maxFracBits: maxFracBits}
f.normalize()
return f
}
func (f *float) normalize() {
n := f.n.BitLen()
if n == 0 {
return
}
if n := f.fracBits - f.maxFracBits; n > 0 {
bit := f.n.Bit(n - 1)
f.n.Rsh(f.n, uint(n))
if bit != 0 {
f.n.Add(f.n, _1)
}
f.fracBits -= n
}
var i int
for ; f.fracBits > 0 && i <= f.fracBits && f.n.Bit(i) == 0; i++ {
f.fracBits--
}
if i != 0 {
f.n.Rsh(f.n, uint(i))
}
}
func (f *float) eq1() bool { return f.fracBits == 0 && f.n.BitLen() == 1 }
func (f *float) ge2() bool { return f.n.BitLen() > f.fracBits+1 }
func (f *float) div2() {
f.fracBits++
f.normalize()
}
func (f *float) sqr() {
f.n = bigfft.Mul(f.n, f.n)
f.fracBits *= 2
f.normalize()
}
// BinaryLog computes the binary logarithm of n. The result consists of a
// characteristic and a mantissa having precision mantissaBits. The value of
// the binary logarithm is
//
// characteristic + mantissa*(2^-mantissaBits)
//
// BinaryLog panics for n <= 0 or mantissaBits < 0.
func BinaryLog(n *big.Int, mantissaBits int) (characteristic int, mantissa *big.Int) {
if n.Sign() <= 0 || mantissaBits < 0 {
panic("invalid argument of BinaryLog")
}
characteristic = n.BitLen() - 1
mantissa = big.NewInt(0)
x := newFloat(n, characteristic, mantissaBits)
for ; mantissaBits != 0 && !x.eq1(); mantissaBits-- {
x.sqr()
mantissa.Lsh(mantissa, 1)
if x.ge2() {
mantissa.SetBit(mantissa, 0, 1)
x.div2()
}
}
return characteristic, mantissa
}

207
vendor/modernc.org/mathutil/bits.go generated vendored Normal file
View File

@ -0,0 +1,207 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"math/big"
)
// BitLenByte returns the bit width of the non zero part of n.
func BitLenByte(n byte) int {
return log2[n] + 1
}
// BitLenUint16 returns the bit width of the non zero part of n.
func BitLenUint16(n uint16) int {
if b := n >> 8; b != 0 {
return log2[b] + 8 + 1
}
return log2[n] + 1
}
// BitLenUint32 returns the bit width of the non zero part of n.
func BitLenUint32(n uint32) int {
if b := n >> 24; b != 0 {
return log2[b] + 24 + 1
}
if b := n >> 16; b != 0 {
return log2[b] + 16 + 1
}
if b := n >> 8; b != 0 {
return log2[b] + 8 + 1
}
return log2[n] + 1
}
// BitLen returns the bit width of the non zero part of n.
func BitLen(n int) int { // Should handle correctly [future] 64 bit Go ints
if IntBits == 64 {
return BitLenUint64(uint64(n))
}
if b := byte(n >> 24); b != 0 {
return log2[b] + 24 + 1
}
if b := byte(n >> 16); b != 0 {
return log2[b] + 16 + 1
}
if b := byte(n >> 8); b != 0 {
return log2[b] + 8 + 1
}
return log2[byte(n)] + 1
}
// BitLenUint returns the bit width of the non zero part of n.
func BitLenUint(n uint) int { // Should handle correctly [future] 64 bit Go uints
if IntBits == 64 {
return BitLenUint64(uint64(n))
}
if b := n >> 24; b != 0 {
return log2[b] + 24 + 1
}
if b := n >> 16; b != 0 {
return log2[b] + 16 + 1
}
if b := n >> 8; b != 0 {
return log2[b] + 8 + 1
}
return log2[n] + 1
}
// BitLenUint64 returns the bit width of the non zero part of n.
func BitLenUint64(n uint64) int {
if b := n >> 56; b != 0 {
return log2[b] + 56 + 1
}
if b := n >> 48; b != 0 {
return log2[b] + 48 + 1
}
if b := n >> 40; b != 0 {
return log2[b] + 40 + 1
}
if b := n >> 32; b != 0 {
return log2[b] + 32 + 1
}
if b := n >> 24; b != 0 {
return log2[b] + 24 + 1
}
if b := n >> 16; b != 0 {
return log2[b] + 16 + 1
}
if b := n >> 8; b != 0 {
return log2[b] + 8 + 1
}
return log2[n] + 1
}
// BitLenUintptr returns the bit width of the non zero part of n.
func BitLenUintptr(n uintptr) int {
if b := n >> 56; b != 0 {
return log2[b] + 56 + 1
}
if b := n >> 48; b != 0 {
return log2[b] + 48 + 1
}
if b := n >> 40; b != 0 {
return log2[b] + 40 + 1
}
if b := n >> 32; b != 0 {
return log2[b] + 32 + 1
}
if b := n >> 24; b != 0 {
return log2[b] + 24 + 1
}
if b := n >> 16; b != 0 {
return log2[b] + 16 + 1
}
if b := n >> 8; b != 0 {
return log2[b] + 8 + 1
}
return log2[n] + 1
}
// PopCountByte returns population count of n (number of bits set in n).
func PopCountByte(n byte) int {
return int(popcnt[n])
}
// PopCountUint16 returns population count of n (number of bits set in n).
func PopCountUint16(n uint16) int {
return int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)])
}
// PopCountUint32 returns population count of n (number of bits set in n).
func PopCountUint32(n uint32) int {
return int(popcnt[byte(n>>24)]) + int(popcnt[byte(n>>16)]) +
int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)])
}
// PopCount returns population count of n (number of bits set in n).
func PopCount(n int) int { // Should handle correctly [future] 64 bit Go ints
if IntBits == 64 {
return PopCountUint64(uint64(n))
}
return PopCountUint32(uint32(n))
}
// PopCountUint returns population count of n (number of bits set in n).
func PopCountUint(n uint) int { // Should handle correctly [future] 64 bit Go uints
if IntBits == 64 {
return PopCountUint64(uint64(n))
}
return PopCountUint32(uint32(n))
}
// PopCountUintptr returns population count of n (number of bits set in n).
func PopCountUintptr(n uintptr) int {
if UintPtrBits == 64 {
return PopCountUint64(uint64(n))
}
return PopCountUint32(uint32(n))
}
// PopCountUint64 returns population count of n (number of bits set in n).
func PopCountUint64(n uint64) int {
return int(popcnt[byte(n>>56)]) + int(popcnt[byte(n>>48)]) +
int(popcnt[byte(n>>40)]) + int(popcnt[byte(n>>32)]) +
int(popcnt[byte(n>>24)]) + int(popcnt[byte(n>>16)]) +
int(popcnt[byte(n>>8)]) + int(popcnt[byte(n)])
}
// PopCountBigInt returns population count of |n| (number of bits set in |n|).
func PopCountBigInt(n *big.Int) (r int) {
for _, v := range n.Bits() {
r += PopCountUintptr(uintptr(v))
}
return
}

46
vendor/modernc.org/mathutil/envelope.go generated vendored Normal file
View File

@ -0,0 +1,46 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"math"
)
// Approximation type determines approximation methods used by e.g. Envelope.
type Approximation int
// Specific approximation method tags
const (
_ Approximation = iota
Linear // As named
Sinusoidal // Smooth for all derivations
)
// Envelope is an utility for defining simple curves using a small (usually)
// set of data points. Envelope returns a value defined by x, points and
// approximation. The value of x must be in [0,1) otherwise the result is
// undefined or the function may panic. Points are interpreted as dividing the
// [0,1) interval in len(points)-1 sections, so len(points) must be > 1 or the
// function may panic. According to the left and right points closing/adjacent
// to the section the resulting value is interpolated using the chosen
// approximation method. Unsupported values of approximation are silently
// interpreted as 'Linear'.
func Envelope(x float64, points []float64, approximation Approximation) float64 {
step := 1 / float64(len(points)-1)
fslot := math.Floor(x / step)
mod := x - fslot*step
slot := int(fslot)
l, r := points[slot], points[slot+1]
rmod := mod / step
switch approximation {
case Sinusoidal:
k := (math.Sin(math.Pi*(rmod-0.5)) + 1) / 2
return l + (r-l)*k
case Linear:
fallthrough
default:
return l + (r-l)*rmod
}
}

5
vendor/modernc.org/mathutil/go.mod generated vendored Normal file
View File

@ -0,0 +1,5 @@
module modernc.org/mathutil
go 1.13
require github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0

2
vendor/modernc.org/mathutil/go.sum generated vendored Normal file
View File

@ -0,0 +1,2 @@
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=

279
vendor/modernc.org/mathutil/int.go generated vendored Normal file
View File

@ -0,0 +1,279 @@
// Copyright (c) 2018 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"fmt"
"math"
"math/big"
)
var (
// MaxInt128 represents the maximun Int128 value as big.Int
MaxInt128 *big.Int
// MinInt128 represents the minimun Int128 value as big.Int
MinInt128 *big.Int
// MaxUint128 represents the maximun Uint128 value as big.Int
MaxUint128 *big.Int
)
func init() {
var ok bool
MaxInt128, ok = big.NewInt(0).SetString("0x7fffffff_ffffffff_ffffffff_ffffffff", 0)
if !ok {
panic("internal error")
}
MinInt128 = big.NewInt(0).Set(MaxInt128)
MinInt128.Add(MinInt128, _1)
MinInt128.Neg(MinInt128)
MaxUint128, ok = big.NewInt(0).SetString("0xffffffff_ffffffff_ffffffff_ffffffff", 0)
if !ok {
panic("internal error")
}
}
const (
maxInt128 = 1<<127 - 1
maxUint128 = 1<<128 - 1
minInt128 = -maxInt128 - 1
)
// Int128 is an 128 bit signed integer.
type Int128 struct {
Lo int64 // Bits 63..0.
Hi int64 // Bits 127..64.
}
// Add returns the sum of x and y and a carry indication.
func (x Int128) Add(y Int128) (r Int128, cy bool) {
r.Lo = x.Lo + y.Lo
r.Hi = x.Hi + y.Hi
if uint64(r.Lo) < uint64(x.Lo) {
r.Hi++
}
return r, (r.Cmp(x) < 0) == (y.Sign() >= 0)
}
// BigInt returns x in the form of a big.Int.
func (x Int128) BigInt() *big.Int {
r := big.NewInt(x.Hi)
r.Lsh(r, 64)
lo := big.NewInt(0)
lo.SetUint64(uint64(x.Lo))
return r.Add(r, lo)
}
// Cmp compares x and y and returns:
//
// -1 if x < y
// 0 if x == y
// +1 if x > y
func (x Int128) Cmp(y Int128) int {
if x.Hi > y.Hi {
return 1
}
if x.Hi < y.Hi {
return -1
}
if uint64(x.Lo) > uint64(y.Lo) {
return 1
}
if uint64(x.Lo) < uint64(y.Lo) {
return -1
}
return 0
}
// Neg returns -x and an indication that x was not equal to MinInt128.
func (x Int128) Neg() (r Int128, ok bool) {
if x == (Int128{Hi: math.MinInt64}) {
return x, false
}
x.Lo = ^x.Lo
x.Hi = ^x.Hi
r, _ = x.Add(Int128{Lo: 1})
return r, true
}
// SetBigInt sets x to y, returns x and an error, if any.
func (x *Int128) SetBigInt(y *big.Int) (r Int128, err error) {
if y.Cmp(MaxInt128) > 0 {
return *x, fmt.Errorf("%T.SetInt: overflow", x)
}
if y.Cmp(MinInt128) < 0 {
return *x, fmt.Errorf("%T.SetInt: underflow", x)
}
neg := y.Sign() < 0
var z big.Int
z.Set(y)
if neg {
z.Neg(&z)
}
r.Lo = z.Int64()
z.Rsh(&z, 64)
r.Hi = z.Int64()
if neg {
r, _ = r.Neg()
}
*x = r
return r, nil
}
// SetInt64 sets x to y and returns x.
func (x *Int128) SetInt64(y int64) (r Int128) {
r.Lo = y
if y >= 0 {
r.Hi = 0
*x = r
return r
}
r.Hi = -1
*x = r
return r
}
// SetUint64 sets x to y and returns x.
func (x *Int128) SetUint64(y uint64) (r Int128) {
r = Int128{Lo: int64(y)}
*x = r
return r
}
// Sign returns:
//
// -1 if x < 0
// 0 if x == 0
// +1 if x > 0
func (x Int128) Sign() int {
if x.Hi < 0 {
return -1
}
if x.Hi != 0 || x.Lo != 0 {
return 1
}
return 0
}
// String implements fmt.Stringer()
func (x Int128) String() string { return x.BigInt().String() }
// NewInt128FromInt64 return a new Int128 value initialized to n.
func NewInt128FromInt64(n int64) (r Int128) {
r.Lo = n
if n < 0 {
r.Hi = -1
}
return r
}
// NewInt128FromUint64 return a new Int128 value initialized to n.
func NewInt128FromUint64(n uint64) (r Int128) { return Int128{Lo: int64(n)} }
// NewInt128FromFloat32 returns a new Int128 value initialized to n. Result is
// not specified in n does not represent a number within the range of Int128
// values.
func NewInt128FromFloat32(n float32) (r Int128) {
if n >= minInt128 && n <= maxInt128 {
if n >= math.MinInt64 && n <= math.MaxInt64 {
return NewInt128FromInt64(int64(n))
}
f := big.NewFloat(float64(n))
bi, _ := f.Int(nil)
r.SetBigInt(bi)
}
return r
}
// NewInt128FromFloat64 returns a new Int128 value initialized to n. Result is
// not specified in n does not represent a number within the range of Int128
// values.
func NewInt128FromFloat64(n float64) (r Int128) {
if n >= minInt128 && n <= maxInt128 {
if n >= math.MinInt64 && n <= math.MaxInt64 {
return NewInt128FromInt64(int64(n))
}
f := big.NewFloat(n)
bi, _ := f.Int(nil)
r.SetBigInt(bi)
}
return r
}
// Uint128 is an 128 bit unsigned integer.
type Uint128 struct {
Lo uint64 // Bits 63..0.
Hi uint64 // Bits 127..64.
}
// NewUint128FromInt64 return a new Uint128 value initialized to n.
func NewUint128FromInt64(n int64) (r Uint128) {
r.Lo = uint64(n)
if n < 0 {
r.Hi = ^uint64(0)
}
return r
}
// NewUint128FromUint64 return a new Uint128 value initialized to n.
func NewUint128FromUint64(n uint64) (r Uint128) { return Uint128{Lo: n} }
// NewUint128FromFloat32 returns a new Uint128 value initialized to n. Result is
// not specified in n does not represent a number within the range of Uint128
// values.
func NewUint128FromFloat32(n float32) (r Uint128) {
if n >= 0 {
if n <= math.MaxUint64 {
return NewUint128FromUint64(uint64(n))
}
f := big.NewFloat(float64(n))
bi, _ := f.Int(nil)
r.SetBigInt(bi)
}
return r
}
// NewUint128FromFloat64 returns a new Uint128 value initialized to n. Result is
// not specified in n does not represent a number within the range of Uint128
// values.
func NewUint128FromFloat64(n float64) (r Uint128) {
if n >= 0 && n <= maxUint128 {
if n <= math.MaxUint64 {
return NewUint128FromUint64(uint64(n))
}
f := big.NewFloat(n)
bi, _ := f.Int(nil)
r.SetBigInt(bi)
}
return r
}
// SetBigInt sets x to y, returns x and an error, if any.
func (x *Uint128) SetBigInt(y *big.Int) (r Uint128, err error) {
if y.Sign() < 0 || y.Cmp(MaxUint128) > 0 {
return *x, fmt.Errorf("%T.SetInt: overflow", x)
}
var z big.Int
z.Set(y)
r.Lo = z.Uint64()
z.Rsh(&z, 64)
r.Hi = z.Uint64()
*x = r
return r, nil
}

1604
vendor/modernc.org/mathutil/mathutil.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

267
vendor/modernc.org/mathutil/nist-sts-2-1-1-report generated vendored Normal file
View File

@ -0,0 +1,267 @@
$ ./example -max 100000000 > rnd.dat
$ ./assess 1000000
G E N E R A T O R S E L E C T I O N
______________________________________
[0] Input File [1] Linear Congruential
[2] Quadratic Congruential I [3] Quadratic Congruential II
[4] Cubic Congruential [5] XOR
[6] Modular Exponentiation [7] Blum-Blum-Shub
[8] Micali-Schnorr [9] G Using SHA-1
Enter Choice: 0
User Prescribed Input File: rnd.dat
S T A T I S T I C A L T E S T S
_________________________________
[01] Frequency [02] Block Frequency
[03] Cumulative Sums [04] Runs
[05] Longest Run of Ones [06] Rank
[07] Discrete Fourier Transform [08] Nonperiodic Template Matchings
[09] Overlapping Template Matchings [10] Universal Statistical
[11] Approximate Entropy [12] Random Excursions
[13] Random Excursions Variant [14] Serial
[15] Linear Complexity
INSTRUCTIONS
Enter 0 if you DO NOT want to apply all of the
statistical tests to each sequence and 1 if you DO.
Enter Choice: 1
P a r a m e t e r A d j u s t m e n t s
-----------------------------------------
[1] Block Frequency Test - block length(M): 128
[2] NonOverlapping Template Test - block length(m): 9
[3] Overlapping Template Test - block length(m): 9
[4] Approximate Entropy Test - block length(m): 10
[5] Serial Test - block length(m): 16
[6] Linear Complexity Test - block length(M): 500
Select Test (0 to continue): 0
How many bitstreams? 200
Input File Format:
[0] ASCII - A sequence of ASCII 0's and 1's
[1] Binary - Each byte in data file contains 8 bits of data
Select input mode: 1
Statistical Testing In Progress.........
Statistical Testing Complete!!!!!!!!!!!!
$ cat experiments/AlgorithmTesting/finalAnalysisReport.txt
------------------------------------------------------------------------------
RESULTS FOR THE UNIFORMITY OF P-VALUES AND THE PROPORTION OF PASSING SEQUENCES
------------------------------------------------------------------------------
generator is <rnd.dat>
------------------------------------------------------------------------------
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 P-VALUE PROPORTION STATISTICAL TEST
------------------------------------------------------------------------------
28 22 17 19 15 8 24 23 19 25 0.093720 198/200 Frequency
20 18 24 14 18 17 16 28 21 24 0.504219 199/200 BlockFrequency
25 22 17 24 19 21 22 15 16 19 0.825505 197/200 CumulativeSums
27 17 16 22 14 26 14 25 19 20 0.304126 199/200 CumulativeSums
22 19 14 23 22 22 13 28 13 24 0.224821 199/200 Runs
20 24 18 21 15 13 22 23 24 20 0.719747 197/200 LongestRun
22 26 18 22 26 15 17 22 20 12 0.410055 199/200 Rank
25 22 26 22 20 16 20 20 16 13 0.585209 195/200 FFT
22 11 15 26 33 24 21 13 14 21 0.013102 197/200 NonOverlappingTemplate
17 11 16 27 19 24 19 20 28 19 0.219006 200/200 NonOverlappingTemplate
23 27 24 15 21 11 18 27 15 19 0.162606 197/200 NonOverlappingTemplate
21 18 13 20 19 23 20 17 26 23 0.749884 197/200 NonOverlappingTemplate
24 22 24 24 24 21 13 15 17 16 0.494392 196/200 NonOverlappingTemplate
24 16 23 15 23 18 25 16 18 22 0.699313 199/200 NonOverlappingTemplate
19 23 21 16 27 18 17 20 18 21 0.859637 198/200 NonOverlappingTemplate
12 20 16 19 26 14 30 20 24 19 0.141256 198/200 NonOverlappingTemplate
18 21 17 21 20 14 25 19 24 21 0.859637 198/200 NonOverlappingTemplate
24 25 21 18 23 15 23 17 16 18 0.749884 199/200 NonOverlappingTemplate
20 22 22 18 16 22 28 16 14 22 0.574903 198/200 NonOverlappingTemplate
18 23 22 17 24 25 19 16 23 13 0.626709 199/200 NonOverlappingTemplate
17 22 14 19 21 21 18 19 24 25 0.842937 198/200 NonOverlappingTemplate
18 17 26 21 22 15 22 18 21 20 0.883171 197/200 NonOverlappingTemplate
19 25 16 32 15 19 20 18 16 20 0.236810 199/200 NonOverlappingTemplate
19 18 15 21 24 22 18 21 20 22 0.964295 200/200 NonOverlappingTemplate
21 14 17 23 26 19 20 22 20 18 0.834308 196/200 NonOverlappingTemplate
15 21 17 27 26 23 21 17 24 9 0.129620 198/200 NonOverlappingTemplate
25 17 19 19 18 22 21 22 21 16 0.951205 196/200 NonOverlappingTemplate
20 19 24 21 19 24 16 18 17 22 0.946308 197/200 NonOverlappingTemplate
27 16 19 18 23 19 22 17 22 17 0.807412 197/200 NonOverlappingTemplate
14 18 21 23 23 20 14 22 20 25 0.719747 198/200 NonOverlappingTemplate
18 22 19 12 24 25 25 22 18 15 0.474986 198/200 NonOverlappingTemplate
21 18 23 17 19 18 28 19 20 17 0.825505 198/200 NonOverlappingTemplate
20 19 15 16 27 20 26 17 20 20 0.657933 198/200 NonOverlappingTemplate
17 25 21 21 11 19 22 16 27 21 0.401199 198/200 NonOverlappingTemplate
19 16 15 18 24 19 25 25 19 20 0.769527 199/200 NonOverlappingTemplate
18 20 20 26 20 12 24 25 19 16 0.524101 198/200 NonOverlappingTemplate
14 16 18 23 21 21 19 19 28 21 0.668321 197/200 NonOverlappingTemplate
21 20 23 25 21 22 19 17 14 18 0.875539 197/200 NonOverlappingTemplate
14 16 29 22 23 13 20 29 17 17 0.099513 197/200 NonOverlappingTemplate
14 19 27 19 17 23 18 24 20 19 0.709558 199/200 NonOverlappingTemplate
18 15 21 19 27 22 21 23 17 17 0.779188 198/200 NonOverlappingTemplate
13 23 13 22 22 23 22 21 21 20 0.689019 199/200 NonOverlappingTemplate
17 14 26 26 16 21 30 15 21 14 0.096578 199/200 NonOverlappingTemplate
18 21 24 23 21 13 23 23 19 15 0.719747 197/200 NonOverlappingTemplate
19 21 14 32 20 15 16 18 24 21 0.202268 199/200 NonOverlappingTemplate
27 22 20 21 21 14 15 22 14 24 0.474986 196/200 NonOverlappingTemplate
31 12 25 11 21 18 19 16 24 23 0.050305 197/200 NonOverlappingTemplate
17 26 20 22 15 27 22 19 12 20 0.383827 199/200 NonOverlappingTemplate
15 22 14 14 31 15 27 18 23 21 0.078086 194/200 NonOverlappingTemplate
19 19 14 15 24 21 25 21 20 22 0.788728 197/200 NonOverlappingTemplate
20 21 19 22 25 18 13 24 28 10 0.153763 195/200 NonOverlappingTemplate
23 17 21 25 21 20 13 30 14 16 0.196920 196/200 NonOverlappingTemplate
17 31 17 22 16 15 28 23 11 20 0.050305 197/200 NonOverlappingTemplate
15 21 26 27 15 18 19 21 18 20 0.605916 198/200 NonOverlappingTemplate
23 18 15 14 20 21 20 20 20 29 0.554420 200/200 NonOverlappingTemplate
22 19 19 18 19 17 22 21 31 12 0.311542 199/200 NonOverlappingTemplate
16 22 23 21 19 19 18 24 21 17 0.960198 197/200 NonOverlappingTemplate
21 21 17 20 16 23 25 22 18 17 0.917870 200/200 NonOverlappingTemplate
27 17 17 16 21 20 22 18 21 21 0.859637 197/200 NonOverlappingTemplate
18 24 15 27 18 21 18 16 24 19 0.657933 199/200 NonOverlappingTemplate
13 16 21 21 15 25 18 22 29 20 0.326749 198/200 NonOverlappingTemplate
18 17 23 23 15 19 26 30 11 18 0.125927 198/200 NonOverlappingTemplate
30 21 18 22 17 21 15 17 21 18 0.544254 195/200 NonOverlappingTemplate
12 18 19 24 16 24 18 24 28 17 0.311542 199/200 NonOverlappingTemplate
20 15 23 15 18 30 23 18 17 21 0.410055 196/200 NonOverlappingTemplate
15 18 23 16 29 21 22 16 19 21 0.544254 200/200 NonOverlappingTemplate
18 16 27 13 21 22 22 21 16 24 0.534146 199/200 NonOverlappingTemplate
20 25 18 21 16 21 17 28 21 13 0.484646 200/200 NonOverlappingTemplate
23 22 13 22 14 20 26 18 19 23 0.574903 197/200 NonOverlappingTemplate
21 24 25 13 19 22 18 13 24 21 0.504219 199/200 NonOverlappingTemplate
19 13 18 25 22 15 23 28 19 18 0.410055 195/200 NonOverlappingTemplate
20 15 27 22 26 26 14 13 21 16 0.181557 198/200 NonOverlappingTemplate
18 18 19 23 18 20 19 21 24 20 0.991468 200/200 NonOverlappingTemplate
18 23 17 14 20 25 22 22 22 17 0.816537 198/200 NonOverlappingTemplate
26 15 15 11 23 21 21 16 36 16 0.005557 196/200 NonOverlappingTemplate
27 13 21 23 21 16 19 20 16 24 0.544254 198/200 NonOverlappingTemplate
16 15 32 17 20 23 22 19 20 16 0.262249 200/200 NonOverlappingTemplate
26 19 24 13 24 16 18 18 13 29 0.137282 199/200 NonOverlappingTemplate
15 18 14 27 32 21 15 20 19 19 0.112047 198/200 NonOverlappingTemplate
22 23 22 18 20 23 19 22 16 15 0.924076 196/200 NonOverlappingTemplate
18 17 21 22 14 17 22 24 20 25 0.798139 199/200 NonOverlappingTemplate
15 17 19 24 21 23 17 25 23 16 0.739918 196/200 NonOverlappingTemplate
22 11 15 26 32 25 21 13 14 21 0.017305 197/200 NonOverlappingTemplate
22 16 19 23 22 21 21 19 17 20 0.985788 200/200 NonOverlappingTemplate
22 28 18 24 14 20 23 21 20 10 0.230755 198/200 NonOverlappingTemplate
14 13 22 28 14 28 17 22 23 19 0.129620 197/200 NonOverlappingTemplate
22 16 22 20 21 21 16 19 18 25 0.935716 198/200 NonOverlappingTemplate
15 20 23 17 19 22 21 23 18 22 0.951205 200/200 NonOverlappingTemplate
20 24 21 19 17 19 19 24 15 22 0.930026 198/200 NonOverlappingTemplate
18 21 15 21 17 28 24 22 20 14 0.534146 200/200 NonOverlappingTemplate
19 15 19 19 20 20 15 25 23 25 0.779188 198/200 NonOverlappingTemplate
17 24 25 16 15 21 18 19 23 22 0.788728 198/200 NonOverlappingTemplate
15 20 18 25 24 15 21 31 18 13 0.141256 200/200 NonOverlappingTemplate
24 17 19 20 18 21 15 22 24 20 0.924076 196/200 NonOverlappingTemplate
23 18 17 21 17 28 23 21 18 14 0.605916 197/200 NonOverlappingTemplate
21 19 22 23 16 17 20 21 22 19 0.985788 200/200 NonOverlappingTemplate
27 17 21 27 24 15 15 17 15 22 0.304126 199/200 NonOverlappingTemplate
25 28 20 24 13 14 16 22 19 19 0.304126 197/200 NonOverlappingTemplate
27 16 14 24 22 18 24 20 18 17 0.564639 196/200 NonOverlappingTemplate
18 18 24 19 19 19 26 11 27 19 0.375313 195/200 NonOverlappingTemplate
20 15 29 19 26 16 21 11 18 25 0.141256 197/200 NonOverlappingTemplate
19 14 21 25 11 23 22 25 26 14 0.176657 199/200 NonOverlappingTemplate
18 23 20 17 19 18 29 22 26 8 0.102526 199/200 NonOverlappingTemplate
22 17 18 16 18 20 19 19 25 26 0.834308 198/200 NonOverlappingTemplate
25 18 14 16 16 24 18 18 30 21 0.268917 198/200 NonOverlappingTemplate
24 21 23 13 12 22 20 23 20 22 0.554420 196/200 NonOverlappingTemplate
18 21 21 30 22 17 19 14 18 20 0.534146 197/200 NonOverlappingTemplate
25 20 22 21 15 18 17 20 17 25 0.825505 199/200 NonOverlappingTemplate
18 21 22 21 18 20 26 16 20 18 0.941144 197/200 NonOverlappingTemplate
23 18 22 25 12 16 17 19 26 22 0.474986 198/200 NonOverlappingTemplate
22 18 29 23 19 23 17 17 15 17 0.534146 198/200 NonOverlappingTemplate
19 21 17 26 18 15 22 26 15 21 0.626709 197/200 NonOverlappingTemplate
16 20 20 23 18 21 18 18 25 21 0.955835 199/200 NonOverlappingTemplate
23 21 20 21 22 10 15 27 15 26 0.186566 198/200 NonOverlappingTemplate
18 26 20 26 26 18 17 17 20 12 0.358641 198/200 NonOverlappingTemplate
24 20 21 18 24 12 19 27 14 21 0.401199 195/200 NonOverlappingTemplate
16 25 15 21 24 18 18 25 22 16 0.657933 199/200 NonOverlappingTemplate
24 14 17 26 15 17 17 25 21 24 0.428095 200/200 NonOverlappingTemplate
22 24 11 20 22 24 19 18 12 28 0.176657 196/200 NonOverlappingTemplate
27 16 27 18 27 14 13 16 21 21 0.141256 197/200 NonOverlappingTemplate
23 25 20 18 23 17 15 23 19 17 0.834308 196/200 NonOverlappingTemplate
19 21 20 27 16 16 18 25 16 22 0.678686 199/200 NonOverlappingTemplate
25 22 21 19 15 19 22 19 25 13 0.657933 197/200 NonOverlappingTemplate
19 28 21 25 20 12 18 13 29 15 0.073417 198/200 NonOverlappingTemplate
20 24 21 19 21 15 17 24 20 19 0.941144 198/200 NonOverlappingTemplate
18 29 23 17 24 19 17 18 16 19 0.585209 200/200 NonOverlappingTemplate
18 28 18 16 25 21 18 20 14 22 0.544254 198/200 NonOverlappingTemplate
22 19 23 22 22 21 21 26 12 12 0.401199 199/200 NonOverlappingTemplate
22 15 25 16 21 27 14 22 21 17 0.484646 199/200 NonOverlappingTemplate
18 25 20 23 30 17 13 22 18 14 0.213309 200/200 NonOverlappingTemplate
20 23 21 21 23 29 16 13 16 18 0.410055 199/200 NonOverlappingTemplate
21 19 16 22 31 18 20 17 18 18 0.514124 198/200 NonOverlappingTemplate
26 22 12 14 23 17 21 24 21 20 0.455937 197/200 NonOverlappingTemplate
21 17 18 17 14 32 21 26 18 16 0.162606 197/200 NonOverlappingTemplate
22 24 22 23 11 15 17 18 29 19 0.230755 198/200 NonOverlappingTemplate
19 27 20 19 23 15 24 15 21 17 0.657933 198/200 NonOverlappingTemplate
20 25 16 10 24 13 23 21 21 27 0.149495 200/200 NonOverlappingTemplate
19 21 21 27 17 17 19 21 21 17 0.904708 200/200 NonOverlappingTemplate
18 23 15 19 24 21 23 21 13 23 0.719747 198/200 NonOverlappingTemplate
26 16 28 19 19 18 17 17 16 24 0.474986 199/200 NonOverlappingTemplate
24 32 17 18 20 13 18 18 19 21 0.236810 195/200 NonOverlappingTemplate
26 25 18 17 12 19 20 23 21 19 0.585209 196/200 NonOverlappingTemplate
18 26 25 12 18 16 24 19 18 24 0.410055 199/200 NonOverlappingTemplate
27 21 22 27 21 14 18 14 23 13 0.219006 197/200 NonOverlappingTemplate
18 23 24 16 19 21 16 26 20 17 0.798139 199/200 NonOverlappingTemplate
19 30 15 27 14 19 24 11 22 19 0.073417 198/200 NonOverlappingTemplate
20 23 22 20 22 15 22 21 18 17 0.964295 198/200 NonOverlappingTemplate
22 31 16 26 13 19 17 22 24 10 0.037566 197/200 NonOverlappingTemplate
18 24 22 14 23 19 16 18 19 27 0.637119 197/200 NonOverlappingTemplate
19 20 21 22 21 18 19 22 20 18 0.999438 198/200 NonOverlappingTemplate
27 15 21 18 28 18 15 23 18 17 0.375313 195/200 NonOverlappingTemplate
26 23 20 20 23 19 20 23 14 12 0.514124 199/200 NonOverlappingTemplate
18 19 11 15 21 24 20 26 23 23 0.428095 198/200 NonOverlappingTemplate
19 16 21 25 19 21 15 24 24 16 0.749884 197/200 NonOverlappingTemplate
17 26 23 18 20 26 23 14 18 15 0.494392 198/200 NonOverlappingTemplate
15 17 19 24 21 23 17 25 23 16 0.739918 196/200 NonOverlappingTemplate
26 19 20 20 24 22 22 13 14 20 0.605916 198/200 OverlappingTemplate
29 24 17 21 18 13 18 21 17 22 0.446556 196/200 Universal
22 18 22 20 20 21 22 21 18 16 0.992952 198/200 ApproximateEntropy
14 8 13 9 11 13 13 8 7 10 0.719747 106/106 RandomExcursions
13 18 9 7 12 12 9 6 12 8 0.236810 104/106 RandomExcursions
11 15 10 7 11 14 9 6 12 11 0.595549 106/106 RandomExcursions
15 7 12 12 9 11 16 8 10 6 0.350485 106/106 RandomExcursions
10 10 12 16 10 12 10 7 13 6 0.554420 106/106 RandomExcursions
8 7 12 10 11 16 11 13 10 8 0.657933 106/106 RandomExcursions
9 6 12 12 14 9 11 13 10 10 0.816537 104/106 RandomExcursions
10 10 7 12 11 9 10 13 14 10 0.911413 105/106 RandomExcursions
8 8 12 9 10 5 13 12 17 12 0.319084 104/106 RandomExcursionsVariant
5 11 10 11 7 11 10 15 11 15 0.455937 104/106 RandomExcursionsVariant
6 12 11 8 12 12 12 13 13 7 0.699313 104/106 RandomExcursionsVariant
14 10 11 6 12 9 8 12 11 13 0.779188 104/106 RandomExcursionsVariant
12 12 10 7 17 6 6 12 13 11 0.262249 103/106 RandomExcursionsVariant
13 8 14 13 7 6 6 13 15 11 0.249284 102/106 RandomExcursionsVariant
12 12 12 13 7 9 6 13 12 10 0.739918 105/106 RandomExcursionsVariant
13 15 12 8 9 10 6 9 14 10 0.574903 106/106 RandomExcursionsVariant
10 15 9 12 14 10 8 11 7 10 0.739918 105/106 RandomExcursionsVariant
13 12 8 11 12 11 9 10 11 9 0.978072 103/106 RandomExcursionsVariant
10 13 12 12 8 13 8 9 14 7 0.739918 104/106 RandomExcursionsVariant
12 10 10 14 7 8 7 13 14 11 0.657933 106/106 RandomExcursionsVariant
10 13 10 10 13 10 12 6 10 12 0.897763 106/106 RandomExcursionsVariant
9 12 15 8 13 8 12 8 11 10 0.779188 106/106 RandomExcursionsVariant
9 13 15 10 10 10 8 14 6 11 0.616305 106/106 RandomExcursionsVariant
7 17 9 12 9 11 10 16 4 11 0.129620 106/106 RandomExcursionsVariant
10 9 10 15 7 12 7 8 12 16 0.419021 106/106 RandomExcursionsVariant
9 12 11 8 8 9 15 12 9 13 0.798139 106/106 RandomExcursionsVariant
17 34 11 22 22 17 19 20 13 25 0.026057 199/200 Serial
22 20 16 22 20 18 20 18 23 21 0.989786 199/200 Serial
12 33 25 29 21 11 21 15 14 19 0.003996 199/200 LinearComplexity
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The minimum pass rate for each statistical test with the exception of the
random excursion (variant) test is approximately = 193 for a
sample size = 200 binary sequences.
The minimum pass rate for the random excursion (variant) test
is approximately = 101 for a sample size = 106 binary sequences.
For further guidelines construct a probability table using the MAPLE program
provided in the addendum section of the documentation.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$

39
vendor/modernc.org/mathutil/permute.go generated vendored Normal file
View File

@ -0,0 +1,39 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"sort"
)
// PermutationFirst generates the first permutation of data.
func PermutationFirst(data sort.Interface) {
sort.Sort(data)
}
// PermutationNext generates the next permutation of data if possible and
// return true. Return false if there is no more permutation left. Based on
// the algorithm described here:
// http://en.wikipedia.org/wiki/Permutation#Generation_in_lexicographic_order
func PermutationNext(data sort.Interface) bool {
var k, l int
for k = data.Len() - 2; ; k-- { // 1.
if k < 0 {
return false
}
if data.Less(k, k+1) {
break
}
}
for l = data.Len() - 1; !data.Less(k, l); l-- { // 2.
}
data.Swap(k, l) // 3.
for i, j := k+1, data.Len()-1; i < j; i++ { // 4.
data.Swap(i, j)
j--
}
return true
}

248
vendor/modernc.org/mathutil/poly.go generated vendored Normal file
View File

@ -0,0 +1,248 @@
// Copyright (c) 2016 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"fmt"
"math/big"
)
func abs(n int) uint64 {
if n >= 0 {
return uint64(n)
}
return uint64(-n)
}
// QuadPolyDiscriminant returns the discriminant of a quadratic polynomial in
// one variable of the form a*x^2+b*x+c with integer coefficients a, b, c, or
// an error on overflow.
//
// ds is the square of the discriminant. If |ds| is a square number, d is set
// to sqrt(|ds|), otherwise d is < 0.
func QuadPolyDiscriminant(a, b, c int) (ds, d int, _ error) {
if 2*BitLenUint64(abs(b)) > IntBits-1 ||
2+BitLenUint64(abs(a))+BitLenUint64(abs(c)) > IntBits-1 {
return 0, 0, fmt.Errorf("overflow")
}
ds = b*b - 4*a*c
s := ds
if s < 0 {
s = -s
}
d64 := SqrtUint64(uint64(s))
if d64*d64 != uint64(s) {
return ds, -1, nil
}
return ds, int(d64), nil
}
// PolyFactor describes an irreducible factor of a polynomial in one variable
// with integer coefficients P, Q of the form P*x+Q.
type PolyFactor struct {
P, Q int
}
// QuadPolyFactors returns the content and the irreducible factors of the
// primitive part of a quadratic polynomial in one variable with integer
// coefficients a, b, c of the form a*x^2+b*x+c in integers, or an error on
// overflow.
//
// If the factorization in integers does not exists, the return value is (0,
// nil, nil).
//
// See also:
// https://en.wikipedia.org/wiki/Factorization_of_polynomials#Primitive_part.E2.80.93content_factorization
func QuadPolyFactors(a, b, c int) (content int, primitivePart []PolyFactor, _ error) {
content = int(GCDUint64(abs(a), GCDUint64(abs(b), abs(c))))
switch {
case content == 0:
content = 1
case content > 0:
if a < 0 || a == 0 && b < 0 {
content = -content
}
}
a /= content
b /= content
c /= content
if a == 0 {
if b == 0 {
return content, []PolyFactor{{0, c}}, nil
}
if b < 0 && c < 0 {
b = -b
c = -c
}
if b < 0 {
b = -b
c = -c
}
return content, []PolyFactor{{b, c}}, nil
}
ds, d, err := QuadPolyDiscriminant(a, b, c)
if err != nil {
return 0, nil, err
}
if ds < 0 || d < 0 {
return 0, nil, nil
}
x1num := -b + d
x1denom := 2 * a
gcd := int(GCDUint64(abs(x1num), abs(x1denom)))
x1num /= gcd
x1denom /= gcd
x2num := -b - d
x2denom := 2 * a
gcd = int(GCDUint64(abs(x2num), abs(x2denom)))
x2num /= gcd
x2denom /= gcd
return content, []PolyFactor{{x1denom, -x1num}, {x2denom, -x2num}}, nil
}
// QuadPolyDiscriminantBig returns the discriminant of a quadratic polynomial
// in one variable of the form a*x^2+b*x+c with integer coefficients a, b, c.
//
// ds is the square of the discriminant. If |ds| is a square number, d is set
// to sqrt(|ds|), otherwise d is nil.
func QuadPolyDiscriminantBig(a, b, c *big.Int) (ds, d *big.Int) {
ds = big.NewInt(0).Set(b)
ds.Mul(ds, b)
x := big.NewInt(4)
x.Mul(x, a)
x.Mul(x, c)
ds.Sub(ds, x)
s := big.NewInt(0).Set(ds)
if s.Sign() < 0 {
s.Neg(s)
}
if s.Bit(1) != 0 { // s is not a square number
return ds, nil
}
d = SqrtBig(s)
x.Set(d)
x.Mul(x, x)
if x.Cmp(s) != 0 { // s is not a square number
d = nil
}
return ds, d
}
// PolyFactorBig describes an irreducible factor of a polynomial in one
// variable with integer coefficients P, Q of the form P*x+Q.
type PolyFactorBig struct {
P, Q *big.Int
}
// QuadPolyFactorsBig returns the content and the irreducible factors of the
// primitive part of a quadratic polynomial in one variable with integer
// coefficients a, b, c of the form a*x^2+b*x+c in integers.
//
// If the factorization in integers does not exists, the return value is (nil,
// nil).
//
// See also:
// https://en.wikipedia.org/wiki/Factorization_of_polynomials#Primitive_part.E2.80.93content_factorization
func QuadPolyFactorsBig(a, b, c *big.Int) (content *big.Int, primitivePart []PolyFactorBig) {
content = bigGCD(bigAbs(a), bigGCD(bigAbs(b), bigAbs(c)))
switch {
case content.Sign() == 0:
content.SetInt64(1)
case content.Sign() > 0:
if a.Sign() < 0 || a.Sign() == 0 && b.Sign() < 0 {
content = bigNeg(content)
}
}
a = bigDiv(a, content)
b = bigDiv(b, content)
c = bigDiv(c, content)
if a.Sign() == 0 {
if b.Sign() == 0 {
return content, []PolyFactorBig{{big.NewInt(0), c}}
}
if b.Sign() < 0 && c.Sign() < 0 {
b = bigNeg(b)
c = bigNeg(c)
}
if b.Sign() < 0 {
b = bigNeg(b)
c = bigNeg(c)
}
return content, []PolyFactorBig{{b, c}}
}
ds, d := QuadPolyDiscriminantBig(a, b, c)
if ds.Sign() < 0 || d == nil {
return nil, nil
}
x1num := bigAdd(bigNeg(b), d)
x1denom := bigMul(_2, a)
gcd := bigGCD(bigAbs(x1num), bigAbs(x1denom))
x1num = bigDiv(x1num, gcd)
x1denom = bigDiv(x1denom, gcd)
x2num := bigAdd(bigNeg(b), bigNeg(d))
x2denom := bigMul(_2, a)
gcd = bigGCD(bigAbs(x2num), bigAbs(x2denom))
x2num = bigDiv(x2num, gcd)
x2denom = bigDiv(x2denom, gcd)
return content, []PolyFactorBig{{x1denom, bigNeg(x1num)}, {x2denom, bigNeg(x2num)}}
}
func bigAbs(n *big.Int) *big.Int {
n = big.NewInt(0).Set(n)
if n.Sign() >= 0 {
return n
}
return n.Neg(n)
}
func bigDiv(a, b *big.Int) *big.Int {
a = big.NewInt(0).Set(a)
return a.Div(a, b)
}
func bigGCD(a, b *big.Int) *big.Int {
a = big.NewInt(0).Set(a)
b = big.NewInt(0).Set(b)
for b.Sign() != 0 {
c := big.NewInt(0)
c.Mod(a, b)
a, b = b, c
}
return a
}
func bigNeg(n *big.Int) *big.Int {
n = big.NewInt(0).Set(n)
return n.Neg(n)
}
func bigMul(a, b *big.Int) *big.Int {
r := big.NewInt(0).Set(a)
return r.Mul(r, b)
}
func bigAdd(a, b *big.Int) *big.Int {
r := big.NewInt(0).Set(a)
return r.Add(r, b)
}

331
vendor/modernc.org/mathutil/primes.go generated vendored Normal file
View File

@ -0,0 +1,331 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"math"
)
// IsPrimeUint16 returns true if n is prime. Typical run time is few ns.
func IsPrimeUint16(n uint16) bool {
return n > 0 && primes16[n-1] == 1
}
// NextPrimeUint16 returns first prime > n and true if successful or an
// undefined value and false if there is no next prime in the uint16 limits.
// Typical run time is few ns.
func NextPrimeUint16(n uint16) (p uint16, ok bool) {
return n + uint16(primes16[n]), n < 65521
}
// IsPrime returns true if n is prime. Typical run time is about 100 ns.
func IsPrime(n uint32) bool {
switch {
case n&1 == 0:
return n == 2
case n%3 == 0:
return n == 3
case n%5 == 0:
return n == 5
case n%7 == 0:
return n == 7
case n%11 == 0:
return n == 11
case n%13 == 0:
return n == 13
case n%17 == 0:
return n == 17
case n%19 == 0:
return n == 19
case n%23 == 0:
return n == 23
case n%29 == 0:
return n == 29
case n%31 == 0:
return n == 31
case n%37 == 0:
return n == 37
case n%41 == 0:
return n == 41
case n%43 == 0:
return n == 43
case n%47 == 0:
return n == 47
case n%53 == 0:
return n == 53 // Benchmarked optimum
case n < 65536:
// use table data
return IsPrimeUint16(uint16(n))
default:
mod := ModPowUint32(2, (n+1)/2, n)
if mod != 2 && mod != n-2 {
return false
}
blk := &lohi[n>>24]
lo, hi := blk.lo, blk.hi
for lo <= hi {
index := (lo + hi) >> 1
liar := liars[index]
switch {
case n > liar:
lo = index + 1
case n < liar:
hi = index - 1
default:
return false
}
}
return true
}
}
// IsPrimeUint64 returns true if n is prime. Typical run time is few tens of µs.
//
// SPRP bases: http://miller-rabin.appspot.com
func IsPrimeUint64(n uint64) bool {
switch {
case n%2 == 0:
return n == 2
case n%3 == 0:
return n == 3
case n%5 == 0:
return n == 5
case n%7 == 0:
return n == 7
case n%11 == 0:
return n == 11
case n%13 == 0:
return n == 13
case n%17 == 0:
return n == 17
case n%19 == 0:
return n == 19
case n%23 == 0:
return n == 23
case n%29 == 0:
return n == 29
case n%31 == 0:
return n == 31
case n%37 == 0:
return n == 37
case n%41 == 0:
return n == 41
case n%43 == 0:
return n == 43
case n%47 == 0:
return n == 47
case n%53 == 0:
return n == 53
case n%59 == 0:
return n == 59
case n%61 == 0:
return n == 61
case n%67 == 0:
return n == 67
case n%71 == 0:
return n == 71
case n%73 == 0:
return n == 73
case n%79 == 0:
return n == 79
case n%83 == 0:
return n == 83
case n%89 == 0:
return n == 89 // Benchmarked optimum
case n <= math.MaxUint16:
return IsPrimeUint16(uint16(n))
case n <= math.MaxUint32:
return ProbablyPrimeUint32(uint32(n), 11000544) &&
ProbablyPrimeUint32(uint32(n), 31481107)
case n < 105936894253:
return ProbablyPrimeUint64_32(n, 2) &&
ProbablyPrimeUint64_32(n, 1005905886) &&
ProbablyPrimeUint64_32(n, 1340600841)
case n < 31858317218647:
return ProbablyPrimeUint64_32(n, 2) &&
ProbablyPrimeUint64_32(n, 642735) &&
ProbablyPrimeUint64_32(n, 553174392) &&
ProbablyPrimeUint64_32(n, 3046413974)
case n < 3071837692357849:
return ProbablyPrimeUint64_32(n, 2) &&
ProbablyPrimeUint64_32(n, 75088) &&
ProbablyPrimeUint64_32(n, 642735) &&
ProbablyPrimeUint64_32(n, 203659041) &&
ProbablyPrimeUint64_32(n, 3613982119)
default:
return ProbablyPrimeUint64_32(n, 2) &&
ProbablyPrimeUint64_32(n, 325) &&
ProbablyPrimeUint64_32(n, 9375) &&
ProbablyPrimeUint64_32(n, 28178) &&
ProbablyPrimeUint64_32(n, 450775) &&
ProbablyPrimeUint64_32(n, 9780504) &&
ProbablyPrimeUint64_32(n, 1795265022)
}
}
// NextPrime returns first prime > n and true if successful or an undefined value and false if there
// is no next prime in the uint32 limits. Typical run time is about 2 µs.
func NextPrime(n uint32) (p uint32, ok bool) {
switch {
case n < 65521:
p16, _ := NextPrimeUint16(uint16(n))
return uint32(p16), true
case n >= math.MaxUint32-4:
return
}
n++
var d0, d uint32
switch mod := n % 6; mod {
case 0:
d0, d = 1, 4
case 1:
d = 4
case 2, 3, 4:
d0, d = 5-mod, 2
case 5:
d = 2
}
p = n + d0
if p < n { // overflow
return
}
for {
if IsPrime(p) {
return p, true
}
p0 := p
p += d
if p < p0 { // overflow
break
}
d ^= 6
}
return
}
// NextPrimeUint64 returns first prime > n and true if successful or an undefined value and false if there
// is no next prime in the uint64 limits. Typical run time is in hundreds of µs.
func NextPrimeUint64(n uint64) (p uint64, ok bool) {
switch {
case n < 65521:
p16, _ := NextPrimeUint16(uint16(n))
return uint64(p16), true
case n >= 18446744073709551557: // last uint64 prime
return
}
n++
var d0, d uint64
switch mod := n % 6; mod {
case 0:
d0, d = 1, 4
case 1:
d = 4
case 2, 3, 4:
d0, d = 5-mod, 2
case 5:
d = 2
}
p = n + d0
if p < n { // overflow
return
}
for {
if ok = IsPrimeUint64(p); ok {
break
}
p0 := p
p += d
if p < p0 { // overflow
break
}
d ^= 6
}
return
}
// FactorTerm is one term of an integer factorization.
type FactorTerm struct {
Prime uint32 // The divisor
Power uint32 // Term == Prime^Power
}
// FactorTerms represent a factorization of an integer
type FactorTerms []FactorTerm
// FactorInt returns prime factorization of n > 1 or nil otherwise.
// Resulting factors are ordered by Prime. Typical run time is few µs.
func FactorInt(n uint32) (f FactorTerms) {
switch {
case n < 2:
return
case IsPrime(n):
return []FactorTerm{{n, 1}}
}
f, w := make([]FactorTerm, 9), 0
for p := 2; p < len(primes16); p += int(primes16[p]) {
if uint(p*p) > uint(n) {
break
}
power := uint32(0)
for n%uint32(p) == 0 {
n /= uint32(p)
power++
}
if power != 0 {
f[w] = FactorTerm{uint32(p), power}
w++
}
if n == 1 {
break
}
}
if n != 1 {
f[w] = FactorTerm{n, 1}
w++
}
return f[:w]
}
// PrimorialProductsUint32 returns a slice of numbers in [lo, hi] which are a
// product of max 'max' primorials. The slice is not sorted.
//
// See also: http://en.wikipedia.org/wiki/Primorial
func PrimorialProductsUint32(lo, hi, max uint32) (r []uint32) {
lo64, hi64 := int64(lo), int64(hi)
if max > 31 { // N/A
max = 31
}
var f func(int64, int64, uint32)
f = func(n, p int64, emax uint32) {
e := uint32(1)
for n <= hi64 && e <= emax {
n *= p
if n >= lo64 && n <= hi64 {
r = append(r, uint32(n))
}
if n < hi64 {
p, _ := NextPrime(uint32(p))
f(n, int64(p), e)
}
e++
}
}
f(1, 2, max)
return
}

27
vendor/modernc.org/mathutil/rat.go generated vendored Normal file
View File

@ -0,0 +1,27 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
// QCmpUint32 compares a/b and c/d and returns:
//
// -1 if a/b < c/d
// 0 if a/b == c/d
// +1 if a/b > c/d
//
func QCmpUint32(a, b, c, d uint32) int {
switch x, y := uint64(a)*uint64(d), uint64(b)*uint64(c); {
case x < y:
return -1
case x == y:
return 0
default: // x > y
return 1
}
}
// QScaleUint32 returns a such that a/b >= c/d.
func QScaleUint32(b, c, d uint32) (a uint64) {
return 1 + (uint64(b)*uint64(c))/uint64(d)
}

383
vendor/modernc.org/mathutil/rnd.go generated vendored Normal file
View File

@ -0,0 +1,383 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
import (
"fmt"
"math"
"math/big"
)
// FC32 is a full cycle PRNG covering the 32 bit signed integer range.
// In contrast to full cycle generators shown at e.g. http://en.wikipedia.org/wiki/Full_cycle,
// this code doesn't produce values at constant delta (mod cycle length).
// The 32 bit limit is per this implementation, the algorithm used has no intrinsic limit on the cycle size.
// Properties include:
// - Adjustable limits on creation (hi, lo).
// - Positionable/randomly accessible (Pos, Seek).
// - Repeatable (deterministic).
// - Can run forward or backward (Next, Prev).
// - For a billion numbers cycle the Next/Prev PRN can be produced in cca 100-150ns.
// That's like 5-10 times slower compared to PRNs generated using the (non FC) rand package.
type FC32 struct {
cycle int64 // On average: 3 * delta / 2, (HQ: 2 * delta)
delta int64 // hi - lo
factors [][]int64 // This trades some space for hopefully a bit of speed (multiple adding vs multiplying).
lo int
mods []int // pos % set
pos int64 // Within cycle.
primes []int64 // Ordered. ∏ primes == cycle.
set []int64 // Reordered primes (magnitude order bases) according to seed.
}
// NewFC32 returns a newly created FC32 adjusted for the closed interval [lo, hi] or an Error if any.
// If hq == true then trade some generation time for improved (pseudo)randomness.
func NewFC32(lo, hi int, hq bool) (r *FC32, err error) {
if lo > hi {
return nil, fmt.Errorf("invalid range %d > %d", lo, hi)
}
if uint64(hi)-uint64(lo) > math.MaxUint32 {
return nil, fmt.Errorf("range out of int32 limits %d, %d", lo, hi)
}
delta := int64(hi) - int64(lo)
// Find the primorial covering whole delta
n, set, p := int64(1), []int64{}, uint32(2)
if hq {
p++
}
for {
set = append(set, int64(p))
n *= int64(p)
if n > delta {
break
}
p, _ = NextPrime(p)
}
// Adjust the set so n ∊ [delta, 2 * delta] (HQ: [delta, 3 * delta])
// while keeping the cardinality of the set (correlates with the statistic "randomness quality")
// at max, i.e. discard atmost one member.
i := -1 // no candidate prime
if n > 2*(delta+1) {
for j, p := range set {
q := n / p
if q < delta+1 {
break
}
i = j // mark the highest candidate prime set index
}
}
if i >= 0 { // shrink the inner cycle
n = n / set[i]
set = delete(set, i)
}
r = &FC32{
cycle: n,
delta: delta,
factors: make([][]int64, len(set)),
lo: lo,
mods: make([]int, len(set)),
primes: set,
}
r.Seed(1) // the default seed should be always non zero
return
}
// Cycle reports the length of the inner FCPRNG cycle.
// Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1).
func (r *FC32) Cycle() int64 {
return r.cycle
}
// Next returns the first PRN after Pos.
func (r *FC32) Next() int {
return r.step(1)
}
// Pos reports the current position within the inner cycle.
func (r *FC32) Pos() int64 {
return r.pos
}
// Prev return the first PRN before Pos.
func (r *FC32) Prev() int {
return r.step(-1)
}
// Seed uses the provided seed value to initialize the generator to a deterministic state.
// A zero seed produces a "canonical" generator with worse randomness than for most non zero seeds.
// Still, the FC property holds for any seed value.
func (r *FC32) Seed(seed int64) {
u := uint64(seed)
r.set = mix(r.primes, &u)
n := int64(1)
for i, p := range r.set {
k := make([]int64, p)
v := int64(0)
for j := range k {
k[j] = v
v += n
}
n *= p
r.factors[i] = mix(k, &u)
}
}
// Seek sets Pos to |pos| % Cycle.
func (r *FC32) Seek(pos int64) { //vet:ignore
if pos < 0 {
pos = -pos
}
pos %= r.cycle
r.pos = pos
for i, p := range r.set {
r.mods[i] = int(pos % p)
}
}
func (r *FC32) step(dir int) int {
for { // avg loops per step: 3/2 (HQ: 2)
y := int64(0)
pos := r.pos
pos += int64(dir)
switch {
case pos < 0:
pos = r.cycle - 1
case pos >= r.cycle:
pos = 0
}
r.pos = pos
for i, mod := range r.mods {
mod += dir
p := int(r.set[i])
switch {
case mod < 0:
mod = p - 1
case mod >= p:
mod = 0
}
r.mods[i] = mod
y += r.factors[i][mod]
}
if y <= r.delta {
return int(y) + r.lo
}
}
}
func delete(set []int64, i int) (y []int64) {
for j, v := range set {
if j != i {
y = append(y, v)
}
}
return
}
func mix(set []int64, seed *uint64) (y []int64) {
for len(set) != 0 {
*seed = rol(*seed)
i := int(*seed % uint64(len(set)))
y = append(y, set[i])
set = delete(set, i)
}
return
}
func rol(u uint64) (y uint64) {
y = u << 1
if int64(u) < 0 {
y |= 1
}
return
}
// FCBig is a full cycle PRNG covering ranges outside of the int32 limits.
// For more info see the FC32 docs.
// Next/Prev PRN on a 1e15 cycle can be produced in about 2 µsec.
type FCBig struct {
cycle *big.Int // On average: 3 * delta / 2, (HQ: 2 * delta)
delta *big.Int // hi - lo
factors [][]*big.Int // This trades some space for hopefully a bit of speed (multiple adding vs multiplying).
lo *big.Int
mods []int // pos % set
pos *big.Int // Within cycle.
primes []int64 // Ordered. ∏ primes == cycle.
set []int64 // Reordered primes (magnitude order bases) according to seed.
}
// NewFCBig returns a newly created FCBig adjusted for the closed interval [lo, hi] or an Error if any.
// If hq == true then trade some generation time for improved (pseudo)randomness.
func NewFCBig(lo, hi *big.Int, hq bool) (r *FCBig, err error) {
if lo.Cmp(hi) > 0 {
return nil, fmt.Errorf("invalid range %d > %d", lo, hi)
}
delta := big.NewInt(0)
delta.Add(delta, hi).Sub(delta, lo)
// Find the primorial covering whole delta
n, set, pp, p := big.NewInt(1), []int64{}, big.NewInt(0), uint32(2)
if hq {
p++
}
for {
set = append(set, int64(p))
pp.SetInt64(int64(p))
n.Mul(n, pp)
if n.Cmp(delta) > 0 {
break
}
p, _ = NextPrime(p)
}
// Adjust the set so n ∊ [delta, 2 * delta] (HQ: [delta, 3 * delta])
// while keeping the cardinality of the set (correlates with the statistic "randomness quality")
// at max, i.e. discard atmost one member.
dd1 := big.NewInt(1)
dd1.Add(dd1, delta)
dd2 := big.NewInt(0)
dd2.Lsh(dd1, 1)
i := -1 // no candidate prime
if n.Cmp(dd2) > 0 {
q := big.NewInt(0)
for j, p := range set {
pp.SetInt64(p)
q.Set(n)
q.Div(q, pp)
if q.Cmp(dd1) < 0 {
break
}
i = j // mark the highest candidate prime set index
}
}
if i >= 0 { // shrink the inner cycle
pp.SetInt64(set[i])
n.Div(n, pp)
set = delete(set, i)
}
r = &FCBig{
cycle: n,
delta: delta,
factors: make([][]*big.Int, len(set)),
lo: lo,
mods: make([]int, len(set)),
pos: big.NewInt(0),
primes: set,
}
r.Seed(1) // the default seed should be always non zero
return
}
// Cycle reports the length of the inner FCPRNG cycle.
// Cycle is atmost the double (HQ: triple) of the generator period (hi - lo + 1).
func (r *FCBig) Cycle() *big.Int {
return r.cycle
}
// Next returns the first PRN after Pos.
func (r *FCBig) Next() *big.Int {
return r.step(1)
}
// Pos reports the current position within the inner cycle.
func (r *FCBig) Pos() *big.Int {
return r.pos
}
// Prev return the first PRN before Pos.
func (r *FCBig) Prev() *big.Int {
return r.step(-1)
}
// Seed uses the provided seed value to initialize the generator to a deterministic state.
// A zero seed produces a "canonical" generator with worse randomness than for most non zero seeds.
// Still, the FC property holds for any seed value.
func (r *FCBig) Seed(seed int64) {
u := uint64(seed)
r.set = mix(r.primes, &u)
n := big.NewInt(1)
v := big.NewInt(0)
pp := big.NewInt(0)
for i, p := range r.set {
k := make([]*big.Int, p)
v.SetInt64(0)
for j := range k {
k[j] = big.NewInt(0)
k[j].Set(v)
v.Add(v, n)
}
pp.SetInt64(p)
n.Mul(n, pp)
r.factors[i] = mixBig(k, &u)
}
}
// Seek sets Pos to |pos| % Cycle.
func (r *FCBig) Seek(pos *big.Int) {
r.pos.Set(pos)
r.pos.Abs(r.pos)
r.pos.Mod(r.pos, r.cycle)
mod := big.NewInt(0)
pp := big.NewInt(0)
for i, p := range r.set {
pp.SetInt64(p)
r.mods[i] = int(mod.Mod(r.pos, pp).Int64())
}
}
func (r *FCBig) step(dir int) (y *big.Int) {
y = big.NewInt(0)
d := big.NewInt(int64(dir))
for { // avg loops per step: 3/2 (HQ: 2)
r.pos.Add(r.pos, d)
switch {
case r.pos.Sign() < 0:
r.pos.Add(r.pos, r.cycle)
case r.pos.Cmp(r.cycle) >= 0:
r.pos.SetInt64(0)
}
for i, mod := range r.mods {
mod += dir
p := int(r.set[i])
switch {
case mod < 0:
mod = p - 1
case mod >= p:
mod = 0
}
r.mods[i] = mod
y.Add(y, r.factors[i][mod])
}
if y.Cmp(r.delta) <= 0 {
y.Add(y, r.lo)
return
}
y.SetInt64(0)
}
}
func deleteBig(set []*big.Int, i int) (y []*big.Int) {
for j, v := range set {
if j != i {
y = append(y, v)
}
}
return
}
func mixBig(set []*big.Int, seed *uint64) (y []*big.Int) {
for len(set) != 0 {
*seed = rol(*seed)
i := int(*seed % uint64(len(set)))
y = append(y, set[i])
set = deleteBig(set, i)
}
return
}

6995
vendor/modernc.org/mathutil/tables.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

11
vendor/modernc.org/mathutil/test_deps.go generated vendored Normal file
View File

@ -0,0 +1,11 @@
// Copyright (c) 2014 The mathutil Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mathutil // import "modernc.org/mathutil"
// Pull test dependencies too.
// Enables easy 'go test X' after 'go get X'
import (
// nothing yet
)