public void bv16width() { var limit = 12; var set1 = BitVector16.All(limit).Select(x => x.Scalar).ToArray(); Claim.eq(mathspan.max(set1.ToSpan()), (ushort)0b111111111111); var set2 = Random.BitVectors(n16, limit).TakeArray((int)Pow2.pow(limit * 2)); Span <int> dist = stackalloc int[limit + 1]; for (var i = 0; i < set2.Length; i++) { var v = set2[i]; Claim.lteq(v.MinWidth, limit); ++dist[v.MinWidth]; } //should approach 2^(limit - 1) double idealRatio = Pow2.pow(limit - 1); Span <double> ratios = stackalloc double[dist.Length]; for (var i = 1; i < dist.Length; i++) { ratios[i] = ((double)dist[i] / Pow2.pow(i)); } var delta = mathspan.sub(ratios.Slice(1), idealRatio); Claim.yea(math.lt(math.abs(delta.Last()), 3.0)); }
void bv_xor128_check() { var vectors = Random.BitVectors(n128); for (var i = 0; i < SampleSize; i++) { var x = vectors.First(); var y = vectors.First(); var z = x ^ y; var xbs = x.ToBitString(); var ybs = y.ToBitString(); var zbs = xbs ^ ybs; Claim.eq(zbs, z.ToBitString()); } }