Beispiel #1
0
        public static int Reduce(List <int> list)
        {
            var            maxSumSR = new MaxSum();
            Opt <int, int> opt      = new Opt <int, int>(maxSumSR, x => x);

            return(opt.Reduce(list));
        }
Beispiel #2
0
        public static int Reduce(List <int> list)
        {
            var maxSumSR  = new MaxSum();
            var evenSumHP = new EvenSum();

            // Generate the index map for the lifted multiplication op ahead of time
            // This is the same information carried by the (+)p operator in the definition
            // of a homomorphic predicate [Emoto def. 10]
            var k_even = new List <Tuple <int, int> > {
                new Tuple <int, int>(0, 0), new Tuple <int, int>(1, 1)
            };
            var k_odd = new List <Tuple <int, int> > {
                new Tuple <int, int>(0, 1), new Tuple <int, int>(1, 0)
            };
            var multMap = new List <List <Tuple <int, int> > > {
                k_even, k_odd
            };

            // Starting with our old Max Sum semiring, lift the even sum H-predicate into a lifted semiring
            ISemiring <LiftedSet <int, char> > liftedSR = new LiftedSemiring <int, char, int>(maxSumSR, evenSumHP, multMap);

            // Note this is the *same* Opt.Reduce we used for the normal maximum initial
            // segment sum problem. It has no knowledge of our goal to filter the segment
            // list to even sum segments only; we've embedded that filtering into a new,
            // lifted semiring that we use as a replacement for the unlifted MaxSum one
            var opt = new Opt <int, LiftedSet <int, char> >(liftedSR, Prepare);
            var ycp = opt.Reduce(list);

            return(ycp.coefficients.ElementAt(0));
        }