From 828bdf38f8ffa4ef984366d928b81fb8e1a9025a Mon Sep 17 00:00:00 2001 From: Shahar Papini <43779613+spapinistarkware@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:21:37 +0200 Subject: [PATCH] Field debug implementations (#501) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change is [Reviewable](https://reviewable.io/reviews/starkware-libs/stwo/501) --- src/core/fields/cm31.rs | 10 ++++++++-- src/core/fields/qm31.rs | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/fields/cm31.rs b/src/core/fields/cm31.rs index a294ab1f0..c585855b6 100644 --- a/src/core/fields/cm31.rs +++ b/src/core/fields/cm31.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use std::fmt::{Debug, Display}; use std::ops::{ Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign, }; @@ -12,7 +12,7 @@ pub const P2: u64 = 4611686014132420609; // (2 ** 31 - 1) ** 2 /// Complex extension field of M31. /// Equivalent to M31\[x\] over (x^2 + 1) as the irreducible polynomial. /// Represented as (a, b) of a + bi. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CM31(pub M31, pub M31); impl_field!(CM31, P2); @@ -34,6 +34,12 @@ impl Display for CM31 { } } +impl Debug for CM31 { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} + {}i", self.0, self.1) + } +} + impl Mul for CM31 { type Output = Self; diff --git a/src/core/fields/qm31.rs b/src/core/fields/qm31.rs index 703092223..7fe683053 100644 --- a/src/core/fields/qm31.rs +++ b/src/core/fields/qm31.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use std::fmt::{Debug, Display}; use std::ops::{ Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Sub, SubAssign, }; @@ -15,7 +15,7 @@ pub const R: CM31 = CM31::from_u32_unchecked(2, 1); /// Extension field of CM31. /// Equivalent to CM31\[x\] over (x^2 - 2 - i) as the irreducible polynomial. /// Represented as ((a, b), (c, d)) of (a + bi) + (c + di)u. -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct QM31(pub CM31, pub CM31); pub type SecureField = QM31; @@ -49,6 +49,12 @@ impl Display for QM31 { } } +impl Debug for QM31 { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "({}) + ({})u", self.0, self.1) + } +} + impl Mul for QM31 { type Output = Self;