示例#1
0
文件: ts_blsi.cs 项目: 0xCM/arrows
 /// <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)));
     }
 }
示例#2
0
        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));
        }
示例#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);
 }
示例#4
0
        /// <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++);
            }
        }
示例#5
0
        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;
        }
示例#6
0
文件: Byte256.cs 项目: 0xCM/arrows
        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));
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
        /// <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));
            }
        }
示例#9
0
文件: posl.cs 项目: 0xCM/arrows
 public static ulong posl(ulong src)
 => Pow2.inv(blsi(src));
示例#10
0
文件: posl.cs 项目: 0xCM/arrows
 public static uint posl(uint src)
 => Pow2.inv(blsi(src));
示例#11
0
文件: posl.cs 项目: 0xCM/arrows
 public static ushort posl(ushort src)
 => Pow2.inv(blsi(src));
示例#12
0
文件: posl.cs 项目: 0xCM/arrows
 public static byte posl(byte src)
 => Pow2.inv(blsi(src));