1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::op_add_count;
use super::op_affine;
use super::super::traits::action;
use super::super::traits::additive;
use super::super::traits::multiplicative;
use std::fmt::Debug;
use std::ops::{Add, Mul};

use action::MonoidAction;
use additive::{AddAssoc, Zero};
use multiplicative::One;
use op_add_count::OpAddCount;
use op_affine::OpAffine;

#[derive(Clone, Copy, Debug, Default)]
pub struct OpAffineOnOpAddCount<T> {
    op_affine: OpAffine<T>,
    op_add_count: OpAddCount<T>,
}

impl<T> MonoidAction for OpAffineOnOpAddCount<T>
where
    T: Ord
        + Eq
        + Clone
        + Add<Output = T>
        + AddAssoc
        + Mul<Output = T>
        + Zero
        + One
        + Sized,
{
    type Operand = OpAddCount<T>;
    type Operator = OpAffine<T>;
    fn operand(&self) -> &Self::Operand { &self.op_add_count }
    fn operator(&self) -> &Self::Operator { &self.op_affine }
    fn act(&self, (xv, xc): (T, T), (y1, y0): (T, T)) -> (T, T) {
        // Sum(ax+b) = a Sum(x) + b Sum(1)
        let xv = y1 * xv + y0 * xc.clone();
        (xv, xc)
    }
}