harness_algebra/arithmetic/
mod.rs

1//! Basic arithmetic traits and operations.
2//!
3//! This module provides fundamental arithmetic traits that are used throughout the algebra crate.
4//! It re-exports standard arithmetic operations from [`std::ops`] and numeric traits from
5//! [`num_traits`].
6//!
7//! # Examples
8//!
9//! ```
10//! use harness_algebra::arithmetic::{Additive, Multiplicative};
11//!
12//! // Types implementing Additive can be added and assigned
13//! fn add<T: Additive>(a: T, b: T) -> T { a + b }
14//!
15//! // Types implementing Multiplicative can be multiplied and assigned
16//! fn multiply<T: Multiplicative>(a: T, b: T) -> T { a * b }
17//! ```
18
19use super::*;
20
21pub mod modular;
22pub mod primitive;
23
24/// A trait for types that support addition (and comparison) operations.
25///
26/// This trait combines the basic requirements for types that can be added together:
27/// - Addition operation with [`Add`] trait
28/// - Addition assignment with [`AddAssign`] trait
29/// - Equality comparison with [`PartialEq`]
30///
31///  # Examples
32/// - All primitive numeric types implement this trait
33/// - [`Boolean`](crate::algebras::boolean::Boolean) type implements this trait using bitwise
34///   [`std::ops::BitXor`]
35/// - Using the [`modular!`] macro, you can define a modular arithmetic type and it will implement
36///   this trait.
37/// - Using the [`prime_field!`] macro, you can define a prime field type and it will implement this
38///   trait.
39pub trait Additive: Add<Output = Self> + AddAssign + PartialEq + Sized {}
40
41/// A trait for types that support multiplication operations.
42///
43/// This trait combines the basic requirements for types that can be multiplied (and compared)
44/// together:
45/// - Multiplication operation with [`Mul`] trait
46/// - Multiplication assignment with [`MulAssign`] trait
47/// - Equality comparison with [`PartialEq`]
48///
49/// # Examples
50/// - All primitive numeric types implement this trait
51/// - [`Boolean`](crate::algebras::boolean::Boolean) type implements this trait using bitwise
52///   [`std::ops::BitAnd`]
53/// - Using the [`modular!`] macro, you can define a modular arithmetic type and it will implement
54///   this trait.
55/// - Using the [`prime_field!`] macro, you can define a prime field type and it will implement this
56///   trait.
57pub trait Multiplicative: Mul<Output = Self> + MulAssign + PartialEq + Sized {}
58
59/// Trait for types that have a concept of positive infinity.
60pub trait Infinity {
61  /// Returns the positive infinity value for the type.
62  const INFINITY: Self;
63}