rcpl

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ruthen71/rcpl

:heavy_check_mark: algebra/monoid/monoid_affine.hpp

Required by

Verified with

Code

#pragma once

template <class T> struct Affine {
    T a;
    T b;
    friend std::ostream& operator<<(std::ostream& os, const Affine& f) {
        return os << f.a << ", " << f.b;
    }
};

template <class T> struct MonoidAffine {
    using value_type = Affine<T>;
    static constexpr value_type operation(const value_type& f,
                                          const value_type& g) noexcept {
        // f(x) := ax + b, g(x) := cx + d
        // g(f(x)) = c(ax + b) + d = cax + cb + d
        return {g.a * f.a, g.a * f.b + g.b};
    }
    static constexpr value_type identity() noexcept { return {T(1), T(0)}; }
};
#line 2 "algebra/monoid/monoid_affine.hpp"

template <class T> struct Affine {
    T a;
    T b;
    friend std::ostream& operator<<(std::ostream& os, const Affine& f) {
        return os << f.a << ", " << f.b;
    }
};

template <class T> struct MonoidAffine {
    using value_type = Affine<T>;
    static constexpr value_type operation(const value_type& f,
                                          const value_type& g) noexcept {
        // f(x) := ax + b, g(x) := cx + d
        // g(f(x)) = c(ax + b) + d = cax + cb + d
        return {g.a * f.a, g.a * f.b + g.b};
    }
    static constexpr value_type identity() noexcept { return {T(1), T(0)}; }
};
Back to top page