Пример #1
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
            });
        }
Пример #2
0
 // Lifted addition operation
 public LiftedSet <γ, Cp> Add(LiftedSet <γ, Cp> a, LiftedSet <γ, Cp> b)
 {
     return(new LiftedSet <γ, Cp>
     {
         // zip the coefficient vectors with the underlying semiring's addition
         coefficients = a.coefficients.Zip <γ, γ, γ>(b.coefficients, _semiring.Add)
     });
 }