malachite_nz/integer/arithmetic/conjugate.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::integer::Integer;
10use malachite_base::num::arithmetic::traits::{Conjugate, ConjugateAssign};
11
12impl Conjugate for Integer {
13 type Output = Self;
14
15 /// Computes the complex conjugate of a [`Integer`], taking it by value. A real number is its
16 /// own conjugate, so this is the identity.
17 ///
18 /// $$
19 /// f(x) = \overline{x} = x.
20 /// $$
21 ///
22 /// # Worst-case complexity
23 /// Constant time and additional memory.
24 ///
25 /// # Examples
26 /// ```
27 /// use malachite_base::num::arithmetic::traits::Conjugate;
28 /// use malachite_nz::integer::Integer;
29 ///
30 /// assert_eq!(Integer::from(-123).conjugate(), Integer::from(-123));
31 /// ```
32 #[inline]
33 fn conjugate(self) -> Self {
34 self
35 }
36}
37
38impl Conjugate for &Integer {
39 type Output = Integer;
40
41 /// Computes the complex conjugate of a [`Integer`], taking it by reference. A real number is
42 /// its own conjugate, so this just clones.
43 ///
44 /// $$
45 /// f(x) = \overline{x} = x.
46 /// $$
47 ///
48 /// # Worst-case complexity
49 /// $T(n) = O(n)$
50 ///
51 /// $M(n) = O(n)$
52 ///
53 /// where $T$ is time, $M$ is additional memory, and $n$ is `self.significant_bits()`.
54 ///
55 /// # Examples
56 /// ```
57 /// use malachite_base::num::arithmetic::traits::Conjugate;
58 /// use malachite_nz::integer::Integer;
59 ///
60 /// assert_eq!((&Integer::from(-123)).conjugate(), Integer::from(-123));
61 /// ```
62 #[inline]
63 fn conjugate(self) -> Integer {
64 self.clone()
65 }
66}
67
68impl ConjugateAssign for Integer {
69 /// Replaces a [`Integer`] with its complex conjugate. A real number is its own conjugate, so
70 /// this does nothing.
71 ///
72 /// $$
73 /// x \gets \overline{x} = x.
74 /// $$
75 ///
76 /// # Worst-case complexity
77 /// Constant time and additional memory.
78 ///
79 /// # Examples
80 /// ```
81 /// use malachite_base::num::arithmetic::traits::ConjugateAssign;
82 /// use malachite_nz::integer::Integer;
83 ///
84 /// let mut x = Integer::from(-123);
85 /// x.conjugate_assign();
86 /// assert_eq!(x, Integer::from(-123));
87 /// ```
88 #[inline]
89 fn conjugate_assign(&mut self) {}
90}