コード例 #1
0
        // This is transcribed directly from [Emoto] p. 570
        private T2 OptCombine(T2 a, T2 b)
        {
            U i = _semiring.Add(a.i, _semiring.Mult(a.s, b.i));
            U s = _semiring.Mult(a.s, b.s);

            return(new T2(i, s));
        }
コード例 #2
0
        // This is transcribed directly from [Emoto] p. 568
        private T4 MitsCombine(T4 a, T4 b)
        {
            U m = _semiring.Add(_semiring.Add(a.m, _semiring.Mult(a.t, b.i)), b.m);
            U i = _semiring.Add(a.i, _semiring.Mult(a.s, b.i));
            U t = _semiring.Add(_semiring.Mult(a.t, b.s), b.t);
            U s = _semiring.Mult(a.s, b.s);

            return(new T4(m, i, t, s));
        }
コード例 #3
0
        // Lifted multiplication operation
        public LiftedSet <γ, Cp> Mult(LiftedSet <γ, Cp> a, LiftedSet <γ, Cp> b)
        {
            List <γ> coefficients = new List <γ>();

            // Sanity check to make sure we have the right number of coefficients
            Debug.Assert(a.coefficients.Count() == _p.Symbols().Count);
            Debug.Assert(b.coefficients.Count() == _p.Symbols().Count);

            foreach (var operandIndices in _multMap)
            {
                γ k = _semiring.AdditiveIdentity;

                foreach (var tuple in operandIndices)
                {
                    var i = tuple.Item1;
                    var j = tuple.Item2;

                    var combined = _semiring.Mult(a.coefficients.ElementAt(i),
                                                  b.coefficients.ElementAt(j));

                    // This Add combines two values to one using the underlying semiring
                    k = _semiring.Add(k, combined);
                }

                // This is List.Add tacking the next coefficient onto the end of the list
                coefficients.Add(k);
            }

            return(new LiftedSet <γ, Cp> {
                coefficients = coefficients
            });
        }