Example #1
0
        public ArithmeticMatrix(NumeralSet numeralSet)
        {
            if (numeralSet == null)
                throw new ArgumentNullException("numeralSet");
            this._numeralSet = numeralSet;

            var keys = this._numeralSet.SymbolSet.As<LinkedList<string>>().Values;
            this._addMap = new SquareLookup<Tuple<string, bool>>(keys);
            this._subtractMap = new SquareLookup<Tuple<string, bool>>(keys);
            this._compareMap = new SquareLookup<bool?>(keys);

            foreach (var key1 in keys)
            {
                foreach (var key2 in keys)
                {
                    var dig1 = numeralSet.GetSymbolicDigit(key1);
                    var rollover = dig1.Add(key2);
                    this._addMap.Add(key1, key2, new Tuple<string, bool>(dig1.Symbol, rollover));

                    dig1 = numeralSet.GetSymbolicDigit(key1);
                    rollover = dig1.Subtract(key2);
                    this._subtractMap.Add(key1, key2, new Tuple<string, bool>(dig1.Symbol, rollover));

                    dig1 = numeralSet.GetSymbolicDigit(key1);
                    var compare = dig1.Compare(key2);
                    this._compareMap.Add(key1, key2, compare);
                }
            }
        }
        private void InitMap()
        {
            var keys = this.NumberSystem.Symbols;
            this._multMap = new SquareLookup<Numeric>(keys);

            foreach (string each in keys)
            {
                foreach (string each2 in keys)
                {
                    //Debug.WriteLine("creating entry for {0} x {1}", each, each2);

                    //add each to itself, each2 times
                    var eachNum = Numeric.New(this.NumberSystem, each);
                    var counter = Numeric.New(this.NumberSystem, each2).HasAddition();
                    var total = eachNum.GetCompatibleZero().HasAddition();

                    counter.PerformThisManyTimes(c =>
                    {
                        //Debug.WriteLine("interim total for {0} x {1} = {2} ", each, each2, total.SymbolsText);
                        total.Add(eachNum);
                    });

                    //register it
                    this._multMap.Add(each, each2, total.InnermostNumeric);
                    //Debug.WriteLine("creating entry for {0} x {1} = {2}", each, each2, total.InnerNumeric.SymbolsText);
                }
            }
        }