/// <summary> /// Illustrates blsi is an identity function over a domain consisting of powers of 2 /// </summary> public void blsi_idpow2() { for (byte i = 0; i < 64; i++) { Claim.eq(Pow2.pow(i), gbits.blsi(Pow2.pow(i))); } }
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)); }
/// <summary> /// Creates a mask for specified powers of two /// </summary> /// <param name="dst">The mask reference</param> /// <param name="exponents">The exponent values, each of which should be within the integral range [0,63] </param> public static ref ulong mask(ref ulong dst, params int[] exponents) { for (var i = 0; i < exponents.Length; i++) { dst |= Pow2.pow(exponents[i]); } return(ref dst); }
/// <summary> /// Enumerates all 32-bit bitvectors whose width is less than or equal to a specified maximum /// </summary> public static IEnumerable <BitVector64> All(int maxwidth) { var maxval = Pow2.pow(maxwidth); var bv = BitVector64.Zero; while (bv < maxval) { yield return(bv++); } }
public GfPoly(params byte[] exponents) { var components = default(T); for (var i = 0; i < exponents.Length; i++) { components = gbits.or(components, Pow2.pow <T>(exponents[i])); } data = components; }
public IEnumerable <(string decidx, string index, string bitseq, string bitchars, string text)> MakeBitStringsUInt8() { var length = 8; var count = (int)Pow2.pow(length) - 1; for (var i = 0; i <= count; i++) { yield return(i.ToString(), MakeBsIndex((byte)i), MakeBsSeq((byte)i), MakeBsArray((byte)i), MakeBsText((byte)i)); } }
/// <summary> /// Defines a binary polynomial from a monotonically decreasing exponent sequence /// </summary> /// <param name="exponents">The exponent sequence</param> /// <typeparam name="T">The primal type</typeparam> public static T Poly <T>(params byte[] exponents) where T : unmanaged { var components = default(T); for (var i = 0; i < exponents.Length; i++) { components = gbits.or(components, Pow2.pow <T>(exponents[i])); } return(components); }
/// <summary> /// Generates all words over the binary alphabet for a specified word length /// </summary> /// <param name="length">The length of the words to generate</param> public override IEnumerable <BitString> Words(int length) { var count = Pow2.pow(length) - 1; for (var i = 0ul; i <= count; i++) { var bs = BitString.FromScalar(i); var bsfmt = bs.Format(true).PadLeft(length, '0'); yield return(BitString.Parse(bsfmt)); } }
public static ulong posl(ulong src) => Pow2.inv(blsi(src));
public static uint posl(uint src) => Pow2.inv(blsi(src));
public static ushort posl(ushort src) => Pow2.inv(blsi(src));
public static byte posl(byte src) => Pow2.inv(blsi(src));