// Copyright Maksym Zhelyeznyakov 2025-2026. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) #ifndef REVERSE_MODE_AUTODIFF_BASIC_OPS_NO_ET_HPP #define REVERSE_MODE_AUTODIFF_BASIC_OPS_NO_ET_HPP #include namespace boost { namespace math { namespace differentiation { namespace reverse_mode { template rvar operator*(const expression &lhs, const expression &rhs) { return mult_expr(lhs, rhs); } /** @brief type promotion is handled by casting the numeric type to * the type inside expression. This is to avoid converting the * entire tape in case you have something like double * rvar * */ template::value>::type> rvar operator*(const expression &arg, const RealType2 &v) { return mult_const_expr(arg, static_cast(v)); } template::value>::type> rvar operator*(const RealType2 &v, const expression &arg) { return mult_const_expr(arg, static_cast(v)); } /****************************************************************************************************************/ /* + */ template rvar operator+(const expression &lhs, const expression &rhs) { return add_expr(lhs, rhs); } template::value>::type> rvar operator+(const expression &arg, const RealType2 &v) { return add_const_expr(arg, static_cast(v)); } template::value>::type> rvar operator+(const RealType2 &v, const expression &arg) { return add_const_expr(arg, static_cast(v)); } /****************************************************************************************************************/ /* - overload */ /** @brief * negation (-1.0*rvar) */ template rvar operator-(const expression &arg) { return mult_const_expr(arg, static_cast(-1.0)); } /** @brief * subtraction rvar-rvar */ template rvar operator-(const expression &lhs, const expression &rhs) { return sub_expr(lhs, rhs); } /** @brief * subtraction float - rvar */ template::value>::type> rvar operator-(const expression &arg, const RealType2 &v) { /* rvar - float = rvar + (-float) */ return add_const_expr(arg, -static_cast(v)); } /** @brief * subtraction float - rvar * @return add_expr> */ template::value>::type> rvar operator-(const RealType2 &v, const expression &arg) { auto neg = -arg; return neg + static_cast(v); } /****************************************************************************************************************/ /* / */ template rvar operator/(const expression &lhs, const expression &rhs) { return div_expr(lhs, rhs); } template::value>::type> rvar operator/(const RealType2 &v, const expression &arg) { return const_div_by_expr(arg, static_cast(v)); } template::value>::type> rvar operator/(const expression &arg, const RealType2 &v) { return div_by_const_expr(arg, static_cast(v)); } } // namespace reverse_mode } // namespace differentiation } // namespace math } // namespace boost #endif