Skip to main content

cova_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 cova_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:
40  Add<Output = Self> + AddAssign + PartialEq + std::fmt::Debug + Sized + 'static {
41}
42
43/// A trait for types that support multiplication operations.
44///
45/// This trait combines the basic requirements for types that can be multiplied (and compared)
46/// together:
47/// - Multiplication operation with [`Mul`] trait
48/// - Multiplication assignment with [`MulAssign`] trait
49/// - Equality comparison with [`PartialEq`]
50///
51/// # Examples
52/// - All primitive numeric types implement this trait
53/// - [`Boolean`](crate::algebras::boolean::Boolean) type implements this trait using bitwise
54///   [`std::ops::BitAnd`]
55/// - Using the [`modular!`] macro, you can define a modular arithmetic type and it will implement
56///   this trait.
57/// - Using the [`prime_field!`] macro, you can define a prime field type and it will implement this
58///   trait.
59pub trait Multiplicative:
60  Mul<Output = Self> + MulAssign + PartialEq + std::fmt::Debug + Sized + 'static {
61}
62
63/// Trait for types that have a concept of positive infinity.
64pub trait Infinity {
65  /// Returns the positive infinity value for the type.
66  const INFINITY: Self;
67}